讀者:
需要在ARM 芯片上調(diào)試潘酗, 如Cotex M4, 使用交叉編譯器/調(diào)試器arm-none-eabi-gcc/gdb
對(duì)原有的console界面或者tui界面覺得不滿意的
需要遠(yuǎn)程調(diào)試的民效,gdbserver enabled by JLINK
準(zhǔn)備:
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, 你會(huì)看到一個(gè)默認(rèn)的配置文件
3.1 如果你有默認(rèn)的初始化腳本冕杠,如以前調(diào)試時(shí)為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/" ? //(可選)進(jìn)入你的gdb初始化腳本目錄
? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? "text": "source some.gdbinit" ? ? ? //加載我們的初始化腳本谨娜,通常初始化腳本會(huì)執(zhí)行target remote connect 等一系列操作
? ? ? ? ? ? ? ? },
? ? ? ? ? ? ],
? ? ? ? ? // "preLaunchTask": "make",
? ? ? ? ? ? "launchCompleteCommand": "None",
? ? ? ? ? ? "externalConsole": false,
? ? ? ? ? ? "cwd": "${workspaceRoot}"
? ? ? ? }
? ? ]
}
3.2 如果你使用的是直接arm-xxx-gdb some.elf 則可替換配置文件為, setup commands內(nèi)容可自行更改:
{
? ? "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. 保存好配置文件呕屎,就可以點(diǎn)擊左上角綠色的箭頭(F5)啟動(dòng)調(diào)試. 如果遇到錯(cuò)誤提示让簿,一般是某某文件沒有找到,可以對(duì)應(yīng)進(jìn)行檢查.如果是某些命令不支持秀睛,建議放入gdbinit腳本中尔当,采用3.1配置
5. 如果vscode 沒有報(bào)錯(cuò) , 芯片的console可以繼續(xù)跑蹂安,基本上就是attach成功椭迎, 加個(gè)斷點(diǎn)試試吧。
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