Debug C++ code from Dart package using dart::ffi
Asked Answered
F

2

4

I am developing a package in C++ to be used in a Flutter app (and therefore in Dart), using dart::ffi and I was wondering if there was a better way to debug (step by step, variable watch, that sort of things) the C++ code, other than logging messages. I've tried both in Android Studio and VS Code, with no success.

Follmer answered 12/6, 2020 at 19:35 Comment(4)
Visual Studio 2019Boffin
How would you suggest I do it? As far as I know, I can't run the Flutter app in Visual Studio 2019Follmer
Why can't you run it?Boffin
According to this, the IDEs that you can use to debug are Android Studio, IntelliJ, VS Code and Emacs. Have you tried running a Flutter app in Visual Studio?Follmer
A
9

Android Studio (or VS Code) doesn't support native (C/C++) code debugging while in Flutter mode (yet). However, there is a workaround! In the project tree, right-click the 'android' folder and select Flutter -> Open Android module in Android Studio. The project will switch to Android development mode where c/c++ debugging is fully supported. Now just search for the 'cpp' folder, set breakpoints in any of the files there and run the app (while still in the Android development mode of course)!

Anodize answered 18/6, 2020 at 10:48 Comment(0)
M
2

I managed to debug some c code in VS Code using the follow configuration in launch.json, for a linux desktop app:

    {
        "name": "Debug Native",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/build/linux/x64/debug/bundle/app",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}/build/linux/x64/debug/bundle",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ]
    }

Just modify the app in program according to the name of your app. Then in the debug tab you will be able to launch this configuration:

launch Debug

This configuration just launches the built executable. If you want it to build everytime before launching you need to add a preLaunchTask.

Mastoid answered 12/3, 2022 at 15:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.