c++gdbcore-file

Howto examine return value from object function in a core?


Example code:

struct Message {
   virtual int id() const { return 0; }
};
struct Ping : public Message {
   virtual int id() const { return 1; }
};

Suppose you have a core file loaded in gdb. Here you have a Message * msg; Are there a simple way to figure out what id function will return on msg?


Solution

  • You can use "set print object on" to enable vtable inspection to print the derived type of objects. This is so desirable for C++ that I've had it in my .gdbinit for 15 years.

    You can't call the methods when using a core, of course, but you can then at least see the real type and look up the method yourself.