103

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

2 Answers 2

156

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
2
  • 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. Jul 12, 2015 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, 2015 at 10:54
27

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

4
  • this should be in comment part May 27, 2016 at 11:01
  • 16
    Please have a look to this page stackoverflow.com/help/privileges/comment : When shouldn't I comment?...."Answering a question or providing an alternate solution to an existing answer;"
    – Meinew
    May 27, 2016 at 11:17
  • 2
    Looks like gcore is only supported in newer gdb versions. Old ones require generate-core-file.
    – scai
    Sep 19, 2018 at 8:23
  • 1
    This appears to be a short name for generate-core-file, both doing the same thing. Dec 24, 2019 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.