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;
}
編譯應(yīng)用程序
book@book-desktop:~/sgy/second_video/j_gdb$ arm-linux-gcc -g -o test_debug test_debug.c
新建工程也可以參考網(wǎng)上的教程,如果沒(méi)有c project這個(gè)選項(xiàng),需要安裝一個(gè)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上會(huì)有報(bào)一個(gè)錯(cuò),應(yīng)該是建立的是makefile工程,在進(jìn)行debug的時(shí)候會(huì)自己去make我們的工程,這個(gè)問(wèn)題應(yīng)該不影響.見(jiàn)windows下的屏蔽錯(cuò)誤.
效果示意圖
windows上的操作
步驟是一樣的,區(qū)別在于gdb工具得選windows上的exe文件,這個(gè)gdb版本可能跟gdbserver版本不一樣,網(wǎng)上說(shuō)會(huì)有問(wèn)題出現(xiàn),但是這樣也能使用.后續(xù)出問(wèn)題再說(shuō)吧!
這里不要make工程,就不會(huì)報(bào)錯(cuò)了
讓程序在開(kāi)發(fā)板上直接運(yùn)行匆背,當(dāng)它發(fā)生錯(cuò)誤時(shí),令它產(chǎn)生core dump文件
然后使用gdb根據(jù)core dump文件找到發(fā)生錯(cuò)誤的地方
在ARM板上:
- ulimit -c unlimited
- 執(zhí)行應(yīng)用程序 : 程序出錯(cuò)時(shí)會(huì)在當(dāng)前目錄下生成名為core的文件
在ubuntu下執(zhí)行命令
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
序號(hào)越大是最上層的程序,3調(diào)用2,2調(diào)用1