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

Debugging fails on macOS #3908

Open segevfiner opened 1 month ago

segevfiner commented 1 month ago

Brief Issue Summary

Debugging fails with:

Starting: "/Library/Developer/CommandLineTools/usr/bin/lldb" --interpreter=mi
error: unknown option: --interpreter=mi
Use 'lldb --help' for a complete list of options.
"/Library/Developer/CommandLineTools/usr/bin/lldb" exited with code 1 (0x1).

Likely due to the extension trying to use lldb instead of VS Code's lldb-mi.

CMake Tools Diagnostics

{
  "os": "darwin",
  "vscodeVersion": "1.91.1",
  "cmtVersion": "1.18.43",
  "configurations": [
    {
      "folder": "/Users/segevfiner/junk/antlr4/cpp",
      "cmakeVersion": "3.30.0",
      "configured": true,
      "generator": "Ninja",
      "usesPresets": false,
      "compilers": {
        "C": "/Library/Developer/CommandLineTools/usr/bin/cc",
        "CXX": "/Library/Developer/CommandLineTools/usr/bin/c++"
      }
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "Debug",
    "buildTypesSeen": [
      "Debug"
    ],
    "requests": [
      "file:///Users/segevfiner/junk/antlr4/cpp/main.cpp",
      "file:///Users/segevfiner/junk/antlr4/antlr4-cpp-runtime/run/include/antlr4-runtime/antlr4-runtime.h",
      "file:///Users/segevfiner/junk/antlr4/antlr4-cpp-runtime/run/include/antlr4-runtime/ANTLRInputStream.h"
    ],
    "responses": [
      {
        "uri": "file:///Users/segevfiner/junk/antlr4/cpp/main.cpp",
        "configuration": {
          "includePath": [
            "/users/segevfiner/junk/antlr4/antlr4-cpp-runtime/run/include/antlr4-runtime",
            "/users/segevfiner/junk/antlr4/cpp/build/antlr4_generated_src/antlr-vb6-lexer",
            "/users/segevfiner/junk/antlr4/cpp/build/antlr4_generated_src/antlr-vb6-parser"
          ],
          "defines": [],
          "compilerPath": "/library/developer/commandlinetools/usr/bin/c++",
          "compilerArgs": [],
          "compilerFragments": [
            "-g -std=gnu++17 -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk"
          ]
        }
      }
    ],
    "partialMatches": [],
    "targetCount": 1,
    "executablesCount": 1,
    "librariesCount": 0,
    "targets": [
      {
        "name": "antlr4-poc",
        "type": "EXECUTABLE"
      }
    ]
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": null
    }
  ]
}

Debug Log

No response

Additional Information

No response

v-frankwang commented 1 month ago

@segevfiner After I add a launch,json file to the project, I can debug successfully. I'm not sure what is causing your error, can you provide a simple project that can reproduce the issue and more detailed steps to do so? Looking forward to your reply!

https://github.com/user-attachments/assets/f4c3cef7-72e4-423e-9e0f-9f58ab3515d6

segevfiner commented 1 month ago

The without launch.json option, using the CMake: Debug command defined by this extension, and bound to a status bar item and keyboard shortcuts, is failing, not the launch.json debug configuration that is supplied by cpptools.

Jack-Bie commented 1 month ago

I also encountered the same problem as you. When using the CMake tools plug-in and lldb to debug the C++ program, an error message was reported

error: unknown option: --interpreter=mi
error: unknown option: --tty=/dev/pts/5

However, when using gdb debugging, the debugging function of CMake tools can run normally, that is, it will output an extra line of information after debugging.

[1] + Done  "/usr/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-vxzegz3r.ndl" 1>"/tmp/Microsoft-MIEngine-Out-wdismh3d.muy"

ChatGPT asked me to add the following settings, but it didn't work

"cmake.debugConfig": {
        "name": "(lldb) Launch",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/build/main",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "lldb",
        "miDebuggerPath": "/usr/bin/lldb",
        "setupCommands": [
            {
                "text": "settings set target.run-args arg1 arg2",
                "description": "设置程序参数",
                "ignoreFailures": true
            }
        ],
        "internalConsoleOptions": "openOnFirstSessionStart"
    }
v-frankwang commented 1 month ago

@gcampbell-msft @segevfiner I used a simple project to verify this, after adding the project and running the CMake:select a kit command, when I select GCC 13.2.0 x86_64, debugging fails with an error message in the bottom right corner, but running the CMake:select a kit command, when I select Clang 15.0.0 x86_64, I can successfully I can successfully debug. But when I run CMake: select a kit command and select Clang 15.0.0 x86_64, debugging fails with error message displayed in the bottom right corner.

https://github.com/user-attachments/assets/be8c4104-e09a-46c1-ac19-a9672b31309b

Jack-Bie commented 1 month ago

@v-frankwang Thank you very much. Following the method you described, the problem that occurs when CMake tools is debugged with lldb can indeed be solved!


In your video, when debugging with the GCC tool chain, you should use gdb for debugging, but CMake tools still seems to use lldb, as can be seen from the output in the figure below:

image

I used to have trouble debugging with CMake tools on MacOS, but now I can solve it. I am very happy. Thank you very much for your help.

gcampbell-msft commented 1 month ago

@Jack-Bie Does this mean that this issue can be closed? Or is there still an underlying issue that we should solve to make this experience easier?

segevfiner commented 1 month ago

You can debug by launch.json using lldb, it's the command from CMake tools that is broken and should be fixed.

v-frankwang commented 1 month ago

@segevfiner Thank you very much for your reply! We'll be going to do further investigation on this issue and we'll update comment with any subsequent developments!

thomas-bc commented 2 weeks ago

I can confirm that this still very much happens and is a really big annoyance. My projects use a CMakePresets.json (https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html) file and I have not found any way to prevent the extension from passing --interpreter=mi to LLDB.... Any guidance?

thomas-bc commented 2 weeks ago

FYI I was able to fix following this guide: https://code.visualstudio.com/docs/cpp/lldb-mi

Basically setting

"miDebuggerPath": "<HOME>/.vscode/extensions/ms-vscode.cpptools-<version>-darwin-x64/debugAdapters/lldb-mi/bin/lldb-mi"

It is a convenient workaround but wasn't straightforward to figure out. This does feel like a bug - the extension should be able to use that adapter since it ships within... I'm happy to take a crack at implementing if yall can give me some pointers as to where to look!

v-frankwang commented 2 weeks ago

@gcampbell-msft The client wants to fix this problem by following the guide https://code.visualstudio.com/docs/cpp/lldb-mi and would like you to provide some help, can you give some advice?

gcampbell-msft commented 2 weeks ago

@v-frankwang They have successfully found a workaround, but we still hope to investigate this and make it easier for users.

We have this item in our "On Deck" Milestone which is where we grab issues from when planning our next release. @thomas-bc Thanks for the workaround!

@thomas-bc I haven't been able to take a look at this much yet, but I would anticipate that this stems from something in this file when we interact with the lldb debugger configuration: https://github.com/microsoft/vscode-cmake-tools/blob/main/src/debugger.ts.

Here is a link to the method where there may be some improvements to be had: https://github.com/microsoft/vscode-cmake-tools/blob/main/src/debugger.ts#L165

veimmone commented 1 day ago

Possibly related: https://github.com/microsoft/vscode-cmake-tools/issues/4050