Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Port debugger to cecil-light
Browse files Browse the repository at this point in the history
  • Loading branch information
jbevain committed Oct 20, 2010
1 parent 04304e5 commit f48c33c
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 74 deletions.
20 changes: 10 additions & 10 deletions backend/mono/MonoLanguageBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,21 @@ public MonoBuiltinTypeInfo (MonoSymbolFile corlib, TargetMemoryAccess memory)

DecimalType = MonoFundamentalType.Create (
corlib, memory, FundamentalKind.Decimal);
Cecil.TypeDefinition decimal_type = corlib.ModuleDefinition.Types ["System.Decimal"];
Cecil.TypeDefinition decimal_type = corlib.ModuleDefinition.GetType ("System.Decimal");
corlib.AddType (decimal_type, DecimalType);

TargetAddress klass = corlib.MonoLanguage.MetadataHelper.GetArrayClass (memory);
Cecil.TypeDefinition array_type = corlib.ModuleDefinition.Types ["System.Array"];
Cecil.TypeDefinition array_type = corlib.ModuleDefinition.GetType ("System.Array");
ArrayType = mono.CreateCoreType (corlib, array_type, memory, klass);
mono.AddCoreType (array_type, ArrayType, ArrayType, klass);

klass = corlib.MonoLanguage.MetadataHelper.GetDelegateClass (memory);
Cecil.TypeDefinition delegate_type = corlib.ModuleDefinition.Types ["System.Delegate"];
Cecil.TypeDefinition delegate_type = corlib.ModuleDefinition.GetType ("System.Delegate");
DelegateType = new MonoClassType (corlib, delegate_type);
mono.AddCoreType (delegate_type, DelegateType, DelegateType, klass);

klass = corlib.MonoLanguage.MetadataHelper.GetExceptionClass (memory);
Cecil.TypeDefinition exception_type = corlib.ModuleDefinition.Types ["System.Exception"];
Cecil.TypeDefinition exception_type = corlib.ModuleDefinition.GetType ("System.Exception");
ExceptionType = mono.CreateCoreType (corlib, exception_type, memory, klass);
mono.AddCoreType (exception_type, ExceptionType, ExceptionType, klass);
}
Expand Down Expand Up @@ -289,7 +289,7 @@ internal bool IsDelegateTrampoline (TargetAddress address)

internal bool TryFindImage (Thread thread, string filename)
{
Cecil.AssemblyDefinition ass = Cecil.AssemblyFactory.GetAssembly (filename);
Cecil.AssemblyDefinition ass = Cecil.AssemblyDefinition.ReadAssembly (filename);
if (ass == null)
return false;

Expand Down Expand Up @@ -325,7 +325,7 @@ public TargetType LookupMonoType (Cecil.TypeReference type)
return new MonoArrayType (element_type, array.Rank);
}

Cecil.ReferenceType reftype = type as Cecil.ReferenceType;
Cecil.ByReferenceType reftype = type as Cecil.ByReferenceType;
if (reftype != null) {
TargetType element_type = LookupMonoType (reftype.ElementType);
if (element_type == null)
Expand Down Expand Up @@ -407,7 +407,7 @@ Cecil.AssemblyDefinition resolve_cecil_asm_name (Cecil.AssemblyNameReference nam

Cecil.TypeDefinition resolve_cecil_type_ref (Cecil.TypeReference type)
{
type = type.GetOriginalType ();
type = type.GetElementType ();

if (type is Cecil.TypeDefinition)
return (Cecil.TypeDefinition) type;
Expand All @@ -418,12 +418,12 @@ Cecil.TypeDefinition resolve_cecil_type_ref (Cecil.TypeReference type)
if (assembly == null)
return null;

return assembly.MainModule.Types [type.FullName];
return assembly.MainModule.GetType (type.FullName);
}

Cecil.ModuleDefinition module = type.Scope as Cecil.ModuleDefinition;
if (module != null)
return module.Types [type.FullName];
return module.GetType (type.FullName);

throw new NotImplementedException ();
}
Expand Down Expand Up @@ -1075,7 +1075,7 @@ public override TargetType LookupType (string name)

foreach (MonoSymbolFile symfile in symfile_by_index.Values) {
try {
Cecil.TypeDefinitionCollection types = symfile.Assembly.MainModule.Types;
var types = symfile.Assembly.MainModule.Types;
// FIXME: Work around an API problem in Cecil.
foreach (Cecil.TypeDefinition type in types) {
if (type.FullName != name)
Expand Down
26 changes: 13 additions & 13 deletions backend/mono/MonoSymbolFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ internal MonoSymbolFile (MonoLanguageBackend language, Process process,
ImageFile = shadow_location;

try {
Assembly = Cecil.AssemblyFactory.GetAssembly (ImageFile);
Assembly = Cecil.AssemblyDefinition.ReadAssembly (ImageFile);
} catch (Exception ex) {
throw new SymbolTableException (
"Cannot load symbol file `{0}': {1}", ImageFile, ex);
Expand All @@ -244,7 +244,7 @@ internal MonoSymbolFile (MonoLanguageBackend language, Process process,
string mdb_file = ImageFile + ".mdb";

try {
File = C.MonoSymbolFile.ReadSymbolFile (Assembly, mdb_file);
File = C.MonoSymbolFile.ReadSymbolFile (ModuleDefinition, mdb_file);
if (File == null)
Report.Error ("Cannot load symbol file `{0}'", mdb_file);
else if (ModuleDefinition.Mvid != File.Guid) {
Expand Down Expand Up @@ -571,7 +571,7 @@ public override MethodSource[] GetMethods (SourceFile file)
// This must match mono_type_get_desc() in mono/metadata/debug-helpers.c.
protected static string GetTypeSignature (Cecil.TypeReference t)
{
Cecil.ReferenceType rtype = t as Cecil.ReferenceType;
Cecil.ByReferenceType rtype = t as Cecil.ByReferenceType;
if (rtype != null)
return GetTypeSignature (rtype.ElementType) + "&";

Expand Down Expand Up @@ -693,7 +693,7 @@ Cecil.MethodDefinition FindCecilMethod (string full_name)
signature = null;
}

Cecil.TypeDefinitionCollection types = Assembly.MainModule.Types;
var types = Assembly.MainModule.Types;
// FIXME: Work around an API problem in Cecil.
foreach (Cecil.TypeDefinition type in types) {
if (!method_name.StartsWith (type.FullName))
Expand Down Expand Up @@ -773,7 +773,7 @@ internal MonoFunctionType GetFunctionType (string class_name, int token)
{
MonoClassType klass = null;

Cecil.TypeDefinitionCollection types = Assembly.MainModule.Types;
var types = Assembly.MainModule.Types;
// FIXME: Work around an API problem in Cecil.
foreach (Cecil.TypeDefinition type in types) {
if (type.FullName != class_name)
Expand Down Expand Up @@ -822,23 +822,23 @@ internal static void CheckCustomAttributes (Cecil.ICustomAttributeProvider type,
if (cname == cgen_attr) {
is_compiler_generated = true;
} else if (cname == debugger_display_attr) {
string text = (string) cattr.ConstructorParameters [0];
string text = (string) cattr.ConstructorArguments [0].Value;
debugger_display = new DebuggerDisplayAttribute (text);
foreach (DictionaryEntry prop in cattr.Properties) {
string key = (string) prop.Key;
foreach (var named_arg in cattr.Properties) {
string key = named_arg.Name;
if (key == "Name")
debugger_display.Name = (string) prop.Value;
debugger_display.Name = (string) named_arg.Argument.Value;
else if (key == "Type")
debugger_display.Type = (string) prop.Value;
debugger_display.Type = (string) named_arg.Argument.Value;
else {
debugger_display = null;
break;
}
}
} else if (cname == browsable_attr) {
browsable_state = (DebuggerBrowsableState) cattr.Blob [2];
browsable_state = (DebuggerBrowsableState) cattr.GetBlob () [2];
} else if (cname == type_proxy_attr) {
string text = (string) cattr.ConstructorParameters [0];
string text = (string) cattr.ConstructorArguments [0].Value;
type_proxy = new DebuggerTypeProxyAttribute (text);
}
}
Expand Down Expand Up @@ -1340,7 +1340,7 @@ void do_read_variables (TargetMemoryAccess memory)
}
}

Cecil.ParameterDefinitionCollection param_info = mdef.Parameters;
var param_info = mdef.Parameters;
for (int i = 0; i < param_info.Count; i++) {
if (captured_vars.ContainsKey (param_info [i].Name))
continue;
Expand Down
4 changes: 2 additions & 2 deletions languages/mono/MonoClassInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public static MonoClassInfo ReadClassInfo (MonoLanguageBackend mono,
throw new InternalError ();

Cecil.TypeDefinition typedef;
typedef = (Cecil.TypeDefinition) file.ModuleDefinition.LookupByToken (
Cecil.Metadata.TokenType.TypeDef, token & 0x00ffffff);
typedef = (Cecil.TypeDefinition) file.ModuleDefinition.LookupToken (
new Cecil.MetadataToken (Cecil.TokenType.TypeDef, token & 0x00ffffff));
if (typedef == null)
throw new InternalError ();

Expand Down
2 changes: 1 addition & 1 deletion languages/mono/MonoClassType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public MonoClassInfo ResolveClass (TargetMemoryAccess target, bool fail)
return class_info;

if (class_info == null) {
int token = (int) type.MetadataToken.ToUInt ();
int token = type.MetadataToken.ToInt32 ();
class_info = file.LookupClassInfo (target, token);
}

Expand Down
6 changes: 3 additions & 3 deletions languages/mono/MonoDebuggerSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ internal static class MonoDebuggerSupport
{
public static int GetMethodToken (Cecil.MethodDefinition method)
{
return (int) (method.MetadataToken.TokenType + method.MetadataToken.RID);
return method.MetadataToken.ToInt32 ();
}

public static Cecil.MethodDefinition GetMethod (Cecil.ModuleDefinition module, int token)
{
return (Cecil.MethodDefinition) module.LookupByToken (
Cecil.Metadata.TokenType.Method, token & 0xffffff);
return (Cecil.MethodDefinition) module.LookupToken (
new Cecil.MetadataToken (Cecil.TokenType.Method, token & 0xffffff));
}
}
}
4 changes: 2 additions & 2 deletions languages/mono/MonoFunctionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal MonoFunctionType (IMonoStructType klass, Cecil.MethodDefinition mdef)
rtype = mdef.DeclaringType;
has_return_type = true;
} else {
rtype = mdef.ReturnType.ReturnType;
rtype = mdef.ReturnType;
has_return_type = rtype.FullName != "System.Void";
}
return_type = klass.File.MonoLanguage.LookupMonoType (rtype);
Expand All @@ -52,7 +52,7 @@ public override MethodSource GetSourceCode ()

internal static string GetMethodName (Cecil.MethodDefinition mdef)
{
Cecil.GenericParameterCollection gen_params = mdef.GenericParameters;
var gen_params = mdef.GenericParameters;
if ((gen_params == null) || (gen_params.Count == 0))
return mdef.Name;
else
Expand Down
30 changes: 15 additions & 15 deletions languages/mono/MonoFundamentalType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,104 +31,104 @@ public static MonoFundamentalType Create (MonoSymbolFile corlib,
case FundamentalKind.Boolean:
klass = corlib.MonoLanguage.MetadataHelper.GetBooleanClass (memory);
fundamental = new MonoFundamentalType (
corlib, corlib.ModuleDefinition.Types ["System.Boolean"],
corlib, corlib.ModuleDefinition.GetType ("System.Boolean"),
"bool", kind, 1);
break;

case FundamentalKind.Char:
klass = corlib.MonoLanguage.MetadataHelper.GetCharClass (memory);
fundamental = new MonoFundamentalType (
corlib, corlib.ModuleDefinition.Types ["System.Char"],
corlib, corlib.ModuleDefinition.GetType ("System.Char"),
"char", kind, 2);
break;

case FundamentalKind.SByte:
klass = corlib.MonoLanguage.MetadataHelper.GetSByteClass (memory);
fundamental = new MonoFundamentalType (
corlib, corlib.ModuleDefinition.Types ["System.SByte"],
corlib, corlib.ModuleDefinition.GetType ("System.SByte"),
"sbyte", kind, 1);
break;

case FundamentalKind.Byte:
klass = corlib.MonoLanguage.MetadataHelper.GetByteClass (memory);
fundamental = new MonoFundamentalType (
corlib, corlib.ModuleDefinition.Types ["System.Byte"],
corlib, corlib.ModuleDefinition.GetType ("System.Byte"),
"byte", kind, 1);
break;

case FundamentalKind.Int16:
klass = corlib.MonoLanguage.MetadataHelper.GetInt16Class (memory);
fundamental = new MonoFundamentalType (
corlib, corlib.ModuleDefinition.Types ["System.Int16"],
corlib, corlib.ModuleDefinition.GetType ("System.Int16"),
"short", kind, 2);
break;

case FundamentalKind.UInt16:
klass = corlib.MonoLanguage.MetadataHelper.GetUInt16Class (memory);
fundamental = new MonoFundamentalType (
corlib, corlib.ModuleDefinition.Types ["System.UInt16"],
corlib, corlib.ModuleDefinition.GetType ("System.UInt16"),
"ushort", kind, 2);
break;

case FundamentalKind.Int32:
klass = corlib.MonoLanguage.MetadataHelper.GetInt32Class (memory);
fundamental = new MonoFundamentalType (
corlib, corlib.ModuleDefinition.Types ["System.Int32"],
corlib, corlib.ModuleDefinition.GetType ("System.Int32"),
"int", kind, 4);
break;

case FundamentalKind.UInt32:
klass = corlib.MonoLanguage.MetadataHelper.GetUInt32Class (memory);
fundamental = new MonoFundamentalType (
corlib, corlib.ModuleDefinition.Types ["System.UInt32"],
corlib, corlib.ModuleDefinition.GetType ("System.UInt32"),
"uint", kind, 4);
break;

case FundamentalKind.Int64:
klass = corlib.MonoLanguage.MetadataHelper.GetInt64Class (memory);
fundamental = new MonoFundamentalType (
corlib, corlib.ModuleDefinition.Types ["System.Int64"],
corlib, corlib.ModuleDefinition.GetType ("System.Int64"),
"long", kind, 8);
break;

case FundamentalKind.UInt64:
klass = corlib.MonoLanguage.MetadataHelper.GetUInt64Class (memory);
fundamental = new MonoFundamentalType (
corlib, corlib.ModuleDefinition.Types ["System.UInt64"],
corlib, corlib.ModuleDefinition.GetType ("System.UInt64"),
"ulong", kind, 8);
break;

case FundamentalKind.Single:
klass = corlib.MonoLanguage.MetadataHelper.GetSingleClass (memory);
fundamental = new MonoFundamentalType (
corlib, corlib.ModuleDefinition.Types ["System.Single"],
corlib, corlib.ModuleDefinition.GetType ("System.Single"),
"float", kind, 4);
break;

case FundamentalKind.Double:
klass = corlib.MonoLanguage.MetadataHelper.GetDoubleClass (memory);
fundamental = new MonoFundamentalType (
corlib, corlib.ModuleDefinition.Types ["System.Double"],
corlib, corlib.ModuleDefinition.GetType ("System.Double"),
"double", kind, 8);
break;

case FundamentalKind.IntPtr:
klass = corlib.MonoLanguage.MetadataHelper.GetIntPtrClass (memory);
fundamental = new MonoFundamentalType (
corlib, corlib.ModuleDefinition.Types ["System.IntPtr"],
corlib, corlib.ModuleDefinition.GetType ("System.IntPtr"),
"System.IntPtr", kind, memory.TargetMemoryInfo.TargetAddressSize);
break;

case FundamentalKind.UIntPtr:
klass = corlib.MonoLanguage.MetadataHelper.GetUIntPtrClass (memory);
fundamental = new MonoFundamentalType (
corlib, corlib.ModuleDefinition.Types ["System.UIntPtr"],
corlib, corlib.ModuleDefinition.GetType ("System.UIntPtr"),
"System.UIntPtr", kind, memory.TargetMemoryInfo.TargetAddressSize);
break;

case FundamentalKind.Decimal:
fundamental = new MonoFundamentalType (
corlib, corlib.ModuleDefinition.Types ["System.Decimal"],
corlib, corlib.ModuleDefinition.GetType ("System.Decimal"),
"decimal", kind, Marshal.SizeOf (typeof (Decimal)));
return fundamental;

Expand Down
2 changes: 1 addition & 1 deletion languages/mono/MonoMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ internal static TargetMemberAccessibility GetAccessibility (Cecil.MethodDefiniti
case Cecil.MethodAttributes.Family:
case Cecil.MethodAttributes.FamANDAssem:
return TargetMemberAccessibility.Protected;
case Cecil.MethodAttributes.Assem:
case Cecil.MethodAttributes.Assembly:
case Cecil.MethodAttributes.FamORAssem:
return TargetMemberAccessibility.Internal;
default:
Expand Down
2 changes: 1 addition & 1 deletion languages/mono/MonoObjectType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static MonoObjectType Create (MonoSymbolFile corlib, TargetMemoryAccess m
int object_size = 2 * memory.TargetMemoryInfo.TargetAddressSize;

MonoObjectType type = new MonoObjectType (
corlib, corlib.ModuleDefinition.Types ["System.Object"],
corlib, corlib.ModuleDefinition.GetType ("System.Object"),
object_size);

TargetAddress klass = corlib.MonoLanguage.MetadataHelper.GetObjectClass (memory);
Expand Down
2 changes: 1 addition & 1 deletion languages/mono/MonoStringType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static MonoStringType Create (MonoSymbolFile corlib, TargetMemoryAccess m
int object_size = 2 * memory.TargetMemoryInfo.TargetAddressSize;

MonoStringType type = new MonoStringType (
corlib, corlib.ModuleDefinition.Types ["System.String"],
corlib, corlib.ModuleDefinition.GetType ("System.String"),
object_size, object_size + 4);

TargetAddress klass = corlib.MonoLanguage.MetadataHelper.GetStringClass (memory);
Expand Down
Loading

0 comments on commit f48c33c

Please sign in to comment.