设为首页 收藏本站
查看: 594|回复: 0

[经验分享] Linux coredump解决流程

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2017-3-10 13:42:26 | 显示全部楼层 |阅读模式
一、打开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(1024);

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.6(+0x77725)[0x7fbe4039f725]
/lib/x86_64-linux-gnu/libc.so.6(+0x7ff4a)[0x7fbe403a7f4a]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7fbe403ababc]
./err[0x400585]
./err[0x4005b6]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7fbe40348830]
./err[0x400499]
======= Memory map: ========
00400000-00401000 r-xp 00000000 08:01 398325                                        /root/code/err
00600000-00601000 r--p 00000000 08:01 398325                                        /root/code/err
00601000-00602000 rw-p 00001000 08:01 398325                                        /root/code/err
01911000-01932000 rw-p 00000000 00:00 0                                                          [heap]
7fbe3c000000-7fbe3c021000 rw-p 00000000 00:00 0
7fbe3c021000-7fbe40000000 ---p 00000000 00:00 0
7fbe40112000-7fbe40128000 r-xp 00000000 08:01 791701  /lib/x86_64-linux-gnu/libgcc_s.so.1
7fbe40128000-7fbe40327000 ---p 00016000 08:01 791701  /lib/x86_64-linux-gnu/libgcc_s.so.1
7fbe40327000-7fbe40328000 rw-p 00015000 08:01 791701  /lib/x86_64-linux-gnu/libgcc_s.so.1
7fbe40328000-7fbe404e8000 r-xp 00000000 08:01 791663  /lib/x86_64-linux-gnu/libc-2.23.so
7fbe404e8000-7fbe406e7000 ---p 001c0000 08:01 791663  /lib/x86_64-linux-gnu/libc-2.23.so
7fbe406e7000-7fbe406eb000 r--p 001bf000 08:01 791663  /lib/x86_64-linux-gnu/libc-2.23.so
7fbe406eb000-7fbe406ed000 rw-p 001c3000 08:01 791663  /lib/x86_64-linux-gnu/libc-2.23.so
7fbe406ed000-7fbe406f1000 rw-p 00000000 00:00 0
7fbe406f1000-7fbe40717000 r-xp 00000000 08:01 791635  /lib/x86_64-linux-gnu/ld-2.23.so
7fbe408fb000-7fbe408fe000 rw-p 00000000 00:00 0
7fbe40913000-7fbe40916000 rw-p 00000000 00:00 0
7fbe40916000-7fbe40917000 r--p 00025000 08:01 791635  /lib/x86_64-linux-gnu/ld-2.23.so
7fbe40917000-7fbe40918000 rw-p 00026000 08:01 791635  /lib/x86_64-linux-gnu/ld-2.23.so
7fbe40918000-7fbe40919000 rw-p 00000000 00:00 0
7ffe51f1b000-7ffe51f3c000 rw-p 00000000 00:00 0       [stack]
7ffe51ff4000-7ffe51ff6000 r--p 00000000 00:00 0       [vvar]
7ffe51ff6000-7ffe51ff8000 r-xp 00000000 00:00 0       [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [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-9665-1489112441
GNU gdb (Ubuntu 7.11-0ubuntu1) 7.11
Copyright (C) 2016 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".
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 9665]
Core was generated by `./err'.
Program terminated with signal SIGABRT, Aborted.
#0  0x00007fbe4035d418 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
54../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) where
#0  0x00007fbe4035d418 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
#1  0x00007fbe4035f01a in __GI_abort () at abort.c:89
#2  0x00007fbe4039f72a in __libc_message (do_abort=do_abort@entry=2, fmt=fmt@entry=0x7fbe404b86b0 "*** Error in `%s': %s: 0x%s ***\n") at ../sysdeps/posix/libc_fatal.c:175
#3  0x00007fbe403a7f4a in malloc_printerr (ar_ptr=<optimized out>, ptr=<optimized out>, str=0x7fbe404b87a0 "double free or corruption (top)", action=3) at malloc.c:5007
#4  _int_free (av=<optimized out>, p=<optimized out>, have_lock=0) at malloc.c:3868
#5  0x00007fbe403ababc in __GI___libc_free (mem=<optimized out>) at malloc.c:2969
#6  0x0000000000400585 in repeatFree(char*) ()
#7  0x00000000004005b6 in main ()

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


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-350609-1-1.html 上篇帖子: smokeping触发不了 告警脚本 帮忙看看哪边错了 下篇帖子: linux-/etc/inittab,rc.sysinit,rc服务类脚本,chkconfig Linux
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表