Is a core dump executable by itself? Is a core dump executable by itself? unix unix

Is a core dump executable by itself?


In older unix variants it was the default to include the text as well as data in the core dump but it was also given in the a.out format and not ELF. Today's default behavior (in Linux for sure, not 100% sure about BSD variants, Solaris etc.) is to have the core dump in ELF format without the text sections but that behavior can be changed.
However, a core dump cannot be executed directly in any case without some help. The reason for that is that there are two things missing from a simple core file. One is the entry point, the other is code to restore the CPU state to the state at or just before the dump occurred (by default also the text sections are missing).
In AIX there used to be a utility called undump but I have no idea what happened to it. It doesn't exist in any standard Linux distribution I know of. As mentioned above (@WumpusQ) there's also an attempt at a similar project for Linux mentioned in above comments, however this project is not complete and doesn't restore the CPU state to the original state. It is, however, still good enough in some specific debugging cases.
It is also worth mentioning that there exist other ELF formatted files that cannot be executes as well which are not core files. Such as object files (compiler output) and .so (shared object) files. Those require a linking stage before being run to resolve external addresses.


I emailed this question the creator of the undump utility for his expertise, and got the following reply:

As mentioned in some of the answers there, it is possible to include the code sections by setting the coredump_filter, but it's not the default for Linux (and I'm not entirely sure about BSD variants and Solaris). If the various code sections are saved in the original core-dump, there is really nothing missing in order to create the new executable. It does, however, require some changes in the original core file (such as including an entry point and pointing that entry point to code that will restore CPU registers). If the core file is modified in this way it will become an executable and you'll be able to run it. Unfortunately, though, some of the states are not going to be saved so the new executable will not be able to run directly. Open files, sockets, pips, etc are not going to be open and may even point to other FDs (which could cause all sorts of weird things). However, it will most probably be enough for most debugging tasks such running small functions from gdb (so that you don't get a "not running an executable" stuff).


As other guys said, I don't think you can execute a core dump file without the original binary.

In case you're interested to debug the binary (and it has debugging symbols included, in other words it is not stripped) then you can run gdb binary core.

Inside gdb you can use bt command (backtrace) to get the stack trace when the application crashed.