1、cd gdb/gdbserver/ 2、配置: ./configure --target=arm-linux --host=arm-linux 3、编译: make CC=arm-linux-gcc
2.3、编译GDBServer的时候会出现以下错误
linux-arm-low.c: In function `arm_stopped_by_watchpoint":linux-arm-low.c:642: error: `PTRACE_GETSIGINFO" undeclared (first use in this function)linux-arm-low.c:642: error: (Each undeclared identifier is reported only oncelinux-arm-low.c:642: error: for each function it appears in.) 该错误是因为找不到PTRACE_GETSIGINFO宏,导致编译错误。我们到交叉编译链去搜索一下,我们交叉编译地址为 /work/tools/gcc-3.4.5-glibc-2.3.6# cd/work/tools/gcc-3.4.5-glibc-2.3.6# grep "PTRACE_GETSIGINFO" * -nRarm-linux/sys-include/linux/ptrace.h:27:#define PTRACE_GETSIGINFO0x4202arm-linux/include/linux/ptrace.h:27:#define PTRACE_GETSIGINFO0x4202distributed/arm-linux/sys-include/linux/ptrace.h:27:#define PTRACE_GETSIGINFO0x4202distributed/arm-linux/include/linux/ptrace.h:27:#define PTRACE_GETSIGINFO0x4202 可以看到,在交叉编译链里面,定义了PTRACE_GETSIGINFO宏为0x4202,头文件为include<linux/ptrace.h>中。 有两种解决办法,可任选其一: ① 在linux-arm-low.c中直接添加宏 #define PTRACE_GETSIGINFO 0x4202 ② 在linux-arm-low.c中将#include <sys/ptrace.h> 更改为 #include <linux/ptrace.h> 再次编译,编译通过。
让程序在开发板上直接运行,当它发生错误时,令它产生core dump文件,然后使用gdb根据core dump文件找到发生错误的地方 在ARM板上: 4.1、 ulimit -c unlimited 4.2、 执行应用程序 : 程序出错时会在当前目录下生成名为core的文件 在PC上: 4.3、首先将core文件拷贝到pc机上 然后:/bin/arm-linux-gdb ./test_debug ./core 打印出如下信息: GNU gdb (GDB) 7.4Copyright (C) 2012 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=i686-pc-linux-gnu --target=arm-linux".For bug reporting instructions, please see:<http://www.gnu.org/software/gdb/bugs/>...Reading symbols from /home/share/jz2440/test_debug...done.[New LWP 748]warning: `/lib/libc.so.6": Shared library architecture unknown is not compatible with target architecture arm.warning: `/lib/ld-linux.so.2": Shared library architecture unknown is not compatible with target architecture arm.Core was generated by `./test_debug".Program terminated with signal 11, Segmentation fault.#00x000084ac in C (p=0x0) at test_debug.c:66 *p = 0x12; 4.4、bt:可以显示调用关系 #00x000084ac in C (p=0x0) at test_debug.c:6#10x000084d0 in B (p=0x0) at test_debug.c:12#20x000084f0 in A (p=0x0) at test_debug.c:17#30x00008554 in main (argc=1, argv=0xbeb32eb4) at test_debug.c:34GDB调试程序用法 http://www.linuxidc.com/Linux/2013-06/86044.htmGDB+GDBserver无源码调试Android 动态链接库的技巧 http://www.linuxidc.com/Linux/2013-06/85936.htm使用hello-gl2建立ndk-GDB环境(有源码和无源码调试环境) http://www.linuxidc.com/Linux/2013-06/85935.htm在Ubuntu上用GDB调试printf源码 http://www.linuxidc.com/Linux/2013-03/80346.htmLinux下用GDB调试可加载模块 http://www.linuxidc.com/Linux/2013-01/77969.htm强大的C/C++ 程序调试工具GDB http://www.linuxidc.com/Linux/2016-09/135171.htmLinux GDB调试 详述 http://www.linuxidc.com/Linux/2016-11/137505.htm使用GDB命令行调试器调试C/C++程序 http://www.linuxidc.com/Linux/2014-11/109845.htmGDB调试命令总结 http://www.linuxidc.com/Linux/2016-08/133988.htmGDB调试工具入门 http://www.linuxidc.com/Linux/2016-09/135168.htmGDB 的详细介绍:请点这里 GDB 的下载地址:请点这里本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-01/139027.htm