1. #include <stdio.h>
    2. int main() {
    3. int b = 1;
    4. int* a;
    5. *a=b; // 非法访问内存
    6. return 0;
    7. }
    1. > gcc -g -o test test.c
    2. > ./test
    3. [1] 8467 segmentation fault ./test
    4. > ls
    5. test test.c
    1. > ulimit -c
    2. 0

    设置产生coredump文件的大小

    1. > ulimit -c unlimited
    2. > ./test
    3. [1] 8911 segmentation fault (core dumped) ./test
    4. > ls
    5. core test test.c

    查看coredumpELF文件的头部

    1. > readelf -h core
    2. ELF Header:
    3. Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
    4. Class: ELF64
    5. Data: 2's complement, little endian
    6. Version: 1 (current)
    7. OS/ABI: UNIX - System V
    8. ABI Version: 0
    9. Type: CORE (Core file)
    10. Machine: Advanced Micro Devices X86-64
    11. Version: 0x1
    12. Entry point address: 0x0
    13. Start of program headers: 64 (bytes into file)
    14. Start of section headers: 0 (bytes into file)
    15. Flags: 0x0
    16. Size of this header: 64 (bytes)
    17. Size of program headers: 56 (bytes)
    18. Number of program headers: 22
    19. Size of section headers: 0 (bytes)
    20. Number of section headers: 0
    21. Section header string table index: 0

    core文件不能单独调试,要与可执行文件一起操作,因为core文件,没有符号表信息,无法调试

    1. > objdump -x core
    2. core: file format elf64-x86-64
    3. core
    4. architecture: i386:x86-64, flags 0x00000000:
    5. start address 0x0000000000000000
    6. Program Header:
    7. NOTE off 0x0000000000000510 vaddr 0x0000000000000000 paddr 0x0000000000000000 align 2**0
    8. filesz 0x0000000000000d28 memsz 0x0000000000000000 flags ---
    9. LOAD off 0x0000000000002000 vaddr 0x0000556e213d1000 paddr 0x0000000000000000 align 2**12
    10. ... ...
    11. Sections:
    12. Idx Name Size VMA LMA File off Algn
    13. 0 note0 00000d28 0000000000000000 0000000000000000 00000510 2**0
    14. CONTENTS, READONLY
    15. 1 .reg/8911 000000d8 0000000000000000 0000000000000000 00000594 2**2
    16. CONTENTS
    17. 2 .reg 000000d8 0000000000000000 0000000000000000 00000594 2**2
    18. CONTENTS
    19. 3 .note.linuxcore.siginfo/8911 00000080 0000000000000000 0000000000000000 00000724 2**2
    20. CONTENTS
    21. 4 .note.linuxcore.siginfo 00000080 0000000000000000 0000000000000000 00000724 2**2
    22. CONTENTS
    23. 5 .auxv 00000140 0000000000000000 0000000000000000 000007b8 2**3
    24. CONTENTS
    25. 6 .note.linuxcore.file/8911 000003c4 0000000000000000 0000000000000000 0000090c 2**2
    26. CONTENTS
    27. 7 .note.linuxcore.file 000003c4 0000000000000000 0000000000000000 0000090c 2**2
    28. CONTENTS
    29. 8 .reg2/8911 00000200 0000000000000000 0000000000000000 00000ce4 2**2
    30. CONTENTS
    31. 9 .reg2 00000200 0000000000000000 0000000000000000 00000ce4 2**2
    32. CONTENTS
    33. 10 .reg-xstate/8911 00000340 0000000000000000 0000000000000000 00000ef8 2**2
    34. CONTENTS
    35. 11 .reg-xstate 00000340 0000000000000000 0000000000000000 00000ef8 2**2
    36. CONTENTS
    37. ... ...
    38. 33 load21 00001000 00007fff6079b000 0000000000000000 0003b000 2**12
    39. CONTENTS, ALLOC, LOAD, READONLY, CODE
    40. SYMBOL TABLE:
    41. 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)