如何使用 lldb 在 VS Code 中进行调试?

Dan*_*eev 4 c++ debugging llvm lldb visual-studio-code

我正在尝试调试一个简单的 C++ 程序,但没有任何反应,并且断点也不起作用。构建任务运行良好,我可以运行该应用程序。

任务.json

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: clang++.exe build active file",
            "command": "F:\\Programs\\LLVM\\bin\\clang++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}
Run Code Online (Sandbox Code Playgroud)

启动.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "clang++.exe - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            "miDebuggerPath": "F:\\Programs\\LLVM\\bin\\lldb-vscode.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: clang++.exe build active file"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

当我按 F5 时,终端中出现以下内容:

PS F:\Projects\Console Apps\testbuild>  & 'c:\Users\daniil\.vscode\extensions\ms-vscode.cpptools-1.7.1\debugAdapters\bin\WindowsDebugLauncher.exe' '--stdin=Microsoft-MIEngine-In-4pf1un21.l04' '--stdout=Microsoft-MIEngine-Out-tpjfi4ip.jse' '--stderr=Microsoft-MIEngine-Error-2nkku53m.1iw' '--pid=Microsoft-MIEngine-Pid-xscepzdp.k00' '--dbgExe=F:\Programs\LLVM\bin\lldb-vscode.exe' '--interpreter=mi'
Run Code Online (Sandbox Code Playgroud)

但我的程序没有任何输出,单步执行/进入/退出按钮显示为灰色,并且断点不起作用。

Dan*_*eev 8

在 launch.json 中我必须写“lldb”,而不是“cppdbg”。现在可以了。

  • 如果我安装了 CodeLLDB 扩展,这对我有用(这似乎工作得很好) (6认同)