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 449 forks source link

Debug command not using launch.json file #3200

Open lucas-yotsui opened 1 year ago

lucas-yotsui commented 1 year ago

Brief Issue Summary

I am trying to create a project to program a Tiva C Series board using VS Code and CMake.

So far, I've managed to make it kinda work, since it builds, flashes and even lets me debug it. However, it was based on sketchy launch.json and tasks.json files and I was not happy with it. So now I'm trying to make it work properly with the CMakeTools extension in a way that I can start the debugger through the button on the bottom navbar provided by the extension. The problem is that it does not seem to use my launch.json file, so when it launches it uses the wrong debugger path and executable (which were properly pointed by the launch.json file).

My project currently look like this: my project structure.

It basically consists of a src folder containing my source code, a CMakeLists.txt file, a cmake folder containing the toolchain configuration, a linker file for the Tiva, a .vscode folder containing the launch.json and tasks.json files and the build output directory generated by CMake.

As of right now, if I click on the build command on the CMakeTools extension navbar it builds correctly and flashes to the Tiva using a custom target command in my CMake. But when I click on the debug button it does not launch properly, instead it gives me this output.

This is my launch.json file:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debugger Tiva",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/projeto.axf",
            "targetArchitecture": "ARM",
            "args": [],
            "stopAtEntry": true,    
            "cwd": "${workspaceFolder}",
            "environment": [],
            "MIMode": "gdb",
            "miDebuggerServerAddress": "localhost:3333",
            "externalConsole": false,
            "miDebuggerPath": "C:/ProgramData/chocolatey/lib/gcc-arm-embedded/tools/gcc-arm-none-eabi-10-2020-q4-major/bin/arm-none-eabi-gdb.exe",
            "preLaunchTask": "Launch OpenOCD",
            "postDebugTask": "Kill OpenOCD"
        }
    ]
}

As can be seen in this launch.json, the path I wanted to get the debugger from is C:/ProgramData/chocolatey/lib/gcc-arm-embedded/tools/gcc-arm-none-eabi-10-2020-q4-major/bin/arm-none-eabi-gdb.exe, but in the picture in the output it shows that it tried to use C:/ProgramData/chocolatey/bin/arm-none-eabi-gdb.exe (which does work so it's fine, I guess). And the biggest problem is apparently it is looking for the launch program as C:/Users/Lucas Yukio/Documents/Projetos Tiva/teste display/build/projeto which is missing the .axf extension at the end.

When I launch the debugger using the f5 keyboard shortcut it launches properly, so my best idea is that the extension is not using the launch.json file I made. Is it correct? And if so, how do I fix it?

CMake Tools Diagnostics

No response

Debug Log

No response

Additional Information

No response

benmcmorran commented 1 year ago

Thanks for the feedback! As currently implemented, it looks like the debug button is only designed to do a quick launch that doesn't use the launch.json configuration. That said, extending the button to support your use case sounds like a reasonable feature request.

bobbrow commented 1 year ago

You can edit some of the properties of Quick Debug with the cmake.debugConfig setting. The properties supported by cmake.debugConfig should be mostly the same as the ones supported by launch.json. I should have updated that documentation a while ago, but kept forgetting.

Example:

{
  "cmake.debugConfig": {
    "MIMode": "gdb",
    "miDebuggerPath": "C:/ProgramData/chocolatey/lib/gcc-arm-embedded/tools/gcc-arm-none-eabi-10-2020-q4-major/bin/arm-none-eabi-gdb.exe"
  }
}
dleclairbb commented 1 year ago

I am having this exact problem!

The only difference is that our debugging solution uses a custom debugger / cannot be configured with the ms-vscode.cpptools debugging engine whatsoever, so we're completely out of luck.

I'd love to see this feature incorporated!!

gcampbell-msft commented 1 year ago

@dleclairbb Thanks for your feedback. Have you been able to test out whether @bobbrow's suggestion helps you here?

Thanks!

dleclairbb commented 1 year ago

@gcampbell-msft I did try but was not able to find any configs that would launch the custom debugging engine I'm trying to use.

gcampbell-msft commented 1 year ago

@dleclairbb Understood, thanks for confirming. Unfortunately this comment: https://github.com/microsoft/vscode-cmake-tools/issues/3200#issuecomment-1589626231, is most accurate of the current state. Currently the debug button is only designed to launch from quick launch.

Currently, you could likely workaround this by figuring out a proper launch.json and use it from the debug menu. As for extending the debug button, we have this work tracked for 1.16 and will be assessing it during that milestone. Thanks!

ArcticLampyrid commented 11 months ago

we have this work tracked for 1.16 and will be assessing it during that milestone.

Having two debug buttons in the window will certainly be confusing. At least we need a configure item to hide it.

Spongman commented 1 month ago

this is a real shame. this extension could be excellent, but the fact that it doesn't integrate into vscode's debug & tasks config makes it almost unusable.