LINUX调试

在linux调试时经常碰到堆栈错误,我们可以使用core文件对问题进行定位,

使用命令ulimit -c 1024设置core文件最大值;

设置后使用ulimit -c 查看设置的值是否生效没有生效显示为0;设置成功为1024;

不同系统生成的core文件命名不同,centos为core.pid,ubuntu为core等

生成后使用命令gdb  profilename core;

就会进入到gdb命令中,使用bt命令查看堆栈调用信息。


具体命令使用如下例子:

dalek@ubuntu:~/test/core$ vim tst.c



#include <stdio.h>
#include <stdlib.h>


struct tt 
{
int i ;
int j;
};
int main()
{


int i = 0;
struct tt t;
memset(&t, 0, sizeof(struct tt));


struct tt *p = &t;


p = NULL;
p->i = 0;




return 0;
}


dalek@ubuntu:~/test/core$ gcc tst.c 
tst.c: In function 鈥榤ain鈥


                             tst.c:14:1: warning: incompatible implicit declaration of built-in function 鈥榤emset鈥[enabled by default]
ls^Hdalek@ubuntu:~/test/core$ 
dalek@ubuntu:~/test/core$ ls
a.out  tst.c
dalek@ubuntu:~/test/core$ ulimit -c
0
dalek@ubuntu:~/test/core$ ulimit -c 1024
dalek@ubuntu:~/test/core$ ulimit -c
1024
dalek@ubuntu:~/test/core$ ./a.out 
Segmentation fault (core dumped)
dalek@ubuntu:~/test/core$ ls 
a.out  core  tst.c
dalek@ubuntu:~/test/core$ ll
ll: command not found
dalek@ubuntu:~/test/core$ ls -l
total 208
-rwxrwxr-x 1 dalek dalek   7121 Jun 28 05:37 a.out
-rw-r----- 1 dalek dalek 200704 Jun 28 05:37 core
-rw-rw-r-- 1 dalek dalek    198 Jun 28 05:36 tst.c
dalek@ubuntu:~/test/core$ gdb -c core 
GNU gdb (Ubuntu/Linaro 7.4-2012.02-0ubuntu2) 7.4-2012.02
Copyright (C) 2012 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 "i686-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>.
[New LWP 11299]
Core was generated by `./a.out'.
Program terminated with signal 11, Segmentation fault.
#0  0x080483e1 in ?? ()
(gdb) bt
#0  0x080483e1 in ?? ()
#1  0x00000000 in ?? ()
(gdb) q
dalek@ubuntu:~/test/core$ gdb a.out core 
GNU gdb (Ubuntu/Linaro 7.4-2012.02-0ubuntu2) 7.4-2012.02
Copyright (C) 2012 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 "i686-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/dalek/test/core/a.out...(no debugging symbols found)...done.
[New LWP 11299]


warning: Can't read pathname for load map: Input/output error.
Core was generated by `./a.out'.
Program terminated with signal 11, Segmentation fault.
#0  0x080483e1 in main ()
(gdb) bt
#0  0x080483e1 in main ()
(gdb) bt
#0  0x080483e1 in main ()
(gdb) q
dalek@ubuntu:~/test/core$ gdb a.out -c core 
GNU gdb (Ubuntu/Linaro 7.4-2012.02-0ubuntu2) 7.4-2012.02
Copyright (C) 2012 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 "i686-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/dalek/test/core/a.out...(no debugging symbols found)...done.
[New LWP 11299]


warning: Can't read pathname for load map: Input/output error.
Core was generated by `./a.out'.
Program terminated with signal 11, Segmentation fault.
#0  0x080483e1 in main ()
(gdb) 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值