linux下的配置
Ubuntu 9.10,
Eclipse ---Version: 3.5.1 Build id: M20090917-0800
gdb版本(gdbserver版本和gdb版本一样)
book@book-desktop:~/sgy/second_video/j_gdb$ /bin/arm-linux-gdb
GNU gdb (GDB) 7.8.1
Copyright (C) 2014 Free Software Foundation, Inc.
使用的源文件test_debug.c
#include <stdio.h>
void C(int *p)
{
*p = 0x12;
}
void B(int *p)
{
C(p);
}
void A(int *p)
{
B(p);
}
void A2(int *p)
{
C(p);
}
int main(int argc, char **argv)
{
int a;
int *p = NULL;
A2(&a); // A2 > C
printf("a = 0x%x\n", a);
A(p); // A > B > C
return 0;
}
编译应用程序
book@book-desktop:~/sgy/second_video/j_gdb$ arm-linux-gcc -g -o test_debug test_debug.c
新建工程也可以参考网上的教程,如果没有c project这个选项,需要安装一个cdt的插件
windows下的操作
arm-2014.05-29-arm-none-linux-gnueabi.exe
Eclipse IDE for C/C++ Developers
Version: Helios Service Release 2
Build id: 20110301-1815
$ arm-none-linux-gnueabi-gdb.exe
GNU gdb (Sourcery CodeBench Lite 2014.05-29) 7.7.50.20140217-cvs
Copyright (C) 2014 Free Software Foundation, Inc.
linux上会有报一个错,应该是建立的是makefile工程,在进行debug的时候会自己去make我们的工程,这个问题应该不影响.见windows下的屏蔽错误.
效果示意图
windows上的操作
步骤是一样的,区别在于gdb工具得选windows上的exe文件,这个gdb版本可能跟gdbserver版本不一样,网上说会有问题出现,但是这样也能使用.后续出问题再说吧!
这里不要make工程,就不会报错了
让程序在开发板上直接运行,当它发生错误时,令它产生core dump文件
然后使用gdb根据core dump文件找到发生错误的地方
在ARM板上:
- ulimit -c unlimited
- 执行应用程序 : 程序出错时会在当前目录下生成名为core的文件
在ubuntu下执行命令
book@book-desktop:~/sgy/second_video/j_gdb$ /bin/arm-linux-gdb ./test ./core
GNU gdb (GDB) 7.8.1
Copyright (C) 2014 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".
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"...
Reading symbols from ./test...done.
[New LWP 775]
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'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x000084ac in C (p=0x0) at test_debug.c:6
6 *p = 0x12;
(gdb)
(gdb) bt
#0 0x000084ac in C (p=0x0) at test_debug.c:6
#1 0x000084d0 in B (p=0x0) at test_debug.c:12
#2 0x000084f0 in A (p=0x0) at test_debug.c:17
#3 0x00008554 in main (argc=1, argv=0xbebb7ec4) at test_debug.c:34
Cannot access memory at address 0x0
序号越大是最上层的程序,3调用2,2调用1