嵌入式爱好者

嵌入式爱好者 门户 知识库 查看内容

gdb远程调试

2023-6-30 20:16| 发布者: snn| 查看: 188| 评论: 0

类目:  >  知识库     文档编号: 1049

1.1 交叉编译应用
GDB,是The GNU Project Debugger 的缩写,是 Linux 下功能全面的调试工具。GDB支持断点、单步执行、打印变量、观察变量、查看寄存器、查看堆栈等调试手段。在Linux环境软件开发中,GDB 是主要的调试工具,用来调试 C 和 C++ 程序。 OK8MP-C的5.4.70默认支持gdbserver,同时我们提供的开发环境默认支持gdb。
编译要调试的应用程序:必须要加-g选项
forlinx@ubuntu:~/ $CC -g test_bug.c -o test_bug

将test_bug拷贝到开发板的/目录下,并在此目录进行调试
1.2 远程调试
1. 设置开发板IP和端口号
root@OK8MP:~# ifconfig eth0 172.16.0.109

root@OK8MP:~# gdbserver 172.16.0.109:2345 test_bug
Process /home/root/test_bug created; pid = 1356
Listening on port 2345

2.给虚拟机设置同网段的ip并保证可以ping通开发板ip
3.虚拟机端选择调试程序
forlinx@ubuntu:~/ aarch64-poky-linux-gdb test_bug
GNU gdb (GDB) 8.3.1
Copyright (C) 2019 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-pokysdk-linux --target=aarch64-poky-linux".
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 test_bug...
(gdb)

4.连接开发板
(gdb) target remote 172.16.0.109:2345
Remote debugging using 172.16.0.109:2345
Reading /lib/ld-linux-aarch64.so.1 from remote target...
warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.
Reading /lib/ld-linux-aarch64.so.1 from remote target...
Reading symbols from target:/lib/ld-linux-aarch64.so.1...
Reading /lib/ld-2.30.so from remote target...
Reading /lib/.debug/ld-2.30.so from remote target...
Reading /lib/.debug/ld-2.30.so from remote target...
Reading symbols from target:/lib/.debug/ld-2.30.so...
0x0000fffff7fcf080 in _start () from target:/lib/ld-linux-aarch64.so.1
(gdb)

5.列举代码
(gdb) l
12 }
13
14 void A(int *p)
15 {
16     B(p);
17 }
18
19 void A2(int *p)
20 {
21     C(p);
(gdb)

此时就可以根据需求进行调试了
6.下面是几个常用的命令
(1)l :列出所有源代码
(2)break main :在main处打断点
         break test_debug.c:11 :在test_debug.c的11行打断点
(3)c :运行到断点处
(4)step :单步执行
(5)next :单步执行,但是step会进入函数里面,但是next不会
(6)print a :打印a这个变量的值
(7)quit :退出,输入此命令则开发板上的gdbserver也退出


已解决

未解决

只是看看

最新评论

QQ|小黑屋| 飞凌嵌入式 ( 冀ICP备12004394号-1 )

GMT+8, 2025-7-6 02:17

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

返回顶部