您的位置:首页 > 其它

使用交叉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)



      
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息