microsoft / vscode-cmake-tools

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

CMake+MinGW+Clang not start `cppdbg` debugger #3667

Open WittonBell opened 7 months ago

WittonBell commented 7 months ago

env: VSCode 1.87.2 c/c++ v1.19.6 CMakeTools v1.17.17 cmake 3.29 clang 18.1.1

repro step:

  1. create any simple c/c++ project. main.c:
    
    #include <stdio.h>

int main(int argc, char *argv[]) { printf("test\n"); while (1) {

} return 0; }


CMakeLists.txt:

cmake_minimum_required(VERSION 3.25.0) project(x)

add_compile_options( -gdwarf-4 ) aux_source_directory(. SRC) add_executable(${PROJECT_NAME} ${SRC})



2. switch kit `[Clang 18.1.1 x86_64-w64-windows-gnu(mingw64)]` from VSCode status bar for `cmake-tools`
3. click debug button from VSCode status bar for `cmake-tools`
![image](https://github.com/microsoft/vscode-cmake-tools/assets/8215947/25c54376-3094-4c28-a381-071f80a2f4ee)
4. `cmake-tools` will start the `cppvsdbg` debugger, not `cppdbg`
![image](https://github.com/microsoft/vscode-cmake-tools/assets/8215947/1da90720-df09-401c-91c0-a583d1230f73)
![image](https://github.com/microsoft/vscode-cmake-tools/assets/8215947/29514ef7-b97a-4d75-9682-3ce770ebaddb)

so, it does not hit the breakpoint when debugging.

![image](https://github.com/microsoft/vscode-cmake-tools/assets/8215947/91330a54-30dd-4026-8d73-54f134545401)

switch kit to `gcc`, it start the `cppdbg` debugger correctly.
gcampbell-msft commented 7 months ago

@WittonBell To clarify, you are using clang.exe and what generator?

In the code, we have two checks that use a cppvsdbg debug type, and that is when the compiler ends with cl.exe and then when the msvc linker is being used (i.e. it ends with link.exe or ld.lld.exe. Here and here.

Is this assumption incorrect? Or is something happening where we are erroneously checking this? Any more information you can provide would help us investigate. Thanks.

WittonBell commented 7 months ago

@gcampbell-msft cmake generator is Ninja.

It is a simple c project, cmake call ninja to use clang.exe to build project.

image

Yingzi1234 commented 6 months ago

@WittonBell Thank you for your feedback, in order to better address your question, could you provide us with the project you have reproduced? Thank you in advance!

WittonBell commented 6 months ago

@Yingzi1234 我前面有提供代码,你可以使用我前述复现步骤中的代码。

Yingzi1234 commented 6 months ago

@WittonBell According to your steps, I get the same result as you in "DEBUG CONSOLE", but the breakpoints in my main.c file can be hit! My reproduction steps are below, could you please check if they are correct for me? If this is incorrect, would you be able to provide us with a recording? This would be very helpful for us to investigate your question

Repro steps:

  1. Create a folder on the desktop and open it with VScode
  2. Create the main.c and CMakeLists.txt files and fill them with the above commands
  3. Click debug button from VSCode status bar

Actual result: 3667 issue

WittonBell commented 6 months ago

@Yingzi1234 看了你的GIF,你实际使用的是VS中的Clang,并非MinGW中的Clang,要复现问题需要使用MinGW中的Clang编译器。

WittonBell commented 6 months ago

按理说,使用不同的工具链,应该使用相应的调试器才对,比如使用MinGW中的GCC,应该默认使用MinGW中的GDB调试器;使用MinGW中的Clang,应该默认使用MinGW中的LLDB调试器;使用VS的CL编译器,才默认使用VS的调试器。

DistinctWind commented 1 month ago

This problem can still be reproduced today using latest clang 18.1.8 (mingw). A workround is to use CodeLLVM plugin to configure lldb.

This is my launch.json and it works for me.

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug with LLDB",
            "type": "lldb",
            "request": "launch",
            "program": "${command:cmake.launchTargetPath}",
            "args": [],
        }
    ]
}

直到刚才我使用clang 18.1.8 (mingw)仍然能复现这一问题。

WittonBell commented 1 month ago

Sorry, I found that the debug button in the status bar is provided by the ms-vscode.cpptools plugin, which should be it's problem. However, the latest version still has this issue.

sean-mcmanus commented 1 month ago

The debug button in the status bar is from CMake Tools and ms-vscode.cpptools.