使用交叉gdb 调试 coredump
2012-04-12 16:35
375 查看
准备交叉gdb,即使用你的交叉开发工具编译出来的GDB:
注意一定要是交叉gdb,如果你看到
[root@yjypmypm Debug]# arm-hismall-linux-gdb hello core
GNU gdb 6.3.50.20050627-cvs
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome 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-hisi-linux"...
GDB can't read core files on this machine.
(gdb)
就说明所使用的gdb 和core 不是同一体系统结构的。
二 准备测试程序如下
hello.c
#include <stdio.h>
#include <stdlib.h>
uint uninitVal;
uint initVal=0x5a5a5a5a;
static int SegFault(int *p){
int *ptr=p;
*ptr=100;
return 0;
}
static int invokSegFault(int *p)
{
SegFault(p);
}
int main(int argc, char** argv) {
int i=0;
printf("hello world\r\n");
printf("uninitVal address 0x%X\r\n",&uninitVal);
printf("initVal address 0x%X\r\n",&initVal);
printf("main address 0x%X\r\n",&main);
write(2,"ddddddddd");
for(i=0;i<10;i++){
printf ("current :->>[%d]<<-\r\n",i);
uninitVal=i;
}
SegFault(&uninitVal);
printf("SegFault 1");
invokSegFault(0);
printf("SegFault 0");
return (42);
}
使用 -g参数编译 产生调试信息。
将产生的二进制下载到目标板上。
以下操作在目标板上:
打开coredump
使用命令 :
ulimit -c unlimited
运行程序 ,结果如下:
/mnt $ ./hello
hello world
uninitVal address 0x107E8
initVal address 0x107DC
main address 0x8510
ddcurrent :->>[0]<<-
current :->>[1]<<-
current :->>[2]<<-
current :->>[3]<<-
current :->>[4]<<-
current :->>[5]<<-
current :->>[6]<<-
current :->>[7]<<-
current :->>[8]<<-
current :->>[9]<<-
Segmentation fault (core dumped) //已生成 coredump 文件 core
使用gdb读取coredump
/mnt $ gdb hello core
GNU gdb 6.8
Copyright (C) 2008 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 "arm-hismall-linux"...
Reading symbols from /lib/libc.so.0...done.
Loaded symbols for /lib/libc.so.0
Reading symbols from /lib/ld-uClibc.so.0...done.
Loaded symbols for /lib/ld-uClibc.so.0
Core was generated by `./hello'. //调用时用的命令。
Program terminated with signal 11, Segmentation fault. //可以看到转储原因 。
[New process 515]
#0 0x000084e0 in SegFault (p=0x0) at ../src/hello.c:19
19 ../src/hello.c: No such file or directory.
in ../src/hello.c
(gdb)
(gdb)where //查看在发生转储前的栈
#0 0x000084e0 in SegFault (p=0x0) at ../src/hello.c:19
#1 0x0000850c in invokSegFault (p=0x0) at ../src/hello.c:26
#2 0x000085bc in main (argc=1, argv=0xbe91ee74) at ../src/hello.c:45
(gdb)
(gdb)frame 2
//查看某一个栈
#2 0x000085bc in main (argc=1, argv=0xbe91ee74) at ../src/hello.c:45
45 in ../src/hello.c
(gdb)
注意一定要是交叉gdb,如果你看到
[root@yjypmypm Debug]# arm-hismall-linux-gdb hello core
GNU gdb 6.3.50.20050627-cvs
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome 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-hisi-linux"...
GDB can't read core files on this machine.
(gdb)
就说明所使用的gdb 和core 不是同一体系统结构的。
二 准备测试程序如下
hello.c
#include <stdio.h>
#include <stdlib.h>
uint uninitVal;
uint initVal=0x5a5a5a5a;
static int SegFault(int *p){
int *ptr=p;
*ptr=100;
return 0;
}
static int invokSegFault(int *p)
{
SegFault(p);
}
int main(int argc, char** argv) {
int i=0;
printf("hello world\r\n");
printf("uninitVal address 0x%X\r\n",&uninitVal);
printf("initVal address 0x%X\r\n",&initVal);
printf("main address 0x%X\r\n",&main);
write(2,"ddddddddd");
for(i=0;i<10;i++){
printf ("current :->>[%d]<<-\r\n",i);
uninitVal=i;
}
SegFault(&uninitVal);
printf("SegFault 1");
invokSegFault(0);
printf("SegFault 0");
return (42);
}
使用 -g参数编译 产生调试信息。
将产生的二进制下载到目标板上。
以下操作在目标板上:
打开coredump
使用命令 :
ulimit -c unlimited
运行程序 ,结果如下:
/mnt $ ./hello
hello world
uninitVal address 0x107E8
initVal address 0x107DC
main address 0x8510
ddcurrent :->>[0]<<-
current :->>[1]<<-
current :->>[2]<<-
current :->>[3]<<-
current :->>[4]<<-
current :->>[5]<<-
current :->>[6]<<-
current :->>[7]<<-
current :->>[8]<<-
current :->>[9]<<-
Segmentation fault (core dumped) //已生成 coredump 文件 core
使用gdb读取coredump
/mnt $ gdb hello core
GNU gdb 6.8
Copyright (C) 2008 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 "arm-hismall-linux"...
Reading symbols from /lib/libc.so.0...done.
Loaded symbols for /lib/libc.so.0
Reading symbols from /lib/ld-uClibc.so.0...done.
Loaded symbols for /lib/ld-uClibc.so.0
Core was generated by `./hello'. //调用时用的命令。
Program terminated with signal 11, Segmentation fault. //可以看到转储原因 。
[New process 515]
#0 0x000084e0 in SegFault (p=0x0) at ../src/hello.c:19
19 ../src/hello.c: No such file or directory.
in ../src/hello.c
(gdb)
(gdb)where //查看在发生转储前的栈
#0 0x000084e0 in SegFault (p=0x0) at ../src/hello.c:19
#1 0x0000850c in invokSegFault (p=0x0) at ../src/hello.c:26
#2 0x000085bc in main (argc=1, argv=0xbe91ee74) at ../src/hello.c:45
(gdb)
(gdb)frame 2
//查看某一个栈
#2 0x000085bc in main (argc=1, argv=0xbe91ee74) at ../src/hello.c:45
45 in ../src/hello.c
(gdb)
相关文章推荐
- 使用 GDB 调试 CoreDump 文件
- gdb调试coredump(使用篇)
- gdb调试coredump(使用篇)
- 交叉编译和交叉调试环境搭建及---环境变量使用----及GDB安装
- gdb调试要点以及arm-linux交叉工具的使用
- GDB使用之调试CoreDump
- ubunut交叉调试GDB的介绍和使用
- (zz)使用GDB调试Coredump文件
- 转载_Linux core dump file详解及使用GDB调试Coredump文件
- Linux下交叉编译gdb,gdbserver+gdb的使用以及通过gdb调试core文件
- 当debug信息单独存放为一个文件时使用gdb调试CoreDump
- Linux下交叉编译gdb,gdbserver+gdb的使用以及通过gdb调试core文件
- gdb调试工具的使用
- 【工具】GDB调试精粹及使用实例
- 使用gdbserver调试arm应用程序
- Linux下gdb调试工具的使用
- 使用GDB调试python调用的C++共享库
- 使用GDB调试Coredump文件
- 使用 GDB 调试多进程程序
- arm-linux-gdb 交叉编译工具的安装使用