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

后端 未结 2 1022
独厮守ぢ
独厮守ぢ 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 18:44

    I would highly recommend using Doxygen as a tool for any sort of code analysis like this. I don't think it has a quick way to find the final overrider for any function in a type, but it should provide a listing of what is inherited and what is implemented, so that you can quickly scan the tree to identify the overrider for any given function (usually, your hierarchy isn't big enough as to make it a big deal). It can also generate call graphs, relation graphs, and hyperlinked source code, which is a fantastic tool.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题