linux下调试core的命令,察看堆栈状态命令
来源:互联网 发布:淘宝网店首页海报尺寸 编辑:程序博客网 时间:2024/05/29 18:05
首先看看默认的一些core的参数,注意core file size是个0,程序出错时不会产生core文件了。
$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) 4
max memory size (kbytes, -m) unlimited
open files (-n) 2048
pipe size (512 bytes, -p) 8
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 7168
virtual memory (kbytes, -v) unlimited
写个简单的程序,看看core文件是不是会被产生。
$ more foo.c
#include <stdio.h>
static void sub(void);
int main(void)
{
sub();
return 0;
}
static void sub(void)
{
int *p = NULL;
/* derefernce a null pointer, expect core dump. */
printf("%d", *p);
}
$ gcc -Wall -g foo.c
$ ./a.out
Segmentation fault
$ ls -l core.*
ls: core.*: No such file or directory
没有找到core文件,我们改改ulimit的设置,让它产生。1024是随便取的,要是core文件大于1024个块,就产生不出来了。
$ ulimit -c 1024 (转者注: 使用-c unlimited不限制core文件大小)
$ ulimit -a
core file size (blocks, -c) 1024
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) 4
max memory size (kbytes, -m) unlimited
open files (-n) 2048
pipe size (512 bytes, -p) 8
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 7168
virtual memory (kbytes, -v) unlimited
$ ./a.out
Segmentation fault (core dumped)
$ ls -l core.*
-rw------- 1 uniware uniware 53248 Jun 30 17:10 core.9128
注意看上述的输出信息,多了个(core dumped)。确实产生了一个core文件,9128是该进程的PID。我们用GDB来看看这个core。
(转者注:默认生成的文件就叫core,不带PID,如果要带PID需要设置,通过echo "1" > /proc/sys/kernel/core_uses_pid能够设置pid)
$ gdb --core=core.9128
GNU gdb Asianux (6.0post-0.20040223.17.1AX)
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 "i386-asianux-linux-gnu".
Core was generated by `./a.out'.
Program terminated with signal 11, Segmentation fault.
#0 0x08048373 in ?? ()
(gdb) bt
#0 0x08048373 in ?? ()
#1 0xbfffd8f8 in ?? ()
#2 0x0804839e in ?? ()
#3 0xb74cc6b3 in ?? ()
#4 0x00000000 in ?? ()
此时用bt看不到backtrace,也就是调用堆栈,原来GDB还不知道符号信息在哪里。我们告诉它一下:
(gdb) file ./a.out
Reading symbols from ./a.out...done.
Using host libthread_db library "/lib/tls/libthread_db.so.1".
(gdb) bt
#0 0x08048373 in sub () at foo.c:17
#1 0x08048359 in main () at foo.c:8
此时backtrace出来了。
8 sub();
9 return 0;
10 }
11
12 static void sub(void)
13 {
14 int *p = NULL;
15
16 /* derefernce a null pointer, expect core dump. */
17 printf("%d", *p);
- linux下调试core的命令,察看堆栈状态命令
- linux下调试core的命令,察看堆栈状态命令
- linux下调试core的命令,察看堆栈状态命令
- linux下调试core的命令,察看堆栈状态命令
- linux下调试core的命令,察看堆栈状态命令
- Linux下察看swap分区大小的命令
- Linux下察看swap分区大小的命令
- linux命令察看图片
- linux察看系统信息的一些命令
- linux下察看cpu状态
- 察看linux内核命令源码
- linux 察看系统及内核命令
- linux ubuntu 察看文件行数命令
- gdb里面的堆栈调试命令
- LINUX下汇编的编译,调试命令
- linux下gdb常用的调试命令
- linux下gdb常用的调试命令
- linux下gdb常用的调试命令 .
- Programming Optimization
- iphone开发之剪贴板详解
- Nested Classes(just for self-learning)
- (转)D7 combobox csDropDownList 赋值
- 彻底接管程序异常处理
- linux下调试core的命令,察看堆栈状态命令
- base sdk missing解决办法
- Java报表条件属性概要
- 周末
- 诺基亚的问题、挑战、未来
- 如何改变浮躁心理
- Firefox和IE,通过JavaScript调用iframe中页面的函数
- Optimizing C and C++ Code
- Lucene Similarity (Lucene 文档评分score机制详解