在 vscode linux 中使用 cpp 扩展设置 lldb 调试

setup lldb debugging with cpp extension in vscode linux

我主要使用 gdb 调试 vscode 中的 c++ 单个文件,但现在想尝试 lldb,但我在为 vscode.

设置它时遇到问题

我首先创建默认 launch.json 表单调试选项卡,选择 cpp gdb/lldb 然后 clang++ 进行配置。

调试开始时..显示以下错误:

然后在 launch.json 中,我将 miDebuggerPath 路径形式 /usr/bin/lldb-mi 更改为 /usr/bin/lldb

然后,当我启动调试器时,它什么都不做,只是在终端中调试顶部和以下行的控件:

warning: ignoring unknown option: --interpreter=mi
warning: ignoring unknown option: --tty=/dev/pts/1

我在这里遗漏了什么吗?

我的整个launch.json是:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "clang++ - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: clang++ build active file",
            "miDebuggerPath": "/usr/bin/lldb"
        }
    ]
}

lldb-mi 不是 LLDB 项目的一部分。见 lists.llvm.org

您仍然可以从项目的 github repo 中自行构建它。您需要先构建 LLDB/Clang/LLVM,因为 lldb-mi编译需要头文件和编译库才能使构建按照 README 中所述的信息工作。

this answer, and discussed here 中所述,使用 lldb-mi 可能不是最佳选择。

lldb-vscode (https://github.com/llvm/llvm-project/tree/main/lldb/tools/lldb-vscode) 在 linux 上的 vscode 中可以很好地启用 lldb 调试,并且是 LLDB 项目的一部分。以下是我使用的步骤(取自自述文件)在 remote-ssh vscode 服务器上进行设置(假设存在 llvm 安装):

  1. 创建 vscode 扩展
    # Create directory for a new VSCode extension
    $ mkdir -p  ~/.vscode-server/extensions/llvm-org.lldb-vscode-0.1.0/bin
    # Copy the extension package.json from GitHub
    $ wget -P ~/.vscode-server/extensions/llvm-org.lldb-vscode-0.1.0/ 
    https://raw.githubusercontent.com/llvm/llvm-project/main/lldb/tools/lldb-vscode/package.json
    # Copy the lldb-vscode binary to the bin directory
    $ cp $(which lldb-vscode) ~/.vscode-server/extensions/llvm-org.lldb-vscode-0.1.0/bin/
    # also make sure all libraries are found by ldd for the copied lldb-vscode
    
    现在,在我的远程主机 vscode 的扩展选项卡下,显示“LLDB 本机调试存根”
  2. 创建一个launch.json,例如
    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Launch lldb-vscode",
                "type": "lldb-vscode",
                "request": "launch",
                "program": "${command:cmake.launchTargetPath}",
                "args": [],
                "env": [],
                "cwd": "${workspaceFolder}",
                "stopOnEntry": false,
                "sourceMap": [["/path/a/", "/path/b"]]
            }
        ]
    }