vscode-cmake-tools icon indicating copy to clipboard operation
vscode-cmake-tools copied to clipboard

Target Debugging

Open vector-of-bool opened this issue 10 years ago • 28 comments

This issue is used to collect feedback on the experimental Target Debugging feature.

If you have tried out target debugging and find that it works and is useful for your project, add a 👍 reaction to let me know.

Any feedback would be highly appreciated.

Learn more about this feature in these docs for Target Debugging.

vector-of-bool avatar Sep 24 '16 23:09 vector-of-bool

This line makes it possible to make tools working:

include(${CMAKE_BINARY_DIR}/CMakeTools/CMakeToolsHelpers.cmake)

magpier84 avatar Sep 29 '16 16:09 magpier84

Launching of application is working but launch.json provide possibility to pass environment variables but CMakeTools are not.

magpier84 avatar Sep 29 '16 16:09 magpier84

CMake Tools sets up the module path such that you only need to

include(CMakeToolsHelpers OPTIONAL)

and it will be fine. No need to specify the full path to the file. Actually: please do not specify the full path, because it may be moved in the future. See the docs on how to configure the debugger, which should let you specify environment variables, program arguments, etc.

Thanks for trying it out! Any feedback is welcome!

vector-of-bool avatar Sep 29 '16 16:09 vector-of-bool

include(CMakeToolsHelpers OPTIONAL)

It doesn't work for me (OSX cmake version 3.6.1).

magpier84 avatar Sep 29 '16 17:09 magpier84

CMake Tools generates a debugging configuration object on-the-fly, when debugging is requested. To set some additional parameters to this debug configuration, use the cmake.debugConfig

How environment variables should be passed to cmake.debugConfig? Thanks!

magpier84 avatar Sep 29 '16 17:09 magpier84

Hmm... do you set(CMAKE_MODULE_PATH ...) at any point in your CMakeLists.txt? Does it fail with any error/warning messages?

For configuring, set the same values in the all section of the cmake.debugConfig that you would in a launch.json file. For example:

"cmake.debugConfig": {
    "all": {
        "request": "launch",
        "cwd": "${workspaceRoot}",
        "environment": [{
            "foo": "bar"
        }],
        "linux": {
            "MIMode": "gdb"
        },
        "osx": {
            "MIMode": "lldb"
        },
        "windows": {
            "MIMode": "gdb"
        }
    }
}

I'll update the docs to talk more about this.

vector-of-bool avatar Sep 29 '16 17:09 vector-of-bool

Yep, I have set CMAKE_MODULE_PATH var before. It's clear now how to set environment variables. Thanks!

magpier84 avatar Sep 29 '16 17:09 magpier84

Ah, ok. Instead of using set to add things to CMAKE_MODULE_PATH, use this:

list(APPEND CMAKE_MODULE_PATH "SomeDirectoryHere")

Replacing SomeDirectoryHere with what you want to add to the path.

I'll add a note to the docs about this.

vector-of-bool avatar Sep 29 '16 17:09 vector-of-bool

I have successfully launched app! Thanks! Is it possible to associate keys for launching debugger?

magpier84 avatar Sep 29 '16 17:09 magpier84

Yes, just add a keybinding for the cmake.debugTarget command

vector-of-bool avatar Sep 29 '16 17:09 vector-of-bool

For some reason, whenever I add the include(CMakeToolsHelpers OPTIONAL) call, I will often see errors from CMake when generating build files through vscode:

CMake Error in CMakeLists.txt:
Evaluation file to be written multiple times for different configurations
or languages with different content:

  <full path omitted>/build/CMakeToolsMeta.txt

The error tends to repeat a dozen or so times in the output. Running the build again works fine and I can pick debug targets and debug with impunity, so it's not clear what exactly is wrong here. This happens on a couple of different trees, so it doesn't sound like something specific to one particular build.

FWIW, I'm running CMake 3.6.1 on Windows, target compiler is MSVC 19 (VS 2015), using the Visual Studio 2015 generator.

nsubtil avatar Oct 05 '16 19:10 nsubtil

@nsubtil, I know what causes that. It's because the Visual Studio generators are multi-config generators. I didn't think about the interaction here. Thanks for the heads up, I'll put in a fix!

vector-of-bool avatar Oct 05 '16 19:10 vector-of-bool

It works for me, on OS X 10.9.5 / VSCode 1.5.3 / CMake 2.8.3 / CMake Tools 0.6.0

Thanks for this, it's very handy ! Somehow the native launch.jsonmethod did not work initially, but this worked like a charm.

franky47 avatar Oct 07 '16 07:10 franky47

Including CMakeToolsHelper breaks my Qt5 applications build.

In order to access a specific Qt build I have a cache entry "QT_ROOT" this is set as the CMAKE_PREFIX_PATH.

Once I use include(CMakeToolsHelpers OPTIONAL) I get the following error during configuration:

-- Configuring done
CMake Error at build/CMakeTools/CMakeToolsHelpers.cmake:59 (file):
  Error evaluating generator expression:

    $<TARGET_FILE:Qt5::qmake>

  No target "Qt5::qmake"
Call Stack (most recent call first):
  CMakeLists.txt:3 (include)

photex avatar Oct 20 '16 10:10 photex

@photex Thanks for the notice. I have a good idea of how to fix that.

vector-of-bool avatar Oct 20 '16 12:10 vector-of-bool

Indeed, just taking a quick peek at the module, it seems to be missing the imported check for executables right?

photex avatar Oct 20 '16 13:10 photex

That's correct. I've noticed it doing this before, but it's never actually caused an error... I'll have to add the check to make sure this error doesn't happen. Usually people aren't interested in debugging an imported executable.

vector-of-bool avatar Oct 20 '16 15:10 vector-of-bool

This works great! MacOS 10.12.1, VSCode 1.6.1, Cmake 3.6.2

HelveticaScenario avatar Nov 01 '16 06:11 HelveticaScenario

it was working but something happened and now there arent any any available targets for debugging. ive tried everything.

HelveticaScenario avatar Nov 05 '16 09:11 HelveticaScenario

That's no good. Can you find a CMakeToolsMeta.txt file? What is inside it? What have you tried?

vector-of-bool avatar Nov 05 '16 15:11 vector-of-bool