When a segmentation fault occurs in Linux, the error message Segmentation fault (core dumped)
will be printed to the terminal (if any), and the program will be terminated. As a C/C++ dev, this happens to me quite often, and I usually ignore it and move onto gdb
, recreating my previous action in order to trigger the invalid memory reference again. Instead, I thought I might be able to perhaps use this "core" instead, as running gdb
all the time is rather tedious, and I cannot always recreate the segmentation fault.
My questions are three:
- Where is this elusive "core" dumped?
- What does it contain?
- What can I do with it?
Best Answer
If other people clean up ...
... you usually don't find nothing. But luckily Linux has a handler for this which you can specify at runtime. In /usr/src/linux/Documentation/sysctl/kernel.txt you will find:
(thanks)
According to the source this is handled by the
abrt
program (that's Automatic Bug Reporting Tool, not abort), but on my Arch Linux it is handled by systemd. You may want to write your own handler or use the current directory.But what's in there?
Now what it contains is system specific, but according to the all knowing encyclopedia:
... so it basically contains everything
gdb
ever wanted, and more.Yeah, but I'd like me to be happy instead of gdb
You can both be happy since
gdb
will load any core dump as long as you have a exact copy of your executable:gdb path/to/binary my/core.dump
. You should then be able to continue business as usual and be annoyed by trying and failing to fix bugs instead of trying and failing to reproduce bugs.