I would like to capture what is, in effect, a heap dump at procedure call time in a C (or C++) program. However, I am interested in what is heap-reachable from global variables and arguments.
This might be done by using some gdb
command that dumps memory - is there a way to restrict that to the heap that is reachable from the entry points above? If not, is it possible to dump core and then reverse engineer the reachable part, or is there a fundamental reason why not?
Another angle might be to run the program under an emulator like valgrind
. But as far as I know, only statistics can be captured this way, not actual heap contents.
Yet another possibility might be to patch/abuse a library like dmalloc
or electric fence. Would this be remotely workable?
Full debug information can be safely assumed, as well as access to the source code, e.g., for instrumentation purposes.