gdb: show typeinfo of some data

吃可爱长大的小学妹 提交于 2019-11-29 06:08:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!