一、打开core文件限制

a.sudo vi /etc/profile

b.文件末尾添加ulimit -c unlimited

source /etc/profile

把文件重新加载到内存

c.root@ubuntu:~/code# ulimit -c

unlimited

说明core文件限制已经去处。

二、让core文件生成在进程当前目录

echo "core-%e-%p-%t" > /proc/sys/kernel/core_pattern

三、写一个同一块内存释放两次引起coredump的例子定位并解决

a.编写err.cpp代码如下,同一块内存释放了两次。

root@ubuntu:~/code# cat err.cpp

#include<cstdlib>
using namespace std;
void repeatFree(char *p)
{
if(NULL != p)
{
free(p);
}
}
int main()
{
char* pstr =(char*) malloc();
free(pstr);
repeatFree(pstr);
}

b.g++ -o err err.cpp

编译生成err可执行文件。

c.  ./err

root@ubuntu:~/code# ./err 

*** Error in `./err': double free or corruption (top): 0x0000000001911010 ***

======= Backtrace: =========

/lib/x86_64-linux-gnu/libc.so.(+0x77725)[0x7fbe4039f725]

/lib/x86_64-linux-gnu/libc.so.(+0x7ff4a)[0x7fbe403a7f4a]

/lib/x86_64-linux-gnu/libc.so.(cfree+0x4c)[0x7fbe403ababc]

./err[0x400585]

./err[0x4005b6]

/lib/x86_64-linux-gnu/libc.so.(__libc_start_main+0xf0)[0x7fbe40348830]

./err[0x400499]

======= Memory map: ========

- r-xp  :  /root/code/err

- r--p  :  /root/code/err

- rw-p  :  /root/code/err

- rw-p  :    [heap]

7fbe3c000000-7fbe3c021000 rw-p  :  

7fbe3c021000-7fbe40000000 ---p  :  

7fbe40112000-7fbe40128000 r-xp  :   /lib/x86_64-linux-gnu/libgcc_s.so.

7fbe40128000-7fbe40327000 ---p  :   /lib/x86_64-linux-gnu/libgcc_s.so.

7fbe40327000-7fbe40328000 rw-p  :   /lib/x86_64-linux-gnu/libgcc_s.so.

7fbe40328000-7fbe404e8000 r-xp  :   /lib/x86_64-linux-gnu/libc-2.23.so

7fbe404e8000-7fbe406e7000 ---p 001c0000 :   /lib/x86_64-linux-gnu/libc-2.23.so

7fbe406e7000-7fbe406eb000 r--p 001bf000 :   /lib/x86_64-linux-gnu/libc-2.23.so

7fbe406eb000-7fbe406ed000 rw-p 001c3000 :   /lib/x86_64-linux-gnu/libc-2.23.so

7fbe406ed000-7fbe406f1000 rw-p  :  

7fbe406f1000-7fbe40717000 r-xp  :   /lib/x86_64-linux-gnu/ld-2.23.so

7fbe408fb000-7fbe408fe000 rw-p  :  

7fbe40913000-7fbe40916000 rw-p  :  

7fbe40916000-7fbe40917000 r--p  :   /lib/x86_64-linux-gnu/ld-2.23.so

7fbe40917000-7fbe40918000 rw-p  :   /lib/x86_64-linux-gnu/ld-2.23.so

7fbe40918000-7fbe40919000 rw-p  :  

7ffe51f1b000-7ffe51f3c000 rw-p  :        [stack]

7ffe51ff4000-7ffe51ff6000 r--p  :        [vvar]

7ffe51ff6000-7ffe51ff8000 r-xp  :        [vdso]

ffffffffff600000-ffffffffff601000 r-xp  :  [vsyscall]

Aborted (core dumped)

产生了core文件

root@ubuntu:~/code# ll

total 168

drwxr-xr-x  2 root root   4096 Mar  9 18:20 ./

drwx------ 10 root root   4096 Mar  9 18:18 ../

-rw-------  1 root root 544768 Mar  9 18:20 core-err-9665-1489112441

-rwxr-xr-x  1 root root   8696 Mar  9 18:20 err*

-rw-r--r--  1 root root    185 Mar  9 18:18 err.cpp

d.gdb ./err core-err-9665-1489112441

执行gdb 执行程序 core文件,然后在gdb里面where

root@ubuntu:~/code# gdb ./err core-err--

GNU gdb (Ubuntu 7.11-0ubuntu1) 7.11

Copyright (C)  Free Software Foundation, Inc.

License GPLv3+: GNU GPL version  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".

Type "show configuration" for configuration details.

For bug reporting instructions, please see:

<http://www.gnu.org/software/gdb/bugs/>.

Find the GDB manual and other documentation resources online at:

<http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".

Type "apropos word" to search for commands related to "word"...

Reading symbols from ./err...(no debugging symbols found)...done.

[New LWP ]

Core was generated by `./err'.

Program terminated with signal SIGABRT, Aborted.

#  0x00007fbe4035d418 in __GI_raise (sig=sig@entry=) at ../sysdeps/unix/sysv/linux/raise.c:

../sysdeps/unix/sysv/linux/raise.c: No such file or directory.

(gdb) where

#  0x00007fbe4035d418 in __GI_raise (sig=sig@entry=) at ../sysdeps/unix/sysv/linux/raise.c:

#  0x00007fbe4035f01a in __GI_abort () at abort.c:

#  0x00007fbe4039f72a in __libc_message (do_abort=do_abort@entry=, fmt=fmt@entry=0x7fbe404b86b0 "*** Error in `%s': %s: 0x%s ***\n") at ../sysdeps/posix/libc_fatal.c:

#  0x00007fbe403a7f4a in malloc_printerr (ar_ptr=<optimized out>, ptr=<optimized out>, str=0x7fbe404b87a0 "double free or corruption (top)", action=) at malloc.c:

#  _int_free (av=<optimized out>, p=<optimized out>, have_lock=) at malloc.c:

#  0x00007fbe403ababc in __GI___libc_free (mem=<optimized out>) at malloc.c:

#  0x0000000000400585 in repeatFree(char*) ()

#  0x00000000004005b6 in main () 

通过调堆栈就能发现死在repeatFree(char*)函数里面,重复释放了同一块内存。

Linux coredump解决流程的更多相关文章

  1. Linux操作系统启动流程梳理

    接触linux系统运维已经好几年了,常常被问到linux系统启动流程问题,刚好今天有空来梳理下这个过程:一般来说,所有的操作系统的启动流程基本就是: 总的来说,linux系统启动流程可以简单总结为以下 ...

  2. Linux 的启动流程(转)

    原文链接:http://blog.jobbole.com/46078/ 半年前,我写了<计算机是如何启动的?>,探讨BIOS和主引导记录的作用. 那篇文章不涉及操作系统,只与主板的板载程序 ...

  3. 【转】Linux 的启动流程

    半年前,我写了<计算机是如何启动的?>,探讨BIOS和主引导记录的作用. 那篇文章不涉及操作系统,只与主板的板载程序有关.今天,我想接着往下写,探讨操作系统接管硬件以后发生的事情,也就是操 ...

  4. Linux 的启动流程

    转载:http://www.ruanyifeng.com/blog/2013/08/linux_boot_process.html 更多文档参见:http://pan.baidu.com/s/1hqo ...

  5. 9.Linux系统引导流程

    一.Linux系统引导流程 当我们按下主机电源键的那时候开始,主板上的CMOS/BIOS模块将进行固件自检,以此检查各个硬件是否正确连接. 在Linux引导流程中,一般可以分为以下几个主要过程: 1. ...

  6. linux --> Linux 的启动流程

    Linux 的启动流程 操作系统接管硬件以后发生的事情,也就是操作系统的启动流程. 因为在BIOS阶段,计算机的行为基本上被写死了,程序员可以做的事情并不多:但一旦进入操作系统,程序员几乎可以定制所有 ...

  7. linux文件系统启动流程、启动脚本

    linux文件系统启动流程.启动脚本 下面是一张Linux启动流程图: 在了解启动流程之前,我们应该先知道系统的几个重要脚本和配置文件,他们对应的路径为: 1. /sbin/init 2. /etc/ ...

  8. I.MX6 Linux Qt 启动流程跟踪

    /************************************************************************** * I.MX6 Linux Qt 启动流程跟踪 ...

  9. Linux 的启动流程--转

    http://cloudbbs.org/forum.php?mod=viewthread&tid=17814 半年前,我写了<计算机是如何启动的?>,探讨BIOS和主引导记录的作用 ...

随机推荐

  1. CITS1401 Computational Thinking with Python

    Department of Computer Science and Software EngineeringCITS1401 ComputationalThinking with PythonPro ...

  2. windows android ndk的某些编译工具报错乱码0x5 或拒绝访问05

    在IDEA或者AndroidStudio的快捷方式上右键属性 > 兼容性 > 以管理员身份运行 解决问题.

  3. MySQL Server8.0版本时出现Client does not support authentication protocol requested by server

    MySQL Server8.0版本时出现Client does not support authentication protocol requested  by server 解决方法: 1.roo ...

  4. python 去掉重复元素 学到再添加

    1. python 内置函数 set(可迭代对象) 返回无重复元素的集合.如在分类中,classification为类别数组 set(classification)为类别数 2.numpy np.un ...

  5. shiro使用redis作为缓存,出现要清除缓存时报错 java.lang.Exception: Failed to deserialize at org.crazycake.shiro.SerializeUtils.deserialize(SerializeUtils.java:41) ~[shiro-redis-2.4.2.1-RELEASE.jar:na]

    shiro使用redis作为缓存,出现要清除缓存时报错 java.lang.Exception: Failed to deserialize at org.crazycake.shiro.Serial ...

  6. redis 3.2 新数据结构:quicklist、String的embstr与raw编码方式分界点

    Redis3.2.0引入了新的quicklist的数据结构做了list的底层存储方案.废弃了原来的两个配置参数, list-max-ziplist-entries list-max-ziplist-v ...

  7. 【Linux】Centos partition

    http://www.cnblogs.com/yogurtwu/p/9494108.html https://www.cnblogs.com/zhangkaimin/p/6251448.html wh ...

  8. JS 变量和函数提升 全局变量和局部变量

    变量提升 1. var a = 10; function test() { a = 100; console.log(a); console.log(this.a); var a; console.l ...

  9. 来测试下你的Java编程能力

    上篇整理了下后面准备更系统化写的Java编程进阶的思路,如果仅看里面的词,很多同学会觉得都懂,但我真心觉得没有多少人是真懂的,所以简单的想了一些题目,感兴趣的同学们可以来做做看,看看自己的Java编程 ...

  10. iOS 开发笔记 - 导航到地图

    导航到地图,已经不是什么新鲜事了.网上有好多参考的资料,我总结出只需要两步 第一步:在info中加上支持的各平台 比如:iosamap高德地图.comgooglemaps谷歌地图.baidumap百度 ...