Skip to content

Latest commit

 

History

History
221 lines (203 loc) · 12.9 KB

File metadata and controls

221 lines (203 loc) · 12.9 KB

Core Files

经过和颖奇讨论,这个主要是应用程序Crash的时候,会自动保存堆载信息,便于调试;

参考文档

测试代码

steps

  • ulimit -c
    0
    
  • ulimit -a
    core file size          (blocks, -c) 0
    data seg size           (kbytes, -d) unlimited
    scheduling priority             (-e) 0
    file size               (blocks, -f) unlimited
    pending signals                 (-i) 30311
    max locked memory       (kbytes, -l) unlimited
    max memory size         (kbytes, -m) unlimited
    open files                      (-n) 1024
    pipe size            (512 bytes, -p) 8
    POSIX message queues     (bytes, -q) 819200
    real-time priority              (-r) 95
    stack size              (kbytes, -s) 8192
    cpu time               (seconds, -t) unlimited
    max user processes              (-u) 30311
    virtual memory          (kbytes, -v) unlimited
    file locks                      (-x) unlimited
    
  • ulimit -c unlimited
  • ulimit -c
    unlimited
    
  • ulimit -a
    core file size          (blocks, -c) unlimited
    data seg size           (kbytes, -d) unlimited
    scheduling priority             (-e) 0
    file size               (blocks, -f) unlimited
    pending signals                 (-i) 30311
    max locked memory       (kbytes, -l) unlimited
    max memory size         (kbytes, -m) unlimited
    open files                      (-n) 1024
    pipe size            (512 bytes, -p) 8
    POSIX message queues     (bytes, -q) 819200
    real-time priority              (-r) 95
    stack size              (kbytes, -s) 8192
    cpu time               (seconds, -t) unlimited
    max user processes              (-u) 30311
    virtual memory          (kbytes, -v) unlimited
    file locks                      (-x) unlimited
    
  • sudo su
  • echo 1 > /proc/sys/kernel/core_uses_pid
  • exit
  • make
  • ./main
  • ls
    core.5871  main  main.c  Makefile
    
  • gdb main core.5871
    GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git
    Copyright (C) 2018 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 main...done.
    [New LWP 3579]
    
    warning: Unexpected size of section `.reg-xstate/3579' in core file.
    Core was generated by `./main'.
    Program terminated with signal SIGSEGV, Segmentation fault.
    
    warning: Unexpected size of section `.reg-xstate/3579' in core file.
    #0  0x00005577ffc01811 in main () at main.c:28
    28	    *ptr = 10; 
    (gdb) list
    23	    }   
    24	    printf("After set rlimit CORE dump current is:%d, max is:%d\n", (int)rlmt.rlim_cur, (int)rlmt.rlim_max);
    25	
    26	    /*测试非法内存,产生core文件*/
    27	    int *ptr = NULL;
    28	    *ptr = 10; 
    29	
    30	    return 0;
    31	}
    (gdb) info args
    No arguments.
    (gdb) info locals
    rlmt = {rlim_cur = 524288000, rlim_max = 524288000}
    ptr = 0x0
    (gdb) bt
    #0  0x00005577ffc01811 in main () at main.c:28
    (gdb) info frame
    Stack level 0, frame at 0x7ffc39b15960:
     rip = 0x5577ffc01811 in main (main.c:28); saved rip = 0x7fa5479b6b97
     source language c.
     Arglist at 0x7ffc39b15950, args: 
     Locals at 0x7ffc39b15950, Previous frame's sp is 0x7ffc39b15960
     Saved registers:
      rbp at 0x7ffc39b15950, rip at 0x7ffc39b15958
    (gdb) x/10x $sp
    0x7ffc39b15920:	0x47d969f0	0x00007fa5	0x00000000	0x00000000
    0x7ffc39b15930:	0x1f400000	0x00000000	0x1f400000	0x00000000
    0x7ffc39b15940:	0x39b15a30	0x00007ffc
    (gdb) q
    • bt: backtrace
  • readelf -Wa core
    ELF Header:
      Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
      Class:                             ELF64
      Data:                              2's complement, little endian
      Version:                           1 (current)
      OS/ABI:                            UNIX - System V
      ABI Version:                       0
      Type:                              CORE (Core file)
      Machine:                           Advanced Micro Devices X86-64
      Version:                           0x1
      Entry point address:               0x0
      Start of program headers:          64 (bytes into file)
      Start of section headers:          0 (bytes into file)
      Flags:                             0x0
      Size of this header:               64 (bytes)
      Size of program headers:           56 (bytes)
      Number of program headers:         19
      Size of section headers:           0 (bytes)
      Number of section headers:         0
      Section header string table index: 0
    
    There are no sections in this file.
    
    There are no sections to group in this file.
    
    Program Headers:
      Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
      NOTE           0x000468 0x0000000000000000 0x0000000000000000 0x000cd0 0x000000     0
      LOAD           0x002000 0x00005577ffc01000 0x0000000000000000 0x001000 0x001000 R E 0x1000
      LOAD           0x003000 0x00005577ffe01000 0x0000000000000000 0x001000 0x001000 R   0x1000
      LOAD           0x004000 0x00005577ffe02000 0x0000000000000000 0x001000 0x001000 RW  0x1000
      LOAD           0x005000 0x0000557800a16000 0x0000000000000000 0x021000 0x021000 RW  0x1000
      LOAD           0x026000 0x00007fa547995000 0x0000000000000000 0x001000 0x1e7000 R E 0x1000
      LOAD           0x027000 0x00007fa547b7c000 0x0000000000000000 0x000000 0x200000     0x1000
      LOAD           0x027000 0x00007fa547d7c000 0x0000000000000000 0x004000 0x004000 R   0x1000
      LOAD           0x02b000 0x00007fa547d80000 0x0000000000000000 0x002000 0x002000 RW  0x1000
      LOAD           0x02d000 0x00007fa547d82000 0x0000000000000000 0x004000 0x004000 RW  0x1000
      LOAD           0x031000 0x00007fa547d86000 0x0000000000000000 0x001000 0x027000 R E 0x1000
      LOAD           0x032000 0x00007fa547f96000 0x0000000000000000 0x002000 0x002000 RW  0x1000
      LOAD           0x034000 0x00007fa547fad000 0x0000000000000000 0x001000 0x001000 R   0x1000
      LOAD           0x035000 0x00007fa547fae000 0x0000000000000000 0x001000 0x001000 RW  0x1000
      LOAD           0x036000 0x00007fa547faf000 0x0000000000000000 0x001000 0x001000 RW  0x1000
      LOAD           0x037000 0x00007ffc39af7000 0x0000000000000000 0x021000 0x021000 RW  0x1000
      LOAD           0x058000 0x00007ffc39ba6000 0x0000000000000000 0x003000 0x003000 R   0x1000
      LOAD           0x05b000 0x00007ffc39ba9000 0x0000000000000000 0x001000 0x001000 R E 0x1000
      LOAD           0x05c000 0xffffffffff600000 0x0000000000000000 0x001000 0x001000   E 0x1000
    
    There is no dynamic section in this file.
    
    There are no relocations in this file.
    
    The decoding of unwind sections for machine type Advanced Micro Devices X86-64 is not currently supported.
    
    Dynamic symbol information is not available for displaying symbols.
    
    No version information found in this file.
    
    Displaying notes found at file offset 0x00000468 with length 0x00000cd0:
      Owner                 Data size	Description
      CORE                 0x00000150	NT_PRSTATUS (prstatus structure)	
      CORE                 0x00000088	NT_PRPSINFO (prpsinfo structure)	
      CORE                 0x00000080	NT_SIGINFO (siginfo_t data)	
      CORE                 0x00000140	NT_AUXV (auxiliary vector)	
      CORE                 0x0000026a	NT_FILE (mapped files)	    Page size: 4096
                     Start                 End         Page Offset
        0x00005577ffc01000  0x00005577ffc02000  0x0000000000000000
            /home/zengjf/zengjf/github/coredump/main
        0x00005577ffe01000  0x00005577ffe02000  0x0000000000000000
            /home/zengjf/zengjf/github/coredump/main
        0x00005577ffe02000  0x00005577ffe03000  0x0000000000000001
            /home/zengjf/zengjf/github/coredump/main
        0x00007fa547995000  0x00007fa547b7c000  0x0000000000000000
            /lib/x86_64-linux-gnu/libc-2.27.so
        0x00007fa547b7c000  0x00007fa547d7c000  0x00000000000001e7
            /lib/x86_64-linux-gnu/libc-2.27.so
        0x00007fa547d7c000  0x00007fa547d80000  0x00000000000001e7
            /lib/x86_64-linux-gnu/libc-2.27.so
        0x00007fa547d80000  0x00007fa547d82000  0x00000000000001eb
            /lib/x86_64-linux-gnu/libc-2.27.so
        0x00007fa547d86000  0x00007fa547dad000  0x0000000000000000
            /lib/x86_64-linux-gnu/ld-2.27.so
        0x00007fa547fad000  0x00007fa547fae000  0x0000000000000027
            /lib/x86_64-linux-gnu/ld-2.27.so
        0x00007fa547fae000  0x00007fa547faf000  0x0000000000000028
            /lib/x86_64-linux-gnu/ld-2.27.so
      CORE                 0x00000200	NT_FPREGSET (floating point registers)	
      LINUX                0x00000440	NT_X86_XSTATE (x86 XSAVE extended state)	   description data: 7f 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ffffff80 1f 00 00 ffffffff ffffffff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1f 00 00 00 00 00 00 ffffff80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 00 00 00 00 00 00 ffffffff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 0c ffffffd8 47 ffffffa5 7f 00 00 30 0c ffffffd8 47 ffffffa5 7f 00 00 0e 00 00 00 00 00 00 00 0e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff 04 00 00 00 04 00 00 00 04 00 00 00 04 00 00 00 6e 74 20 69 73 3a 25 64 2c 20 6d 61 78 20 69 73 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
    
  • gdb binary-file core-file
    • 暂时不知道有什么用途