Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

More Cecil stuff.

svn path=/branches/debugger-cecil/; revision=49562
  • Loading branch information...
commit adf5dbf30cc34635c7f74a7270a2ed2e46ee9f6b 1 parent f4220f4
Martin Baulig authored
View
7 backends/mono/MonoArrayType.cs
@@ -1,6 +1,7 @@
using System;
using System.Text;
using C = Mono.CompilerServices.SymbolWriter;
+using Cecil = Mono.Cecil;
namespace Mono.Debugger.Languages.Mono
{
@@ -24,13 +25,13 @@ internal class MonoArrayType : MonoType, ITargetArrayType
protected MonoType element_type;
protected MonoArrayType subarray_type;
- public MonoArrayType (MonoSymbolFile file, Type type)
+ public MonoArrayType (MonoSymbolFile file, Cecil.IArrayType type)
: base (file, TargetObjectKind.Array, type)
{
- this.Rank = type.GetArrayRank ();
+ this.Rank = type.Rank;
this.Dimension = 0;
- element_type = file.MonoLanguage.LookupMonoType (type.GetElementType ());
+ element_type = file.LookupMonoType (type.ElementType);
if (Dimension + 1 < Rank)
subarray_type = new MonoArrayType (this);
View
132 backends/mono/MonoClassType.cs
@@ -1,7 +1,7 @@
using System;
using System.Text;
-using R = System.Reflection;
using C = Mono.CompilerServices.SymbolWriter;
+using Cecil = Mono.Cecil;
namespace Mono.Debugger.Languages.Mono
{
@@ -21,11 +21,14 @@ internal class MonoClassType : MonoType, ITargetClassType
int num_methods = 0, num_smethods = 0;
internal int first_method = 0, first_smethod = 0;
+ Cecil.ITypeDefinition type;
MonoClassType parent_type;
- public MonoClassType (MonoSymbolFile file, Type type)
+ public MonoClassType (MonoSymbolFile file, Cecil.ITypeDefinition type)
: base (file, TargetObjectKind.Class, type)
{
+ this.type = type;
+
if (type.BaseType != null)
parent_type = file.MonoLanguage.LookupMonoType (type.BaseType) as MonoClassType;
}
@@ -49,11 +52,7 @@ void get_fields ()
int num_fields = 0, num_sfields = 0;
- R.FieldInfo[] finfo = type.GetFields (
- R.BindingFlags.DeclaredOnly | R.BindingFlags.Static | R.BindingFlags.Instance |
- R.BindingFlags.Public | R.BindingFlags.NonPublic);
-
- foreach (R.FieldInfo field in finfo) {
+ foreach (Cecil.IFieldDefinition field in type.Fields) {
if (field.IsStatic)
num_sfields++;
else
@@ -63,15 +62,17 @@ void get_fields ()
fields = new MonoFieldInfo [num_fields];
static_fields = new MonoFieldInfo [num_sfields];
- int pos = 0, spos = 0;
- for (int i = 0; i < finfo.Length; i++) {
- if (finfo [i].IsStatic) {
- static_fields [spos] = new MonoFieldInfo (File, spos, i, finfo [i]);
+ int pos = 0, spos = 0, i = 0;
+ foreach (Cecil.IFieldDefinition field in type.Fields) {
+ if (field.IsStatic) {
+ static_fields [spos] = new MonoFieldInfo (File, spos, i, field);
spos++;
} else {
- fields [pos] = new MonoFieldInfo (File, pos, i, finfo [i]);
+ fields [pos] = new MonoFieldInfo (File, pos, i, field);
pos++;
}
+
+ i++;
}
}
@@ -138,12 +139,8 @@ void get_methods ()
if (methods != null)
return;
- R.MethodInfo[] minfo = type.GetMethods (
- R.BindingFlags.DeclaredOnly | R.BindingFlags.Static | R.BindingFlags.Instance |
- R.BindingFlags.Public | R.BindingFlags.NonPublic);
-
- foreach (R.MethodInfo method in minfo) {
- if ((method.Attributes & R.MethodAttributes.SpecialName) != 0)
+ foreach (Cecil.IMethodDefinition method in type.Methods) {
+ if ((method.Attributes & Cecil.MethodAttributes.SpecialName) != 0)
continue;
if (method.IsStatic)
num_smethods++;
@@ -161,14 +158,14 @@ void get_methods ()
}
int pos = 0, spos = 0;
- for (int i = 0; i < minfo.Length; i++) {
- if ((minfo [i].Attributes & R.MethodAttributes.SpecialName) != 0)
+ foreach (Cecil.IMethodDefinition method in type.Methods) {
+ if ((method.Attributes & Cecil.MethodAttributes.SpecialName) != 0)
continue;
- if (minfo [i].IsStatic) {
- static_methods [spos] = new MonoMethodInfo (this, first_smethod + spos, minfo [i]);
+ if (method.IsStatic) {
+ static_methods [spos] = new MonoMethodInfo (this, spos, method);
spos++;
} else {
- methods [pos] = new MonoMethodInfo (this, first_method + pos, minfo [i]);
+ methods [pos] = new MonoMethodInfo (this, pos, method);
pos++;
}
}
@@ -212,23 +209,35 @@ void get_properties ()
if (properties != null)
return;
- R.PropertyInfo[] pinfo = type.GetProperties (
- R.BindingFlags.DeclaredOnly | R.BindingFlags.Instance |
- R.BindingFlags.Public | R.BindingFlags.NonPublic);
+ int num_sproperties = 0, num_properties = 0;
- properties = new MonoPropertyInfo [pinfo.Length];
+ foreach (Cecil.IPropertyDefinition prop in type.Properties) {
+ Cecil.IMethodDefinition m = prop.GetMethod;
+ if (m == null) m = prop.SetMethod;
- for (int i = 0; i < pinfo.Length; i++)
- properties [i] = new MonoPropertyInfo (this, i, pinfo [i], false);
+ if (m.IsStatic)
+ num_sproperties++;
+ else
+ num_properties++;
+ }
- pinfo = type.GetProperties (
- R.BindingFlags.DeclaredOnly | R.BindingFlags.Static |
- R.BindingFlags.Public | R.BindingFlags.NonPublic);
+ properties = new MonoPropertyInfo [num_properties];
+ static_properties = new MonoPropertyInfo [num_sproperties];
- static_properties = new MonoPropertyInfo [pinfo.Length];
+ int pos = 0, spos = 0;
+ foreach (Cecil.IPropertyDefinition prop in type.Properties) {
+ Cecil.IMethodDefinition m = prop.GetMethod;
+ if (m == null) m = prop.SetMethod;
- for (int i = 0; i < pinfo.Length; i++)
- static_properties [i] = new MonoPropertyInfo (this, i, pinfo [i], true);
+ if (m.IsStatic) {
+ static_properties [spos] = new MonoPropertyInfo (this, spos, prop, true);
+ spos++;
+ }
+ else {
+ static_properties [pos] = new MonoPropertyInfo (this, spos, prop, false);
+ pos++;
+ }
+ }
}
internal MonoPropertyInfo[] Properties {
@@ -264,23 +273,32 @@ void get_events ()
if (events != null)
return;
- R.EventInfo[] einfo = type.GetEvents (
- R.BindingFlags.DeclaredOnly | R.BindingFlags.Instance |
- R.BindingFlags.Public | R.BindingFlags.NonPublic);
-
- events = new MonoEventInfo [einfo.Length];
+ int num_sevents = 0, num_events = 0;
+ foreach (Cecil.IEventDefinition ev in type.Events) {
+ Cecil.IMethodDefinition m = ev.AddMethod;
- for (int i = 0; i < einfo.Length; i++)
- events [i] = new MonoEventInfo (this, i, einfo [i], false);
+ if (m.IsStatic)
+ num_sevents++;
+ else
+ num_events++;
+ }
- einfo = type.GetEvents (
- R.BindingFlags.DeclaredOnly | R.BindingFlags.Static |
- R.BindingFlags.Public | R.BindingFlags.NonPublic);
+ events = new MonoEventInfo [num_events];
+ static_events = new MonoEventInfo [num_sevents];
- static_events = new MonoEventInfo [einfo.Length];
+ int pos = 0, spos = 0;
+ foreach (Cecil.IEventDefinition ev in type.Events) {
+ Cecil.IMethodDefinition m = ev.AddMethod;
- for (int i = 0; i < einfo.Length; i++)
- static_events [i] = new MonoEventInfo (this, i, einfo [i], true);
+ if (m.IsStatic) {
+ static_events [spos] = new MonoEventInfo (this, spos, ev, true);
+ spos++;
+ }
+ else {
+ static_events [pos] = new MonoEventInfo (this, spos, ev, false);
+ pos++;
+ }
+ }
}
public ITargetEventInfo[] Events {
@@ -310,27 +328,23 @@ void get_constructors ()
int num_ctors = 0, num_sctors = 0;
- R.ConstructorInfo[] minfo = type.GetConstructors (
- R.BindingFlags.DeclaredOnly | R.BindingFlags.Static | R.BindingFlags.Instance |
- R.BindingFlags.Public | R.BindingFlags.NonPublic);
-
- foreach (R.ConstructorInfo method in minfo) {
+ foreach (Cecil.IMethodDefinition method in type.Constructors) {
if (method.IsStatic)
num_sctors++;
else
num_ctors++;
}
- constructors = new MonoMethodInfo [num_ctors];
- static_constructors = new MonoMethodInfo [num_sctors];
+ constructors = new MonoMethodInfo [num_methods];
+ static_constructors = new MonoMethodInfo [num_smethods];
int pos = 0, spos = 0;
- for (int i = 0; i < minfo.Length; i++) {
- if (minfo [i].IsStatic) {
- static_constructors [spos] = new MonoMethodInfo (this, spos, minfo [i]);
+ foreach (Cecil.IMethodDefinition method in type.Constructors) {
+ if (method.IsStatic) {
+ static_constructors [spos] = new MonoMethodInfo (this, spos, method);
spos++;
} else {
- constructors [pos] = new MonoMethodInfo (this, pos, minfo [i]);
+ constructors [pos] = new MonoMethodInfo (this, pos, method);
pos++;
}
}
View
30 backends/mono/MonoEnumType.cs
@@ -1,7 +1,7 @@
using System;
using System.Text;
-using R = System.Reflection;
using C = Mono.CompilerServices.SymbolWriter;
+using Cecil = Mono.Cecil;
namespace Mono.Debugger.Languages.Mono
{
@@ -10,9 +10,13 @@ internal class MonoEnumType : MonoType, ITargetEnumType
MonoFieldInfo[] fields;
MonoFieldInfo[] static_fields;
- public MonoEnumType (MonoSymbolFile file, Type type)
+ Cecil.ITypeDefinition type;
+
+ public MonoEnumType (MonoSymbolFile file, Cecil.ITypeDefinition type)
: base (file, TargetObjectKind.Enum, type)
- { }
+ {
+ this.type = type;
+ }
public override bool IsByRef {
get { return !type.IsValueType; }
@@ -25,11 +29,7 @@ void get_fields ()
int num_fields = 0, num_sfields = 0;
- R.FieldInfo[] finfo = type.GetFields (
- R.BindingFlags.DeclaredOnly | R.BindingFlags.Static | R.BindingFlags.Instance |
- R.BindingFlags.Public | R.BindingFlags.NonPublic);
-
- foreach (R.FieldInfo field in finfo) {
+ foreach (Cecil.IFieldDefinition field in type.Fields) {
if (field.IsStatic)
num_sfields++;
else
@@ -39,17 +39,19 @@ void get_fields ()
fields = new MonoFieldInfo [num_fields];
static_fields = new MonoFieldInfo [num_sfields];
- int pos = 0, spos = 0;
- for (int i = 0; i < finfo.Length; i++) {
- if (finfo [i].IsStatic) {
- static_fields [spos] = new MonoFieldInfo (File, spos, i, finfo [i]);
+ int pos = 0, spos = 0, i = 0;
+ foreach (Cecil.IFieldDefinition field in type.Fields) {
+ if (field.IsStatic) {
+ static_fields [spos] = new MonoFieldInfo (File, spos, i, field);
spos++;
} else {
- if (finfo[i].Name != "value__")
+ if (field.Name != "value__")
throw new InternalError ("Mono enum type has instance field with name other than 'value__'.");
- fields [pos] = new MonoFieldInfo (File, pos, i, finfo [i]);
+ fields [pos] = new MonoFieldInfo (File, pos, i, field);
pos++;
}
+
+ i++;
}
if (pos > 1)
throw new InternalError ("Mono enum type has more than one instance field.");
View
30 backends/mono/MonoFunctionType.cs
@@ -1,41 +1,41 @@
using System;
using System.Collections;
-using R = System.Reflection;
using C = Mono.CompilerServices.SymbolWriter;
+using Cecil = Mono.Cecil;
namespace Mono.Debugger.Languages.Mono
{
internal class MonoFunctionType : MonoType, ITargetFunctionType
{
MonoClassType klass;
- R.MethodBase method_info;
+ Cecil.IMethodDefinition method_info;
MonoType return_type;
MonoType[] parameter_types;
bool has_return_type;
int token;
- public MonoFunctionType (MonoSymbolFile file, MonoClassType klass, R.MethodBase mbase)
- : base (file, TargetObjectKind.Function, mbase.ReflectedType)
+ public MonoFunctionType (MonoSymbolFile file, MonoClassType klass,
+ Cecil.IMethodDefinition mdef)
+ : base (file, TargetObjectKind.Function, mdef.DeclaringType)
{
this.klass = klass;
- this.method_info = mbase;
- this.token = MonoDebuggerSupport.GetMethodToken (mbase);
+ this.method_info = mdef;
+ this.token = MonoDebuggerSupport.GetMethodToken (mdef);
- Type rtype;
- if (mbase is R.ConstructorInfo) {
- rtype = mbase.DeclaringType;
+ Cecil.ITypeReference rtype;
+ if (mdef.IsConstructor) {
+ rtype = mdef.DeclaringType;
has_return_type = true;
} else {
- rtype = ((R.MethodInfo) mbase).ReturnType;
- has_return_type = rtype != typeof (void);
+ rtype = mdef.ReturnType.ReturnType;
+ has_return_type = rtype != null;
}
return_type = file.MonoLanguage.LookupMonoType (rtype);
- R.ParameterInfo[] pinfo = mbase.GetParameters ();
- parameter_types = new MonoType [pinfo.Length];
- for (int i = 0; i < parameter_types.Length; i++)
+ parameter_types = new MonoType [mdef.Parameters.Count];
+ for (int i = 0; i < mdef.Parameters.Count; i++)
parameter_types [i] = file.MonoLanguage.LookupMonoType (
- pinfo [i].ParameterType);
+ mdef.Parameters[i].ParameterType);
}
public override bool IsByRef {
View
2  backends/mono/MonoFundamentalType.cs
@@ -9,7 +9,7 @@ internal class MonoFundamentalType : MonoType, ITargetFundamentalType
protected readonly TargetAddress klass_address;
protected readonly FundamentalKind fundamental_kind;
- public MonoFundamentalType (MonoSymbolFile file, Type type,
+ public MonoFundamentalType (MonoSymbolFile file, Cecil.ITypeDefinition type,
FundamentalKind kind, int size, TargetAddress klass)
: base (file, TargetObjectKind.Fundamental, type)
{
View
108 backends/mono/MonoLanguageBackend.cs
@@ -1,11 +1,11 @@
using System;
using System.IO;
using System.Text;
-using R = System.Reflection;
using System.Runtime.InteropServices;
using System.Collections;
using System.Threading;
using C = Mono.CompilerServices.SymbolWriter;
+using R = System.Reflection;
using Mono.Debugger;
using Mono.Debugger.Backends;
using Mono.Debugger.Architecture;
@@ -127,89 +127,88 @@ internal class MonoBuiltinTypeInfo
TargetAddress klass = mono_defaults.ReadGlobalAddress ();
int object_size = 2 * corlib.TargetInfo.TargetAddressSize;
- Type object_type = corlib.Assembly.GetType ("System.Object");
+ Cecil.ITypeDefinition object_type = corlib.Module.Types ["System.Object"];
ObjectType = new MonoObjectType (corlib, object_type, object_size, klass);
corlib.AddCoreType (ObjectType);
klass = mono_defaults.ReadGlobalAddress ();
- Type byte_type = corlib.Assembly.GetType ("System.Byte");
- ByteType = new MonoFundamentalType (
- corlib, byte_type, FundamentalKind.Byte, 1, klass);
+ Cecil.ITypeDefinition byte_type = corlib.Module.Types ["System.Byte"];
+ ByteType = new MonoFundamentalType (corlib, byte_type, FundamentalKind.Byte, 1, klass);
corlib.AddCoreType (ByteType);
klass = mono_defaults.ReadGlobalAddress ();
- Type void_type = corlib.Assembly.GetType ("System.Void");
+ Cecil.ITypeDefinition void_type = corlib.Module.Types ["System.Void"];
VoidType = new MonoOpaqueType (corlib, void_type);
corlib.AddCoreType (VoidType);
klass = mono_defaults.ReadGlobalAddress ();
- Type bool_type = corlib.Assembly.GetType ("System.Boolean");
+ Cecil.ITypeDefinition bool_type = corlib.Module.Types ["System.Boolean"];
BooleanType = new MonoFundamentalType (corlib, bool_type, FundamentalKind.Byte, 1, klass);
corlib.AddCoreType (BooleanType);
klass = mono_defaults.ReadGlobalAddress ();
- Type sbyte_type = corlib.Assembly.GetType ("System.SByte");
+ Cecil.ITypeDefinition sbyte_type = corlib.Module.Types ["System.SByte"];
SByteType = new MonoFundamentalType (corlib, sbyte_type, FundamentalKind.SByte, 1, klass);
corlib.AddCoreType (SByteType);
klass = mono_defaults.ReadGlobalAddress ();
- Type short_type = corlib.Assembly.GetType ("System.Int16");
+ Cecil.ITypeDefinition short_type = corlib.Module.Types ["System.Int16"];
Int16Type = new MonoFundamentalType (corlib, short_type, FundamentalKind.Int16, 2, klass);
corlib.AddCoreType (Int16Type);
klass = mono_defaults.ReadGlobalAddress ();
- Type ushort_type = corlib.Assembly.GetType ("System.UInt16");
+ Cecil.ITypeDefinition ushort_type = corlib.Module.Types ["System.UInt16"];
UInt16Type = new MonoFundamentalType (corlib, ushort_type, FundamentalKind.UInt16, 2, klass);
corlib.AddCoreType (UInt16Type);
klass = mono_defaults.ReadGlobalAddress ();
- Type int_type = corlib.Assembly.GetType ("System.Int32");
+ Cecil.ITypeDefinition int_type = corlib.Module.Types ["System.Int32"];
Int32Type = new MonoFundamentalType (corlib, int_type, FundamentalKind.Int32, 4, klass);
Int32Type.GetTypeInfo ();
corlib.AddCoreType (Int32Type);
klass = mono_defaults.ReadGlobalAddress ();
- Type uint_type = corlib.Assembly.GetType ("System.UInt32");
+ Cecil.ITypeDefinition uint_type = corlib.Module.Types ["System.UInt32"];
UInt32Type = new MonoFundamentalType (corlib, uint_type, FundamentalKind.UInt32, 4, klass);
corlib.AddCoreType (UInt32Type);
klass = mono_defaults.ReadGlobalAddress ();
- Type intptr_type = corlib.Assembly.GetType ("System.IntPtr");
+ Cecil.ITypeDefinition intptr_type = corlib.Module.Types ["System.IntPtr"];
IntType = new MonoFundamentalType (corlib, intptr_type, FundamentalKind.IntPtr, 4, klass);
corlib.AddCoreType (IntType);
klass = mono_defaults.ReadGlobalAddress ();
- Type uintptr_type = corlib.Assembly.GetType ("System.UIntPtr");
- UIntType = new MonoFundamentalType (corlib, uintptr_type, FundamentalKind.UIntPtr, 4, klass);
+ Cecil.ITypeDefinition uintptr_type = corlib.Module.Types ["System.UIntPtr"];
+ UIntType = new MonoFundamentalType (corlib, uintptr_type, FundamentalKind.Object, 4, klass);
corlib.AddCoreType (UIntType);
klass = mono_defaults.ReadGlobalAddress ();
- Type long_type = corlib.Assembly.GetType ("System.Int64");
+ Cecil.ITypeDefinition long_type = corlib.Module.Types ["System.Int64"];
Int64Type = new MonoFundamentalType (corlib, long_type, FundamentalKind.Int64, 8, klass);
corlib.AddCoreType (Int64Type);
klass = mono_defaults.ReadGlobalAddress ();
- Type ulong_type = corlib.Assembly.GetType ("System.UInt64");
+ Cecil.ITypeDefinition ulong_type = corlib.Module.Types ["System.UInt64"];
UInt64Type = new MonoFundamentalType (corlib, ulong_type, FundamentalKind.UInt64, 8, klass);
corlib.AddCoreType (UInt64Type);
klass = mono_defaults.ReadGlobalAddress ();
- Type float_type = corlib.Assembly.GetType ("System.Single");
+ Cecil.ITypeDefinition float_type = corlib.Module.Types ["System.Single"];
SingleType = new MonoFundamentalType (corlib, float_type, FundamentalKind.Single, 4, klass);
corlib.AddCoreType (SingleType);
klass = mono_defaults.ReadGlobalAddress ();
- Type double_type = corlib.Assembly.GetType ("System.Double");
+ Cecil.ITypeDefinition double_type = corlib.Module.Types ["System.Double"];
DoubleType = new MonoFundamentalType (corlib, double_type, FundamentalKind.Double, 8, klass);
corlib.AddCoreType (DoubleType);
klass = mono_defaults.ReadGlobalAddress ();
- Type char_type = corlib.Assembly.GetType ("System.Char");
+ Cecil.ITypeDefinition char_type = corlib.Module.Types ["System.Char"];
CharType = new MonoFundamentalType (corlib, char_type, FundamentalKind.Char, 2, klass);
corlib.AddCoreType (CharType);
klass = mono_defaults.ReadGlobalAddress ();
- Type string_type = corlib.Assembly.GetType ("System.String");
+ Cecil.ITypeDefinition string_type = corlib.Module.Types ["System.String"];
StringType = new MonoStringType (
corlib, string_type, object_size, object_size + 4, klass);
corlib.AddCoreType (StringType);
@@ -219,7 +218,7 @@ internal class MonoBuiltinTypeInfo
// and get to the Exception class
klass = mono_defaults.ReadGlobalAddress ();
- Type exception_type = corlib.Assembly.GetType ("System.Exception");
+ Cecil.ITypeDefinition exception_type = corlib.Module.Types ["System.Exception"];
ExceptionType = new MonoClassType (corlib, exception_type);
corlib.AddCoreType (ExceptionType);
}
@@ -228,22 +227,15 @@ internal class MonoBuiltinTypeInfo
internal static class MonoDebuggerSupport
{
static GetTypeFunc get_type;
- static GetMethodTokenFunc get_method_token;
- static GetMethodFunc get_method;
static GetLocalTypeFromSignatureFunc local_type_from_sig;
static GetGuidFunc get_guid;
static CheckRuntimeVersionFunc check_runtime_version;
- static MakeArrayTypeFunc make_array_type;
- static ResolveTypeFunc resolve_type;
- static GetTypeTokenFunc get_type_token;
delegate Type GetTypeFunc (R.Assembly assembly, int token);
- delegate int GetMethodTokenFunc (R.MethodBase method);
delegate R.MethodBase GetMethodFunc (R.Assembly assembly, int token);
delegate Type GetLocalTypeFromSignatureFunc (R.Assembly assembly, byte[] sig);
delegate Guid GetGuidFunc (R.Module module);
delegate string CheckRuntimeVersionFunc (string filename);
- delegate Type MakeArrayTypeFunc (Type type, int rank);
delegate Type ResolveTypeFunc (R.Module module, int token);
delegate int GetTypeTokenFunc (Type type);
@@ -263,14 +255,6 @@ static MonoDebuggerSupport ()
typeof (R.Assembly), typeof (GetTypeFunc),
"MonoDebugger_GetType");
- get_method_token = (GetMethodTokenFunc) create_delegate (
- typeof (R.Assembly), typeof (GetMethodTokenFunc),
- "MonoDebugger_GetMethodToken");
-
- get_method = (GetMethodFunc) create_delegate (
- typeof (R.Assembly), typeof (GetMethodFunc),
- "MonoDebugger_GetMethod");
-
local_type_from_sig = (GetLocalTypeFromSignatureFunc) create_delegate (
typeof (R.Assembly), typeof (GetLocalTypeFromSignatureFunc),
"MonoDebugger_GetLocalTypeFromSignature");
@@ -281,18 +265,6 @@ static MonoDebuggerSupport ()
check_runtime_version = (CheckRuntimeVersionFunc) create_delegate (
typeof (R.Assembly), typeof (CheckRuntimeVersionFunc),
"MonoDebugger_CheckRuntimeVersion");
-
- make_array_type = (MakeArrayTypeFunc) create_delegate (
- typeof (R.Assembly), typeof (MakeArrayTypeFunc),
- "MonoDebugger_MakeArrayType");
-
- resolve_type = (ResolveTypeFunc) create_delegate (
- typeof (R.Module), typeof (ResolveTypeFunc),
- "MonoDebugger_ResolveType");
-
- get_type_token = (GetTypeTokenFunc) create_delegate (
- typeof (R.Assembly), typeof (GetTypeTokenFunc),
- "MonoDebugger_GetTypeToken");
}
public static Type GetType (R.Assembly assembly, int token)
@@ -300,14 +272,15 @@ public static Type GetType (R.Assembly assembly, int token)
return get_type (assembly, token);
}
- public static int GetMethodToken (R.MethodBase method)
+ public static int GetMethodToken (Cecil.IMethodDefinition method)
{
- return get_method_token (method);
+ return (int) (method.MetadataToken.TokenType + method.MetadataToken.RID);
}
- public static R.MethodBase GetMethod (R.Assembly assembly, int token)
+ public static Cecil.IMethodDefinition GetMethod (Cecil.IModuleDefinition module, int token)
{
- return get_method (assembly, token);
+ return (Cecil.IMethodDefinition) module.LookupByToken (
+ Cecil.Metadata.TokenType.Method, token & 0xffffff);
}
public static Type GetLocalTypeFromSignature (R.Assembly assembly, byte[] sig)
@@ -325,19 +298,21 @@ public static Guid GetGuid (R.Module module)
return get_guid (module);
}
- public static Type MakeArrayType (Type type, int rank)
+ public static Cecil.ITypeReference MakeArrayType (Cecil.ITypeReference type, int rank)
{
- return make_array_type (type, rank);
+ /// XXXX - TODO
+ throw new NotImplementedException ();
}
- public static Type ResolveType (R.Module module, int token)
+ public static Cecil.ITypeReference ResolveType (Cecil.IModuleDefinition module, int token)
{
- return resolve_type (module, token);
+ return (Cecil.ITypeReference) module.LookupByToken (
+ Cecil.Metadata.TokenType.TypeDef, token);
}
- public static int GetTypeToken (Type type)
+ public static int GetTypeToken (Cecil.ITypeReference type)
{
- return get_type_token (type);
+ return (int) (type.MetadataToken.TokenType + type.MetadataToken.RID);
}
}
@@ -410,11 +385,12 @@ internal bool TryFindImage (Process process, string filename)
return true;
}
- public MonoType LookupMonoType (Type type)
+ public MonoType LookupMonoType (Cecil.ITypeReference type)
{
- MonoSymbolFile file = (MonoSymbolFile) assembly_hash [type.Assembly];
+ MonoSymbolFile file = (MonoSymbolFile) assembly_hash [type.Module.Assembly];
if (file == null) {
- Console.WriteLine ("Type `{0}' from unknown assembly `{1}'", type, type.Assembly);
+ Console.WriteLine ("Type `{0}' from unknown assembly `{1}'",
+ type, type.Module.Assembly);
return null;
}
@@ -772,7 +748,7 @@ public ITargetType LookupType (StackFrame frame, string name)
mutex.Unlock ();
foreach (MonoSymbolFile symfile in symbol_files) {
- Type type = symfile.Assembly.GetType (name);
+ Cecil.ITypeDefinition type = symfile.Assembly.MainModule.Types [name];
if (type == null)
continue;
return symfile.LookupMonoType (type);
@@ -783,16 +759,20 @@ public ITargetType LookupType (StackFrame frame, string name)
public bool CanCreateInstance (Type type)
{
- return LookupMonoType (type) != null;
+ return false;
}
public ITargetObject CreateInstance (StackFrame frame, object obj)
{
+#if FIXME
MonoFundamentalType type = LookupMonoType (obj.GetType ()) as MonoFundamentalType;
if (type == null)
return null;
return type.CreateInstance (frame, obj);
+#else
+ throw new NotImplementedException ();
+#endif
}
public ITargetFundamentalObject CreateInstance (ITargetAccess target, int value)
View
47 backends/mono/MonoMember.cs
@@ -1,7 +1,6 @@
using System;
using System.Text;
-using R = System.Reflection;
-using C = Mono.CompilerServices.SymbolWriter;
+using Cecil = Mono.Cecil;
namespace Mono.Debugger.Languages.Mono
{
@@ -13,7 +12,7 @@ internal abstract class MonoMember : ITargetMemberInfo
public readonly int Index;
public readonly bool IsStatic;
- public MonoMember (MonoSymbolFile file, R.MemberInfo minfo, int index,
+ public MonoMember (MonoSymbolFile file, Cecil.IMemberReference minfo, int index,
bool is_static)
{
this.File = file;
@@ -58,10 +57,10 @@ internal class MonoFieldInfo : MonoMember, ITargetFieldInfo
bool is_literal;
[NonSerialized]
- public readonly R.FieldInfo FieldInfo;
+ public readonly Cecil.IFieldDefinition FieldInfo;
public readonly int Position;
- public MonoFieldInfo (MonoSymbolFile file, int index, int pos, R.FieldInfo finfo)
+ public MonoFieldInfo (MonoSymbolFile file, int index, int pos, Cecil.IFieldDefinition finfo)
: base (file, finfo, index, finfo.IsStatic)
{
FieldInfo = finfo;
@@ -89,13 +88,17 @@ public ITargetObject GetConstValue (ITargetAccess target)
// from a null instance (i.e. it's a static
// field. we need to take into account
// finfo.IsStatic, though.
+#if FIXME
if ((FieldInfo != null) && FieldInfo.DeclaringType.IsEnum) {
- object value = FieldInfo.GetValue (null);
+ object value = FieldInfo.Constant;
return type.File.MonoLanguage.CreateInstance (target, (int)value);
} else {
throw new InvalidOperationException ();
}
+#else
+ throw new NotImplementedException ();
+#endif
}
protected override string MyToString ()
@@ -111,7 +114,7 @@ internal class MonoMethodInfo : MonoMember, ITargetMethodInfo
public readonly MonoClassType Klass;
public readonly string FullName;
- internal MonoMethodInfo (MonoClassType klass, int index, R.MethodBase minfo)
+ internal MonoMethodInfo (MonoClassType klass, int index, Cecil.IMethodDefinition minfo)
: base (klass.File, minfo, index, minfo.IsStatic)
{
Klass = klass;
@@ -135,11 +138,11 @@ internal MonoMethodInfo (MonoClassType klass, int index, R.MethodBase minfo)
}
}
- string compute_fullname (R.MethodBase minfo)
+ string compute_fullname (Cecil.IMethodDefinition minfo)
{
StringBuilder sb = new StringBuilder ();
bool first = true;
- foreach (R.ParameterInfo pinfo in minfo.GetParameters ()) {
+ foreach (Cecil.IParameterReference pinfo in minfo.Parameters) {
if (first)
first = false;
else
@@ -172,18 +175,18 @@ internal class MonoEventInfo : MonoMember, ITargetEventInfo
public readonly MonoClassType Klass;
public readonly MonoFunctionType AddType, RemoveType;
- internal MonoEventInfo (MonoClassType klass, int index, R.EventInfo einfo,
+ internal MonoEventInfo (MonoClassType klass, int index, Cecil.IEventDefinition einfo,
bool is_static)
: base (klass.File, einfo, index, is_static)
{
Klass = klass;
- type = File.MonoLanguage.LookupMonoType (einfo.EventHandlerType);
+ type = File.MonoLanguage.LookupMonoType (einfo.EventType);
- R.MethodInfo add = einfo.GetAddMethod ();
+ Cecil.IMethodDefinition add = einfo.AddMethod;
AddType = new MonoFunctionType (File, Klass, add);
- R.MethodInfo remove = einfo.GetRemoveMethod ();
+ Cecil.IMethodDefinition remove = einfo.RemoveMethod;
RemoveType = new MonoFunctionType (File, Klass, remove);
}
@@ -217,24 +220,20 @@ internal class MonoPropertyInfo : MonoMember, ITargetPropertyInfo
public readonly MonoFunctionType GetterType, SetterType;
public readonly bool CanRead, CanWrite;
- internal MonoPropertyInfo (MonoClassType klass, int index, R.PropertyInfo pinfo,
+ internal MonoPropertyInfo (MonoClassType klass, int index, Cecil.IPropertyDefinition pinfo,
bool is_static)
: base (klass.File, pinfo, index, is_static)
{
Klass = klass;
type = File.MonoLanguage.LookupMonoType (pinfo.PropertyType);
- CanRead = pinfo.CanRead;
- CanWrite = pinfo.CanWrite;
+ CanRead = pinfo.GetMethod != null;
+ CanWrite = pinfo.SetMethod != null;
- if (CanRead) {
- R.MethodInfo getter = pinfo.GetGetMethod (true);
- GetterType = new MonoFunctionType (File, Klass, getter);
- }
+ if (pinfo.GetMethod != null)
+ GetterType = new MonoFunctionType (File, Klass, pinfo.GetMethod);
- if (CanWrite) {
- R.MethodInfo setter = pinfo.GetSetMethod (true);
- SetterType = new MonoFunctionType (File, Klass, setter);
- }
+ if (pinfo.SetMethod != null)
+ SetterType = new MonoFunctionType (File, Klass, pinfo.SetMethod);
}
public override MonoType Type {
View
3  backends/mono/MonoObjectType.cs
@@ -1,4 +1,5 @@
using System;
+using Cecil = Mono.Cecil;
namespace Mono.Debugger.Languages.Mono
{
@@ -7,7 +8,7 @@ internal class MonoObjectType : MonoType, ITargetPointerType
int size;
TargetAddress klass_address;
- public MonoObjectType (MonoSymbolFile file, Type type, int size, TargetAddress klass)
+ public MonoObjectType (MonoSymbolFile file, Cecil.ITypeReference type, int size, TargetAddress klass)
: base (file, TargetObjectKind.Pointer, type)
{
this.size = size;
View
5 backends/mono/MonoOpaqueType.cs
@@ -1,11 +1,12 @@
using System;
+using Cecil = Mono.Cecil;
namespace Mono.Debugger.Languages.Mono
{
internal class MonoOpaqueType : MonoType
{
- public MonoOpaqueType (MonoSymbolFile file, Type type)
- : base (file, TargetObjectKind.Opaque, type)
+ public MonoOpaqueType (MonoSymbolFile file, Cecil.ITypeReference typeref)
+ : base (file, TargetObjectKind.Opaque, typeref)
{ }
public override bool IsByRef {
View
3  backends/mono/MonoStringType.cs
@@ -1,4 +1,5 @@
using System;
+using Cecil = Mono.Cecil;
namespace Mono.Debugger.Languages.Mono
{
@@ -8,7 +9,7 @@ internal class MonoStringType : MonoFundamentalType
protected readonly TargetAddress CreateString;
- public MonoStringType (MonoSymbolFile file, Type type, int object_size,
+ public MonoStringType (MonoSymbolFile file, Cecil.ITypeDefinition type, int object_size,
int size, TargetAddress klass)
: base (file, type, FundamentalKind.String, size, klass)
{
View
129 backends/mono/MonoSymbolFile.cs
@@ -2,7 +2,6 @@
using System.Collections;
using System.Globalization;
using System.Text;
-using R = System.Reflection;
using C = Mono.CompilerServices.SymbolWriter;
using Mono.Debugger;
using Mono.Debugger.Backends;
@@ -202,8 +201,8 @@ public override string ToString ()
internal class MonoSymbolFile : Module, ISymbolFile, ISimpleSymbolTable, IDisposable
{
internal readonly int Index;
- internal readonly R.Assembly Assembly;
- internal readonly R.Module Module;
+ internal readonly Cecil.IAssemblyDefinition Assembly;
+ internal readonly Cecil.IModuleDefinition Module;
internal readonly TargetAddress MonoImage;
internal readonly string ImageFile;
internal readonly C.MonoSymbolFile File;
@@ -255,20 +254,21 @@ internal class MonoSymbolFile : Module, ISymbolFile, ISimpleSymbolTable, IDispos
MonoImage = memory.ReadGlobalAddress (address);
address += address_size;
- Assembly = R.Assembly.LoadFrom (ImageFile);
- Module = Assembly.GetModules () [0];
+ Assembly = Cecil.AssemblyFactory.GetAssembly (ImageFile);
+ Module = Assembly.MainModule;
Report.Debug (DebugFlags.JitSymtab, "SYMBOL TABLE READER: {0}", ImageFile);
try {
- File = C.MonoSymbolFile.ReadSymbolFile (Assembly);
+ System.Reflection.Assembly ass = System.Reflection.Assembly.LoadFrom (ImageFile);
+ File = C.MonoSymbolFile.ReadSymbolFile (ass);
} catch (Exception ex) {
Console.WriteLine (ex.Message);
}
symtab = new MonoSymbolTable (this);
- name = Assembly.GetName (true).Name;
+ name = Assembly.Name.FullName;
backend.ModuleManager.AddModule (this);
@@ -354,27 +354,36 @@ internal void AddClassEntry (ITargetMemoryReader reader, byte[] contents)
if (entry.Rank == 0)
class_entry_hash.Add (new TypeHashEntry (entry), entry);
else {
+#if FIXME
Type etype = MonoDebuggerSupport.ResolveType (Module, entry.Token);
Type atype = MonoDebuggerSupport.MakeArrayType (etype, entry.Rank);
MonoType type = LookupMonoType (atype);
MonoLanguage.AddClass (entry.KlassAddress, type);
+#endif
}
}
- public MonoType LookupMonoType (Type type)
+ public MonoType LookupMonoType (Cecil.ITypeReference type)
{
MonoType result = (MonoType) type_hash [type];
if (result != null)
return result;
- int rank = type.GetArrayRank ();
- if (rank > 0)
- result = new MonoArrayType (this, type);
+ if (type is Cecil.IArrayType)
+ result = new MonoArrayType (this, (Cecil.IArrayType)type);
+ else if (type is Cecil.ITypeDefinition)
+ result = new MonoClassType (this, (Cecil.ITypeDefinition)type);
+#if CECIL_NOTYET
else if (type.IsEnum)
result = new MonoEnumType (this, type);
- else
- result = new MonoClassType (this, type);
+#endif
+ else {
+ // XXX should this be here? do we ever
+ // call LookupMonoType on something that
+ // won't be defined?
+ result = new MonoOpaqueType (this, type);
+ }
type_hash.Add (type, result);
return result;
@@ -492,15 +501,15 @@ SourceMethod CreateSourceMethod (SourceFile file, int index)
C.MethodEntry entry = File.GetMethod (index);
C.MethodSourceEntry source = File.GetMethodSource (index);
- R.MethodBase mbase = MonoDebuggerSupport.GetMethod (
- File.Assembly, entry.Token);
+ Cecil.IMethodDefinition mdef = MonoDebuggerSupport.GetMethod (
+ Module, entry.Token);
- StringBuilder sb = new StringBuilder (mbase.DeclaringType.FullName);
+ StringBuilder sb = new StringBuilder (mdef.DeclaringType.FullName);
sb.Append (".");
- sb.Append (mbase.Name);
+ sb.Append (mdef.Name);
sb.Append ("(");
bool first = true;
- foreach (R.ParameterInfo param in mbase.GetParameters ()) {
+ foreach (Cecil.IParameterReference param in mdef.Parameters) {
if (first)
first = false;
else
@@ -570,10 +579,10 @@ protected MonoMethod GetMonoMethod (int index)
SourceMethod method = GetSourceMethod (index);
C.MethodEntry entry = File.GetMethod (index);
- R.MethodBase mbase = MonoDebuggerSupport.GetMethod (
- File.Assembly, entry.Token);
+ Cecil.IMethodDefinition mdef = MonoDebuggerSupport.GetMethod (
+ Module, entry.Token);
- mono_method = new MonoMethod (this, method, entry, mbase);
+ mono_method = new MonoMethod (this, method, entry, mdef);
method_hash.Add (index, mono_method);
return mono_method;
}
@@ -636,7 +645,7 @@ protected class MonoMethod : MethodBase
MonoSymbolFile file;
SourceMethod info;
C.MethodEntry method;
- R.MethodBase rmethod;
+ Cecil.IMethodDefinition mdef;
MonoClassType decl_type;
MonoType[] param_types;
MonoType[] local_types;
@@ -649,17 +658,17 @@ protected class MonoMethod : MethodBase
Hashtable load_handlers;
public MonoMethod (MonoSymbolFile file, SourceMethod info,
- C.MethodEntry method, R.MethodBase rmethod)
+ C.MethodEntry method, Cecil.IMethodDefinition mdef)
: base (info.Name, file.ImageFile, file)
{
this.file = file;
this.info = info;
this.method = method;
- this.rmethod = rmethod;
+ this.mdef = mdef;
}
public override object MethodHandle {
- get { return rmethod; }
+ get { return mdef; }
}
public void Load (TargetBinaryReader dynamic_reader, AddressDomain domain)
@@ -683,11 +692,11 @@ void get_variables ()
if (has_variables || !is_loaded)
return;
- R.ParameterInfo[] param_info = rmethod.GetParameters ();
- param_types = new MonoType [param_info.Length];
- parameters = new IVariable [param_info.Length];
- for (int i = 0; i < param_info.Length; i++) {
- Type type = param_info [i].ParameterType;
+ Cecil.IParameterDefinitionCollection param_info = mdef.Parameters;
+ param_types = new MonoType [param_info.Count];
+ parameters = new IVariable [param_info.Count];
+ for (int i = 0; i < param_info.Count; i++) {
+ Cecil.ITypeReference type = param_info [i].ParameterType;
param_types [i] = file.MonoLanguage.LookupMonoType (type);
@@ -700,9 +709,10 @@ void get_variables ()
local_types = new MonoType [method.NumLocals];
locals = new IVariable [method.NumLocals];
for (int i = 0; i < method.NumLocals; i++) {
+#if FIXME
C.LocalVariableEntry local = method.Locals [i];
- Type type = MonoDebuggerSupport.GetLocalTypeFromSignature (
- file.Assembly, local.Signature);
+ Cecil.ITypeReference type = MonoDebuggerSupport.GetLocalTypeFromSignature (
+ file.Assembly, local.Signature);
local_types [i] = file.MonoLanguage.LookupMonoType (type);
@@ -720,9 +730,10 @@ void get_variables ()
true, local_types [i].IsByRef, this,
address.LocalVariableInfo [i]);
}
+#endif
}
- decl_type = (MonoClassType) file.MonoLanguage.LookupMonoType (rmethod.DeclaringType);
+ decl_type = (MonoClassType) file.MonoLanguage.LookupMonoType (mdef.DeclaringType);
if (address.HasThis)
this_var = new MonoVariable (
@@ -803,23 +814,23 @@ void get_variables ()
}
// This must match mono_type_get_desc() in mono/metadata/debug-helpers.c.
- string GetTypeSignature (Type t)
+ string GetTypeSignature (Cecil.ITypeReference t)
{
- switch (Type.GetTypeCode (t)) {
- case TypeCode.Char: return "char";
- case TypeCode.Boolean: return "bool";
- case TypeCode.Byte: return "byte";
- case TypeCode.SByte: return "sbyte";
- case TypeCode.Int16: return "int16";
- case TypeCode.UInt16: return "uint16";
- case TypeCode.Int32: return "int";
- case TypeCode.UInt32: return "uint";
- case TypeCode.Int64: return "long";
- case TypeCode.UInt64: return "ulong";
- case TypeCode.Single: return "single";
- case TypeCode.Double: return "double";
- case TypeCode.String: return "string";
- case TypeCode.Object:
+ switch (t.Name) {
+ case "System.Char": return "char";
+ case "System.Boolean": return "bool";
+ case "System.Byte": return "byte";
+ case "System.SByte": return "sbyte";
+ case "System.Int16": return "int16";
+ case "System.UInt16": return "uint16";
+ case "System.Int32": return "int";
+ case "System.UInt32": return "uint";
+ case "System.Int64": return "long";
+ case "System.UInt64": return "ulong";
+ case "System.Single": return "single";
+ case "System.Double": return "double";
+ case "System.String": return "string";
+ case "System.Object":
default: return t.FullName;
}
}
@@ -830,15 +841,14 @@ string GetTypeSignature (Type t)
object user_data)
{
StringBuilder sb = new StringBuilder ();
- sb.Append (rmethod.ReflectedType.FullName);
+ sb.Append (mdef.DeclaringType.FullName);
sb.Append (":");
- sb.Append (rmethod.Name);
+ sb.Append (mdef.Name);
sb.Append ("(");
- R.ParameterInfo[] pi = rmethod.GetParameters ();
- for (int i = 0; i < pi.Length; i++) {
+ for (int i = 0; i < mdef.Parameters.Count; i++) {
if (i > 0)
sb.Append (",");
- sb.Append (GetTypeSignature (pi [i].ParameterType).Replace ('+','/'));
+ sb.Append (GetTypeSignature (mdef.Parameters[i].ParameterType).Replace ('+','/'));
}
sb.Append (")");
string full_name = sb.ToString ();
@@ -1257,13 +1267,16 @@ protected struct TypeHashEntry
public readonly int Token;
public readonly int Rank;
- public TypeHashEntry (Type type)
+ public TypeHashEntry (Cecil.ITypeReference type)
{
- while (type.GetArrayRank () > 0)
- type = type.GetElementType ();
+ Cecil.IArrayType array = type as Cecil.IArrayType;
+ if (array != null) {
+ type = array.ElementType;
+ Rank = array.Rank;
+ } else
+ Rank = 0;
Token = MonoDebuggerSupport.GetTypeToken (type);
- Rank = type.GetArrayRank ();
}
public TypeHashEntry (ClassEntry entry)
View
17 backends/mono/MonoType.cs
@@ -1,23 +1,24 @@
using System;
+using Mono.Cecil;
namespace Mono.Debugger.Languages.Mono
{
internal abstract class MonoType : MarshalByRefObject, ITargetType
{
- protected readonly Type type;
+ protected readonly Cecil.ITypeReference typeref;
protected readonly MonoSymbolFile file;
protected readonly TargetObjectKind kind;
protected MonoTypeInfo type_info;
- public MonoType (MonoSymbolFile file, TargetObjectKind kind, Type type)
+ public MonoType (MonoSymbolFile file, TargetObjectKind kind, Cecil.ITypeReference typeref)
{
this.file = file;
- this.type = type;
+ this.typeref = typeref;
this.kind = kind;
}
- public Type Type {
- get { return type; }
+ public Cecil.ITypeReference Type {
+ get { return typeref; }
}
public TargetObjectKind Kind {
@@ -29,11 +30,11 @@ public MonoType (MonoSymbolFile file, TargetObjectKind kind, Type type)
}
public virtual string Name {
- get { return type.FullName; }
+ get { return typeref.FullName; }
}
- public Type TypeHandle {
- get { return type; }
+ public Cecil.ITypeReference TypeHandle {
+ get { return typeref; }
}
public abstract bool IsByRef {
View
3  wrapper/Makefile.am
@@ -63,7 +63,8 @@ MDB_SERVER_SRCLIST = \
LIBRARY_DEPS = \
-r:Mono.GetOptions \
-r:Mono.CompilerServices.SymbolWriter \
- -r:System.Runtime.Remoting
+ -r:System.Runtime.Remoting \
+ -r:Mono.Cecil
MDB_DEPS = \
-r:Mono.GetOptions \
Please sign in to comment.
Something went wrong with that request. Please try again.