/* test.c */
#include stdio.h>
int main()
{
int i;
i = 10;
printf("i = %d\n", i);
return 0;
}
4、编译可运行于目标板的机器代码,并下载到目标机上
如果目标板是arm,那么应该这么编译:
shell> arm-linux-gcc -g -o test test.c
我这里直接这么编译就可以拉:
shell> gcc -g -o test test.c编译好以后就要下载到目标机上,并且在宿主机上也要保留一份。
5、在目标机上运行gdbserver服务
shell> gdbserver 127.0.0.1:2345 test
Process test created; pid = 12655
Listening on port 2345
6、在宿主机上发起连接和调试
shell> gdb test
GNU gdb 6.4-debian
Copyright 2005 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) target remote 127.0.0.1:2345
Remote debugging using 127.0.0.1:2345
0xb7f4d790 in ?? ()
这个时候我们可以看到目标机那边有了出现了下面的信息:
Remote debugging from host 127.0.0.1
说明连接成功,下面就可以在宿主机上进行调试拉。这个调试和我们平时在桌面系统进行gdb调试是一样的。
比如列出源代码信息:
(gdb) l
1 /* test.c */
2 #include
3
4 int main()
5 {
6 int i;
7
8 i = 10;
9
10 printf("i = %d\n", i);
如果想进行内核调试的话,可以用kgdb。内核调试步骤大概如下:
1、在http://kgdb.linsyssoft.com/downloads上下载当前使用内核的kgdb patch,在主机端安装patch:
shell> cd /path/to/kernel/source
shell> patch -p1 -i /path/to/patch/file
运行make menuconfig命令确保kgdb选项中的KERNEL_HACKING被选上,重新编译内核,把新生成的内核镜像zImage复制到开发板。
2、在启动开发板上的内核前需要设置:gdb gdbttyS=0 gdbbaud=38400。这样系统启动的时候将在创建init内核线程之前听下来,等待主机的gdb连接。
3、在主机端建立和目标机(开发板)的KGDB调试接口的连接:
shell> cd /path/to/kernel/source
shell> gdb vmlinux
gdb: set remotebaud 38400
gdb: target remote /dev/ttyS0
之后的过程就和普通gdb调试类似拉。这里的KGDB和GDBSERVER一样也是一个stub哦。在目标机端用来和主机端的gdb调试器进行通信,从而实现远程调试。
说明:以上内容为《嵌入式系统开发原理与实践》第7章学习笔记。