GDB调试
GDB远程调试
嵌入式开发中,为了开发方便,需要对应用在调试,此时可以使用GDB的远程调试功能,使用前需要开发板上安装gdbserver软件包。以下是使用步骤。
例程代码如下:
#include <stdio.h>
int main(int argc, char* argv[])
{
printf("hello, world!\r\n");
return 0;
}
使用工具链编译为二进制文件后,复制到开发板的目录下。开发板需要连接网络,并且和PC是在同一个IP网段。
# gdbserver 192.168.2.110:1234 helloworld
rocess spidev_test created; pid = 530
Listening on port 1234
执行后开发板的gdbserver在监听1234端口,等待连接。
在PC端加载工具链环境后,运行如下命令
$GDB helloworld
GNU gdb (GDB) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-i2somsdk-linux --target=arm-i2som-linux-gnueabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from spidev_test...done.
然后执行如下命令,连接到开发板的gdbserver
(gdb) target remote 192.168.2.110:1234
Remote debugging using 192.168.2.110:1234
Reading /lib/ld-linux-armhf.so.3 from remote target...
warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.
Reading /lib/ld-linux-armhf.so.3 from remote target...
Reading symbols from target:/lib/ld-linux-armhf.so.3...Reading /lib/ld-2.24.so from remote target...
Reading /lib/.debug/ld-2.24.so from remote target...
这里还需要指定相关库的sysroot目录,以方便gdb加载符号信息
(gdb) set sysroot /home/builder/i2SOM-yocto-meta/2.2-r0/sysroots/cortexa7hf-neon-i2som-linux-gnueabi
warning: .dynamic section for "/home/builder/i2SOM-yocto-meta/2.2-r0/sysroots/cortexa7hf-neon-i2som-linux-gnueabi/lib/ld-linux-armhf.so.3" is not at the expected address (wrong library or version mismatch?)
Reading symbols from /home/builder/i2SOM-yocto-meta/2.2-r0/sysroots/cortexa7hf-neon-i2som-linux-gnueabi/lib/ld-linux-armhf.so.3...Reading symbols from /home/builder/i2SOM-yocto-meta/2.2-r0/sysroots/cortexa7hf-neon-i2som-linux-gnueabi/lib/.debug/ld-2.24.so...done.
done.
Reading symbols from /home/builder/i2SOM-yocto-meta/2.2-r0/sysroots/cortexa7hf-neon-i2som-linux-gnueabi/lib/ld-linux-armhf.so.3...Reading symbols from /home/blackrose/myir_workspace/i2SOM-yocto-meta/2.2-r0/sysroots/cortexa7hf-neon-i2som-linux-gnueabi/lib/.debug/ld-2.24.so...done.
done.
接下来就可以使用gdb的命令对应用做调试手段。
作者:SteveChen 创建时间:2024-10-10 10:54
最后编辑:SteveChen 更新时间:2024-10-10 10:54
最后编辑:SteveChen 更新时间:2024-10-10 10:54