平头哥RISC-V+gdb+vscode调试
- RISC-V
- 2024-05-07
- 680热度
- 0评论
工具准备
- T-HeadDebugServer工具:[链接](https://www.xrvm.cn/community/download?id=4238019891233361920 \"链接\")
- T-HeadDebugServer使用说明:[链接](https://www.xrvm.cn/community/download?id=4170589434888130560 \"链接\")
- vscode下载:[链接](https://code.visualstudio.com/ \"链接\")
- cklink:硬件调试器(网上购买)
安装完成工具后,硬件平台要使能调试模式,一般是GPIO的复用要打开为JTAG模式。
T-headDebugServer工具
安装好T-headDebugServer以及对应的cklink驱动后,并且使能了硬件平台的gpio复用为jtag,打开T-headDebugServer即可链接上硬件平台。如下图所示,表示连接成功。
如果连接不成功,可以修改下配置,再进行尝试。
mobarX远程服务器代码与本地T-HeadDebuger GDB调试
设置T-HeadDebugServer监听端口
设置好监听端口后启动
设置mobaXterm
启动代理连接,有可能要输入ssh访问远程服务的账号和密码
gdb连接
如果架构相关不正确,可使用set architecture riscv:rv64来设置。
为了便捷快速连接,也可以将常用的指令设置到.gdbinit脚本中。
vscode+gdb调试
如果不习惯mobarXiterm上gdb命令行方式调试,可以使用vscode搭建gdb的调试环境,下面介绍vscode的gdb调试方法,前置条件为设置好mobarXiterm的代理。
安装Remote-SSH
ssh连接服务器
错误解决
Could not establish connetion to xxxx
如果报下面的错误
则进行配置remote-SSH,右键->Extension Setting
参考:https://blog.csdn.net/qq_41854763/article/details/103317116
XHR failedscode
参考:https://blog.csdn.net/m0_38040006/article/details/126752751
gdb连接
创建一个lauch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "{workspaceFolder}/xxx/img/rt_system.elf",
"args": [],
"stopAtEntry": false,
"cwd": "{fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "${workspaceFolder}/xxx/riscv64-elf-x86_64-20201104/bin/riscv64-unknown-elf-gdb",
"miDebuggerServerAddress": "localhost:8193",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "set remotetimeout 20",
"ignoreFailures": true
}
]
}
]
}
修改好elf、gdb的位置,然后再设置好mobarXiterm的代理端口,这样就可以启动连接了。
常用技巧
在汇编代码中支持打断点
ctrl+鼠标左键生效
进入VScode的首选项,选择设置(快捷键 Ctrl + , ),输入Go to definition,找到如下两个设置。
Editor: Multi Cursor Modifier 设置成 alt
“editor.gotoLocation.multipleDefinitions” 设置成 “goto”。
重启vscode
在vscode中实时显示汇编
在代码处右键->Open Disassembly View。