102

Is it possible to save/dump core file using gdb? Sometimes I want to save file to analyze it later.

Maciej Piechotka
  • 7,028
  • 6
  • 39
  • 61

2 Answers2

155

Issue the 'generate-core-file' command in gdb.

(gdb) help generate-core-file
Save a core file with the current state of the debugged process.
Argument is optional filename.  Default filename is 'core.<process_id>'.
(gdb) break main
Breakpoint 1 at 0x400e0b: file utils/udec.c, line 36.
(gdb) r
Starting program: /home/nos/build/utils/udec

Breakpoint 1, main (argc=1, argv=0x7fffffffe9a8) at utils/udec.c:36
36              int fileargc = 1;
(gdb) generate-core-file
Saved corefile core.7336
nos
  • 223,662
  • 58
  • 417
  • 506
  • 4
    It will be saved in GDB's current working directory, which can be seen via the `pwd` command. If you need to change it, you can do so with `cd`, just like at a shell. – Jonathon Reinhart Jul 12 '15 at 13:58
  • 3
    @Jonathon_Reinhart pass core-file path as `generate-core-file` first argument if you want to save it in certain place – SergA Dec 18 '15 at 10:54
26

You can also use gcore <pid> to produce cores.

Meinew
  • 484
  • 8
  • 17