问题描述
随着程序越来越复杂,单靠输出信息调试程序已然是不合适的,所以必须考虑使用gdb调试,由于板子上比较难加载代码,所以最合适的办法应该是gdb+gdbserver远程调试,这样我们可以清楚地看到程序的运行信息。gdb官方文档,可下载最新的pdf。
how
030sdk解压之后,在
osdrv/tools/board/gdb/
路径下有两个压缩包,gdb-7.9.1.tar.gz
和ncurses-6.0.tar.gz
,实测gdb-8.3.1.tar.gz
可用,下载链接。
- 解压
带有调试信息的程序
- 修改
CMakeLists.txt
的命令行参数配置,生成包含调试信息的文件:
cmake -B ./build -S . -DCMAKE_C_COMPILER=/opt/hisi-linux/x86-arm/aarch64-himix100-linux/bin/aarch64-himix100-linux-gcc -DCMAKE_BUILD_TYPE:STRING="Debug"
cmake --build ./build
生成gdb
#由于gdb在host上跑,所以不配置host,默认当前ubuntu系统下运行
./configure --prefix="$PWD/install" --target=aarch64-himix100-linux --program-prefix=hisi-
make -j16
make install
如果出现makeinfo未找到命令
,则安装texinfo
即可。
- 在路径
/home/flatfish/hisi/Resources/Hi3559AV100_SDK_V2.0.3.0/osdrv/tools/board/gdb/gdb-8.3.1/install/bin
下生成可以在host上跑的gdb
可以将hisi-gdb
拷贝到/usr/local/bin/
cp hisi-gdb /usr/local/gdb
这样在其他位置也能调用hisi-gdb
调试程序了。
生成gdbserver
在路径/home/flatfish/hisi/Resources/Hi3559AV100_SDK_V2.0.3.0/osdrv/tools/board/gdb/gdb-8.3.1/gdb/gdbserver
下,执行类似刚才的配置,区别在于,gdbserver
是跑在板端的,所以需要设定host,具体配置如下:
./configure --prefix="$PWD/install" --target=aarch64-himix100-linux --host=aarch64-himix100-linux --program-prefix=hisi-
make -j16
make install
- 将需要调试的程序拷贝到板端
You need a copy of the program you want to debug,
including any libraries it requires. gdbserver does not need your program’s symbol table,
so you can strip the program if necessary to save space. gdb on the host system does all
the symbol handling.
- 将
hisi-gdbserver
拷贝到板子的/usr/local/bin
调试
- 在板端启动程序
#host为本地ip,6666为端口号,不冲突即可,test为程序,foo.txt为参数
gdbserver host:6666 test foo.txt
- 本地gdb加载
hisi-gdb test
#remoteip代表板端ip,比如192.168.125.12
(gdb) target remote remoteip:6666
接下来本地就可以使用layout next
,continue
之类的指令调试了。