First, open the core file limit
A.sudo Vi/etc/profile
B. Add Ulimit-c Unlimited at the end of the file
Source/etc/profile
Reload the file into memory
[Email protected]:~/code# ulimit-c
Unlimited
Indicates that the core file limit has been taken place.
Second, let the core file generated in the process current directory
echo "Core-%e-%p-%t" >/proc/sys/kernel/core_pattern
Three, write a same piece of memory released two times caused Coredump example to locate and solve
A. Write the Err.cpp code as follows, releasing the same piece of memory two times.
[Email protected]:~/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
Compile to generate the Err executable file.
C../err
[Email protected]:~/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)
Produced a core file
[Email protected]:~/code# ll
Total 168
Drwxr-xr-x 2 root root 4096 Mar 9 18:20.
drwx------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
Executes the GDB execution core file, and then inside GDB where
[Email protected]:~/code# gdb./err core-err-9665-1489112441
GNU gdb (Ubuntu 7.11-0ubuntu1) 7.11
Copyright (C) Free Software Foundation, Inc.
License gplv3+: GNU GPL version 3 or later
This was free software:you was 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 is configured as "X86_64-linux-gnu".
Type "Show Configuration" for configuration details.
For bugs reporting instructions, please see:
Find the GDB manual and other documentation resources online at:
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 is generated by './err '.
Program terminated with signal SIGABRT, aborted.
#0 0x00007fbe4035d418 in __gi_raise ([e-mail protected]=6) at: /sysdeps/unix/sysv/linux/raise.c:54
A.. /sysdeps/unix/sysv/linux/raise.c:no such file or directory.
(GDB) where
#0 0x00007fbe4035d418 in __gi_raise ([e-mail protected]=6) at: /sysdeps/unix/sysv/linux/raise.c:54
#1 0x00007fbe4035f01a in __gi_abort () at abort.c:89
#2 0x00007fbe4039f72a in __libc_message ([email protected]=2, [email protected]=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 ()
By tuning the stack, you can find dead in the Repeatfree (char*) function, repeatedly releasing the same piece of memory.
This article is from the "Ubuntu1604 Install Golang" blog, so be sure to keep this source http://terrytong914.blog.51cto.com/2081604/1905041
Linux Coredump Solution Process