Saving core file in gdb
Asked Answered
P

2

105

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

Plato answered 24/9, 2010 at 17:32 Comment(0)
C
161

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
Crippling answered 24/9, 2010 at 18:55 Comment(2)
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.Toxic
@Jonathon_Reinhart pass core-file path as generate-core-file first argument if you want to save it in certain placeFradin
D
27

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

Diez answered 27/5, 2016 at 10:42 Comment(5)
this should be in comment partMcbride
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;"Diez
Looks like gcore is only supported in newer gdb versions. Old ones require generate-core-file.Killy
This appears to be a short name for generate-core-file, both doing the same thing.Ferguson
gcore is also a binary, not only a gdb command.Clavicytherium

© 2022 - 2024 — McMap. All rights reserved.