vscode+gdbserver
修改launch.json来配置连接gdb信息, tasks.json来配置编译选项,如果已经编译完成的,可以忽视,只修改lauch.json就行。
launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gcc - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/do",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerServerAddress": "172.168.3.51:1234",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc 生成活动文件",
"miDebuggerPath": "/usr/bin/gdb-multiarch"
}
]
}
几个注意的地方:
- 应该是 “request”: “launch”, 不是 “attach”, 此后也并不需要记录进程 ID
- 需要填对 “miDebuggerServerAddress”: “172.168.3.51:1234”, 有这个设置才会开启 gdb 远程调试
- “engineLogging”: true 可以看到 gdb 自身的详细消息
- 必须是 “externalConsole”: false 否则报错
- /path/to/myprogram 应该是在 gdbserver 和 launch.json 里都要填一次
- “miDebuggerPath”: “/usr/bin/gdb-multiarch"或者”/usr/bin/gdb",其中mips架构只能用gdb-multiarch
- “program”: “${fileDirname}/do”,填充远程执行的二进制文件
tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc 生成活动文件",
"command": "/opt/mips-loongson-gcc7.3-linux-gnu/2019.06-29/bin/mips-linux-gnu-gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/do"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
注意的地方
命令行
-exec + [传统命令]
-exec r
-exec b
-exec bt
-exec info local
|