vscode搭建gdb调试交叉编译代码
1.vscode环境搭建
- c++插件
- openssh插件
2.调试配置添加
-
在代码工程中的run and debug菜单中添加launch.json文件,然后点击add configuration添加gdb和运行信息,其中需要配置的有如下
- program:运行的bin文件路径
- miDebuggerPath : 交叉编译器gdb的路径
- miDebuggerServerAddress : 目标主板的ip以及端口号
{ // 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":*/path/bin", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", "miDebuggerPath": "**、arm-rockchip830-linux-uclibcgnueabihf-gdb", "miDebuggerServerAddress":"192.168.80.159:9001", "environment": [], "externalConsole": false, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true }, { "description": "Set Disassembly Flavor to Intel", "text": "-gdb-set disassembly-flavor intel", "ignoreFailures": true } ] } ] }
3.开发板运行
- 开发板的ip地址需要分配,然后把ip对应到vscode中的miDebuggerServerAddress中
- 编译的gdbserver拷贝到目标开发板上,
- 执行gdbserver ip+端口 目标文件
4.vscode代码调试
- 启动gdb,添加断点 查看变量