0

I am debugging a c++ program with gdb in eclipse. How can I now the exact class of an object? Let's say I am debugging a method

void foo(Instruction *I){
  I->bar();
}

Let's say also that Instruction has a lot of subclasses. how can I know which subclass of Instruction instantiates object I?

Giacomo Tagliabue
  • 1,679
  • 2
  • 15
  • 31
  • Give your subclass Tag fields. It can be just simple enum. Set them in each subclass's constructors. –  Apr 05 '13 at 22:08
  • I am searching for a solution within GDB, without modifying the code – Giacomo Tagliabue Apr 05 '13 at 22:09
  • Can you dynamic_cast in gdb's command line? Otherwise, find a vptr? – Alex Chamberlain Apr 05 '13 at 22:11
  • I can dynamic cast in gdb, but, since the sublasses are more than 50, it would be cumbersome. What is vptr? – Giacomo Tagliabue Apr 05 '13 at 22:12
  • I know visual studio show you this information. There should be something similar in eclipse. –  Apr 05 '13 at 22:17
  • As identified by [this q](http://stackoverflow.com/questions/8528979/how-to-determine-whether-an-object-is-an-instance-of-certain-c-class-in-gdb) use the gdb command `set print object on` so that when you invoke `ptype I` the derived class will be identified. – jeffmagill Apr 06 '13 at 03:20

1 Answers1

0

You want "set print object on". This will use the RTTI information to print the full object.

This should be the default; hopefully it will be eventually.

Tom Tromey
  • 21,507
  • 2
  • 45
  • 63