public static MonoClassInfo ReadClassInfo(MonoLanguageBackend mono,
TargetMemoryAccess target,
TargetAddress klass)
{
TargetAddress image = mono.MetadataHelper.MonoClassGetMonoImage (target, klass);
MonoSymbolFile file = mono.GetImage (image);
if (file == null)
throw new InternalError ();
int token = mono.MetadataHelper.MonoClassGetToken (target, klass);
if ((token & 0xff000000) != 0x02000000)
throw new InternalError ();
Cecil.TypeDefinition typedef;
typedef = (Cecil.TypeDefinition) file.ModuleDefinition.LookupByToken (
Cecil.Metadata.TokenType.TypeDef, token & 0x00ffffff);
if (typedef == null)
throw new InternalError ();
MonoClassInfo info = new MonoClassInfo (file, typedef, target, klass);
if ((file == mono.BuiltinTypes.Corlib) &&
(typedef.FullName == "System.Decimal")) {
MonoFundamentalType ftype = mono.BuiltinTypes.DecimalType;
if (ftype.ClassType == null) {
MonoClassType ctype = new MonoClassType (file, typedef, info);
((IMonoStructType) ctype).ClassInfo = info;
ftype.SetClass (ctype);
}
info.struct_type = (IMonoStructType) ftype.ClassType;
info.type = ftype;
} else if (info.IsGenericClass) {
info.struct_type = (IMonoStructType)
file.MonoLanguage.ReadGenericClass (
target, info.GenericClass, false);
info.type = info.struct_type.Type;
} else {
info.type = file.LookupMonoType (typedef);
if (info.type is TargetClassType)
info.struct_type = (IMonoStructType) info.type;
else
info.struct_type = (IMonoStructType) info.type.ClassType;
}
info.struct_type.ClassInfo = info;
return info;
}