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

Debugging fails on macOS

Open segevfiner opened this issue 1 year ago • 33 comments

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

segevfiner avatar Jul 16 '24 14:07 segevfiner

@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

v-frankwang avatar Jul 18 '24 02:07 v-frankwang

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.

segevfiner avatar Jul 18 '24 06:07 segevfiner

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"
    }

ZiKun007 avatar Jul 18 '24 15:07 ZiKun007

@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

v-frankwang avatar Jul 19 '24 09:07 v-frankwang

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

ZiKun007 avatar Jul 19 '24 16:07 ZiKun007

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

gcampbell-msft avatar Jul 19 '24 18:07 gcampbell-msft

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

segevfiner avatar Jul 19 '24 18:07 segevfiner

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

v-frankwang avatar Jul 26 '24 07:07 v-frankwang

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 avatar Aug 22 '24 00:08 thomas-bc

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!

thomas-bc avatar Aug 22 '24 00:08 thomas-bc

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

v-frankwang avatar Aug 23 '24 07:08 v-frankwang

@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

gcampbell-msft avatar Aug 23 '24 18:08 gcampbell-msft

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

veimmone avatar Sep 08 '24 08:09 veimmone

@gcampbell-msft The user thinks that the bug might be related to this issue: https://github.com/microsoft/vscode-cmake-tools/issues/4050 he raised, but we can't be sure if that's the case, can you give us some suggestions?

v-frankwang avatar Sep 13 '24 08:09 v-frankwang

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"

I have just tried it and... it didn't work for me. I am getting the following error message:

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

Not sure what I did wrong or what I am missing, but it's very frustrating. :/

FWIW, the contents of my .vscode/launch.json file is:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch (lldb)",
      "type": "cppdbg",
      "request": "launch",
      "program": "${command:cmake.launchTargetPath}",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}",
      "externalConsole": false,
      "miDebuggerPath": "/Users/Alan/.vscode/extensions/ms-vscode.cpptools-1.22.11-darwin-arm64/debugAdapters/lldb-mi/bin/lldb-mi"
    }
  ]
}

and /Users/Alan/.vscode/extensions/ms-vscode.cpptools-1.22.11-darwin-arm64/debugAdapters/lldb-mi/bin/lldb-mi definitely exists (and can be run).

agarny avatar Nov 07 '24 23:11 agarny

What eventually ended up working for me was to replace /Applications/Xcode.app/Contents/Developer/usr/bin/lldb with /Users/Alan/.vscode/extensions/ms-vscode.cpptools-1.22.11-darwin-arm64/debugAdapters/lldb-mi/bin/lldb-mi. Not sure I like it, but... 🙄

agarny avatar Nov 08 '24 00:11 agarny

"miDebuggerPath" shows up as an unknown configuration setting. Is there something I'm missing ?

Edit: Yes I was missing the fact that miDebuggerPath needs to be specified in the launch.json not the global vscode configuration.

ghost avatar Nov 17 '24 18:11 ghost

@punowo @agarny Thanks for your questions, we have it marked for the next milestone and will be investigating it soon, thanks!

gcampbell-msft avatar Nov 19 '24 16:11 gcampbell-msft

Using this path looks more generic and should work for everyone.

"miDebuggerPath": "${extensionInstallFolder:ms-vscode.cpptools}/debugAdapters/lldb-mi/bin/lldb-mi"

eddielin0926 avatar Dec 28 '24 15:12 eddielin0926

@eddielin0926 thanks for your sharing, happy coding!

Amy-Li03 avatar Jan 02 '25 07:01 Amy-Li03

In the WSL2 environment on the Windows platform, I am similarly/still unable to debug using the status bar debug icon. When using the LLDB debugger with the CMake Tools plugin, it automatically adds the --interpreter=mi and --tty options, which are not recognized. However, when I switch to the GDB debugger, it works fine.

https://github.com/user-attachments/assets/61d484f5-b8de-410c-8703-6798c538cd94

CMake Tool version:1.19.52 VSC version:1.96.2 lldb version:14.0.0 gdb version: GNU gdb (Ubuntu 12.1-0ubuntu1~22.04.2) 12.1

cuixing158 avatar Jan 02 '25 10:01 cuixing158

Hi @cuixing158 , thanks for your info! I can reproduce your issue on our side, cmake debug failed when using the LLDB debugger in the WSL2 environment of Windows platform, we will be investigating issue soon. Image

@gcampbell-msft FYI

Amy-Li03 avatar Jan 03 '25 06:01 Amy-Li03

@gcampbell-msft @Amy-Li03 (and others working on this) Some more info about the issue:

I was able to use the debugger without any modifications until I added a CMakePresets.json file to my project - then the issue with the interpreter flag started appearing.

I removed the CMakePresets file to see what commands were originally being run and found this: Image

It seems like when the CMakePresets file is absent it attempts to use lldb-mi, but if it's missing it switches to using the debugAdapter binary & works just fine.

vaughnrichard avatar Jan 05 '25 06:01 vaughnrichard

Hi @vaughnrichard , thank you for your more information, we will be investigating this soon.

Amy-Li03 avatar Jan 07 '25 05:01 Amy-Li03

hello,anything new?

LinHuan86 avatar Mar 03 '25 03:03 LinHuan86

@LinHuan86 Looks like this is still a bug that we need to address, but in the meantime, an easy workaround is to construct your own launch.json configuration for debugging. Thanks for the follow up.

gcampbell-msft avatar Mar 03 '25 12:03 gcampbell-msft

@eddielin0926 Worked for me thanks for sharing

Using this path looks more generic and should work for everyone.

"miDebuggerPath": "${extensionInstallFolder:ms-vscode.cpptools}/debugAdapters/lldb-mi/bin/lldb-mi"

Joshua-T-Winterflood avatar Mar 04 '25 10:03 Joshua-T-Winterflood

Using this path looks more generic and should work for everyone.

"miDebuggerPath": "${extensionInstallFolder:ms-vscode.cpptools}/debugAdapters/lldb-mi/bin/lldb-mi"

This change works for me

fisherinsz avatar Mar 25 '25 08:03 fisherinsz

Also fails in a devcontainer running ubuntu-24, with lldb-20 and without any cmake.

error: unknown option: --interpreter=mi
error: unknown option: --tty=/dev/pts/2
Use 'lldb-20 --help' for a complete list of options.
[1] + Done(1)                    "/usr/bin/lldb-20" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-zedia1nn.c5q" 1>"/tmp/Microsoft-MIEngine-Out-myp4eup5.yqj"

The workaround does not work.

"miDebuggerPath": "${extensionInstallFolder:ms-vscode.cpptools}/debugAdapters/lldb-mi/bin/lldb-mi"
{
	"name": "Debug current C++ file (clang++)",
	"type": "cppdbg",
	"request": "launch",
	"program": "${fileDirname}/${fileBasenameNoExtension}.out",
	"args": [],
	"stopAtEntry": false,
	"cwd": "${fileDirname}",
	"environment": [],
	"externalConsole": false,
	"MIMode": "lldb", 
	"miDebuggerPath": "/usr/bin/lldb-20",
	"setupCommands": [
		{
			"description": "Enable pretty-printing for lldb",
			"text": "type synthetic add -x \"^std::(deque|forward_list|list|map|multimap|set|multiset|unordered_map|unordered_multimap|unordered_set|unordered_multiset|vector)<.+>$\" --python-class lldb.formatters.cpp.libcxx.std_container_synthetic.SyntheticFormatter --category libcxx",
			"ignoreFailures": true
		},
	],
	"preLaunchTask": "Build current C++ file (clang++)"
}

moemode avatar May 05 '25 16:05 moemode

Hi all, our team will investigate this issue sooner, and updated the progress here. Thanks for help us build a better CMake Tools!

Amy-Li03 avatar May 07 '25 01:05 Amy-Li03