20150502 调试分析之 使用gdb远程调试ARM开发板
2015-05-02 Lover雪儿
今天我们要学习的是使用gdb和gdbserver来远程调试开发板程序.
下面是本人的一些具体步骤:
|
下载gdb-7.9.tar.gz地址: http://ftp.gnu.org/gnu/gdb/gdb-7.9.tar.gz 安装gdb tar -jxvf gdb-7.9.tar.bz2 ./configure -target=arm-none-linux-gnueabi --prefix=/home/study/nfs_home/rootfs_imx257/arm-linux-gdb –program-prefix=arm-none-linux-gnueabi- make make install 安装gdbserver ./configure -target=arm-none-linux-gnueabi --prefix=/home/study/nfs_home/rootfs_imx257/arm-linux-gdbserver --host=arm-none-linux-gnueabi make make install |
具体安装步骤如下:
|
编译安装gdb root@Lover雪:/home/study/nfs_home/system# tar -jxvf gdb-7.9.tar.bz2 root@Lover雪:/home/study/nfs_home/system# cd gdb-7.9 root@Lover雪:/home/study/nfs_home/system/gdb-7.9# mkdir ../../rootfs_imx257/arm-linux-gdb root@Lover雪:/home/study/nfs_home/system/gdb-7.9# ./configure -target=arm-none-linux-gnueabi --prefix=/home/study/nfs_home/rootfs_imx257/arm-linux-gdb --program-prefix=arm-none-linux-gnueabi- checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking target system type... arm-none-linux-gnueabi ########################### root@Lover雪:/home/study/nfs_home/system/gdb-7.9# make root@Lover雪:/home/study/nfs_home/system/gdb-7.9# make install 安装完毕发现多了一些文件夹 root@Lover雪:/home/study/nfs_home/system/gdb-7.9# ll ../../rootfs_imx257/arm-linux-gdb/ 总用量 24 drwxr-xr-x 6 root root 4096 5月 2 06:34 ./ drwxrwxrwx 14 root root 4096 5月 2 06:11 ../ drwxr-xr-x 2 root root 4096 5月 2 06:34 bin/ drwxr-xr-x 3 root root 4096 5月 2 06:34 include/ drwxr-xr-x 2 root root 4096 5月 2 06:34 lib/ drwxr-xr-x 5 root root 4096 5月 2 06:34 share/ root@Lover雪:/home/study/nfs_home/system/gdb-7.9# root@Lover雪:/home/study/nfs_home/system/gdb-7.9# cd gdb ########################### 编译安装gdbserver root@Lover雪:/home/study/nfs_home/system/gdb-7.9/gdb# cd gdbserver/ root@Lover雪:/home/study/nfs_home/system/gdb-7.9/gdb/gdbserver# mkdir /home/study/nfs_home/rootfs_imx257/arm-linux-gdbserver root@Lover雪:/home/study/nfs_home/system/gdb-7.9/gdb/gdbserver# ./configure -target=arm-none-linux-gnueabi --prefix=/home/study/nfs_home/rootfs_imx257/arm-linux-gdbserver --host=arm-none-linux-gnueabi configure: WARNING: If you wanted to set the --build type, don't use --host. If a cross compiler is detected then cross compile mode will be used. checking whether to enable maintainer-specific portions of Makefiles... no checking for arm-none-linux-gnueabi-gcc... arm-none-linux-gnueabi-gcc checking for C compiler default output file name... a.out ########################### root@Lover雪:/home/study/nfs_home/system/gdb-7.9# make root@Lover雪:/home/study/nfs_home/system/gdb-7.9# make install 进入安装目录运行gdb查看版本 loverxueer@Lover雪:/home/study/nfs_home/rootfs_imx257$ ./arm-linux-gdb/bin/arm-none-linux-gnueabi-gdb GNU gdb (GDB) 7.9 Copyright (C) 2015 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-unknown-linux-gnu --target=arm-none-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". (gdb) q 进入开发板目录,再开发板上运行gdbserver查看版本 root@EasyARM-iMX257 /mnt/nfs/rootfs_imx257# ./arm-linux-gdbserver/bin/arm-none-l inux-gnueabi-gdbserver --version GNU gdbserver (GDB) 7.9 Copyright (C) 2015 Free Software Foundation, Inc. gdbserver is free software, covered by the GNU General Public License. This gdbserver was configured as "arm-none-linux-gnueabi" root@EasyARM-iMX257 /mnt/nfs/rootfs_imx257# |
使用gdb和gdbserver远程调试程序
附上应用程序gdb_test.c
1 #include <stdio.h> 2 3 char *p = "hello,this is test gdb & gdbserver "; 4 5 void delay(int m) 6 { 7 int n; 8 while(m--) 9 for(n =0; n<100; n++); 10 } 11 12 void print(char *p, int cnt) 13 { 14 printf("%s cnt=%d\n",p,cnt); 15 } 16 17 int main(void) 18 { 19 int cnt = 0; 20 while(1) 21 { 22 cnt++; 23 print(p,cnt); 24 delay(100000); 25 } 26 return 0; 27 }