本文主要是介绍openwrt gdb gdbserver调试方法汇总,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.使能gdb, gdbserver
make menuconfig
enable gdb
enable gdbserver
.config 新增两行配置
CONFIG_PACKAGE_gdb=y
CONFIG_PACKAGE_gdbserver=y
2.程序开启 -g 选项
1.openwrt通用添加方法: 推荐
修改进程对应的 openwrt Makefile, 添加 TARGET_CFLAGS += -g
2.修改程序源代码Makefile
以修改dnsmasq为例:
tar -xf dnsmasq-2.85.tar.xz
cd dnsmasq-2.85/
vim Makefile
--CFLAGS = -Wall -W -o2
++CFLAGS = -Wall -W -g
tar -cf dnsmasq-2.85.tar dnsmasq-2.85
xz -z dnsmasq-2.85.tar
md5sum dnsmasq-2.85.tar.xz
更新对应的openwrt Makefile HASH PKG_HASH:=ea8e29cd4cb1f64092482be89b0856edc0c2a36a9b051aecb2d8763145a3ac32
3.尝试修改out目录代码
openwrt修改文件之后,再次编译默认是覆盖out目录,大家根据自己的SDK尝试
3.调试程序
方法1: gdb 调试程序
PC
scp dnsmasq root@192.168.1.1:/usr/sbin #替换源程序,也可以用winscp,adb 等工具替换
scp -rf dnsmasq/src/* root@192.168.1.1:/tmp/src/dnsmasq #将源代码拷贝进/tmp/src/dnsmasq
开发板
mkdir /tmp/src/dnsmasq
/etc/init.d/dnsmasq stop
gdb /usr/sbin/dnsmasq
(gdb) dir /tmp/src/dnsmasq #修改调试程序 源代码目录
(gdb) l main #加载源代码,设置断点
剩下的就和gdb调试一样。
方法1.1: mount挂载源代码
如果mount支持nfs/cifs 远程挂载,还可以挂载目录, 更加方便调试
方法2: gdbserver调试程序
开发板
#1.运行程序
gdbserver 192.168.1.1:7788 /usr/sbin/dnsmasq -C xxx.conf #注意运行参数
#2.已经运行的程序
gdbserver --attach 192.168.1.1:7788 16924 #16924是dnsmasq程序pid
注意:开发版对应INPUT, OUTPUT链是否允许通过端口 7788(自定义远程调试端口号)
PC端:
gdb dnsmasq
(gdb)dir src #非必要,如果提示找不到symbol在修改
(gdb)b main #设置断点
(gdb)remote 192.168.1.1:7788
方法3: 配合IDE调试
目前已配合VS code实现远程调试
参考:
手把手教你使用VSCode + gdb + gdbserver调试ARM程序 - 知乎 (zhihu.com)
VS Code与GDB Server远程调试 - 知乎 (zhihu.com)j
建议:
建议先在自己的PC上实现gdbservere远程调试,属性环境,参数配置。再去开发板验证。
个人配置参考:
.vscode/launch.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": "gdbserver remote debug","type": "cppdbg","request": "launch",//"program": "${fileDirname}/${fileBasenameNoExtension}",//1.dnsmasq"program": "/home/kali/liuj/xxx/dnsmasq-nodhcpv6/dnsmasq-2.85/src/dnsmasq",
"args": [],"stopAtEntry": false,"cwd": "${fileDirname}","environment": [],"externalConsole": false,"MIMode": "gdb","setupCommands": [{"description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": true}],//"preLaunchTask": "C/C++: gcc-11 build active file", //注释掉"miDebuggerServerAddress":"192.168.1.1:7788", //远程 ip:port"miDebuggerPath": "/home/kali/xxx/aarch64-openwrt-linux-gdb" //交叉编译gdb位置}]
}
交流邮箱: lj1637664504@outlook.com
这篇关于openwrt gdb gdbserver调试方法汇总的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!