What exactly is and what does a core dump of process contain

core-dumpdebugginggdbmemoryprocess

It's clear that GDB can generate a core dump of process for example via its wrapper – gcore, however it's not clear what exactly it includes and it's really hard to find an answear because different sources say totally different things.

Because of that I've got following questions:

  1. Does it contain a whole virtual memory of process? If not, what part of it? All writable regions or stack only or just (as its name suggests) some essential part or what?

  2. Is it possible to generate a core file with complete memory of process via GDB? If so, how?

  3. What would be the difference between a "dump" generated by saving and concatenating memory from all regions according to process' memory map and automatically generated file with gcore command?

  4. A process wrote some data somewhere into RAM. Can I be sure that the data will be (always) accessed and saved in a core file generated with gcore command? If not, why? What does it depend on?

Best Answer

The core file contains all the parts of the process's virtual memory that are specific to that process, which is generally the data and stack segments. It doesn't include the text segment, which contains the executable code -- when you want to debug a core file, you have to tell the debugger what program was being run.

You can find a detailed explanation of the contents at Anatomy of an ELF core file