搭建交叉调试环境Arm-Linux-Gdb与gdbserver

gdb-6.5使用了autoconf/automake。因此,通过设置configure脚本的–target,–host,–prefix参数就可以方便的移植到别的平台。

–target指定了需要调试的目标机环境,一般设置为交叉编译器的前缀,比如–target=arm-linux, –target=mips-linux,–target=armv5-linux-uclibc, –target的缺省值为i386-linux, 也就是i386PC机

–host指定编译后的文件的运行环境,取值可以是i386-linux或者交叉编译器的前缀,缺省为i386-linux

–prefix指定要安装的目录。@ubuntu:~/downloads$ tar jxvf gdb-6.5.tar.bz2@ubuntu:~/downloads$ cd gdb-6.5@ubuntu:~/downloads/gdb-6.5$ ./configure –target=arm-linux –prefix=/opt/crosstool/arm-gdb@ubuntu:~/downloads/gdb-6.5$ make@ubuntu:~/downloads/gdb-6.5$ sudo make install@ubuntu:~/downloads/gdb-6.5$ ls /opt/crosstool/arm-gdb/binarm-linux-gdb arm-linux-gdbtui arm-linux-run安装后,在/opt/crosstool/arm-gdb/bin可以看到arm-linux-gdb、arm-linux-gdbtui、arm-linux-run等配置环境变量@ubuntu:~/downloads/gdb-6.5$ vi ~/.bashrc在文件最后加上if [ -d /opt/crosstool/arm-gdb/bin ]; thenPATH=/opt/crosstool/arm-gdb/bin:$PATHfi使刚配置的环境变量生效@ubuntu:~/downloads/gdb-6.5$ source ~/.bashrc3、编译gdbserver@ubuntu:~/downloads/gdb-6.5$ cd ../gdb-6.5/gdb/gdbserver@ubuntu:~/downloads/gdb-6.5/gdb/gdbserver$ ./configure –target=arm-linux –host=arm-linux@ubuntu:~/downloads/gdb-6.5/gdb/gdbserver$ make CC=/opt/crosstool/gcc-4.1.1-glibc-2.3.2/arm-linux/bin/arm-linux-gcc #这里是交叉编译器的路径@ubuntu:~/downloads/gdb-6.5/gdb/gdbserver$ ls可以看到刚刚生成的gdbserver,将其拷贝到nfs共享目录下,因为gdbserver最终是在目标机上运行。@ubuntu:~/downloads/gdb-6.5/gdb/gdbserver$ cp gdbserver ~/arm2410s4、拷贝libthread库(这一步不做的话,运行gdbserver会出错!)@ubuntu:~/downloads/gdb-6.5/gdb/gdbserver$ cd /opt/crosstool/gcc-4.1.1-glibc-2.3.2/arm-linux/arm-linux/lib@ubuntu:/opt/crosstool/gcc-4.1.1-glibc-2.3.2/arm-linux/arm-linux/lib$ ls -l libthread_db*-rwxr-xr-x 1 www.linuxidc.com 28092 2009-12-29 18:51 libthread_db-1.0.solrwxrwxrwx 1 www.linuxidc.com 17 2009-12-29 18:51 libthread_db.so -> libthread_db.so.1lrwxrwxrwx 1 www.linuxidc.com 19 2009-12-29 18:51 libthread_db.so.1 -> libthread_db-1.0.so将libthread_db-1.0.so拷贝到nfs共享目录下,我的是~/arm2410s,~/arm2410s/lib是我的外部库存放位置(我的跟文件系统是cramfs,无法直接拷贝到目标板的/lib)@ubuntu:/opt/crosstool/gcc-4.1.1-glibc-2.3.2/arm-linux/arm-linux/lib$ mkdir ~/arm2410s/lib@ubuntu:/opt/crosstool/gcc-4.1.1-glibc-2.3.2/arm-linux/arm-linux/lib$ cp libthread_db-1.0.so ~/arm2410s/lib@ubuntu:/opt/crosstool/gcc-4.1.1-glibc-2.3.2/arm-linux/arm-linux/lib$ cd ~/arm2410s/lib@ubuntu:~/arm2410s/lib$ ln -s libthread_db-1.0.so libthread_db.so.1@ubuntu:~/arm2410s/lib$ ln -s libthread_db-1.0.so libthread_db.so然后在你在开发板上运行gdbserver前,先设置一下库文件搜索路径LD_LIBRARAY_PATHminicom下root@:/# mount -t nfs -o intr,nolock,rsize=1024,wsize=1024 192.168.1.123:/home/www.linuxidc.com/arm2410s /tmproot@:/# export LD_LIBRARAY_PATH=${LD_LIBRARAY_PATH}:/tmp/lib若根文件系统非只读文件系统,那你大可以直接将libthread_db-1.0.so拷贝到开发板的/lib或/usr/lib,然后建立相应的符合链接4、测试写一个程序,用arm-linux-gcc -g 编译, 放到nfs共享目录/home/www.linuxidc.com/arm2410s目录下,我的程序名为gprsminicom下root@:/# cd /tmproot@:/tmp# ./gdbserver 192.168.1.123:6666 gprsProcess gprs created; pid = 825Listening on port 6666其中,gpbserver使用方法:

gpbserver 主机ip地址:通信端口 要调试的程序 【程序的命令行参数】

程序的命令行参数是可选的

启动一个终端,运行如下命令@ubuntu:~$ cd arm2410s/@ubuntu:~/arm2410s$ arm-linux-gdb gprsGNU gdb 6.5Copyright (C) 2006 Free Software Foundation, Inc.GDB is free software, covered by the GNU General Public License, and you arewelcome 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 “–host=i686-pc-linux-gnu –target=arm-linux”…(gdb) target remote 192.168.1.21:6666 #连接目标:target remote 开发板ip地址:通信端口Remote debugging using 192.168.1.21:66660×40001330 in ?? ()(gdb)此时,开发板终端可以看到应答信息Remote debugging from host 192.168.1.123root@:/tmp# gdbserver 192.168.1.123:6666 gprsProcess gprs created; pid = 825Listening on port 6666Remote debugging from host 192.168.1.123现在就可以通过l查看程序源码, 然后b设置断点了;运行则用命令c。

5、常用的GDB命令: load:装入一个程序 symbol-file:装入符号库文件,可以是用-g参数编译的可执行文件。 f(ile):指定一个可执行文件进行调试,gdb将读取些文件的调试讯息,,如f a.exe l(ist):列程序出源文件 r(un) :装载完要调试的可执行文件后,可以用run命令运行可执行文件 b(reak):设置断点(break point),如b 25,则在源程序的第25行设置一个断点,当程序执行到第25行时,就会产生中断;也可以使用b funcname,funcname为函数的名称,当程序运行到断点停下来时, c(ontinue):c命令可以另中断的程序继续执行,直到下一个中断点或程序结束 p(rint):输入某个变量的值,如程序定义了一个int a的就是,p a就会输出aa的当前值 n(ext):程序执行到断点时中断执行,可以用n指令进行单步执行 s(tep):程序执行到断点时中断执行,可以用s指令进行单步执行进某一函数 q(uit):退出GDB使用简化命令,如l,和完整命令list,效果是一样的。

6、需要注意的问题

1)、简化命令f不一定能用,gdb会提示(gdb) f gprsNo symbol table is loaded. Use the “file” command.可用完整命令file代替

人生的大部份时间里,承诺同义词是束缚,奈何我们向往束缚。

搭建交叉调试环境Arm-Linux-Gdb与gdbserver

相关文章:

你感兴趣的文章:

标签云: