问题
Basically, I want to get typeid(*this).name()
, i.e. the real type of this
.
I want to get this in GDB (without modifying the source code). I tried print typeid(*this)
but it says that typeid
is unknown (because I didn't included it there in the source file).
回答1:
Use ptype
command, like this:
(gdb) ptype 42
type = int
回答2:
The 'ptype [ARG]' command will print the type.
回答3:
This question may be related: vtable in polymorphic class of C++ using gdb:
(gdb) help set print object
Set printing of object's derived type based on vtable info.
It's not exactly typeid() but it should show the real object type when inspecting a polymorphic pointer (e.g. this
in a base class). Naturally works only for classes with a vtable (i.e. at least one virtual method) but so does typeid
.
来源:https://stackoverflow.com/questions/9568201/gdb-show-typeinfo-of-some-data