1、实验目的
1.了解和掌握GDB的命令和使用方法;
2.了解远程调试的概念,掌握远程调试的方法;
3.学会使用GDB调试程序;
2、实验环境
预装redhat9.0(内核版本2.4.x)的PC机一台,XScale嵌入式实验箱一台(已构建嵌入式linux系统),以太网线一根,交叉编译工具链。
3、实验步骤
对给定的一个有错误的程序源文件,使用gcc编译,并使用gdb进行本地调试,知道程序
正确为止。
A.解压tar vzxf gdb-5.3.tar.gz
[root @localhost ~]# mkdir XSBASE/xsbase/temp
[root @localhost ~]# cp XSBASE/xsbase/GDB/gdb-5.3.tar.gz /XSBASE/xsbase/temp
[root @localhost ~]# cd XSBASE/xsbase/temp
[root @localhost temp]# tar zvxf gdb-5.3.tar.gz
[root @localhost temp]# cd gdb-5.3
[root @localhost gdb-5.3]# ./configure --target=arm-linux --prefix=/usr/local/arm-gdb -v
[root @localhost gdb-5.3]# make
[root @localhost gdb-5.3]# make install
B.配置选项
[root @localhost gdb-5.3]# vi ~/.bash_profile
添加路径:
[root @localhost gdb-5.3]# source ~/.bash_profile
设置宿主机和目标版IP
[root @localhost gdb-5.3]# ifconfig eth0 192.168.0.77
[root @XSBASE /root]$ ifconfig eth0 192.168.0.88
C.写一个有问题的代码(此处略,待gdb调试的时候把程序list出来);
[root @localhost ~]# mkdir XSBASE/xsbase/temp
[root @localhost ~]# cd XSBASE/xsbase/temp
[root @localhost temp]# vi test
把程序敲好之后,继续执行命令:
[root @localhost temp]# arm-linux-gcc -o test_hehui test.c
修改交叉编译工具链中gdb的Makefile,生成交叉编译的gdbserver;
[root @localhost gdb-5.3]# vi gdb/gdbserver/config.h
找到要修改的行:#define HAVE_SYS_REG_H 1
注释该行://#define HAVE_SYS_REG_H 1
将gdbserver下载到目标版上。
XSBase255> boot
[root @XSBASE /root]$ tfp 192.168.0.77
ftp>cd /
ftp>get /XSBASE/xsbase/GDB/gdb-5.3.tar.gz/XSBASE/xsbase/temp/gdb-5.3/gdb/gdbserver/gdbserver
④使用target remote实现远程连接;
目标板:
[root @XSBASE /root]$ ./gdbserver 192.168.0.77
宿主机:
[root @localhost temp]# ./arm-linux-gdb test_hehui
[root @localhost temp]# target remote 192.168.0.88:1234
⑤调试程序,直到程序正确为止;
4、思考题
1.嵌入式开发中为什么需要使用远程调试?
答:使用GDB进行远程调试时运行在宿主机上的GDB通过串口或TCP连接与运行在目标机上的调试插桩stub以GDB标准远程串行协议协同工作从而实现对目标机上的系统内核和上层应用的监控和调试功能调试stub是嵌入式系统中的一段代码作为宿主机GDB和目标机调试程序间的一个媒介而存在GDB远程调试结构。
2.gdb中怎么设断点?怎么查看变量的值?
答:gdb中使用b设置断点。使用p查看变量的值。
3.远程调试使用什么命令建立远程连接?
答:目标板:
[root @XSBASE /root]$ ./gdbserver 192.168.0.77
宿主机:
[root @localhost temp]# ./arm-linux-gdb test_hehui
[root @localhost temp]# target remote 192.168.0.88:1234下载本文