读者:
需要在ARM 芯片上调试, 如Cotex M4, 使用交叉编译器/调试器arm-none-eabi-gcc/gdb
对原有的console界面或者tui界面觉得不满意的
需要远程调试的,gdbserver enabled by JLINK
准备:
code 1.19.1
Ubuntu 16.04
arm-none-eabi-gdb 7.10.1
正文
1. 打开VS CODE, menu -> view -> debug( ctrl + shift + D )
2. menu -> debug -> Open configurations, 你会看到一个默认的配置文件
3.1 如果你有默认的初始化脚本,如以前调试时为arm-xxx-gdb -x xxx.gdbinit, 替换配置文件为以下:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "cppdbg",
"request": "launch",
"miDebuggerPath": "/user/local/bin/arm-none-eabi-gdb",
"targetArchitecture": "arm",
"program": "${workspaceRoot}/output/Some.elf",
"setupCommands": [
{
"text": "cd ${workspaceRoot}/build/gcc/" //(可选)进入你的gdb初始化脚本目录
},
{
"text": "source some.gdbinit" //加载我们的初始化脚本,通常初始化脚本会执行target remote connect 等一系列操作
},
],
// "preLaunchTask": "make",
"launchCompleteCommand": "None",
"externalConsole": false,
"cwd": "${workspaceRoot}"
}
]
}
3.2 如果你使用的是直接arm-xxx-gdb some.elf 则可替换配置文件为, setup commands内容可自行更改:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "cppdbg",
"request": "launch",
"miDebuggerPath": "/usr/local/bin/arm-none-eabi-gdb",
"targetArchitecture": "arm",
"program": "${workspaceRoot}/output.elf",
"setupCommands": [
{
"text": "file '${workspaceRoot}/output.elf'"
},
{
"text": "target extended-remote /dev/cu.usbmodemXXXXXXXX"
},
{
"text": "monitor tpwr enable"
},
{
"text": "monitor swdp_scan"
},
{
"text": "attach 1"
},
{
"text": "load ${workspaceRoot}/output.elf"
}
],
"preLaunchTask": "make",
"launchCompleteCommand": "None",
"externalConsole": false,
"cwd": "${workspaceRoot}"
}
]
}
4. 保存好配置文件,就可以点击左上角绿色的箭头(F5)启动调试. 如果遇到错误提示,一般是某某文件没有找到,可以对应进行检查.如果是某些命令不支持,建议放入gdbinit脚本中,采用3.1配置
5. 如果vscode 没有报错 , 芯片的console可以继续跑,基本上就是attach成功, 加个断点试试吧。
Thanks~
引用:
https://github.com/Microsoft/vscode-cpptools/issues/328
https://jeasonstudio.gitbooks.io/vscode-cn-doc/content/md/%E7%BC%96%E8%BE%91%E5%99%A8/%E8%B0%83%E8%AF%95.html
作者:
云一JL