A core dump is the recorded state of the working memory of a computer program at a specific time, generally when the program has terminated abnormally (crashed). In practice, other key pieces of program state are usually dumped at the same time, including the processor registers, which may include the program counter and stack pointer, memory management information, and other processor and operating system flags and information.
2. 启用core dump
1 2 3
acrn@acrn:~$ help ulimit Options: -c the maximum size of core files created
acrn@acrn:~/test$ gdb test core-test-14363-1618606735 Reading symbols from test...done. [New LWP 14363] Core was generated by `./test'. Program terminated with signal SIGABRT, Aborted. #0 0x00007fb1be3b9428 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) bt #0 0x00007fb1be3b9428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54 #1 0x00007fb1be3bb02a in __GI_abort () at abort.c:89 #2 0x00007fb1be3fb7ea in __libc_message (do_abort=do_abort@entry=2, fmt=fmt@entry=0x7fb1be514ed8 "*** Error in `%s': %s: 0x%s ***\n") at ../sysdeps/posix/libc_fatal.c:175 #3 0x00007fb1be40437a in malloc_printerr (ar_ptr=<optimized out>, ptr=<optimized out>, str=0x7fb1be514fa0 "double free or corruption (fasttop)", action=3) at malloc.c:5006 #4 _int_free (av=<optimized out>, p=<optimized out>, have_lock=0) at malloc.c:3867 #5 0x00007fb1be40853c in __GI___libc_free (mem=<optimized out>) at malloc.c:2968 #6 0x0000000000400585 in repeatFree (p=0x164c010 "") at test.c:8 #7 0x00000000004005b6 in main () at test.c:18
在 gdb 内,输入 where 或者bt可以看出, 我们写的程序出错的两行:
1 2
#6 0x0000000000400585 in repeatFree (p=0x164c010 "") at test.c:8 #7 0x00000000004005b6 in main () at test.c:18
在 repeatFree 函数中,test.c 文件的第 8 行错啦,释放了两次内存。
还有一个值得挖掘的信息是:Program terminated with signal SIGABRT, Aborted.