I'm trying to implement managed debugger looking at MDBG sample. Currently I'm stuck trying to get base class hierarchy methods using IMetaDataImport.
EnumMethods, that I'm using, enumerates MethodDef tokens representing methods of the specified type. But I want to enumerate all the methods in class hierarchy. To do that I'm using GetTypeDefProps, that returns ptkExtends, which is token representing the base class. The problem is that base class could be represented by TypeDef, TypeRef or TypeSpec.
How can I get base class TypeDef from relative TypeSpec?
I've read ECMA part II specifications, but it didn't help me a lot...
Here is what I got so far:
int size;
TypeAttributes pdwTypeDefFlags;
m_importer.GetTypeDefProps(m_typeToken,
null,
0,
out size,
out pdwTypeDefFlags,
out ptkExtends
);
//ptkExtends is correct TypeSpec token
IntPtr ppvSig;
uint pcbSig;
m_importer.GetTypeSpecFromToken(ptkExtends, out ppvSig, out pcbSig);
//I'm getting the TypeSpec Blob signature in ppvSig, how to use it to get TypeDef?!
As stated previously, the TypeSpec format is defined in Partition II Section 23.2.14, its expressed with something resembling EBNF with the terminals defined in section 23.1.16.
A TypeSpec can represent a range of different kinds of types, but the only one that makes sense for a base class is
GENERICINST
(a closed generic type).TypeDefOrRefEncoded
is defined in section 23.2.8, compressed integers are defined at the start of section 23.2 andType
is defined in section 23.2.12.Given the bytes from your previous example (
15 12 3C 01 12 36
), my 'back of the napkin' scratching's come up with the following: