2

I have looked for a similar question to mine but the closest I found was Continue debugging after SegFault in GDB

My goal is to invoke a function in GDB from a coredump. I have a C++ type which has the operator<< defined and I would like to pretty print this type without having to write a pretty printer in python.

From what I have found so far it seems that GDB treats coredumps differently from regular inferiors which have active execution and hence cannot invoke functions (as is confirmed by this answer which states you can't use continue for a coredump).

Though I can see why that might be the case by default, could GDB be patched to load a coredump into memory and invoke it as a running process? If the program terminated due to a Seg. Fault then it is possible to manually alter the broken path after loading the core in GDB and potentially even continue executing the program after.

nonsensickle
  • 4,438
  • 2
  • 34
  • 61
  • Very close to [c++ - gdb pretty printing with direct function calls - Stack Overflow](https://stackoverflow.com/questions/8578320/gdb-pretty-printing-with-direct-function-calls) – user202729 Mar 10 '22 at 02:09
  • Side note, you can also choose to write **only** a pretty printer in Python, then call it from C++ side to pretty print it: [How can I make a C++ function that can pretty print every object, using gdb? - Stack Overflow](https://stackoverflow.com/questions/60343020/how-can-i-make-a-c-function-that-can-pretty-print-every-object-using-gdb/71418512#71418512) – user202729 Mar 10 '22 at 03:52
  • This is a great question, did you make any progress on this ? – Anton Belov Oct 14 '22 at 11:25

1 Answers1

2

Though I can see why that might be the case by default, could GDB be patched to load a coredump into memory and invoke it as a running process?

In theory, this is possible. In practice, you'll find that this is a major undertaking, which will (likely) take you at least several weeks, if not several months.

I would like to pretty print this type without having to write a pretty printer in python.

I can assure you that writing a pretty-printer in Python is a lot less work.

If the program terminated due to a Seg. Fault then it is possible to manually alter the broken path after loading the core in GDB and potentially even continue executing the program after.

Not if the program uses any OS-level resources which are not captured in the core dump. All sockets, files, SysV IPCs, etc. etc. will be gone. This answer agrees.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362