Vscode-cmake-tools: Can't debug in Visual Studio Code

Created on 10 Dec 2019  路  7Comments  路  Source: microsoft/vscode-cmake-tools

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

  • Operating System: macOS 10.15
  • CMake Version: 3.15.5
  • VSCode Version: 1.40.2
  • CMake Tools Extension Version: 1.2.3
  • Compiler/Toolchain: Xcode
debulaunch bug upstream

Most helpful comment

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

    "cmake.debugConfig": {
        "miDebuggerPath": "/path/to/lldb-mi"
    },

All 7 comments

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.

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

@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?

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.

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.

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

    "cmake.debugConfig": {
        "miDebuggerPath": "/path/to/lldb-mi"
    },

@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.

Was this page helpful?
0 / 5 - 0 ratings