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

CMake+MinGW+Clang not start `cppdbg` debugger

Open WittonBell opened this issue 11 months ago • 7 comments

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})
  1. switch kit [Clang 18.1.1 x86_64-w64-windows-gnu(mingw64)] from VSCode status bar for cmake-tools
  2. click debug button from VSCode status bar for cmake-tools image
  3. cmake-tools will start the cppvsdbg debugger, not cppdbg image image

so, it does not hit the breakpoint when debugging.

image

switch kit to gcc, it start the cppdbg debugger correctly.

WittonBell avatar Mar 26 '24 14:03 WittonBell

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

gcampbell-msft avatar Mar 29 '24 13:03 gcampbell-msft

@gcampbell-msft cmake generator is Ninja.

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

image

WittonBell avatar Mar 30 '24 07:03 WittonBell

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

Yingzi1234 avatar Apr 18 '24 09:04 Yingzi1234

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

WittonBell avatar Apr 18 '24 12:04 WittonBell

@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

Yingzi1234 avatar Apr 25 '24 09:04 Yingzi1234

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

WittonBell avatar Apr 25 '24 10:04 WittonBell

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

WittonBell avatar Apr 25 '24 10:04 WittonBell

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)仍然能复现这一问题。

DistinctWind avatar Sep 13 '24 09:09 DistinctWind

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.

WittonBell avatar Sep 14 '24 08:09 WittonBell

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

sean-mcmanus avatar Sep 16 '24 16:09 sean-mcmanus