#include <stdio.h>int main() {int b = 1;int* a;*a=b; // 非法访问内存return 0;}
> gcc -g -o test test.c> ./test[1] 8467 segmentation fault ./test> lstest test.c
> ulimit -c0
设置产生coredump文件的大小
> ulimit -c unlimited> ./test[1] 8911 segmentation fault (core dumped) ./test> lscore test test.c
查看coredumpELF文件的头部
> readelf -h coreELF Header:Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00Class: ELF64Data: 2's complement, little endianVersion: 1 (current)OS/ABI: UNIX - System VABI Version: 0Type: CORE (Core file)Machine: Advanced Micro Devices X86-64Version: 0x1Entry point address: 0x0Start of program headers: 64 (bytes into file)Start of section headers: 0 (bytes into file)Flags: 0x0Size of this header: 64 (bytes)Size of program headers: 56 (bytes)Number of program headers: 22Size of section headers: 0 (bytes)Number of section headers: 0Section header string table index: 0
core文件不能单独调试,要与可执行文件一起操作,因为core文件,没有符号表信息,无法调试
> objdump -x corecore: file format elf64-x86-64corearchitecture: i386:x86-64, flags 0x00000000:start address 0x0000000000000000Program Header:NOTE off 0x0000000000000510 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**0filesz 0x0000000000000d28 memsz 0x0000000000000000 flags ---LOAD off 0x0000000000002000 vaddr 0x0000556e213d1000 paddr 0x0000000000000000 align 2**12... ...Sections:Idx Name Size VMA LMA File off Algn0 note0 00000d28 0000000000000000 0000000000000000 00000510 2**0CONTENTS, READONLY1 .reg/8911 000000d8 0000000000000000 0000000000000000 00000594 2**2CONTENTS2 .reg 000000d8 0000000000000000 0000000000000000 00000594 2**2CONTENTS3 .note.linuxcore.siginfo/8911 00000080 0000000000000000 0000000000000000 00000724 2**2CONTENTS4 .note.linuxcore.siginfo 00000080 0000000000000000 0000000000000000 00000724 2**2CONTENTS5 .auxv 00000140 0000000000000000 0000000000000000 000007b8 2**3CONTENTS6 .note.linuxcore.file/8911 000003c4 0000000000000000 0000000000000000 0000090c 2**2CONTENTS7 .note.linuxcore.file 000003c4 0000000000000000 0000000000000000 0000090c 2**2CONTENTS8 .reg2/8911 00000200 0000000000000000 0000000000000000 00000ce4 2**2CONTENTS9 .reg2 00000200 0000000000000000 0000000000000000 00000ce4 2**2CONTENTS10 .reg-xstate/8911 00000340 0000000000000000 0000000000000000 00000ef8 2**2CONTENTS11 .reg-xstate 00000340 0000000000000000 0000000000000000 00000ef8 2**2CONTENTS... ...33 load21 00001000 00007fff6079b000 0000000000000000 0003b000 2**12CONTENTS, ALLOC, LOAD, READONLY, CODESYMBOL TABLE:no symbols
查看程序core的位置
gdb test core
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
Copyright (C) 2020 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 test...
[New LWP 8911]
Core was generated by `./test'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x0000556e213d213f in main () at test.c:6
6 *a=b; // 非法访问内存
(gdb)
