如何在VScode中配置json文件进行远程调试?

问题描述

我想要一个远程选项来调试应用程序。为此,我从以下配置创建了“launch.json”文件

{
    "version": "0.2.0","configurations": [
        {
            "type": "gdb","request": "attach","name": "Attach to gdbserver","executable": "/home/jakub/repo/app/build/app","target": "193.168.100.1:2345","remote": true,"cwd": "/home/jakub/repo/app","gdbpath": "/home/jakub/repo/ext-toolchain/bin/arm-linux-gnueabihf-gdb","autorun": [
                    "info break"
                ]
        }
    ]
}

首先我在arm板上启动GDB Server:

# gdbserver :2345 app
Process app created; pid = 173
Listening on port 2345

然后调试器在 vscode 中触发但没有任何反应,没有错误或反应。我只有暂停、重启和断开连接按钮。该程序绝对正确构建为调试,因为我能够通过 GDB 控制台进行连接

解决方法

它应该适用于这个启动配置:

{
    "name": "Attach to gdbserver","type": "cppdbg","request": "launch","program": "/home/jakub/repo/app/build/app","args": [],"stopAtEntry": false,"cwd": "${workspaceRoot}","environment": [],"externalConsole": true,"MIMode": "gdb","setupCommands": [
        {
            "description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": true
        }
    ],"miDebuggerServerAddress": "193.168.100.1:2345","miDebuggerPath": "/home/jakub/repo/ext-toolchain/bin/arm-linux-gnueabihf-gdb"
}

运行后: gdbserver localhost:2345 app

连接所有东西可能需要几秒钟的时间。