Reconstructing a Managed C++ vtbl using IDiaSymbol: problems



We are reconstructing the virtual function table (vtbl) of a managed C++
class. We use IDiaSymbol::get_token() to get the token associated with a
virtual function, and IDiaSymbol::get_virtualBaseOffset() to retrieve the
offset in the virtual function table.

Both these methods have been observed to return incorrect data. get_token()
sometimes returns S_OK and outputs the method's MSIL token, and sometimes
returns S_FALSE. get_virtualBaseOffset() has been observed to output the
same offset for several overloads of a method, with S_OK return code; it has
also been observed to return very large values (e.g., 650), but we have not
developed a reproducible test case for this latter behavior. We do have a
test case that outputs the same virtualBaseOffset value for distinct
overloads of a method, and returns S_FALSE for some SymTagFunction symbols'
get_token().

Our desired result is a std::map<size_t, mdToken> which maps method tokens
by their offset within the vtbl. If get_token() always returned the method's
token, and get_virtualBaseOffset() returned "the offset in the virtual
function table of a virtual function", to quote its documentation, then we
could develop our desired table.

Our questions, then, are:

1. Are we using the correct routines to extract information from DIA?
2. If so, are there bugfixes to cause DIA to consistently return MSIL
tokens, and to return correct vtbl offsets?
3. If not, is there an alternative way to extract this information? We
also have the PE file open and can use IMetadataImport APIs, or query the PE
metadata directly.


REPRODUCIBLE TEST CASE:

Our test case consists of a modification to the Microsoft sample "dia2dump"
application, and a sample Managed C++ project whose PDB data exhibits the
problem. The changes to dia2dump attempt to extract the token and
virtualBaseOffset properties from a SymTagFunction IDiaSymbol.

.



Relevant Pages

  • Re: Pointer to virtual object on stack
    ... > I need help to resolve confusion on following example: ... > virtual methods then B's virtual methods. ... They share the vtbl. ... a virtual function call is to be made, ...
    (comp.lang.cpp)
  • Re: Cant export vector<> from DLL
    ... Clients may override its implementation, but if they don't then I ... the new DLL isn't backward compatible. ... vicinity of a call to my new virtual function. ... Given that you changed the vtbl layout by adding a virtual function, ...
    (microsoft.public.dotnet.languages.vc)
  • Inspecting object virtual function table & memory layout?
    ... I'm wondering if there's an easy way to inspect the virtual function table ... (a.k.a. vtable or vtbl) ... and memory layout of an C++ object. ... I've been trying to use dumpbin to do ...
    (microsoft.public.vc.language)

Loading