microsoft / vscode-cmake-tools

CMake integration in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=vector-of-bool.cmake-tools
MIT License
1.46k stars 450 forks source link

Can't debug in Visual Studio Code #965

Closed zhouhao27 closed 2 years ago

zhouhao27 commented 4 years ago

Brief Issue Summary

Can't make the Visual Studio Code debugger work.

Expected:

  1. Run CMake Configuration
Screenshot 2019-12-10 at 4 01 19 PM

The result:

[cmake] Configuring done
[cmake] CMake Deprecation Warning:
[cmake]   The 'cmake-server(7)' is deprecated.  Please port clients to use the
[cmake]   'cmake-file-api(7)' instead.
[cmake] 
[cmake] 
[cmake] Generating done
  1. Select Clang 11.0
Screenshot 2019-12-10 at 4 15 43 PM
  1. Allow IntelliSense for this folder
Screenshot 2019-12-10 at 4 15 53 PM
  1. Build
Screenshot 2019-12-10 at 4 18 06 PM

The result:

[build] Starting build
[proc] Executing command: /usr/local/bin/cmake --build /Users/xxx/Desktop/cmake/hello/build --config Debug --target all -- -j 6
[build] Scanning dependencies of target say-hello
[build] [ 25%] Building CXX object CMakeFiles/say-hello.dir/hello.cpp.o
[build] [ 50%] Linking CXX static library libsay-hello.a
[build] [ 50%] Built target say-hello
[build] Scanning dependencies of target hello
[build] [ 75%] Building CXX object CMakeFiles/hello.dir/main.cpp.o
[build] [100%] Linking CXX executable hello
[build] [100%] Built target hello
[build] Build finished with exit code 0
  1. Set the break point and run Debug
Screenshot 2019-12-10 at 4 08 23 PM Screenshot 2019-12-10 at 4 19 44 PM

Apparent Behavior:

  1. It seems the editor hangs
  2. The information in Output
[build] Starting build
[proc] Executing command: /usr/local/bin/cmake --build /Users/xxx/Desktop/cmake/test/build --config Debug --target hello -- -j 6
[build] [ 50%] Built target say-hello
[build] [100%] Built target hello
[build] Build finished with exit code 0
[proc] Executing command: /usr/bin/lldb-mi --version
[proc] Executing command: /usr/bin/gdb --version
[proc] Executing command: /usr/bin/lldb --version
[proc] Executing command: /usr/bin/lldb --version

Platform and Versions

Hadatko commented 4 years ago

As long as i know cmake is only for building final image/binary. You need install extension for debugging for device you want to. E.g. i am debugging arm embedded device so i am using gdb debugger or cortex debugger.

bobbrow commented 4 years ago

Are you hitting this issue? https://github.com/microsoft/vscode-cpptools/issues/3829 We're working on it (with the C++ extension).

zhouhao27 commented 4 years ago

@bobbrow Yes, I have the same issue. Thanks for your information.

Based on this youtube video, we even don't need to setup launch.json or task.json to debug. Is that true?

bobbrow commented 4 years ago

That is correct. You shouldn't need a launch.json or tasks.json. If you do need to override a setting for debugging, you can use the cmake.debugConfig setting.

kaidokert commented 4 years ago

The problem is this:

[proc] Executing command: /usr/bin/lldb --version

The default lldb gets picked, which will not work. The launch command of /usr/bin/lldb --interpreter=mi will just fail with

Starting: "/usr/bin/lldb" --interpreter=mi
lldb: unrecognized option `--interpreter=mi'

The root of the issue is in this fallback codepath in this plugin: https://github.com/microsoft/vscode-cmake-tools/blob/50fc5ba265ee13f53dc9f273d0f1635c8861bd7d/src/debugger.ts#L163

If your compiler is "/usr/bin/clang" it tries to use "/usr/bin/lldb" as a debugger, and does not respect the "miDebuggerPath" setting in launch.json ( as launch.json might not even exist here ).

It works fine when hardcoding something like : let clang_debugger_path = '/Applications/Xcode.app/Contents/Developer/usr/bin/lldb-mi'; instead, which is what the plugin code should probably be trying by default, or alternatively look for lldb-mi provided by vscode-cpptools

Also, the default miDebuggerPath should probably be a global setting for this plugin, which would get used when launch.json doesn't exist and built-in guesses fail.

bobbrow commented 4 years ago

FYI, miDebuggerPath can be set via the cmake.debugConfig setting:

    "cmake.debugConfig": {
        "miDebuggerPath": "/path/to/lldb-mi"
    },
hroumani commented 4 years ago

@bobbrow your suggestion did the trick for me, before I applied that: [main] Starting debugger with following configuration. ... "miDebuggerPath":"gdb"

So it was effectively ignoring: "miDebuggerPath": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\gdb.exe"

In launch.json.

bobbrow commented 2 years ago

I believe this issue was addressed but was never closed. If any of you are still having issues, we encourage you to open a new issue.