linux下的dump调试

  Linux下的dump文件一般称为core文件 ,可以用来记录程序崩溃前的线程callstack信息,内存信息等,可以作为排错的一种辅助手段。生存的core大小可以限制,保存的内容也可以灵活的选择,因此在MID上也可以使用。

一 core文件的生成

  1 查看core信息

     输入 ulimit -a,显示如下:

core file size          (blocks, -c) 1024
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 20
file size               (blocks, -f) unlimited
pending signals                 (-i) 16382
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) unlimited
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited


    如果core file size为0的话,则输入ulimit -c 1024, 表示设置成1024个block,如果超过这个值就不再写core文件


   2 测试程序如下

   

#include <stdio.h>

int test()

{

   int * p = NULL;              

   printf("%d /n",*p);

}

int main()

{

 test();

}

在ubuntu上编译程序:

gcc –Wall  -g  test.c 

加上可执行权限

chmod +x a.out

执行 ,在同级目录下生成了一个core文件


拷贝core文件到本机,执行

gdb --core=core

显示如下:

GNU gdb 6.8-debian
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 "x86_64-linux-gnu".
(no debugging symbols found)
Core was generated by `./a.out'.
Program terminated with signal 11, Segmentation fault.
[New process 18079]
#0  0x0000000000400520 in ?? ()
(gdb)

接下来指定可执行文件(含调试信息)

(gdb) file ./a.out

显示如下:

Reading symbols from /home/share/test/a.out...done.

执行(gdb) bt,显示如下:

#0  0x0000000000400520 in just_a_test () at hello.c:8
#1  0x0000000000400546 in main () at hello.c:15

即定位到相应的错误行




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值