How can one inspect a vtable in Visual C++?

后端 未结 2 1023
独厮守ぢ
独厮守ぢ 2021-02-10 18:00

Suppose one had inherited a complex codebase (in Visual C++, assume 2003 or perhaps later) with a large and complex inheritance graph. Suppose it\'s deep, and there\'s lots of v

2条回答
  •  你的背包
    2021-02-10 19:02

    With Visual Studio 2005 there are two undocumented flags that does exactly what you need. They are the reportAllClassLayout and reportSingleClassLayout flags. For example try "/d1 reportAllClassLayout" on the cl.exe commandline. It will show you the full class layout including virtual tables, here's an Example. Also see http://blogs.msdn.com/vcblog/archive/2007/05/17/diagnosing-hidden-odr-violations-in-visual-c-and-fixing-lnk2022.aspx There isn't too much information on these flags because they are undocumented for now but maybe Microsoft will officially support them in future versions of visual studio.

    Another approach, and actually what I prefer, is to use the IDA Pro Interactive disassembler. There is a huge learning curve, but IDA is smart enough to help you build VTables and links them to your classes. It's used to reverse engineer binaries that you don't have symbols for traditionally but it does use visual studio pdb files too. Doing so you will see exactly what all your vtables look like. Which virtual tables are being used for what methods, or what methods are being overridden, all whilst stepping through the code. In other words you actually see your method calls being traced into the vtable during runtime debugging. Typical debuggers like VS debugger don't trace into virtual tables as you've noticed.

提交回复
热议问题