tags:

views:

56

answers:

2

Is it possible, under any circumstances, to restore the state of a program to what it was during the generation of a core file?

The reason I ask is that in order to take advantage of gdb's ability to execute functions and so forth you need to have a running instance. Surely it should be possible to produce a mock process of the same executable with the state set to be the contents of the core?

If not what alternatives are there for the sort of situation that made me want to do this in the first place? In this case the back-trace of the core led to a library function and I wanted to replicate the inputs to this function call but one of the inputs is was complex object which could easily be serialized to a string with a function call in a running instance but not so in a core dump.

+2  A: 

That's what a core file does already? If you load gdb with the original executable and the core file

gdb myprogram.exe -c mycorefile

Then it'll go to the point at where it crashed. You can use all the normal inspection functionality to view the variables, see the stack trace and so on.

Or have I misunderstood your question?

Jeff Foster
You can't execute functions in gdb when you're debugging a core file.So say I have a core file, locate a variable of a complex class Foo and I want to execute Foo.getSerialization() to get a nice simple string representation I can't because it's not a running process.So the question is can one go from core to a running process.
cyborg
You can write some code to make gdb pretty print values. See the Python API here (http://sourceware.org/gdb/current/onlinedocs/gdb/Python-API.html#Python-API).
Jeff Foster
+1  A: 

It is theoretically possible to do exactly what you want, but (AFAICT) there is no support for this in GDB (yet).

Your best bet is to use GDB-7.0 and use its embedded python scripting to re-implement the serialization function.

Employed Russian
Thanks - don't know if python scripting would be able to do what I want but it sounds very useful all the same.
cyborg