debugging 如何使用vscode连接到远程gdb?

shstlldc  于 2023-05-07  发布在  Vscode
关注(0)|答案(4)|浏览(268)

我想用vscode做远程C/C++ gdb调试。我使用“本地调试”扩展,我做配置。下面是我的 * launch.json * 配置

{
        "type": "gdb",
        "request": "launch",
        "name": "Launch Program (SSH)",
        "target": "./hello",
        "cwd": "/home/root/test1/",
        "ssh": {
            "host": "192.168.15.130",
            "cwd": "/home/root/test1/",
            "password": "",
            "user": "root"
}

我奔向目标

gdbserver localhost:2000 ./hello

不幸的是,我不能与远程设备连接调试后。是否有人有配置此的经验?

np8igboo

np8igboo1#

我在这里找到了这个问题的答案:Is it possible to attach to a remote gdb target with vscode?
总结:
首先,你需要安装VS Code的Native Debug扩展。
然后编辑launch.json文件并添加:

{
    "type": "gdb",
    "request": "attach",
    "name": "Attach to gdbserver",
    "executable": "<path to the elf/exe file relative to workspace root in order to load the symbols>",
    "target": "X.X.X.X:9999",
    "remote": true,
    "cwd": "${workspaceRoot}", 
    "gdbpath": "path/to/your/gdb",
    "autorun": [
            "any gdb commands to initiate your environment, if it is needed"
        ]
}

然后,您可以重新启动VS Code并开始调试。确保没有其他客户端连接到gdb服务器,否则您将获得超时错误。

dy2hfwbg

dy2hfwbg2#

您必须在远程机器上安装gdbserver。例如:

apt-get install gdbserver

在远程机器上启动gdbserver

gdbserver :1234 ./mybinary

选择您喜欢的任何端口-在此1234
通过键入以下命令测试从本地计算机到gdbserver的连接

gdb
(gdb) target remote myremotehostname:1234

触发任何gdb命令来检查它是否工作-例如c(或continue)继续运行mybinary
将以下内容放入.vscode/launch.json

{
      "name": "C++ Launch",
      "type": "cppdbg",
      "request": "launch",
      "program": "${workspaceRoot}/mybinary",
      "miDebuggerServerAddress": "myremotehostname:1234",
      "cwd": "${workspaceRoot}",
      "externalConsole": true,
      "linux": {
        "MIMode": "gdb"
      }
    }

或者使用其他答案中给出的"type": "gdb"启动配置。
为了让代码浏览和其他东西正常工作,让本地和远程端的源目录保持同步是很重要的。使用网络文件系统,手动复制,git触发器或类似的东西来设置它。

xdnvmnnf

xdnvmnnf3#

1.安装VS代码(本地)和gdb(远程)
1.安装SSH远程插件
1.使用远程ssh连接在Vs代码中打开工作区
1.在vs_code debug选项卡中,单击设置图标,它应该打开launch. json/ create one if does ' exist
1.在launch.json中添加以下代码(编辑二进制文件,工作区根,process_id)

{
       
        "version": "0.2.0",
        "configurations": [      
            {
                "name": "(gdb) Attach",
                "type": "cppdbg",
                "request": "attach",
                "program": "${path to binary}",
                "processId": "${process id to attach to}",
                "MIMode": "gdb",
                "cwd":"${workspaceRoot}",
                "setupCommands": [
                    {
                        "description": "Enable pretty-printing for gdb",
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    }
                ]
            }
        ]
    }

1.保存更改,然后单击“运行和调试”选项卡上的“绿色开始”按钮。
类似问题https://stackoverflow.com/a/72580854/19317199

vmjh9lq9

vmjh9lq94#

这就是我的工作:

{
  "version": "0.2.0",
  "configurations": [{
    "type": "cppdbg",
    "request": "launch",
    "program": "${workspaceFolder}/vmlinux", // for loading symbols from running program
    "cwd": "${workspaceFolder}",

    // if you want to connect at entry point (requires remote program to start paused)
    "stopAtEntry": true,
    "stopAtConnect": true,

    "MIMode": "gdb",
    "miDebuggerPath": "/usr/bin/gdb",
    "miDebuggerServerAddress": "localhost:1234",
    "setupCommands": [{
      "description": "Enable pretty-printing for gdb",
      "text": "-enable-pretty-printing",
      "ignoreFailures": true,
  }]
}]
}

相关问题