使用 VSCode 设置 GDB 参数

问题描述 投票:0回答:1

我通过 VSCode 运行 GDB。我的系统在另一个目标上运行,因此正在使用 gdbserver。由于开发系统和目标系统之间的差异,src 文件位于不同的位置。使用

set substitute-path
命令已经起作用,但必须等待 GDB 会话启动、中断它,然后在 VSCode 终端中运行该命令,然后 GDB 才能将开发计算机上的 src 与目标计算机的 src 连接起来。有没有办法设置 .vscode/launch.json 文件来为我运行此命令?我对 GDB 的熟悉程度很低,但我引用了
gdb --help
并注意到了
-ex
选项来评估单个 GDB 命令。 VSCode launch.json 上的文档指出您可以在配置中使用“miDebuggerArgs”来设置调试器 (gdb) 的参数。

这是我的配置文件:

    "version": "0.2.0",
    "configurations": 
    [
        {
            "type": "gdb",
            "request": "attach",
            "name": "gdbserver",
            "gdbpath": "/usr/bin/gdb",
            "miDebuggerArgs": "-ex \"set substitute-path /workspace /other/dir",
            "program": "/app/bin/exe",
            "target": "target_ip:port",
            "remote": true,
            "cwd": "/"
        }
    ]
}

我找不到

miDebuggerArgs
部分的特定语法;我也试过
"miDebuggerArgs": [ "-flag input" ]

我尝试的配置中的另一个部分是

"setupCommands": [ { "text": "-ex \"set substitute-path /workspace /path\"" } ] 

我尝试的第三个解决方案是

searchPaths
中的
symbolOptions
选项。

"symbolOptions":    
        {
            "searchPaths": 
                [
                    "/dir", 
                    "/another/dir", 
                    "${workspaceFolder}"
                ],
        }

我尝试的第四件事是

sourceFileMap
选项。

"sourceFileMap":
        {
            "/workspace": "${workspaceFolder}"
        }
c++ visual-studio-code gdb gdbserver
1个回答
0
投票

将此条目添加到 launch.json 对我有用

"preAttachCommands": [
     "set substitute-path /path/during/build /path/for/debuging",
],

来自 https://github.com/Marus/cortex-debug/issues/611#issuecomment-1076250854

在你的情况下,那就是

"version": "0.2.0",
"configurations": 
[
    {
        "type": "gdb",
        "request": "attach",
        "name": "gdbserver",
        "gdbpath": "/usr/bin/gdb",
        "program": "/app/bin/exe",
        "target": "target_ip:port",
        "remote": true,
        "cwd": "/",
        "preAttachCommands": [
            "set substitute-path /path/during/build /path/for/debuging",
        ],
    }
]
© www.soinside.com 2019 - 2024. All rights reserved.