Permalink
Fetching contributors…
Cannot retrieve contributors at this time
7798 lines (7337 sloc) 251 KB
From 0c1737789419d6d36dd74bf9e7375c3c6c9bde37 Mon Sep 17 00:00:00 2001
From: Martin Baulig <martin@novell.com>
Date: Mon, 7 Sep 2009 12:02:06 +0200
Subject: [PATCH] .
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------1.5.6"
This is a multi-part message in MIME format.
--------------1.5.6
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit
---
backend/Makefile.am | 2 +-
backend/ProcessServant.cs | 1 +
backend/SingleSteppingEngine.cs | 1 +
backend/arch/CoreFile.cs | 2 +-
backend/mono/.gitignore | 2 +
backend/mono/Makefile.am | 1 +
backend/mono/MonoRuntime.cs | 700 +++++++++++++++++++++++++++++++++
backend/mono/MonoThreadManager.cs | 639 ++++++++++++++++++++++++++++++
build/Makefile.am | 1 +
configure.in | 1 +
languages/mono/MonoClassInfo.cs | 1 +
languages/mono/MonoLanguageBackend.cs | 1 +
12 files changed, 1350 insertions(+), 2 deletions(-)
create mode 100644 backend/mono/.gitignore
create mode 100644 backend/mono/Makefile.am
create mode 100644 backend/mono/MonoRuntime.cs
create mode 100644 backend/mono/MonoThreadManager.cs
--------------1.5.6
Content-Type: text/x-patch; name="0c1737789419d6d36dd74bf9e7375c3c6c9bde37.diff"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline; filename="0c1737789419d6d36dd74bf9e7375c3c6c9bde37.diff"
diff --git a/backend/Makefile.am b/backend/Makefile.am
index c430e8b..6a86764 100644
--- a/backend/Makefile.am
+++ b/backend/Makefile.am
@@ -1,3 +1,3 @@
-SUBDIRS = arch os server
+SUBDIRS = arch os mono server
EXTRA_DIST = $(srcdir)/*.cs
diff --git a/backend/ProcessServant.cs b/backend/ProcessServant.cs
index 4764743..9261e74 100644
--- a/backend/ProcessServant.cs
+++ b/backend/ProcessServant.cs
@@ -8,6 +8,7 @@ using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using Mono.Debugger.Backend;
+using Mono.Debugger.Backend.Mono;
using Mono.Debugger.Architectures;
using Mono.Debugger.Languages;
using Mono.Debugger.Languages.Native;
diff --git a/backend/SingleSteppingEngine.cs b/backend/SingleSteppingEngine.cs
index d8958ee..661bf8b 100644
--- a/backend/SingleSteppingEngine.cs
+++ b/backend/SingleSteppingEngine.cs
@@ -16,6 +16,7 @@ using System.Runtime.Remoting.Messaging;
using Mono.Debugger.Languages;
using Mono.Debugger.Languages.Mono;
using Mono.Debugger.Architectures;
+using Mono.Debugger.Backend.Mono;
namespace Mono.Debugger.Backend
{
diff --git a/backend/arch/CoreFile.cs b/backend/arch/CoreFile.cs
index 5dc81b1..12a9ad0 100644
--- a/backend/arch/CoreFile.cs
+++ b/backend/arch/CoreFile.cs
@@ -3,8 +3,8 @@ using System.IO;
using System.Collections;
using ST = System.Threading;
using System.Runtime.InteropServices;
+using Mono.Debugger.Backend.Mono;
using Mono.Debugger.Languages;
-using Mono.Debugger.Languages.Mono;
namespace Mono.Debugger.Backend
{
diff --git a/backend/mono/.gitignore b/backend/mono/.gitignore
new file mode 100644
index 0000000..9ee6454
--- /dev/null
+++ b/backend/mono/.gitignore
@@ -0,0 +1,2 @@
+/Makefile.in
+/Makefile
diff --git a/backend/mono/Makefile.am b/backend/mono/Makefile.am
new file mode 100644
index 0000000..bd74aad
--- /dev/null
+++ b/backend/mono/Makefile.am
@@ -0,0 +1 @@
+EXTRA_DIST = $(srcdir)/*.cs
diff --git a/backend/mono/MonoRuntime.cs b/backend/mono/MonoRuntime.cs
new file mode 100644
index 0000000..d2f6add
--- /dev/null
+++ b/backend/mono/MonoRuntime.cs
@@ -0,0 +1,700 @@
+using System;
+
+using Mono.Debugger.Languages;
+using Mono.Debugger.Languages.Mono;
+
+namespace Mono.Debugger.Backend.Mono
+{
+ internal enum MonoTypeEnum
+ {
+ MONO_TYPE_END = 0x00, /* End of List */
+ MONO_TYPE_VOID = 0x01,
+ MONO_TYPE_BOOLEAN = 0x02,
+ MONO_TYPE_CHAR = 0x03,
+ MONO_TYPE_I1 = 0x04,
+ MONO_TYPE_U1 = 0x05,
+ MONO_TYPE_I2 = 0x06,
+ MONO_TYPE_U2 = 0x07,
+ MONO_TYPE_I4 = 0x08,
+ MONO_TYPE_U4 = 0x09,
+ MONO_TYPE_I8 = 0x0a,
+ MONO_TYPE_U8 = 0x0b,
+ MONO_TYPE_R4 = 0x0c,
+ MONO_TYPE_R8 = 0x0d,
+ MONO_TYPE_STRING = 0x0e,
+ MONO_TYPE_PTR = 0x0f, /* arg: <type> token */
+ MONO_TYPE_BYREF = 0x10, /* arg: <type> token */
+ MONO_TYPE_VALUETYPE = 0x11, /* arg: <type> token */
+ MONO_TYPE_CLASS = 0x12, /* arg: <type> token */
+ MONO_TYPE_VAR = 0x13, /* number */
+ MONO_TYPE_ARRAY = 0x14, /* type, rank, boundsCount, bound1, loCount, lo1 */
+ MONO_TYPE_GENERICINST= 0x15, /* <type> <type-arg-count> <type-1> \x{2026} <type-n> */
+ MONO_TYPE_TYPEDBYREF = 0x16,
+ MONO_TYPE_I = 0x18,
+ MONO_TYPE_U = 0x19,
+ MONO_TYPE_FNPTR = 0x1b, /* arg: full method signature */
+ MONO_TYPE_OBJECT = 0x1c,
+ MONO_TYPE_SZARRAY = 0x1d, /* 0-based one-dim-array */
+ MONO_TYPE_MVAR = 0x1e, /* number */
+ MONO_TYPE_CMOD_REQD = 0x1f, /* arg: typedef or typeref token */
+ MONO_TYPE_CMOD_OPT = 0x20, /* optional arg: typedef or typref token */
+ MONO_TYPE_INTERNAL = 0x21, /* CLR internal type */
+
+ MONO_TYPE_MODIFIER = 0x40, /* Or with the following types */
+ MONO_TYPE_SENTINEL = 0x41, /* Sentinel for varargs method signature */
+ MONO_TYPE_PINNED = 0x45, /* Local var that points to pinned object */
+
+ MONO_TYPE_ENUM = 0x55 /* an enumeration */
+ }
+
+ internal class MonoRuntime : DebuggerMarshalByRefObject
+ {
+ protected readonly MonoDebuggerInfo MonoDebuggerInfo;
+ protected readonly MetadataInfo MonoMetadataInfo;
+
+ protected MonoRuntime (MonoDebuggerInfo info, MetadataInfo metadata)
+ {
+ this.MonoDebuggerInfo = info;
+ this.MonoMetadataInfo = metadata;
+ }
+
+ public static MonoRuntime Create (TargetMemoryAccess memory, MonoDebuggerInfo info)
+ {
+ MetadataInfo metadata = new MetadataInfo (memory, info.MonoMetadataInfo);
+ return new MonoRuntime (info, metadata);
+ }
+
+ //
+ // MonoClass
+ //
+
+ public TargetAddress MonoClassGetMonoImage (TargetMemoryAccess memory,
+ TargetAddress klass)
+ {
+ return memory.ReadAddress (klass + MonoMetadataInfo.KlassImageOffset);
+ }
+
+ public int MonoClassGetToken (TargetMemoryAccess memory,
+ TargetAddress klass)
+ {
+ return memory.ReadInteger (klass + MonoMetadataInfo.KlassTokenOffset);
+ }
+
+ public int MonoClassGetInstanceSize (TargetMemoryAccess memory,
+ TargetAddress klass)
+ {
+ int flags = memory.ReadInteger (klass + 4 * memory.TargetAddressSize);
+
+ bool size_inited = (flags & 4) != 0;
+ bool valuetype = (flags & 8) != 0;
+
+ if (!size_inited)
+ throw new TargetException (TargetError.ClassNotInitialized);
+
+ int size = memory.ReadInteger (klass + 4 + 3 * memory.TargetAddressSize);
+ if (valuetype)
+ size -= 2 * memory.TargetAddressSize;
+
+ return size;
+ }
+
+ public TargetAddress MonoClassGetParent (TargetMemoryAccess memory,
+ TargetAddress klass)
+ {
+ return memory.ReadAddress (klass + MonoMetadataInfo.KlassParentOffset);
+ }
+
+ public TargetAddress MonoClassGetGenericClass (TargetMemoryAccess memory,
+ TargetAddress klass)
+ {
+ return memory.ReadAddress (klass + MonoMetadataInfo.KlassGenericClassOffset);
+ }
+
+ public TargetAddress MonoClassGetGenericContainer (TargetMemoryAccess memory,
+ TargetAddress klass)
+ {
+ return memory.ReadAddress (klass + MonoMetadataInfo.KlassGenericContainerOffset);
+ }
+
+ public TargetAddress MonoClassGetByValType (TargetMemoryAccess memory,
+ TargetAddress klass)
+ {
+ return klass + MonoMetadataInfo.KlassByValArgOffset;
+ }
+
+ public bool MonoClassHasFields (TargetMemoryAccess memory, TargetAddress klass)
+ {
+ TargetAddress fields = memory.ReadAddress (
+ klass + MonoMetadataInfo.KlassFieldOffset);
+ return !fields.IsNull;
+ }
+
+ public int MonoClassGetFieldCount (TargetMemoryAccess memory, TargetAddress klass)
+ {
+ return memory.ReadInteger (klass + MonoMetadataInfo.KlassFieldCountOffset);
+ }
+
+ public TargetAddress MonoClassGetFieldType (TargetMemoryAccess memory, TargetAddress klass,
+ int index)
+ {
+ int offset = index * MonoMetadataInfo.FieldInfoSize +
+ MonoMetadataInfo.FieldInfoTypeOffset;
+
+ TargetAddress fields = memory.ReadAddress (
+ klass + MonoMetadataInfo.KlassFieldOffset);
+ if (fields.IsNull)
+ throw new TargetException (TargetError.ClassNotInitialized);
+
+ return memory.ReadAddress (fields + offset);
+ }
+
+ public int MonoClassGetFieldOffset (TargetMemoryAccess memory, TargetAddress klass,
+ int index)
+ {
+ int offset = index * MonoMetadataInfo.FieldInfoSize +
+ MonoMetadataInfo.FieldInfoOffsetOffset;
+
+ TargetAddress fields = memory.ReadAddress (
+ klass + MonoMetadataInfo.KlassFieldOffset);
+ if (fields.IsNull)
+ throw new TargetException (TargetError.ClassNotInitialized);
+
+ return memory.ReadInteger (fields + offset);
+ }
+
+ public bool MonoClassHasMethods (TargetMemoryAccess memory, TargetAddress klass)
+ {
+ TargetAddress methods = memory.ReadAddress (
+ klass + MonoMetadataInfo.KlassMethodsOffset);
+ return !methods.IsNull;
+ }
+
+ public int MonoClassGetMethodCount (TargetMemoryAccess memory, TargetAddress klass)
+ {
+ return memory.ReadInteger (klass + MonoMetadataInfo.KlassMethodCountOffset);
+ }
+
+ public TargetAddress MonoClassGetMethod (TargetMemoryAccess memory, TargetAddress klass,
+ int index)
+ {
+ TargetAddress methods = memory.ReadAddress (
+ klass + MonoMetadataInfo.KlassMethodsOffset);
+
+ if (methods.IsNull)
+ throw new TargetException (TargetError.ClassNotInitialized);
+
+ methods += index * memory.TargetAddressSize;
+ return memory.ReadAddress (methods);
+ }
+
+ //
+ // MonoMethod
+ //
+
+ public int MonoMethodGetToken (TargetMemoryAccess memory, TargetAddress method)
+ {
+ return memory.ReadInteger (method + MonoMetadataInfo.MonoMethodTokenOffset);
+ }
+
+ public TargetAddress MonoMethodGetClass (TargetMemoryAccess memory, TargetAddress method)
+ {
+ return memory.ReadAddress (method + MonoMetadataInfo.MonoMethodKlassOffset);
+ }
+
+ //
+ // MonoType
+ //
+
+ public MonoTypeEnum MonoTypeGetType (TargetMemoryAccess memory, TargetAddress type)
+ {
+ uint flags = (uint) memory.ReadInteger (
+ type + memory.TargetMemoryInfo.TargetAddressSize);
+
+ return (MonoTypeEnum) ((flags & 0x00ff0000) >> 16);
+ }
+
+ public bool MonoTypeGetIsByRef (TargetMemoryAccess memory, TargetAddress type)
+ {
+ uint flags = (uint) memory.ReadInteger (
+ type + memory.TargetMemoryInfo.TargetAddressSize);
+ return (int) ((flags & 0x40000000) >> 30) != 0;
+ }
+
+ public TargetAddress MonoTypeGetData (TargetMemoryAccess memory, TargetAddress type)
+ {
+ return memory.ReadAddress (type);
+ }
+
+ public TargetAddress MonoArrayTypeGetClass (TargetMemoryAccess memory,
+ TargetAddress atype)
+ {
+ return memory.ReadAddress (atype);
+ }
+
+ public int MonoArrayTypeGetRank (TargetMemoryAccess memory,
+ TargetAddress atype)
+ {
+ return memory.ReadByte (atype + memory.TargetAddressSize);
+ }
+
+ public int MonoArrayTypeGetNumSizes (TargetMemoryAccess memory,
+ TargetAddress atype)
+ {
+ return memory.ReadByte (atype + memory.TargetAddressSize + 1);
+ }
+
+ public int MonoArrayTypeGetNumLoBounds (TargetMemoryAccess memory,
+ TargetAddress atype)
+ {
+ return memory.ReadByte (atype + memory.TargetAddressSize + 2);
+ }
+
+ internal void MonoArrayTypeGetBounds (TargetMemoryAccess memory,
+ TargetAddress data)
+ {
+ //
+ // FIXME: Only check whether the low bounds are all zero
+ //
+ int num_sizes = memory.ReadByte (data + memory.TargetAddressSize + 1);
+ if (num_sizes != 0)
+ throw new InternalError ();
+
+ int num_lobounds = memory.ReadByte (data + memory.TargetAddressSize + 2);
+ if (num_lobounds == 0)
+ return;
+
+ TargetAddress array = memory.ReadAddress (data + 3 * memory.TargetAddressSize);
+ TargetBinaryReader bounds = memory.ReadMemory (array, num_lobounds * 4).GetReader ();
+ for (int i = 0; i < num_lobounds; i++) {
+ int bound = bounds.ReadInt32 ();
+ if (bound != 0)
+ throw new InternalError ();
+ }
+ }
+
+ //
+ // Fundamental types
+ //
+
+ public TargetAddress GetBooleanClass (TargetMemoryAccess memory)
+ {
+ return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
+ MonoMetadataInfo.MonoDefaultsBooleanOffset);
+ }
+
+ public TargetAddress GetCharClass (TargetMemoryAccess memory)
+ {
+ return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
+ MonoMetadataInfo.MonoDefaultsCharOffset);
+ }
+
+ public TargetAddress GetSByteClass (TargetMemoryAccess memory)
+ {
+ return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
+ MonoMetadataInfo.MonoDefaultsSByteOffset);
+ }
+
+ public TargetAddress GetByteClass (TargetMemoryAccess memory)
+ {
+ return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
+ MonoMetadataInfo.MonoDefaultsByteOffset);
+ }
+
+ public TargetAddress GetInt16Class (TargetMemoryAccess memory)
+ {
+ return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
+ MonoMetadataInfo.MonoDefaultsInt16Offset);
+ }
+
+ public TargetAddress GetUInt16Class (TargetMemoryAccess memory)
+ {
+ return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
+ MonoMetadataInfo.MonoDefaultsUInt16Offset);
+ }
+
+ public TargetAddress GetInt32Class (TargetMemoryAccess memory)
+ {
+ return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
+ MonoMetadataInfo.MonoDefaultsInt32Offset);
+ }
+
+ public TargetAddress GetUInt32Class (TargetMemoryAccess memory)
+ {
+ return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
+ MonoMetadataInfo.MonoDefaultsUInt32Offset);
+ }
+
+ public TargetAddress GetInt64Class (TargetMemoryAccess memory)
+ {
+ return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
+ MonoMetadataInfo.MonoDefaultsInt64Offset);
+ }
+
+ public TargetAddress GetUInt64Class (TargetMemoryAccess memory)
+ {
+ return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
+ MonoMetadataInfo.MonoDefaultsUInt64Offset);
+ }
+
+ public TargetAddress GetSingleClass (TargetMemoryAccess memory)
+ {
+ return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
+ MonoMetadataInfo.MonoDefaultsSingleOffset);
+ }
+
+ public TargetAddress GetDoubleClass (TargetMemoryAccess memory)
+ {
+ return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
+ MonoMetadataInfo.MonoDefaultsDoubleOffset);
+ }
+
+ public TargetAddress GetIntPtrClass (TargetMemoryAccess memory)
+ {
+ return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
+ MonoMetadataInfo.MonoDefaultsIntOffset);
+ }
+
+ public TargetAddress GetUIntPtrClass (TargetMemoryAccess memory)
+ {
+ return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
+ MonoMetadataInfo.MonoDefaultsUIntOffset);
+ }
+
+ public TargetAddress GetVoidClass (TargetMemoryAccess memory)
+ {
+ return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
+ MonoMetadataInfo.MonoDefaultsVoidOffset);
+ }
+
+ public TargetAddress GetStringClass (TargetMemoryAccess memory)
+ {
+ return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
+ MonoMetadataInfo.MonoDefaultsStringOffset);
+ }
+
+ public TargetAddress GetObjectClass (TargetMemoryAccess memory)
+ {
+ return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
+ MonoMetadataInfo.MonoDefaultsObjectOffset);
+ }
+
+ public TargetAddress GetArrayClass (TargetMemoryAccess memory)
+ {
+ return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
+ MonoMetadataInfo.MonoDefaultsArrayOffset);
+ }
+
+ public TargetAddress GetDelegateClass (TargetMemoryAccess memory)
+ {
+ return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
+ MonoMetadataInfo.MonoDefaultsDelegateOffset);
+ }
+
+ public TargetAddress GetExceptionClass (TargetMemoryAccess memory)
+ {
+ return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
+ MonoMetadataInfo.MonoDefaultsExceptionOffset);
+ }
+
+ public MonoMethodSignature GetMethodSignature (MonoLanguageBackend mono,
+ TargetMemoryAccess memory,
+ TargetAddress signature)
+ {
+ int count = memory.ReadInteger (signature + 4) & 0x0000ffff;
+
+ int offset = memory.TargetAddressSize == 8 ? 16 : 12;
+ TargetAddress ret = memory.ReadAddress (signature + offset);
+
+ TargetType ret_type = mono.ReadType (memory, ret);
+ if (count == 0)
+ return new MonoMethodSignature (ret_type, new TargetType [0]);
+
+ offset += memory.TargetAddressSize;
+ TargetReader reader = new TargetReader (
+ memory.ReadMemory (signature + offset, count * memory.TargetAddressSize));
+
+ TargetType[] param_types = new TargetType [count];
+ for (int i = 0; i < count; i++)
+ param_types [i] = mono.ReadType (memory, reader.ReadAddress ());
+
+ return new MonoMethodSignature (ret_type, param_types);
+ }
+
+ protected class MetadataInfo
+ {
+ public readonly int MonoDefaultsSize;
+ public readonly TargetAddress MonoDefaultsAddress;
+ public readonly int TypeSize;
+ public readonly int ArrayTypeSize;
+ public readonly int KlassSize;
+ public readonly int ThreadSize;
+
+ public readonly int ThreadTidOffset;
+ public readonly int ThreadStackPtrOffset;
+ public readonly int ThreadEndStackOffset;
+
+ public readonly int KlassImageOffset;
+ public readonly int KlassInstanceSizeOffset;
+ public readonly int KlassParentOffset;
+ public readonly int KlassTokenOffset;
+ public readonly int KlassFieldOffset;
+ public readonly int KlassFieldCountOffset;
+ public readonly int KlassMethodsOffset;
+ public readonly int KlassMethodCountOffset;
+ public readonly int KlassThisArgOffset;
+ public readonly int KlassByValArgOffset;
+ public readonly int KlassGenericClassOffset;
+ public readonly int KlassGenericContainerOffset;
+ public readonly int KlassVTableOffset;
+ public readonly int FieldInfoSize;
+ public readonly int FieldInfoTypeOffset;
+ public readonly int FieldInfoOffsetOffset;
+
+ public readonly int MonoDefaultsCorlibOffset;
+ public readonly int MonoDefaultsObjectOffset;
+ public readonly int MonoDefaultsByteOffset;
+ public readonly int MonoDefaultsVoidOffset;
+ public readonly int MonoDefaultsBooleanOffset;
+ public readonly int MonoDefaultsSByteOffset;
+ public readonly int MonoDefaultsInt16Offset;
+ public readonly int MonoDefaultsUInt16Offset;
+ public readonly int MonoDefaultsInt32Offset;
+ public readonly int MonoDefaultsUInt32Offset;
+ public readonly int MonoDefaultsIntOffset;
+ public readonly int MonoDefaultsUIntOffset;
+ public readonly int MonoDefaultsInt64Offset;
+ public readonly int MonoDefaultsUInt64Offset;
+ public readonly int MonoDefaultsSingleOffset;
+ public readonly int MonoDefaultsDoubleOffset;
+ public readonly int MonoDefaultsCharOffset;
+ public readonly int MonoDefaultsStringOffset;
+ public readonly int MonoDefaultsEnumOffset;
+ public readonly int MonoDefaultsArrayOffset;
+ public readonly int MonoDefaultsDelegateOffset;
+ public readonly int MonoDefaultsExceptionOffset;
+
+ public readonly int MonoMethodKlassOffset;
+ public readonly int MonoMethodTokenOffset;
+ public readonly int MonoMethodFlagsOffset;
+ public readonly int MonoMethodInflatedOffset;
+
+ public readonly int MonoVTableKlassOffset;
+ public readonly int MonoVTableVTableOffset;
+
+ public MetadataInfo (TargetMemoryAccess memory, TargetAddress address)
+ {
+ int size = memory.ReadInteger (address);
+ TargetBinaryReader reader = memory.ReadMemory (address, size).GetReader ();
+ reader.ReadInt32 ();
+
+ MonoDefaultsSize = reader.ReadInt32 ();
+ MonoDefaultsAddress = new TargetAddress (
+ memory.AddressDomain, reader.ReadAddress ());
+
+ TypeSize = reader.ReadInt32 ();
+ ArrayTypeSize = reader.ReadInt32 ();
+ KlassSize = reader.ReadInt32 ();
+ ThreadSize = reader.ReadInt32 ();
+
+ ThreadTidOffset = reader.ReadInt32 ();
+ ThreadStackPtrOffset = reader.ReadInt32 ();
+ ThreadEndStackOffset = reader.ReadInt32 ();
+
+ KlassImageOffset = reader.ReadInt32 ();
+ KlassInstanceSizeOffset = reader.ReadInt32 ();
+ KlassParentOffset = reader.ReadInt32 ();
+ KlassTokenOffset = reader.ReadInt32 ();
+ KlassFieldOffset = reader.ReadInt32 ();
+ KlassMethodsOffset = reader.ReadInt32 ();
+ KlassMethodCountOffset = reader.ReadInt32 ();
+ KlassThisArgOffset = reader.ReadInt32 ();
+ KlassByValArgOffset = reader.ReadInt32 ();
+ KlassGenericClassOffset = reader.ReadInt32 ();
+ KlassGenericContainerOffset = reader.ReadInt32 ();
+ KlassVTableOffset = reader.ReadInt32 ();
+
+ FieldInfoSize = reader.ReadInt32 ();
+ FieldInfoTypeOffset = reader.ReadInt32 ();
+ FieldInfoOffsetOffset = reader.ReadInt32 ();
+
+ KlassFieldCountOffset = KlassMethodCountOffset - 8;
+
+ MonoDefaultsCorlibOffset = reader.ReadInt32 ();
+ MonoDefaultsObjectOffset = reader.ReadInt32 ();
+ MonoDefaultsByteOffset = reader.ReadInt32 ();
+ MonoDefaultsVoidOffset = reader.ReadInt32 ();
+ MonoDefaultsBooleanOffset = reader.ReadInt32 ();
+ MonoDefaultsSByteOffset = reader.ReadInt32 ();
+ MonoDefaultsInt16Offset = reader.ReadInt32 ();
+ MonoDefaultsUInt16Offset = reader.ReadInt32 ();
+ MonoDefaultsInt32Offset = reader.ReadInt32 ();
+ MonoDefaultsUInt32Offset = reader.ReadInt32 ();
+ MonoDefaultsIntOffset = reader.ReadInt32 ();
+ MonoDefaultsUIntOffset = reader.ReadInt32 ();
+ MonoDefaultsInt64Offset = reader.ReadInt32 ();
+ MonoDefaultsUInt64Offset = reader.ReadInt32 ();
+ MonoDefaultsSingleOffset = reader.ReadInt32 ();
+ MonoDefaultsDoubleOffset = reader.ReadInt32 ();
+ MonoDefaultsCharOffset = reader.ReadInt32 ();
+ MonoDefaultsStringOffset = reader.ReadInt32 ();
+ MonoDefaultsEnumOffset = reader.ReadInt32 ();
+ MonoDefaultsArrayOffset = reader.ReadInt32 ();
+ MonoDefaultsDelegateOffset = reader.ReadInt32 ();
+ MonoDefaultsExceptionOffset = reader.ReadInt32 ();
+
+ MonoMethodKlassOffset = reader.ReadInt32 ();
+ MonoMethodTokenOffset = reader.ReadInt32 ();
+ MonoMethodFlagsOffset = reader.ReadInt32 ();
+ MonoMethodInflatedOffset = reader.ReadInt32 ();
+
+ MonoVTableKlassOffset = reader.ReadInt32 ();
+ MonoVTableVTableOffset = reader.ReadInt32 ();
+ }
+ }
+
+ //
+ // The following API is new in `terrania'.
+ //
+
+ public GenericClassInfo GetGenericClass (TargetMemoryAccess memory,
+ TargetAddress address)
+ {
+ int addr_size = memory.TargetMemoryInfo.TargetAddressSize;
+
+ TargetReader reader = new TargetReader (memory.ReadMemory (address, 5 * addr_size));
+ TargetAddress container = reader.ReadAddress ();
+ TargetAddress class_inst = reader.ReadAddress ();
+ reader.ReadAddress (); /* method_inst */
+ reader.ReadAddress ();
+ TargetAddress cached_class = reader.ReadAddress ();
+
+ int inst_id = memory.ReadInteger (class_inst);
+ int inst_data = memory.ReadInteger (class_inst + 4);
+
+ TargetAddress inst_argv;
+ if (MonoDebuggerInfo.MajorVersion == 80)
+ inst_argv = memory.ReadAddress (class_inst + 8);
+ else
+ inst_argv = class_inst + 8;
+
+ int type_argc = inst_data & 0x3fffff;
+
+ TargetReader argv_reader = new TargetReader (
+ memory.ReadMemory (inst_argv, type_argc * addr_size));
+
+ TargetAddress[] type_args = new TargetAddress [type_argc];
+ for (int i = 0; i < type_argc; i++)
+ type_args [i] = argv_reader.ReadAddress ();
+
+ TargetAddress cached_class_ptr = address + 4 * addr_size;
+
+ return new GenericClassInfo (container, type_args, cached_class_ptr,
+ cached_class);
+ }
+
+ public class GenericClassInfo
+ {
+ /* `MonoClass *' of the container class. */
+ public readonly TargetAddress ContainerClass;
+
+ /* `MonoType *' array of the instantiation. */
+ public readonly TargetAddress[] TypeArguments;
+
+ /* `MonoClass *' of this instantiation, if present. */
+ public readonly TargetAddress KlassPtr;
+ public readonly TargetAddress Klass;
+
+ public GenericClassInfo (TargetAddress container, TargetAddress[] type_args,
+ TargetAddress klass_ptr, TargetAddress klass)
+ {
+ this.ContainerClass = container;
+ this.TypeArguments = type_args;
+ this.KlassPtr = klass_ptr;
+ this.Klass = klass;
+ }
+ }
+
+ public GenericParamInfo GetGenericParameter (TargetMemoryAccess memory,
+ TargetAddress address)
+ {
+ int addr_size = memory.TargetMemoryInfo.TargetAddressSize;
+
+ TargetReader reader = new TargetReader (
+ memory.ReadMemory (address, 4 * addr_size + 4));
+ TargetAddress container = reader.ReadAddress ();
+ TargetAddress klass = reader.ReadAddress ();
+ TargetAddress name_addr = reader.ReadAddress ();
+ reader.BinaryReader.ReadInt16 (); /* flags */
+ int pos = reader.BinaryReader.ReadInt16 ();
+
+ string name;
+ if (!name_addr.IsNull)
+ name = memory.ReadString (name_addr);
+ else
+ name = String.Format ("!{0}", pos);
+
+ return new GenericParamInfo (container, klass, name, pos);
+ }
+
+ public class GenericParamInfo
+ {
+ public readonly TargetAddress Container;
+ public readonly TargetAddress Klass;
+ public readonly string Name;
+ public readonly int Position;
+
+ public GenericParamInfo (TargetAddress container, TargetAddress klass,
+ string name, int pos)
+ {
+ this.Container = container;
+ this.Klass = klass;
+ this.Name = name;
+ this.Position = pos;
+ }
+ }
+
+ public AppDomainInfo GetAppDomainInfo (MonoLanguageBackend mono, TargetMemoryAccess memory,
+ TargetAddress address)
+ {
+ int addr_size = memory.TargetMemoryInfo.TargetAddressSize;
+ TargetReader reader = new TargetReader (memory.ReadMemory (address, 12 * addr_size));
+
+ return new AppDomainInfo (mono, memory, reader);
+ }
+
+ public class AppDomainInfo
+ {
+ public readonly string ApplicationBase;
+ public readonly string ApplicationName;
+ public readonly string CachePath;
+ public readonly string ConfigFile;
+ public readonly string DynamicBase;
+ public readonly string ShadowCopyDirectories;
+ public readonly bool ShadowCopyFiles;
+
+ public string ShadowCopyPath;
+
+ public AppDomainInfo (MonoLanguageBackend mono, TargetMemoryAccess memory, TargetReader reader)
+ {
+ int addr_size = memory.TargetMemoryInfo.TargetAddressSize;
+
+ reader.Offset = 2 * addr_size;
+ ApplicationBase = MonoStringObject.ReadString (mono, memory, reader.ReadAddress ());
+ ApplicationName = MonoStringObject.ReadString (mono, memory, reader.ReadAddress ());
+ CachePath = MonoStringObject.ReadString (mono, memory, reader.ReadAddress ());
+ ConfigFile = MonoStringObject.ReadString (mono, memory, reader.ReadAddress ());
+ DynamicBase = MonoStringObject.ReadString (mono, memory, reader.ReadAddress ());
+ reader.Offset += 3 * addr_size;
+ ShadowCopyDirectories = MonoStringObject.ReadString (mono, memory, reader.ReadAddress ());
+ ShadowCopyFiles = MonoStringObject.ReadString (mono, memory, reader.ReadAddress ()) == "true";
+ }
+
+ public override string ToString ()
+ {
+ return String.Format ("AppDomainInfo ({0}:{1}:{2}:{3}:{4}:{5}:{6})",
+ ApplicationBase, ApplicationName, CachePath, ConfigFile,
+ DynamicBase, ShadowCopyDirectories, ShadowCopyFiles);
+ }
+ }
+ }
+}
diff --git a/backend/mono/MonoThreadManager.cs b/backend/mono/MonoThreadManager.cs
new file mode 100644
index 0000000..88138df
--- /dev/null
+++ b/backend/mono/MonoThreadManager.cs
@@ -0,0 +1,639 @@
+using System;
+using System.IO;
+using System.Text;
+using System.Threading;
+using System.Configuration;
+using System.Globalization;
+using System.Reflection;
+using System.Diagnostics;
+using System.Collections;
+using System.Collections.Generic;
+using System.Collections.Specialized;
+using System.Runtime.InteropServices;
+
+using Mono.Debugger;
+using Mono.Debugger.Languages;
+using Mono.Debugger.Languages.Mono;
+
+
+namespace Mono.Debugger.Backend.Mono
+{
+
+// <summary>
+// MonoThreadManager is a special case handler for thread events when
+// we know we're running a managed app.
+// </summary>
+
+ internal enum NotificationType {
+ InitializeManagedCode = 1,
+ InitializeCorlib,
+ JitBreakpoint,
+ InitializeThreadManager,
+ AcquireGlobalThreadLock,
+ ReleaseGlobalThreadLock,
+ WrapperMain,
+ MainExited,
+ UnhandledException,
+ ThrowException,
+ HandleException,
+ ThreadCreated,
+ ThreadCleanup,
+ GcThreadCreated,
+ GcThreadExited,
+ ReachedMain,
+ FinalizeManagedCode,
+ LoadModule,
+ UnloadModule,
+ DomainCreate,
+ DomainUnload,
+ ClassInitialized,
+ InterruptionRequest,
+ CreateAppDomain,
+ UnloadAppDomain,
+
+ Trampoline = 256
+ }
+
+ internal enum ThreadFlags {
+ None = 0,
+ Internal = 1,
+ ThreadPool = 2
+ };
+
+ internal delegate bool ManagedCallbackFunction (SingleSteppingEngine engine);
+
+ internal class MonoThreadManager
+ {
+ ProcessServant process;
+ MonoDebuggerInfo debugger_info;
+
+ protected MonoThreadManager (ProcessServant process, Inferior inferior,
+ MonoDebuggerInfo debugger_info)
+ {
+ this.process = process;
+ this.debugger_info = debugger_info;
+
+ inferior.WriteInteger (debugger_info.UsingMonoDebugger, 1);
+
+ notification_bpt = new InitializeBreakpoint (this, debugger_info.Initialize);
+ notification_bpt.Insert (inferior);
+ }
+
+ public static MonoThreadManager Initialize (ProcessServant process, Inferior inferior,
+ TargetAddress info, bool attach)
+ {
+ MonoDebuggerInfo debugger_info = MonoDebuggerInfo.Create (inferior, info);
+ if (debugger_info == null)
+ return null;
+
+ if (attach) {
+ if (!debugger_info.CheckRuntimeVersion (81, 2)) {
+ Report.Error ("The Mono runtime of the target application is too old to support attaching,\n" +
+ "attaching as a native application.");
+ return null;
+ }
+
+ if ((debugger_info.RuntimeFlags & 1) != 1) {
+ Report.Error ("The Mono runtime of the target application does not support attaching,\n" +
+ "attaching as a native application.");
+ return null;
+ }
+ }
+
+ return new MonoThreadManager (process, inferior, debugger_info);
+ }
+
+ AddressBreakpoint notification_bpt;
+ IntPtr mono_runtime_info;
+ int debugger_version;
+
+ internal bool HasCodeBuffer {
+ get;
+ private set;
+ }
+
+ [DllImport("monodebuggerserver")]
+ static extern IntPtr mono_debugger_server_initialize_mono_runtime (
+ int address_size, long notification_address,
+ long executable_code_buffer, int executable_code_buffer_size,
+ long breakpoint_info, long breakpoint_info_index,
+ int breakpoint_table_size);
+
+ [DllImport("monodebuggerserver")]
+ static extern void mono_debugger_server_finalize_mono_runtime (IntPtr handle);
+
+ [DllImport("monodebuggerserver")]
+ static extern void mono_debugger_server_initialize_code_buffer (
+ IntPtr runtime, long executable_code_buffer,
+ int executable_code_buffer_size);
+
+ protected void initialize_notifications (Inferior inferior)
+ {
+ TargetAddress executable_code_buffer = inferior.ReadAddress (
+ debugger_info.ExecutableCodeBuffer);
+ HasCodeBuffer = !executable_code_buffer.IsNull;
+
+ mono_runtime_info = mono_debugger_server_initialize_mono_runtime (
+ inferior.TargetAddressSize,
+ debugger_info.NotificationAddress.Address,
+ executable_code_buffer.Address,
+ debugger_info.ExecutableCodeBufferSize,
+ debugger_info.BreakpointInfo.Address,
+ debugger_info.BreakpointInfoIndex.Address,
+ debugger_info.BreakpointArraySize);
+ inferior.SetRuntimeInfo (mono_runtime_info);
+
+ debugger_version = inferior.ReadInteger (debugger_info.DebuggerVersion);
+
+ if (notification_bpt != null) {
+ notification_bpt.Remove (inferior);
+ notification_bpt = null;
+ }
+ }
+
+ internal void InitCodeBuffer (Inferior inferior, TargetAddress code_buffer)
+ {
+ HasCodeBuffer = true;
+ mono_debugger_server_initialize_code_buffer (
+ mono_runtime_info, code_buffer.Address,
+ debugger_info.ExecutableCodeBufferSize);
+ }
+
+ protected class InitializeBreakpoint : AddressBreakpoint
+ {
+ protected readonly MonoThreadManager manager;
+
+ public InitializeBreakpoint (MonoThreadManager manager, TargetAddress address)
+ : base ("initialize", ThreadGroup.System, address)
+ {
+ this.manager = manager;
+ }
+
+ public override bool CheckBreakpointHit (Thread target, TargetAddress address)
+ {
+ return true;
+ }
+
+ internal override bool BreakpointHandler (Inferior inferior,
+ out bool remain_stopped)
+ {
+ manager.initialize_notifications (inferior);
+ remain_stopped = false;
+ return true;
+ }
+ }
+
+ internal bool InitializeAfterAttach (Inferior inferior)
+ {
+ initialize_notifications (inferior);
+
+ inferior.WriteAddress (debugger_info.ThreadVTablePtr,
+ debugger_info.ThreadVTable);
+ inferior.WriteAddress (debugger_info.EventHandlerPtr,
+ debugger_info.EventHandler);
+ inferior.WriteInteger (debugger_info.UsingMonoDebugger, 1);
+
+ csharp_language = inferior.Process.CreateMonoLanguage (debugger_info);
+ csharp_language.InitializeAttach (inferior);
+
+ return true;
+ }
+
+ internal void Detach (Inferior inferior)
+ {
+ inferior.WriteAddress (debugger_info.ThreadVTablePtr, TargetAddress.Null);
+ inferior.WriteAddress (debugger_info.EventHandler, TargetAddress.Null);
+ inferior.WriteInteger (debugger_info.UsingMonoDebugger, 0);
+ }
+
+ internal void AddManagedCallback (Inferior inferior, ManagedCallbackData data)
+ {
+ inferior.WriteInteger (MonoDebuggerInfo.InterruptionRequest, 1);
+ managed_callbacks.Enqueue (data);
+ }
+
+ internal Queue<ManagedCallbackData> ClearManagedCallbacks (Inferior inferior)
+ {
+ inferior.WriteInteger (MonoDebuggerInfo.InterruptionRequest, 0);
+ Queue<ManagedCallbackData> retval = managed_callbacks;
+ managed_callbacks = new Queue<ManagedCallbackData> ();
+ return retval;
+ }
+
+ TargetAddress main_function;
+ TargetAddress main_thread;
+ MonoLanguageBackend csharp_language;
+ Queue<ManagedCallbackData> managed_callbacks = new Queue<ManagedCallbackData> ();
+
+ internal bool CanExecuteCode {
+ get { return mono_runtime_info != IntPtr.Zero; }
+ }
+
+ internal MonoDebuggerInfo MonoDebuggerInfo {
+ get { return debugger_info; }
+ }
+
+ int index;
+ internal void ThreadCreated (SingleSteppingEngine sse)
+ {
+ sse.Inferior.SetRuntimeInfo (mono_runtime_info);
+ if (!MonoDebuggerInfo.CheckRuntimeVersion (81, 3) && !process.IsAttached) {
+ if (++index < 3)
+ sse.Thread.ThreadFlags |= Thread.Flags.Daemon | Thread.Flags.Immutable;
+ } else {
+ sse.Thread.ThreadFlags |= Thread.Flags.Daemon | Thread.Flags.Immutable;
+ }
+ }
+
+ void check_thread_flags (SingleSteppingEngine engine, ThreadFlags flags)
+ {
+ if ((flags & (ThreadFlags.Internal | ThreadFlags.ThreadPool)) != ThreadFlags.Internal) {
+ engine.Thread.ThreadFlags &= ~(Thread.Flags.Daemon | Thread.Flags.Immutable);
+ if (engine != process.MainThread)
+ process.Debugger.Client.OnManagedThreadCreatedEvent (engine.Thread);
+ } else if ((flags & ThreadFlags.ThreadPool) != 0) {
+ engine.Thread.ThreadFlags &= ~Thread.Flags.Immutable;
+ }
+ }
+
+ internal void InitializeThreads (Inferior inferior)
+ {
+ TargetAddress ptr = inferior.ReadAddress (MonoDebuggerInfo.ThreadTable);
+ while (!ptr.IsNull) {
+ int size;
+ if (MonoDebuggerInfo.CheckRuntimeVersion (81, 3))
+ size = 60 + inferior.TargetMemoryInfo.TargetAddressSize;
+ else
+ size = 32 + inferior.TargetMemoryInfo.TargetAddressSize;
+ TargetReader reader = new TargetReader (inferior.ReadMemory (ptr, size));
+
+ long tid = reader.ReadLongInteger ();
+ TargetAddress lmf_addr = reader.ReadAddress ();
+ TargetAddress end_stack = reader.ReadAddress ();
+
+ TargetAddress extended_notifications_addr = ptr + 24;
+
+ if (inferior.TargetMemoryInfo.TargetAddressSize == 4)
+ tid &= 0x00000000ffffffffL;
+
+ reader.Offset += 8;
+ ptr = reader.ReadAddress ();
+
+ ThreadFlags flags = ThreadFlags.None;
+ if (MonoDebuggerInfo.CheckRuntimeVersion (81, 3)) {
+ reader.Offset = 56 + inferior.TargetAddressSize;
+ flags = (ThreadFlags) reader.ReadInteger ();
+ }
+
+ bool found = false;
+ foreach (SingleSteppingEngine engine in process.Engines) {
+ if (engine.TID != tid)
+ continue;
+
+ engine.SetManagedThreadData (lmf_addr, extended_notifications_addr);
+ engine.OnManagedThreadCreated (end_stack);
+ check_thread_flags (engine, flags);
+ found = true;
+ break;
+ }
+
+ if (!found)
+ Report.Error ("Cannot find thread {0:x} in {1}",
+ tid, process.ProcessStart.CommandLine);
+ }
+ }
+
+ internal bool HandleChildEvent (SingleSteppingEngine engine, Inferior inferior,
+ ref Inferior.ChildEvent cevent, out bool resume_target)
+ {
+ if (cevent.Type == Inferior.ChildEventType.CHILD_NOTIFICATION) {
+ NotificationType type = (NotificationType) cevent.Argument;
+
+ Report.Debug (DebugFlags.EventLoop,
+ "{0} received notification {1}: {2}",
+ engine, type, cevent);
+
+ switch (type) {
+ case NotificationType.AcquireGlobalThreadLock:
+ Report.Debug (DebugFlags.Threads,
+ "{0} received notification {1}", engine, type);
+ engine.ProcessServant.AcquireGlobalThreadLock (engine);
+ break;
+
+ case NotificationType.ReleaseGlobalThreadLock:
+ Report.Debug (DebugFlags.Threads,
+ "{0} received notification {1}", engine, type);
+ engine.ProcessServant.ReleaseGlobalThreadLock (engine);
+ break;
+
+ case NotificationType.ThreadCreated: {
+ TargetAddress data = new TargetAddress (
+ inferior.AddressDomain, cevent.Data2);
+
+ TargetAddress lmf = inferior.ReadAddress (data + 8);
+ engine.SetManagedThreadData (lmf, data + 24);
+
+ if (MonoDebuggerInfo.CheckRuntimeVersion (81, 3)) {
+ int flags_offset = 56 + inferior.TargetAddressSize;
+ ThreadFlags flags = (ThreadFlags) inferior.ReadInteger (data + flags_offset);
+ check_thread_flags (engine, flags);
+ }
+
+ Report.Debug (DebugFlags.Threads,
+ "{0} managed thread created: {1:x} {2} {3} - {4}",
+ engine, cevent.Data1, data, lmf, engine.LMFAddress);
+ break;
+ }
+
+ case NotificationType.ThreadCleanup: {
+ TargetAddress data = new TargetAddress (
+ inferior.AddressDomain, cevent.Data1);
+
+ Report.Debug (DebugFlags.Threads,
+ "{0} managed thread cleanup: {1:x} {2}",
+ engine, cevent.Data2, data);
+ break;
+ }
+
+ case NotificationType.GcThreadCreated: {
+ TargetAddress data = new TargetAddress (
+ inferior.AddressDomain, cevent.Data1);
+ long tid = cevent.Data2;
+
+ Report.Debug (DebugFlags.Threads,
+ "{0} created gc thread: {1:x} {2}",
+ engine, tid, data);
+
+ engine = engine.ProcessServant.GetEngineByTID (inferior, tid);
+ if (engine == null)
+ throw new InternalError ();
+
+ engine.OnManagedThreadCreated (data);
+ break;
+ }
+
+ case NotificationType.GcThreadExited:
+ Report.Debug (DebugFlags.Threads, "{0} gc thread exited", engine);
+ engine.OnManagedThreadExited ();
+ try {
+ inferior.Continue ();
+ } catch {
+ // Ignore errors; for some reason, the thread may have died
+ // already by the time get this notification.
+ }
+ resume_target = false;
+ return true;
+
+ case NotificationType.InitializeThreadManager:
+ csharp_language = inferior.Process.CreateMonoLanguage (
+ debugger_info);
+ if (engine.ProcessServant.IsAttached)
+ csharp_language.InitializeAttach (inferior);
+ else
+ csharp_language.Initialize (inferior);
+
+ break;
+
+ case NotificationType.ReachedMain: {
+ Inferior.StackFrame iframe = inferior.GetCurrentFrame (false);
+ engine.SetMainReturnAddress (iframe.StackPointer);
+ engine.ProcessServant.OnProcessReachedMainEvent ();
+ resume_target = !engine.InitializeBreakpoints ();
+ return true;
+ }
+
+ case NotificationType.WrapperMain:
+ break;
+ case NotificationType.MainExited:
+ engine.SetMainReturnAddress (TargetAddress.Null);
+ break;
+
+ case NotificationType.UnhandledException:
+ cevent = new Inferior.ChildEvent (
+ Inferior.ChildEventType.UNHANDLED_EXCEPTION,
+ 0, cevent.Data1, cevent.Data2);
+ resume_target = false;
+ return false;
+
+ case NotificationType.HandleException:
+ cevent = new Inferior.ChildEvent (
+ Inferior.ChildEventType.HANDLE_EXCEPTION,
+ 0, cevent.Data1, cevent.Data2);
+ resume_target = false;
+ return false;
+
+ case NotificationType.ThrowException:
+ cevent = new Inferior.ChildEvent (
+ Inferior.ChildEventType.THROW_EXCEPTION,
+ 0, cevent.Data1, cevent.Data2);
+ resume_target = false;
+ return false;
+
+ case NotificationType.FinalizeManagedCode:
+ mono_debugger_server_finalize_mono_runtime (mono_runtime_info);
+ mono_runtime_info = IntPtr.Zero;
+ csharp_language = null;
+ break;
+
+ case NotificationType.Trampoline:
+ resume_target = false;
+ return false;
+
+ case NotificationType.ClassInitialized:
+ break;
+
+ case NotificationType.InterruptionRequest:
+ inferior.WriteInteger (MonoDebuggerInfo.InterruptionRequest, 0);
+ var callbacks = managed_callbacks;
+ managed_callbacks = new Queue<ManagedCallbackData> ();
+ resume_target = !engine.OnManagedCallback (callbacks);
+ return true;
+
+ default: {
+ TargetAddress data = new TargetAddress (
+ inferior.AddressDomain, cevent.Data1);
+
+ resume_target = csharp_language.Notification (
+ engine, inferior, type, data, cevent.Data2);
+ return true;
+ }
+ }
+
+ resume_target = true;
+ return true;
+ }
+
+ if ((cevent.Type == Inferior.ChildEventType.CHILD_STOPPED) &&
+ (cevent.Argument == inferior.MonoThreadAbortSignal)) {
+ resume_target = true;
+ return true;
+ }
+
+ if ((cevent.Type == Inferior.ChildEventType.CHILD_STOPPED) && (cevent.Argument != 0) && !
+ engine.Process.Session.Config.StopOnManagedSignals) {
+ if (inferior.IsManagedSignal ((int) cevent.Argument)) {
+ resume_target = true;
+ return true;
+ }
+ }
+
+ resume_target = false;
+ return false;
+ }
+ }
+
+ // <summary>
+ // This class is the managed representation of the MONO_DEBUGGER__debugger_info struct.
+ // as defined in mono/mini/debug-debugger.h
+ // </summary>
+ internal class MonoDebuggerInfo
+ {
+ // These constants must match up with those in mono/mono/metadata/mono-debug.h
+ public const int MinDynamicVersion = 80;
+ public const int MaxDynamicVersion = 81;
+ public const long DynamicMagic = 0x7aff65af4253d427;
+
+ public readonly int MajorVersion;
+ public readonly int MinorVersion;
+
+ public readonly int RuntimeFlags;
+
+ public readonly int MonoTrampolineNum;
+ public readonly TargetAddress MonoTrampolineCode;
+ public readonly TargetAddress NotificationAddress;
+ public readonly TargetAddress SymbolTable;
+ public readonly int SymbolTableSize;
+ public readonly TargetAddress MonoMetadataInfo;
+ public readonly TargetAddress DebuggerVersion;
+ public readonly TargetAddress CompileMethod;
+ public readonly TargetAddress GetVirtualMethod;
+ public readonly TargetAddress GetBoxedObjectMethod;
+ public readonly TargetAddress RuntimeInvoke;
+ public readonly TargetAddress CreateString;
+ public readonly TargetAddress ClassGetStaticFieldData;
+ public readonly TargetAddress LookupClass;
+ public readonly TargetAddress RunFinally;
+ public readonly TargetAddress InsertMethodBreakpoint;
+ public readonly TargetAddress InsertSourceBreakpoint;
+ public readonly TargetAddress RemoveBreakpoint;
+ public readonly TargetAddress RegisterClassInitCallback;
+ public readonly TargetAddress RemoveClassInitCallback;
+ public readonly TargetAddress Initialize;
+ public readonly TargetAddress ThreadTable;
+ public readonly TargetAddress ExecutableCodeBuffer;
+ public readonly TargetAddress BreakpointInfo;
+ public readonly TargetAddress BreakpointInfoIndex;
+ public readonly int ExecutableCodeBufferSize;
+ public readonly int BreakpointArraySize;
+ public readonly TargetAddress GetMethodSignature;
+ public readonly TargetAddress InitCodeBuffer;
+
+ public readonly TargetAddress ThreadVTablePtr;
+ public readonly TargetAddress ThreadVTable;
+ public readonly TargetAddress EventHandlerPtr;
+ public readonly TargetAddress EventHandler;
+
+ public readonly TargetAddress UsingMonoDebugger;
+ public readonly TargetAddress InterruptionRequest;
+
+ public static MonoDebuggerInfo Create (TargetMemoryAccess memory, TargetAddress info)
+ {
+ TargetBinaryReader header = memory.ReadMemory (info, 24).GetReader ();
+ long magic = header.ReadInt64 ();
+ if (magic != DynamicMagic) {
+ Report.Error ("`MONO_DEBUGGER__debugger_info' at {0} has unknown magic {1:x}.", info, magic);
+ return null;
+ }
+
+ int version = header.ReadInt32 ();
+ if (version < MinDynamicVersion) {
+ Report.Error ("`MONO_DEBUGGER__debugger_info' has version {0}, " +
+ "but expected at least {1}.", version,
+ MonoDebuggerInfo.MinDynamicVersion);
+ return null;
+ }
+ if (version > MaxDynamicVersion) {
+ Report.Error ("`MONO_DEBUGGER__debugger_info' has version {0}, " +
+ "but expected at most {1}.", version,
+ MonoDebuggerInfo.MaxDynamicVersion);
+ return null;
+ }
+
+ header.ReadInt32 (); // minor version
+ header.ReadInt32 ();
+
+ int size = header.ReadInt32 ();
+
+ TargetReader reader = new TargetReader (memory.ReadMemory (info, size));
+ return new MonoDebuggerInfo (memory, reader);
+ }
+
+ public bool CheckRuntimeVersion (int major, int minor)
+ {
+ if (MajorVersion < major)
+ return false;
+ if (MajorVersion > major)
+ return true;
+ return MinorVersion >= minor;
+ }
+
+ protected MonoDebuggerInfo (TargetMemoryAccess memory, TargetReader reader)
+ {
+ reader.Offset = 8;
+ MajorVersion = reader.ReadInteger ();
+ MinorVersion = reader.ReadInteger ();
+
+ RuntimeFlags = reader.ReadInteger ();
+
+ reader.Offset = 24;
+
+ SymbolTableSize = reader.ReadInteger ();
+ MonoTrampolineNum = reader.ReadInteger ();
+ MonoTrampolineCode = reader.ReadAddress ();
+ NotificationAddress = reader.ReadAddress ();
+ SymbolTable = reader.ReadAddress ();
+ MonoMetadataInfo = reader.ReadAddress ();
+ DebuggerVersion = reader.ReadAddress ();
+
+ CompileMethod = reader.ReadAddress ();
+ GetVirtualMethod = reader.ReadAddress ();
+ GetBoxedObjectMethod = reader.ReadAddress ();
+ RuntimeInvoke = reader.ReadAddress ();
+ ClassGetStaticFieldData = reader.ReadAddress ();
+ RunFinally = reader.ReadAddress ();
+ Initialize = reader.ReadAddress ();
+
+ CreateString = reader.ReadAddress ();
+ LookupClass = reader.ReadAddress ();
+
+ InsertMethodBreakpoint = reader.ReadAddress ();
+ InsertSourceBreakpoint = reader.ReadAddress ();
+ RemoveBreakpoint = reader.ReadAddress ();
+
+ RegisterClassInitCallback = reader.ReadAddress ();
+ RemoveClassInitCallback = reader.ReadAddress ();
+
+ ThreadTable = reader.ReadAddress ();
+
+ ExecutableCodeBuffer = reader.ReadAddress ();
+ BreakpointInfo = reader.ReadAddress ();
+ BreakpointInfoIndex = reader.ReadAddress ();
+
+ ExecutableCodeBufferSize = reader.ReadInteger ();
+ BreakpointArraySize = reader.ReadInteger ();
+
+ GetMethodSignature = reader.ReadAddress ();
+ InitCodeBuffer = reader.ReadAddress ();
+
+ ThreadVTablePtr = reader.ReadAddress ();
+ ThreadVTable = reader.ReadAddress ();
+ EventHandlerPtr = reader.ReadAddress ();
+ EventHandler = reader.ReadAddress ();
+
+ UsingMonoDebugger = reader.ReadAddress ();
+ InterruptionRequest = reader.ReadAddress ();
+
+ Report.Debug (DebugFlags.JitSymtab, this);
+ }
+ }
+}
diff --git a/build/Makefile.am b/build/Makefile.am
index 5af084a..ba6090f 100644
--- a/build/Makefile.am
+++ b/build/Makefile.am
@@ -65,6 +65,7 @@ DEBUGGER_SRCLIST = \
$(top_srcdir)/interface/*.cs \
$(top_srcdir)/backend/arch/*.cs \
$(top_srcdir)/backend/os/*.cs \
+ $(top_srcdir)/backend/mono/*.cs \
$(top_srcdir)/backend/*.cs \
$(top_srcdir)/languages/*.cs \
$(top_srcdir)/languages/mono/*.cs \
diff --git a/configure.in b/configure.in
index 2d87a81..8a6899f 100644
--- a/configure.in
+++ b/configure.in
@@ -359,6 +359,7 @@ build/Mono.Debugger.dll.config
backend/Makefile
backend/server/Makefile
backend/arch/Makefile
+backend/mono/Makefile
backend/os/Makefile
backend/os/bfd/libiberty/Makefile
backend/os/bfd/opcodes/Makefile
diff --git a/languages/mono/MonoClassInfo.cs b/languages/mono/MonoClassInfo.cs
index 16f747c..f2407d7 100644
--- a/languages/mono/MonoClassInfo.cs
+++ b/languages/mono/MonoClassInfo.cs
@@ -2,6 +2,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using Mono.Debugger.Backend;
+using Mono.Debugger.Backend.Mono;
namespace Mono.Debugger.Languages.Mono
{
diff --git a/languages/mono/MonoLanguageBackend.cs b/languages/mono/MonoLanguageBackend.cs
index 679261b..e855226 100644
--- a/languages/mono/MonoLanguageBackend.cs
+++ b/languages/mono/MonoLanguageBackend.cs
@@ -9,6 +9,7 @@ using System.Threading;
using C = Mono.CompilerServices.SymbolWriter;
using Mono.Debugger.Backend;
+using Mono.Debugger.Backend.Mono;
namespace Mono.Debugger.Languages.Mono
{
--------------1.5.6--
From 4d4e17955280ca902fecfb5db1692d5686bd9ea9 Mon Sep 17 00:00:00 2001
From: Martin Baulig <martin@novell.com>
Date: Mon, 7 Sep 2009 12:07:23 +0200
Subject: [PATCH] .
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------1.5.6"
This is a multi-part message in MIME format.
--------------1.5.6
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit
---
backend/MonoThreadManager.cs | 639 ------------------
{languages => backend}/mono/MonoLanguageBackend.cs | 0
languages/mono/MonoRuntime.cs | 699 --------------------
3 files changed, 0 insertions(+), 1338 deletions(-)
delete mode 100644 backend/MonoThreadManager.cs
rename {languages => backend}/mono/MonoLanguageBackend.cs (100%)
delete mode 100644 languages/mono/MonoRuntime.cs
--------------1.5.6
Content-Type: text/x-patch; name="4d4e17955280ca902fecfb5db1692d5686bd9ea9.diff"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline; filename="4d4e17955280ca902fecfb5db1692d5686bd9ea9.diff"
diff --git a/backend/MonoThreadManager.cs b/backend/MonoThreadManager.cs
deleted file mode 100644
index 998147c..0000000
--- a/backend/MonoThreadManager.cs
+++ /dev/null
@@ -1,639 +0,0 @@
-using System;
-using System.IO;
-using System.Text;
-using System.Threading;
-using System.Configuration;
-using System.Globalization;
-using System.Reflection;
-using System.Diagnostics;
-using System.Collections;
-using System.Collections.Generic;
-using System.Collections.Specialized;
-using System.Runtime.InteropServices;
-
-using Mono.Debugger;
-using Mono.Debugger.Languages;
-using Mono.Debugger.Languages.Mono;
-
-
-namespace Mono.Debugger.Backend
-{
-
-// <summary>
-// MonoThreadManager is a special case handler for thread events when
-// we know we're running a managed app.
-// </summary>
-
- internal enum NotificationType {
- InitializeManagedCode = 1,
- InitializeCorlib,
- JitBreakpoint,
- InitializeThreadManager,
- AcquireGlobalThreadLock,
- ReleaseGlobalThreadLock,
- WrapperMain,
- MainExited,
- UnhandledException,
- ThrowException,
- HandleException,
- ThreadCreated,
- ThreadCleanup,
- GcThreadCreated,
- GcThreadExited,
- ReachedMain,
- FinalizeManagedCode,
- LoadModule,
- UnloadModule,
- DomainCreate,
- DomainUnload,
- ClassInitialized,
- InterruptionRequest,
- CreateAppDomain,
- UnloadAppDomain,
-
- Trampoline = 256
- }
-
- internal enum ThreadFlags {
- None = 0,
- Internal = 1,
- ThreadPool = 2
- };
-
- internal delegate bool ManagedCallbackFunction (SingleSteppingEngine engine);
-
- internal class MonoThreadManager
- {
- ProcessServant process;
- MonoDebuggerInfo debugger_info;
-
- protected MonoThreadManager (ProcessServant process, Inferior inferior,
- MonoDebuggerInfo debugger_info)
- {
- this.process = process;
- this.debugger_info = debugger_info;
-
- inferior.WriteInteger (debugger_info.UsingMonoDebugger, 1);
-
- notification_bpt = new InitializeBreakpoint (this, debugger_info.Initialize);
- notification_bpt.Insert (inferior);
- }
-
- public static MonoThreadManager Initialize (ProcessServant process, Inferior inferior,
- TargetAddress info, bool attach)
- {
- MonoDebuggerInfo debugger_info = MonoDebuggerInfo.Create (inferior, info);
- if (debugger_info == null)
- return null;
-
- if (attach) {
- if (!debugger_info.CheckRuntimeVersion (81, 2)) {
- Report.Error ("The Mono runtime of the target application is too old to support attaching,\n" +
- "attaching as a native application.");
- return null;
- }
-
- if ((debugger_info.RuntimeFlags & 1) != 1) {
- Report.Error ("The Mono runtime of the target application does not support attaching,\n" +
- "attaching as a native application.");
- return null;
- }
- }
-
- return new MonoThreadManager (process, inferior, debugger_info);
- }
-
- AddressBreakpoint notification_bpt;
- IntPtr mono_runtime_info;
- int debugger_version;
-
- internal bool HasCodeBuffer {
- get;
- private set;
- }
-
- [DllImport("monodebuggerserver")]
- static extern IntPtr mono_debugger_server_initialize_mono_runtime (
- int address_size, long notification_address,
- long executable_code_buffer, int executable_code_buffer_size,
- long breakpoint_info, long breakpoint_info_index,
- int breakpoint_table_size);
-
- [DllImport("monodebuggerserver")]
- static extern void mono_debugger_server_finalize_mono_runtime (IntPtr handle);
-
- [DllImport("monodebuggerserver")]
- static extern void mono_debugger_server_initialize_code_buffer (
- IntPtr runtime, long executable_code_buffer,
- int executable_code_buffer_size);
-
- protected void initialize_notifications (Inferior inferior)
- {
- TargetAddress executable_code_buffer = inferior.ReadAddress (
- debugger_info.ExecutableCodeBuffer);
- HasCodeBuffer = !executable_code_buffer.IsNull;
-
- mono_runtime_info = mono_debugger_server_initialize_mono_runtime (
- inferior.TargetAddressSize,
- debugger_info.NotificationAddress.Address,
- executable_code_buffer.Address,
- debugger_info.ExecutableCodeBufferSize,
- debugger_info.BreakpointInfo.Address,
- debugger_info.BreakpointInfoIndex.Address,
- debugger_info.BreakpointArraySize);
- inferior.SetRuntimeInfo (mono_runtime_info);
-
- debugger_version = inferior.ReadInteger (debugger_info.DebuggerVersion);
-
- if (notification_bpt != null) {
- notification_bpt.Remove (inferior);
- notification_bpt = null;
- }
- }
-
- internal void InitCodeBuffer (Inferior inferior, TargetAddress code_buffer)
- {
- HasCodeBuffer = true;
- mono_debugger_server_initialize_code_buffer (
- mono_runtime_info, code_buffer.Address,
- debugger_info.ExecutableCodeBufferSize);
- }
-
- protected class InitializeBreakpoint : AddressBreakpoint
- {
- protected readonly MonoThreadManager manager;
-
- public InitializeBreakpoint (MonoThreadManager manager, TargetAddress address)
- : base ("initialize", ThreadGroup.System, address)
- {
- this.manager = manager;
- }
-
- public override bool CheckBreakpointHit (Thread target, TargetAddress address)
- {
- return true;
- }
-
- internal override bool BreakpointHandler (Inferior inferior,
- out bool remain_stopped)
- {
- manager.initialize_notifications (inferior);
- remain_stopped = false;
- return true;
- }
- }
-
- internal bool InitializeAfterAttach (Inferior inferior)
- {
- initialize_notifications (inferior);
-
- inferior.WriteAddress (debugger_info.ThreadVTablePtr,
- debugger_info.ThreadVTable);
- inferior.WriteAddress (debugger_info.EventHandlerPtr,
- debugger_info.EventHandler);
- inferior.WriteInteger (debugger_info.UsingMonoDebugger, 1);
-
- csharp_language = inferior.Process.CreateMonoLanguage (debugger_info);
- csharp_language.InitializeAttach (inferior);
-
- return true;
- }
-
- internal void Detach (Inferior inferior)
- {
- inferior.WriteAddress (debugger_info.ThreadVTablePtr, TargetAddress.Null);
- inferior.WriteAddress (debugger_info.EventHandler, TargetAddress.Null);
- inferior.WriteInteger (debugger_info.UsingMonoDebugger, 0);
- }
-
- internal void AddManagedCallback (Inferior inferior, ManagedCallbackData data)
- {
- inferior.WriteInteger (MonoDebuggerInfo.InterruptionRequest, 1);
- managed_callbacks.Enqueue (data);
- }
-
- internal Queue<ManagedCallbackData> ClearManagedCallbacks (Inferior inferior)
- {
- inferior.WriteInteger (MonoDebuggerInfo.InterruptionRequest, 0);
- Queue<ManagedCallbackData> retval = managed_callbacks;
- managed_callbacks = new Queue<ManagedCallbackData> ();
- return retval;
- }
-
- TargetAddress main_function;
- TargetAddress main_thread;
- MonoLanguageBackend csharp_language;
- Queue<ManagedCallbackData> managed_callbacks = new Queue<ManagedCallbackData> ();
-
- internal bool CanExecuteCode {
- get { return mono_runtime_info != IntPtr.Zero; }
- }
-
- internal MonoDebuggerInfo MonoDebuggerInfo {
- get { return debugger_info; }
- }
-
- int index;
- internal void ThreadCreated (SingleSteppingEngine sse)
- {
- sse.Inferior.SetRuntimeInfo (mono_runtime_info);
- if (!MonoDebuggerInfo.CheckRuntimeVersion (81, 3) && !process.IsAttached) {
- if (++index < 3)
- sse.Thread.ThreadFlags |= Thread.Flags.Daemon | Thread.Flags.Immutable;
- } else {
- sse.Thread.ThreadFlags |= Thread.Flags.Daemon | Thread.Flags.Immutable;
- }
- }
-
- void check_thread_flags (SingleSteppingEngine engine, ThreadFlags flags)
- {
- if ((flags & (ThreadFlags.Internal | ThreadFlags.ThreadPool)) != ThreadFlags.Internal) {
- engine.Thread.ThreadFlags &= ~(Thread.Flags.Daemon | Thread.Flags.Immutable);
- if (engine != process.MainThread)
- process.Debugger.Client.OnManagedThreadCreatedEvent (engine.Thread);
- } else if ((flags & ThreadFlags.ThreadPool) != 0) {
- engine.Thread.ThreadFlags &= ~Thread.Flags.Immutable;
- }
- }
-
- internal void InitializeThreads (Inferior inferior)
- {
- TargetAddress ptr = inferior.ReadAddress (MonoDebuggerInfo.ThreadTable);
- while (!ptr.IsNull) {
- int size;
- if (MonoDebuggerInfo.CheckRuntimeVersion (81, 3))
- size = 60 + inferior.TargetMemoryInfo.TargetAddressSize;
- else
- size = 32 + inferior.TargetMemoryInfo.TargetAddressSize;
- TargetReader reader = new TargetReader (inferior.ReadMemory (ptr, size));
-
- long tid = reader.ReadLongInteger ();
- TargetAddress lmf_addr = reader.ReadAddress ();
- TargetAddress end_stack = reader.ReadAddress ();
-
- TargetAddress extended_notifications_addr = ptr + 24;
-
- if (inferior.TargetMemoryInfo.TargetAddressSize == 4)
- tid &= 0x00000000ffffffffL;
-
- reader.Offset += 8;
- ptr = reader.ReadAddress ();
-
- ThreadFlags flags = ThreadFlags.None;
- if (MonoDebuggerInfo.CheckRuntimeVersion (81, 3)) {
- reader.Offset = 56 + inferior.TargetAddressSize;
- flags = (ThreadFlags) reader.ReadInteger ();
- }
-
- bool found = false;
- foreach (SingleSteppingEngine engine in process.Engines) {
- if (engine.TID != tid)
- continue;
-
- engine.SetManagedThreadData (lmf_addr, extended_notifications_addr);
- engine.OnManagedThreadCreated (end_stack);
- check_thread_flags (engine, flags);
- found = true;
- break;
- }
-
- if (!found)
- Report.Error ("Cannot find thread {0:x} in {1}",
- tid, process.ProcessStart.CommandLine);
- }
- }
-
- internal bool HandleChildEvent (SingleSteppingEngine engine, Inferior inferior,
- ref Inferior.ChildEvent cevent, out bool resume_target)
- {
- if (cevent.Type == Inferior.ChildEventType.CHILD_NOTIFICATION) {
- NotificationType type = (NotificationType) cevent.Argument;
-
- Report.Debug (DebugFlags.EventLoop,
- "{0} received notification {1}: {2}",
- engine, type, cevent);
-
- switch (type) {
- case NotificationType.AcquireGlobalThreadLock:
- Report.Debug (DebugFlags.Threads,
- "{0} received notification {1}", engine, type);
- engine.ProcessServant.AcquireGlobalThreadLock (engine);
- break;
-
- case NotificationType.ReleaseGlobalThreadLock:
- Report.Debug (DebugFlags.Threads,
- "{0} received notification {1}", engine, type);
- engine.ProcessServant.ReleaseGlobalThreadLock (engine);
- break;
-
- case NotificationType.ThreadCreated: {
- TargetAddress data = new TargetAddress (
- inferior.AddressDomain, cevent.Data2);
-
- TargetAddress lmf = inferior.ReadAddress (data + 8);
- engine.SetManagedThreadData (lmf, data + 24);
-
- if (MonoDebuggerInfo.CheckRuntimeVersion (81, 3)) {
- int flags_offset = 56 + inferior.TargetAddressSize;
- ThreadFlags flags = (ThreadFlags) inferior.ReadInteger (data + flags_offset);
- check_thread_flags (engine, flags);
- }
-
- Report.Debug (DebugFlags.Threads,
- "{0} managed thread created: {1:x} {2} {3} - {4}",
- engine, cevent.Data1, data, lmf, engine.LMFAddress);
- break;
- }
-
- case NotificationType.ThreadCleanup: {
- TargetAddress data = new TargetAddress (
- inferior.AddressDomain, cevent.Data1);
-
- Report.Debug (DebugFlags.Threads,
- "{0} managed thread cleanup: {1:x} {2}",
- engine, cevent.Data2, data);
- break;
- }
-
- case NotificationType.GcThreadCreated: {
- TargetAddress data = new TargetAddress (
- inferior.AddressDomain, cevent.Data1);
- long tid = cevent.Data2;
-
- Report.Debug (DebugFlags.Threads,
- "{0} created gc thread: {1:x} {2}",
- engine, tid, data);
-
- engine = engine.ProcessServant.GetEngineByTID (inferior, tid);
- if (engine == null)
- throw new InternalError ();
-
- engine.OnManagedThreadCreated (data);
- break;
- }
-
- case NotificationType.GcThreadExited:
- Report.Debug (DebugFlags.Threads, "{0} gc thread exited", engine);
- engine.OnManagedThreadExited ();
- try {
- inferior.Continue ();
- } catch {
- // Ignore errors; for some reason, the thread may have died
- // already by the time get this notification.
- }
- resume_target = false;
- return true;
-
- case NotificationType.InitializeThreadManager:
- csharp_language = inferior.Process.CreateMonoLanguage (
- debugger_info);
- if (engine.ProcessServant.IsAttached)
- csharp_language.InitializeAttach (inferior);
- else
- csharp_language.Initialize (inferior);
-
- break;
-
- case NotificationType.ReachedMain: {
- Inferior.StackFrame iframe = inferior.GetCurrentFrame (false);
- engine.SetMainReturnAddress (iframe.StackPointer);
- engine.ProcessServant.OnProcessReachedMainEvent ();
- resume_target = !engine.InitializeBreakpoints ();
- return true;
- }
-
- case NotificationType.WrapperMain:
- break;
- case NotificationType.MainExited:
- engine.SetMainReturnAddress (TargetAddress.Null);
- break;
-
- case NotificationType.UnhandledException:
- cevent = new Inferior.ChildEvent (
- Inferior.ChildEventType.UNHANDLED_EXCEPTION,
- 0, cevent.Data1, cevent.Data2);
- resume_target = false;
- return false;
-
- case NotificationType.HandleException:
- cevent = new Inferior.ChildEvent (
- Inferior.ChildEventType.HANDLE_EXCEPTION,
- 0, cevent.Data1, cevent.Data2);
- resume_target = false;
- return false;
-
- case NotificationType.ThrowException:
- cevent = new Inferior.ChildEvent (
- Inferior.ChildEventType.THROW_EXCEPTION,
- 0, cevent.Data1, cevent.Data2);
- resume_target = false;
- return false;
-
- case NotificationType.FinalizeManagedCode:
- mono_debugger_server_finalize_mono_runtime (mono_runtime_info);
- mono_runtime_info = IntPtr.Zero;
- csharp_language = null;
- break;
-
- case NotificationType.Trampoline:
- resume_target = false;
- return false;
-
- case NotificationType.ClassInitialized:
- break;
-
- case NotificationType.InterruptionRequest:
- inferior.WriteInteger (MonoDebuggerInfo.InterruptionRequest, 0);
- var callbacks = managed_callbacks;
- managed_callbacks = new Queue<ManagedCallbackData> ();
- resume_target = !engine.OnManagedCallback (callbacks);
- return true;
-
- default: {
- TargetAddress data = new TargetAddress (
- inferior.AddressDomain, cevent.Data1);
-
- resume_target = csharp_language.Notification (
- engine, inferior, type, data, cevent.Data2);
- return true;
- }
- }
-
- resume_target = true;
- return true;
- }
-
- if ((cevent.Type == Inferior.ChildEventType.CHILD_STOPPED) &&
- (cevent.Argument == inferior.MonoThreadAbortSignal)) {
- resume_target = true;
- return true;
- }
-
- if ((cevent.Type == Inferior.ChildEventType.CHILD_STOPPED) && (cevent.Argument != 0) && !
- engine.Process.Session.Config.StopOnManagedSignals) {
- if (inferior.IsManagedSignal ((int) cevent.Argument)) {
- resume_target = true;
- return true;
- }
- }
-
- resume_target = false;
- return false;
- }
- }
-
- // <summary>
- // This class is the managed representation of the MONO_DEBUGGER__debugger_info struct.
- // as defined in mono/mini/debug-debugger.h
- // </summary>
- internal class MonoDebuggerInfo
- {
- // These constants must match up with those in mono/mono/metadata/mono-debug.h
- public const int MinDynamicVersion = 80;
- public const int MaxDynamicVersion = 81;
- public const long DynamicMagic = 0x7aff65af4253d427;
-
- public readonly int MajorVersion;
- public readonly int MinorVersion;
-
- public readonly int RuntimeFlags;
-
- public readonly int MonoTrampolineNum;
- public readonly TargetAddress MonoTrampolineCode;
- public readonly TargetAddress NotificationAddress;
- public readonly TargetAddress SymbolTable;
- public readonly int SymbolTableSize;
- public readonly TargetAddress MonoMetadataInfo;
- public readonly TargetAddress DebuggerVersion;
- public readonly TargetAddress CompileMethod;
- public readonly TargetAddress GetVirtualMethod;
- public readonly TargetAddress GetBoxedObjectMethod;
- public readonly TargetAddress RuntimeInvoke;
- public readonly TargetAddress CreateString;
- public readonly TargetAddress ClassGetStaticFieldData;
- public readonly TargetAddress LookupClass;
- public readonly TargetAddress RunFinally;
- public readonly TargetAddress InsertMethodBreakpoint;
- public readonly TargetAddress InsertSourceBreakpoint;
- public readonly TargetAddress RemoveBreakpoint;
- public readonly TargetAddress RegisterClassInitCallback;
- public readonly TargetAddress RemoveClassInitCallback;
- public readonly TargetAddress Initialize;
- public readonly TargetAddress ThreadTable;
- public readonly TargetAddress ExecutableCodeBuffer;
- public readonly TargetAddress BreakpointInfo;
- public readonly TargetAddress BreakpointInfoIndex;
- public readonly int ExecutableCodeBufferSize;
- public readonly int BreakpointArraySize;
- public readonly TargetAddress GetMethodSignature;
- public readonly TargetAddress InitCodeBuffer;
-
- public readonly TargetAddress ThreadVTablePtr;
- public readonly TargetAddress ThreadVTable;
- public readonly TargetAddress EventHandlerPtr;
- public readonly TargetAddress EventHandler;
-
- public readonly TargetAddress UsingMonoDebugger;
- public readonly TargetAddress InterruptionRequest;
-
- public static MonoDebuggerInfo Create (TargetMemoryAccess memory, TargetAddress info)
- {
- TargetBinaryReader header = memory.ReadMemory (info, 24).GetReader ();
- long magic = header.ReadInt64 ();
- if (magic != DynamicMagic) {
- Report.Error ("`MONO_DEBUGGER__debugger_info' at {0} has unknown magic {1:x}.", info, magic);
- return null;
- }
-
- int version = header.ReadInt32 ();
- if (version < MinDynamicVersion) {
- Report.Error ("`MONO_DEBUGGER__debugger_info' has version {0}, " +
- "but expected at least {1}.", version,
- MonoDebuggerInfo.MinDynamicVersion);
- return null;
- }
- if (version > MaxDynamicVersion) {
- Report.Error ("`MONO_DEBUGGER__debugger_info' has version {0}, " +
- "but expected at most {1}.", version,
- MonoDebuggerInfo.MaxDynamicVersion);
- return null;
- }
-
- header.ReadInt32 (); // minor version
- header.ReadInt32 ();
-
- int size = header.ReadInt32 ();
-
- TargetReader reader = new TargetReader (memory.ReadMemory (info, size));
- return new MonoDebuggerInfo (memory, reader);
- }
-
- public bool CheckRuntimeVersion (int major, int minor)
- {
- if (MajorVersion < major)
- return false;
- if (MajorVersion > major)
- return true;
- return MinorVersion >= minor;
- }
-
- protected MonoDebuggerInfo (TargetMemoryAccess memory, TargetReader reader)
- {
- reader.Offset = 8;
- MajorVersion = reader.ReadInteger ();
- MinorVersion = reader.ReadInteger ();
-
- RuntimeFlags = reader.ReadInteger ();
-
- reader.Offset = 24;
-
- SymbolTableSize = reader.ReadInteger ();
- MonoTrampolineNum = reader.ReadInteger ();
- MonoTrampolineCode = reader.ReadAddress ();
- NotificationAddress = reader.ReadAddress ();
- SymbolTable = reader.ReadAddress ();
- MonoMetadataInfo = reader.ReadAddress ();
- DebuggerVersion = reader.ReadAddress ();
-
- CompileMethod = reader.ReadAddress ();
- GetVirtualMethod = reader.ReadAddress ();
- GetBoxedObjectMethod = reader.ReadAddress ();
- RuntimeInvoke = reader.ReadAddress ();
- ClassGetStaticFieldData = reader.ReadAddress ();
- RunFinally = reader.ReadAddress ();
- Initialize = reader.ReadAddress ();
-
- CreateString = reader.ReadAddress ();
- LookupClass = reader.ReadAddress ();
-
- InsertMethodBreakpoint = reader.ReadAddress ();
- InsertSourceBreakpoint = reader.ReadAddress ();
- RemoveBreakpoint = reader.ReadAddress ();
-
- RegisterClassInitCallback = reader.ReadAddress ();
- RemoveClassInitCallback = reader.ReadAddress ();
-
- ThreadTable = reader.ReadAddress ();
-
- ExecutableCodeBuffer = reader.ReadAddress ();
- BreakpointInfo = reader.ReadAddress ();
- BreakpointInfoIndex = reader.ReadAddress ();
-
- ExecutableCodeBufferSize = reader.ReadInteger ();
- BreakpointArraySize = reader.ReadInteger ();
-
- GetMethodSignature = reader.ReadAddress ();
- InitCodeBuffer = reader.ReadAddress ();
-
- ThreadVTablePtr = reader.ReadAddress ();
- ThreadVTable = reader.ReadAddress ();
- EventHandlerPtr = reader.ReadAddress ();
- EventHandler = reader.ReadAddress ();
-
- UsingMonoDebugger = reader.ReadAddress ();
- InterruptionRequest = reader.ReadAddress ();
-
- Report.Debug (DebugFlags.JitSymtab, this);
- }
- }
-}
diff --git a/languages/mono/MonoLanguageBackend.cs b/backend/mono/MonoLanguageBackend.cs
similarity index 100%
rename from languages/mono/MonoLanguageBackend.cs
rename to backend/mono/MonoLanguageBackend.cs
diff --git a/languages/mono/MonoRuntime.cs b/languages/mono/MonoRuntime.cs
deleted file mode 100644
index cc8a0f4..0000000
--- a/languages/mono/MonoRuntime.cs
+++ /dev/null
@@ -1,699 +0,0 @@
-using System;
-
-using Mono.Debugger.Backend;
-
-namespace Mono.Debugger.Languages.Mono
-{
- internal enum MonoTypeEnum
- {
- MONO_TYPE_END = 0x00, /* End of List */
- MONO_TYPE_VOID = 0x01,
- MONO_TYPE_BOOLEAN = 0x02,
- MONO_TYPE_CHAR = 0x03,
- MONO_TYPE_I1 = 0x04,
- MONO_TYPE_U1 = 0x05,
- MONO_TYPE_I2 = 0x06,
- MONO_TYPE_U2 = 0x07,
- MONO_TYPE_I4 = 0x08,
- MONO_TYPE_U4 = 0x09,
- MONO_TYPE_I8 = 0x0a,
- MONO_TYPE_U8 = 0x0b,
- MONO_TYPE_R4 = 0x0c,
- MONO_TYPE_R8 = 0x0d,
- MONO_TYPE_STRING = 0x0e,
- MONO_TYPE_PTR = 0x0f, /* arg: <type> token */
- MONO_TYPE_BYREF = 0x10, /* arg: <type> token */
- MONO_TYPE_VALUETYPE = 0x11, /* arg: <type> token */
- MONO_TYPE_CLASS = 0x12, /* arg: <type> token */
- MONO_TYPE_VAR = 0x13, /* number */
- MONO_TYPE_ARRAY = 0x14, /* type, rank, boundsCount, bound1, loCount, lo1 */
- MONO_TYPE_GENERICINST= 0x15, /* <type> <type-arg-count> <type-1> \x{2026} <type-n> */
- MONO_TYPE_TYPEDBYREF = 0x16,
- MONO_TYPE_I = 0x18,
- MONO_TYPE_U = 0x19,
- MONO_TYPE_FNPTR = 0x1b, /* arg: full method signature */
- MONO_TYPE_OBJECT = 0x1c,
- MONO_TYPE_SZARRAY = 0x1d, /* 0-based one-dim-array */
- MONO_TYPE_MVAR = 0x1e, /* number */
- MONO_TYPE_CMOD_REQD = 0x1f, /* arg: typedef or typeref token */
- MONO_TYPE_CMOD_OPT = 0x20, /* optional arg: typedef or typref token */
- MONO_TYPE_INTERNAL = 0x21, /* CLR internal type */
-
- MONO_TYPE_MODIFIER = 0x40, /* Or with the following types */
- MONO_TYPE_SENTINEL = 0x41, /* Sentinel for varargs method signature */
- MONO_TYPE_PINNED = 0x45, /* Local var that points to pinned object */
-
- MONO_TYPE_ENUM = 0x55 /* an enumeration */
- }
-
- internal class MonoRuntime : DebuggerMarshalByRefObject
- {
- protected readonly MonoDebuggerInfo MonoDebuggerInfo;
- protected readonly MetadataInfo MonoMetadataInfo;
-
- protected MonoRuntime (MonoDebuggerInfo info, MetadataInfo metadata)
- {
- this.MonoDebuggerInfo = info;
- this.MonoMetadataInfo = metadata;
- }
-
- public static MonoRuntime Create (TargetMemoryAccess memory, MonoDebuggerInfo info)
- {
- MetadataInfo metadata = new MetadataInfo (memory, info.MonoMetadataInfo);
- return new MonoRuntime (info, metadata);
- }
-
- //
- // MonoClass
- //
-
- public TargetAddress MonoClassGetMonoImage (TargetMemoryAccess memory,
- TargetAddress klass)
- {
- return memory.ReadAddress (klass + MonoMetadataInfo.KlassImageOffset);
- }
-
- public int MonoClassGetToken (TargetMemoryAccess memory,
- TargetAddress klass)
- {
- return memory.ReadInteger (klass + MonoMetadataInfo.KlassTokenOffset);
- }
-
- public int MonoClassGetInstanceSize (TargetMemoryAccess memory,
- TargetAddress klass)
- {
- int flags = memory.ReadInteger (klass + 4 * memory.TargetAddressSize);
-
- bool size_inited = (flags & 4) != 0;
- bool valuetype = (flags & 8) != 0;
-
- if (!size_inited)
- throw new TargetException (TargetError.ClassNotInitialized);
-
- int size = memory.ReadInteger (klass + 4 + 3 * memory.TargetAddressSize);
- if (valuetype)
- size -= 2 * memory.TargetAddressSize;
-
- return size;
- }
-
- public TargetAddress MonoClassGetParent (TargetMemoryAccess memory,
- TargetAddress klass)
- {
- return memory.ReadAddress (klass + MonoMetadataInfo.KlassParentOffset);
- }
-
- public TargetAddress MonoClassGetGenericClass (TargetMemoryAccess memory,
- TargetAddress klass)
- {
- return memory.ReadAddress (klass + MonoMetadataInfo.KlassGenericClassOffset);
- }
-
- public TargetAddress MonoClassGetGenericContainer (TargetMemoryAccess memory,
- TargetAddress klass)
- {
- return memory.ReadAddress (klass + MonoMetadataInfo.KlassGenericContainerOffset);
- }
-
- public TargetAddress MonoClassGetByValType (TargetMemoryAccess memory,
- TargetAddress klass)
- {
- return klass + MonoMetadataInfo.KlassByValArgOffset;
- }
-
- public bool MonoClassHasFields (TargetMemoryAccess memory, TargetAddress klass)
- {
- TargetAddress fields = memory.ReadAddress (
- klass + MonoMetadataInfo.KlassFieldOffset);
- return !fields.IsNull;
- }
-
- public int MonoClassGetFieldCount (TargetMemoryAccess memory, TargetAddress klass)
- {
- return memory.ReadInteger (klass + MonoMetadataInfo.KlassFieldCountOffset);
- }
-
- public TargetAddress MonoClassGetFieldType (TargetMemoryAccess memory, TargetAddress klass,
- int index)
- {
- int offset = index * MonoMetadataInfo.FieldInfoSize +
- MonoMetadataInfo.FieldInfoTypeOffset;
-
- TargetAddress fields = memory.ReadAddress (
- klass + MonoMetadataInfo.KlassFieldOffset);
- if (fields.IsNull)
- throw new TargetException (TargetError.ClassNotInitialized);
-
- return memory.ReadAddress (fields + offset);
- }
-
- public int MonoClassGetFieldOffset (TargetMemoryAccess memory, TargetAddress klass,
- int index)
- {
- int offset = index * MonoMetadataInfo.FieldInfoSize +
- MonoMetadataInfo.FieldInfoOffsetOffset;
-
- TargetAddress fields = memory.ReadAddress (
- klass + MonoMetadataInfo.KlassFieldOffset);
- if (fields.IsNull)
- throw new TargetException (TargetError.ClassNotInitialized);
-
- return memory.ReadInteger (fields + offset);
- }
-
- public bool MonoClassHasMethods (TargetMemoryAccess memory, TargetAddress klass)
- {
- TargetAddress methods = memory.ReadAddress (
- klass + MonoMetadataInfo.KlassMethodsOffset);
- return !methods.IsNull;
- }
-
- public int MonoClassGetMethodCount (TargetMemoryAccess memory, TargetAddress klass)
- {
- return memory.ReadInteger (klass + MonoMetadataInfo.KlassMethodCountOffset);
- }
-
- public TargetAddress MonoClassGetMethod (TargetMemoryAccess memory, TargetAddress klass,
- int index)
- {
- TargetAddress methods = memory.ReadAddress (
- klass + MonoMetadataInfo.KlassMethodsOffset);
-
- if (methods.IsNull)
- throw new TargetException (TargetError.ClassNotInitialized);
-
- methods += index * memory.TargetAddressSize;
- return memory.ReadAddress (methods);
- }
-
- //
- // MonoMethod
- //
-
- public int MonoMethodGetToken (TargetMemoryAccess memory, TargetAddress method)
- {
- return memory.ReadInteger (method + MonoMetadataInfo.MonoMethodTokenOffset);
- }
-
- public TargetAddress MonoMethodGetClass (TargetMemoryAccess memory, TargetAddress method)
- {
- return memory.ReadAddress (method + MonoMetadataInfo.MonoMethodKlassOffset);
- }
-
- //
- // MonoType
- //
-
- public MonoTypeEnum MonoTypeGetType (TargetMemoryAccess memory, TargetAddress type)
- {
- uint flags = (uint) memory.ReadInteger (
- type + memory.TargetMemoryInfo.TargetAddressSize);
-
- return (MonoTypeEnum) ((flags & 0x00ff0000) >> 16);
- }
-
- public bool MonoTypeGetIsByRef (TargetMemoryAccess memory, TargetAddress type)
- {
- uint flags = (uint) memory.ReadInteger (
- type + memory.TargetMemoryInfo.TargetAddressSize);
- return (int) ((flags & 0x40000000) >> 30) != 0;
- }
-
- public TargetAddress MonoTypeGetData (TargetMemoryAccess memory, TargetAddress type)
- {
- return memory.ReadAddress (type);
- }
-
- public TargetAddress MonoArrayTypeGetClass (TargetMemoryAccess memory,
- TargetAddress atype)
- {
- return memory.ReadAddress (atype);
- }
-
- public int MonoArrayTypeGetRank (TargetMemoryAccess memory,
- TargetAddress atype)
- {
- return memory.ReadByte (atype + memory.TargetAddressSize);
- }
-
- public int MonoArrayTypeGetNumSizes (TargetMemoryAccess memory,
- TargetAddress atype)
- {
- return memory.ReadByte (atype + memory.TargetAddressSize + 1);
- }
-
- public int MonoArrayTypeGetNumLoBounds (TargetMemoryAccess memory,
- TargetAddress atype)
- {
- return memory.ReadByte (atype + memory.TargetAddressSize + 2);
- }
-
- internal void MonoArrayTypeGetBounds (TargetMemoryAccess memory,
- TargetAddress data)
- {
- //
- // FIXME: Only check whether the low bounds are all zero
- //
- int num_sizes = memory.ReadByte (data + memory.TargetAddressSize + 1);
- if (num_sizes != 0)
- throw new InternalError ();
-
- int num_lobounds = memory.ReadByte (data + memory.TargetAddressSize + 2);
- if (num_lobounds == 0)
- return;
-
- TargetAddress array = memory.ReadAddress (data + 3 * memory.TargetAddressSize);
- TargetBinaryReader bounds = memory.ReadMemory (array, num_lobounds * 4).GetReader ();
- for (int i = 0; i < num_lobounds; i++) {
- int bound = bounds.ReadInt32 ();
- if (bound != 0)
- throw new InternalError ();
- }
- }
-
- //
- // Fundamental types
- //
-
- public TargetAddress GetBooleanClass (TargetMemoryAccess memory)
- {
- return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
- MonoMetadataInfo.MonoDefaultsBooleanOffset);
- }
-
- public TargetAddress GetCharClass (TargetMemoryAccess memory)
- {
- return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
- MonoMetadataInfo.MonoDefaultsCharOffset);
- }
-
- public TargetAddress GetSByteClass (TargetMemoryAccess memory)
- {
- return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
- MonoMetadataInfo.MonoDefaultsSByteOffset);
- }
-
- public TargetAddress GetByteClass (TargetMemoryAccess memory)
- {
- return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
- MonoMetadataInfo.MonoDefaultsByteOffset);
- }
-
- public TargetAddress GetInt16Class (TargetMemoryAccess memory)
- {
- return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
- MonoMetadataInfo.MonoDefaultsInt16Offset);
- }
-
- public TargetAddress GetUInt16Class (TargetMemoryAccess memory)
- {
- return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
- MonoMetadataInfo.MonoDefaultsUInt16Offset);
- }
-
- public TargetAddress GetInt32Class (TargetMemoryAccess memory)
- {
- return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
- MonoMetadataInfo.MonoDefaultsInt32Offset);
- }
-
- public TargetAddress GetUInt32Class (TargetMemoryAccess memory)
- {
- return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
- MonoMetadataInfo.MonoDefaultsUInt32Offset);
- }
-
- public TargetAddress GetInt64Class (TargetMemoryAccess memory)
- {
- return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
- MonoMetadataInfo.MonoDefaultsInt64Offset);
- }
-
- public TargetAddress GetUInt64Class (TargetMemoryAccess memory)
- {
- return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
- MonoMetadataInfo.MonoDefaultsUInt64Offset);
- }
-
- public TargetAddress GetSingleClass (TargetMemoryAccess memory)
- {
- return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
- MonoMetadataInfo.MonoDefaultsSingleOffset);
- }
-
- public TargetAddress GetDoubleClass (TargetMemoryAccess memory)
- {
- return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
- MonoMetadataInfo.MonoDefaultsDoubleOffset);
- }
-
- public TargetAddress GetIntPtrClass (TargetMemoryAccess memory)
- {
- return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
- MonoMetadataInfo.MonoDefaultsIntOffset);
- }
-
- public TargetAddress GetUIntPtrClass (TargetMemoryAccess memory)
- {
- return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
- MonoMetadataInfo.MonoDefaultsUIntOffset);
- }
-
- public TargetAddress GetVoidClass (TargetMemoryAccess memory)
- {
- return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
- MonoMetadataInfo.MonoDefaultsVoidOffset);
- }
-
- public TargetAddress GetStringClass (TargetMemoryAccess memory)
- {
- return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
- MonoMetadataInfo.MonoDefaultsStringOffset);
- }
-
- public TargetAddress GetObjectClass (TargetMemoryAccess memory)
- {
- return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
- MonoMetadataInfo.MonoDefaultsObjectOffset);
- }
-
- public TargetAddress GetArrayClass (TargetMemoryAccess memory)
- {
- return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
- MonoMetadataInfo.MonoDefaultsArrayOffset);
- }
-
- public TargetAddress GetDelegateClass (TargetMemoryAccess memory)
- {
- return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
- MonoMetadataInfo.MonoDefaultsDelegateOffset);
- }
-
- public TargetAddress GetExceptionClass (TargetMemoryAccess memory)
- {
- return memory.ReadAddress (MonoMetadataInfo.MonoDefaultsAddress +
- MonoMetadataInfo.MonoDefaultsExceptionOffset);
- }
-
- public MonoMethodSignature GetMethodSignature (MonoLanguageBackend mono,
- TargetMemoryAccess memory,
- TargetAddress signature)
- {
- int count = memory.ReadInteger (signature + 4) & 0x0000ffff;
-
- int offset = memory.TargetAddressSize == 8 ? 16 : 12;
- TargetAddress ret = memory.ReadAddress (signature + offset);
-
- TargetType ret_type = mono.ReadType (memory, ret);
- if (count == 0)
- return new MonoMethodSignature (ret_type, new TargetType [0]);
-
- offset += memory.TargetAddressSize;
- TargetReader reader = new TargetReader (
- memory.ReadMemory (signature + offset, count * memory.TargetAddressSize));
-
- TargetType[] param_types = new TargetType [count];
- for (int i = 0; i < count; i++)
- param_types [i] = mono.ReadType (memory, reader.ReadAddress ());
-
- return new MonoMethodSignature (ret_type, param_types);
- }
-
- protected class MetadataInfo
- {
- public readonly int MonoDefaultsSize;
- public readonly TargetAddress MonoDefaultsAddress;
- public readonly int TypeSize;
- public readonly int ArrayTypeSize;
- public readonly int KlassSize;
- public readonly int ThreadSize;
-
- public readonly int ThreadTidOffset;
- public readonly int ThreadStackPtrOffset;
- public readonly int ThreadEndStackOffset;
-
- public readonly int KlassImageOffset;
- public readonly int KlassInstanceSizeOffset;
- public readonly int KlassParentOffset;
- public readonly int KlassTokenOffset;
- public readonly int KlassFieldOffset;
- public readonly int KlassFieldCountOffset;
- public readonly int KlassMethodsOffset;
- public readonly int KlassMethodCountOffset;
- public readonly int KlassThisArgOffset;
- public readonly int KlassByValArgOffset;
- public readonly int KlassGenericClassOffset;
- public readonly int KlassGenericContainerOffset;
- public readonly int KlassVTableOffset;
- public readonly int FieldInfoSize;
- public readonly int FieldInfoTypeOffset;
- public readonly int FieldInfoOffsetOffset;
-
- public readonly int MonoDefaultsCorlibOffset;
- public readonly int MonoDefaultsObjectOffset;
- public readonly int MonoDefaultsByteOffset;
- public readonly int MonoDefaultsVoidOffset;
- public readonly int MonoDefaultsBooleanOffset;
- public readonly int MonoDefaultsSByteOffset;
- public readonly int MonoDefaultsInt16Offset;
- public readonly int MonoDefaultsUInt16Offset;
- public readonly int MonoDefaultsInt32Offset;
- public readonly int MonoDefaultsUInt32Offset;
- public readonly int MonoDefaultsIntOffset;
- public readonly int MonoDefaultsUIntOffset;
- public readonly int MonoDefaultsInt64Offset;
- public readonly int MonoDefaultsUInt64Offset;
- public readonly int MonoDefaultsSingleOffset;
- public readonly int MonoDefaultsDoubleOffset;
- public readonly int MonoDefaultsCharOffset;
- public readonly int MonoDefaultsStringOffset;
- public readonly int MonoDefaultsEnumOffset;
- public readonly int MonoDefaultsArrayOffset;
- public readonly int MonoDefaultsDelegateOffset;
- public readonly int MonoDefaultsExceptionOffset;
-
- public readonly int MonoMethodKlassOffset;
- public readonly int MonoMethodTokenOffset;
- public readonly int MonoMethodFlagsOffset;
- public readonly int MonoMethodInflatedOffset;
-
- public readonly int MonoVTableKlassOffset;
- public readonly int MonoVTableVTableOffset;
-
- public MetadataInfo (TargetMemoryAccess memory, TargetAddress address)
- {
- int size = memory.ReadInteger (address);
- TargetBinaryReader reader = memory.ReadMemory (address, size).GetReader ();
- reader.ReadInt32 ();
-
- MonoDefaultsSize = reader.ReadInt32 ();
- MonoDefaultsAddress = new TargetAddress (
- memory.AddressDomain, reader.ReadAddress ());
-
- TypeSize = reader.ReadInt32 ();
- ArrayTypeSize = reader.ReadInt32 ();
- KlassSize = reader.ReadInt32 ();
- ThreadSize = reader.ReadInt32 ();
-
- ThreadTidOffset = reader.ReadInt32 ();
- ThreadStackPtrOffset = reader.ReadInt32 ();
- ThreadEndStackOffset = reader.ReadInt32 ();
-
- KlassImageOffset = reader.ReadInt32 ();
- KlassInstanceSizeOffset = reader.ReadInt32 ();
- KlassParentOffset = reader.ReadInt32 ();
- KlassTokenOffset = reader.ReadInt32 ();
- KlassFieldOffset = reader.ReadInt32 ();
- KlassMethodsOffset = reader.ReadInt32 ();
- KlassMethodCountOffset = reader.ReadInt32 ();
- KlassThisArgOffset = reader.ReadInt32 ();
- KlassByValArgOffset = reader.ReadInt32 ();
- KlassGenericClassOffset = reader.ReadInt32 ();
- KlassGenericContainerOffset = reader.ReadInt32 ();
- KlassVTableOffset = reader.ReadInt32 ();
-
- FieldInfoSize = reader.ReadInt32 ();
- FieldInfoTypeOffset = reader.ReadInt32 ();
- FieldInfoOffsetOffset = reader.ReadInt32 ();
-
- KlassFieldCountOffset = KlassMethodCountOffset - 8;
-
- MonoDefaultsCorlibOffset = reader.ReadInt32 ();
- MonoDefaultsObjectOffset = reader.ReadInt32 ();
- MonoDefaultsByteOffset = reader.ReadInt32 ();
- MonoDefaultsVoidOffset = reader.ReadInt32 ();
- MonoDefaultsBooleanOffset = reader.ReadInt32 ();
- MonoDefaultsSByteOffset = reader.ReadInt32 ();
- MonoDefaultsInt16Offset = reader.ReadInt32 ();
- MonoDefaultsUInt16Offset = reader.ReadInt32 ();
- MonoDefaultsInt32Offset = reader.ReadInt32 ();
- MonoDefaultsUInt32Offset = reader.ReadInt32 ();
- MonoDefaultsIntOffset = reader.ReadInt32 ();
- MonoDefaultsUIntOffset = reader.ReadInt32 ();
- MonoDefaultsInt64Offset = reader.ReadInt32 ();
- MonoDefaultsUInt64Offset = reader.ReadInt32 ();
- MonoDefaultsSingleOffset = reader.ReadInt32 ();
- MonoDefaultsDoubleOffset = reader.ReadInt32 ();
- MonoDefaultsCharOffset = reader.ReadInt32 ();
- MonoDefaultsStringOffset = reader.ReadInt32 ();
- MonoDefaultsEnumOffset = reader.ReadInt32 ();
- MonoDefaultsArrayOffset = reader.ReadInt32 ();
- MonoDefaultsDelegateOffset = reader.ReadInt32 ();
- MonoDefaultsExceptionOffset = reader.ReadInt32 ();
-
- MonoMethodKlassOffset = reader.ReadInt32 ();
- MonoMethodTokenOffset = reader.ReadInt32 ();
- MonoMethodFlagsOffset = reader.ReadInt32 ();
- MonoMethodInflatedOffset = reader.ReadInt32 ();
-
- MonoVTableKlassOffset = reader.ReadInt32 ();
- MonoVTableVTableOffset = reader.ReadInt32 ();
- }
- }
-
- //
- // The following API is new in `terrania'.
- //
-
- public GenericClassInfo GetGenericClass (TargetMemoryAccess memory,
- TargetAddress address)
- {
- int addr_size = memory.TargetMemoryInfo.TargetAddressSize;
-
- TargetReader reader = new TargetReader (memory.ReadMemory (address, 5 * addr_size));
- TargetAddress container = reader.ReadAddress ();
- TargetAddress class_inst = reader.ReadAddress ();
- reader.ReadAddress (); /* method_inst */
- reader.ReadAddress ();
- TargetAddress cached_class = reader.ReadAddress ();
-
- int inst_id = memory.ReadInteger (class_inst);
- int inst_data = memory.ReadInteger (class_inst + 4);
-
- TargetAddress inst_argv;
- if (MonoDebuggerInfo.MajorVersion == 80)
- inst_argv = memory.ReadAddress (class_inst + 8);
- else
- inst_argv = class_inst + 8;
-
- int type_argc = inst_data & 0x3fffff;
-
- TargetReader argv_reader = new TargetReader (
- memory.ReadMemory (inst_argv, type_argc * addr_size));
-
- TargetAddress[] type_args = new TargetAddress [type_argc];
- for (int i = 0; i < type_argc; i++)
- type_args [i] = argv_reader.ReadAddress ();
-
- TargetAddress cached_class_ptr = address + 4 * addr_size;
-
- return new GenericClassInfo (container, type_args, cached_class_ptr,
- cached_class);
- }
-
- public class GenericClassInfo
- {
- /* `MonoClass *' of the container class. */
- public readonly TargetAddress ContainerClass;
-
- /* `MonoType *' array of the instantiation. */
- public readonly TargetAddress[] TypeArguments;
-
- /* `MonoClass *' of this instantiation, if present. */
- public readonly TargetAddress KlassPtr;
- public readonly TargetAddress Klass;
-
- public GenericClassInfo (TargetAddress container, TargetAddress[] type_args,
- TargetAddress klass_ptr, TargetAddress klass)
- {
- this.ContainerClass = container;
- this.TypeArguments = type_args;
- this.KlassPtr = klass_ptr;
- this.Klass = klass;
- }
- }
-
- public GenericParamInfo GetGenericParameter (TargetMemoryAccess memory,
- TargetAddress address)
- {
- int addr_size = memory.TargetMemoryInfo.TargetAddressSize;
-
- TargetReader reader = new TargetReader (
- memory.ReadMemory (address, 4 * addr_size + 4));
- TargetAddress container = reader.ReadAddress ();
- TargetAddress klass = reader.ReadAddress ();
- TargetAddress name_addr = reader.ReadAddress ();
- reader.BinaryReader.ReadInt16 (); /* flags */
- int pos = reader.BinaryReader.ReadInt16 ();
-
- string name;
- if (!name_addr.IsNull)
- name = memory.ReadString (name_addr);
- else
- name = String.Format ("!{0}", pos);
-
- return new GenericParamInfo (container, klass, name, pos);
- }
-
- public class GenericParamInfo
- {
- public readonly TargetAddress Container;
- public readonly TargetAddress Klass;
- public readonly string Name;
- public readonly int Position;
-
- public GenericParamInfo (TargetAddress container, TargetAddress klass,
- string name, int pos)
- {
- this.Container = container;
- this.Klass = klass;
- this.Name = name;
- this.Position = pos;
- }
- }
-
- public AppDomainInfo GetAppDomainInfo (MonoLanguageBackend mono, TargetMemoryAccess memory,
- TargetAddress address)
- {
- int addr_size = memory.TargetMemoryInfo.TargetAddressSize;
- TargetReader reader = new TargetReader (memory.ReadMemory (address, 12 * addr_size));
-
- return new AppDomainInfo (mono, memory, reader);
- }
-
- public class AppDomainInfo
- {
- public readonly string ApplicationBase;
- public readonly string ApplicationName;
- public readonly string CachePath;
- public readonly string ConfigFile;
- public readonly string DynamicBase;
- public readonly string ShadowCopyDirectories;
- public readonly bool ShadowCopyFiles;
-
- public string ShadowCopyPath;
-
- public AppDomainInfo (MonoLanguageBackend mono, TargetMemoryAccess memory, TargetReader reader)
- {
- int addr_size = memory.TargetMemoryInfo.TargetAddressSize;
-
- reader.Offset = 2 * addr_size;
- ApplicationBase = MonoStringObject.ReadString (mono, memory, reader.ReadAddress ());
- ApplicationName = MonoStringObject.ReadString (mono, memory, reader.ReadAddress ());
- CachePath = MonoStringObject.ReadString (mono, memory, reader.ReadAddress ());
- ConfigFile = MonoStringObject.ReadString (mono, memory, reader.ReadAddress ());
- DynamicBase = MonoStringObject.ReadString (mono, memory, reader.ReadAddress ());
- reader.Offset += 3 * addr_size;
- ShadowCopyDirectories = MonoStringObject.ReadString (mono, memory, reader.ReadAddress ());
- ShadowCopyFiles = MonoStringObject.ReadString (mono, memory, reader.ReadAddress ()) == "true";
- }
-
- public override string ToString ()
- {
- return String.Format ("AppDomainInfo ({0}:{1}:{2}:{3}:{4}:{5}:{6})",
- ApplicationBase, ApplicationName, CachePath, ConfigFile,
- DynamicBase, ShadowCopyDirectories, ShadowCopyFiles);
- }
- }
- }
-}
--------------1.5.6--
From b0f85359e1717c8abce0061a67d35f4b1cf6e805 Mon Sep 17 00:00:00 2001
From: Martin Baulig <martin@novell.com>
Date: Tue, 8 Sep 2009 17:05:20 +0200
Subject: [PATCH] library ...
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------1.5.6"
This is a multi-part message in MIME format.
--------------1.5.6
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit
---
backend/mono/Makefile.am | 13 +++++++++++++
backend/mono/MonoLanguageBackend.cs | 24 ++++++++++++++++++++++++
backend/mono/MonoThreadManager.cs | 4 ++++
frontend/Command.cs | 9 +++++++++
languages/Language.cs | 2 ++
languages/native/NativeLanguage.cs | 5 +++++
6 files changed, 57 insertions(+), 0 deletions(-)
--------------1.5.6
Content-Type: text/x-patch; name="b0f85359e1717c8abce0061a67d35f4b1cf6e805.diff"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline; filename="b0f85359e1717c8abce0061a67d35f4b1cf6e805.diff"
diff --git a/backend/mono/Makefile.am b/backend/mono/Makefile.am
index bd74aad..7f89d42 100644
--- a/backend/mono/Makefile.am
+++ b/backend/mono/Makefile.am
@@ -1 +1,14 @@
EXTRA_DIST = $(srcdir)/*.cs
+
+INCLUDES = @SERVER_DEPENDENCIES_CFLAGS@ @server_cflags@
+
+lib_LTLIBRARIES = libmonodebuggerlibrary.la
+
+libmonodebuggerlibrary_la_SOURCES = \
+ library.c \
+ library.h
+
+libmonodebuggerlibrary_la_LDFLAGS = \
+ -no-undefined -export-dynamic -shared
+
+CLEANFILES = lib*.a lib*.dll
diff --git a/backend/mono/MonoLanguageBackend.cs b/backend/mono/MonoLanguageBackend.cs
index e855226..115ad06 100644
--- a/backend/mono/MonoLanguageBackend.cs
+++ b/backend/mono/MonoLanguageBackend.cs
@@ -1381,6 +1381,30 @@ namespace Mono.Debugger.Languages.Mono
}
}
+ public override void Test (Thread thread)
+ {
+ Console.WriteLine ("TEST !!!");
+
+ var path = Path.Combine (AssemblyInfo.libdir, "libmonodebuggerlibrary.so");
+
+ TargetAddress test = thread.CallMethod (info.Test, TargetAddress.Null, 0, 0, path);
+
+ Console.WriteLine ("TEST: {0}", test);
+
+ TargetBinaryReader reader = thread.ReadMemory (test, 24).GetReader ();
+ long magic = reader.ReadAddress ();
+ int major = reader.ReadInt32 ();
+ int minor = reader.ReadInt32 ();
+
+ TargetAddress func = new TargetAddress (thread.AddressDomain, reader.ReadAddress ());
+
+ Console.WriteLine ("TEST: {0:x} {1} {2} - {3}", magic, major, minor, func);
+
+ TargetAddress ret = thread.CallMethod (func, 0x12345678, 0xdeadbeaf);
+
+ Console.WriteLine ("TEST #2: {0}", ret);
+ }
+
public bool Notification (SingleSteppingEngine engine, Inferior inferior,
NotificationType type, TargetAddress data, long arg)
{
diff --git a/backend/mono/MonoThreadManager.cs b/backend/mono/MonoThreadManager.cs
index 88138df..c9e95bf 100644
--- a/backend/mono/MonoThreadManager.cs
+++ b/backend/mono/MonoThreadManager.cs
@@ -536,6 +536,8 @@ namespace Mono.Debugger.Backend.Mono
public readonly TargetAddress UsingMonoDebugger;
public readonly TargetAddress InterruptionRequest;
+ public readonly TargetAddress Test;
+
public static MonoDebuggerInfo Create (TargetMemoryAccess memory, TargetAddress info)
{
TargetBinaryReader header = memory.ReadMemory (info, 24).GetReader ();
@@ -633,6 +635,8 @@ namespace Mono.Debugger.Backend.Mono
UsingMonoDebugger = reader.ReadAddress ();
InterruptionRequest = reader.ReadAddress ();
+ Test = reader.ReadAddress ();
+
Report.Debug (DebugFlags.JitSymtab, this);
}
}
diff --git a/frontend/Command.cs b/frontend/Command.cs
index b8ce3c7..819f564 100644
--- a/frontend/Command.cs
+++ b/frontend/Command.cs
@@ -92,6 +92,7 @@ namespace Mono.Debugger.Frontend
RegisterCommand ("module", typeof (ModuleCommand));
RegisterCommand ("config", typeof (ConfigCommand));
RegisterCommand ("less", typeof (LessCommand));
+ RegisterCommand ("test", typeof (TestCommand));
}
}
@@ -3935,4 +3936,12 @@ namespace Mono.Debugger.Frontend
public string Documentation { get { return ""; } }
}
+ public class TestCommand : FrameCommand
+ {
+ protected override object DoExecute (ScriptingContext context)
+ {
+ context.CurrentFrame.Language.Test (context.CurrentThread);
+ return null;
+ }
+ }
}
diff --git a/languages/Language.cs b/languages/Language.cs
index d24ac7d..889719f 100644
--- a/languages/Language.cs
+++ b/languages/Language.cs
@@ -77,5 +77,7 @@ namespace Mono.Debugger.Languages
public abstract TargetPointerType CreatePointerType (TargetType type);
public abstract bool IsExceptionType (TargetClassType type);
+
+ public abstract void Test (Thread thread);
}
}
diff --git a/languages/native/NativeLanguage.cs b/languages/native/NativeLanguage.cs
index 2ddb755..2c1f931 100644
--- a/languages/native/NativeLanguage.cs
+++ b/languages/native/NativeLanguage.cs
@@ -182,6 +182,11 @@ namespace Mono.Debugger.Languages.Native
return false;
}
+ public override void Test (Thread thread)
+ {
+ throw new NotImplementedException ();
+ }
+
private bool disposed = false;
private void check_disposed ()
--------------1.5.6--
From 09a1c24d87258fd4d93c9f9456e7c60ca59b0707 Mon Sep 17 00:00:00 2001
From: Martin Baulig <martin@novell.com>
Date: Tue, 8 Sep 2009 21:15:51 +0200
Subject: [PATCH] .
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------1.5.6"
This is a multi-part message in MIME format.
--------------1.5.6
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit
---
backend/mono/Makefile.am | 3 +
backend/mono/MonoLanguageBackend.cs | 5 +-
backend/mono/library.c | 77 +++++++++++++++++++++++++++++++++++
backend/mono/library.h | 10 +++++
4 files changed, 93 insertions(+), 2 deletions(-)
create mode 100644 backend/mono/library.c
create mode 100644 backend/mono/library.h
--------------1.5.6
Content-Type: text/x-patch; name="09a1c24d87258fd4d93c9f9456e7c60ca59b0707.diff"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline; filename="09a1c24d87258fd4d93c9f9456e7c60ca59b0707.diff"
diff --git a/backend/mono/Makefile.am b/backend/mono/Makefile.am
index 7f89d42..37952c9 100644
--- a/backend/mono/Makefile.am
+++ b/backend/mono/Makefile.am
@@ -11,4 +11,7 @@ libmonodebuggerlibrary_la_SOURCES = \
libmonodebuggerlibrary_la_LDFLAGS = \
-no-undefined -export-dynamic -shared
+libmonodebuggerlibrary_la_LIBADD = \
+ @SERVER_DEPENDENCIES_LIBS@
+
CLEANFILES = lib*.a lib*.dll
diff --git a/backend/mono/MonoLanguageBackend.cs b/backend/mono/MonoLanguageBackend.cs
index 115ad06..8f8797f 100644
--- a/backend/mono/MonoLanguageBackend.cs
+++ b/backend/mono/MonoLanguageBackend.cs
@@ -1391,16 +1391,17 @@ namespace Mono.Debugger.Languages.Mono
Console.WriteLine ("TEST: {0}", test);
- TargetBinaryReader reader = thread.ReadMemory (test, 24).GetReader ();
+ TargetBinaryReader reader = thread.ReadMemory (test, 32).GetReader ();
long magic = reader.ReadAddress ();
int major = reader.ReadInt32 ();
int minor = reader.ReadInt32 ();
+ TargetAddress init = new TargetAddress (thread.AddressDomain, reader.ReadAddress ());
TargetAddress func = new TargetAddress (thread.AddressDomain, reader.ReadAddress ());
Console.WriteLine ("TEST: {0:x} {1} {2} - {3}", magic, major, minor, func);
- TargetAddress ret = thread.CallMethod (func, 0x12345678, 0xdeadbeaf);
+ TargetAddress ret = thread.CallMethod (func, corlib.MonoImage, 0);
Console.WriteLine ("TEST #2: {0}", ret);
}
diff --git a/backend/mono/library.c b/backend/mono/library.c
new file mode 100644
index 0000000..6209b37
--- /dev/null
+++ b/backend/mono/library.c
@@ -0,0 +1,77 @@
+#include <library.h>
+#include <mono/metadata/image.h>
+#include <mono/metadata/class.h>
+
+typedef struct _MonoDebuggerLibraryHelpers {
+ MonoGenericInst * (* get_generic_inst) (int argc, MonoType **type_argv);
+ MonoGenericContext * (* get_generic_context) (MonoGenericInst *class_inst, MonoGenericInst *method_inst);
+} MonoDebuggerLibraryHelpers;
+
+typedef struct _MartinDebuggerTest {
+ guint64 magic;
+ guint32 major_version;
+ guint32 minor_version;
+
+ void (*initialize) (MonoDebuggerLibraryHelpers *helpers);
+ guint64 (*test) (guint64 argument);
+} MartinDebuggerTest;
+
+static MonoDebuggerLibraryHelpers *library_helpers = NULL;
+
+static void
+debugger_initialize (MonoDebuggerLibraryHelpers *helpers);
+
+static guint64
+debugger_library_test (guint64);
+
+MartinDebuggerTest MARTIN_DEBUGGER__test = {
+ 0x7aff65af4253d427ULL,
+ 1,
+ 2,
+ &debugger_initialize,
+ &debugger_library_test
+};
+
+static void
+debugger_initialize (MonoDebuggerLibraryHelpers *helpers)
+{
+ g_message (G_STRLOC ": %p", helpers);
+ library_helpers = helpers;
+}
+
+guint64
+debugger_library_test (guint64 image_arg)
+{
+ MonoImage *image = (MonoImage *) GUINT_TO_POINTER ((gsize) image_arg);
+ MonoClass *int32_klass, *klass;
+ MonoGenericInst *ginst;
+ MonoGenericContext *gcontext;
+ MonoType *int32_type;
+ MonoType *inflated;
+
+ g_message (G_STRLOC ": %p - %s", image, mono_image_get_name (image));
+
+ int32_klass = mono_class_from_name (image, "System", "Int32");
+ g_message (G_STRLOC ": Int32 - %p", klass);
+
+ klass = mono_class_from_name (image, "System.Collections.Generic", "List`1");
+ g_message (G_STRLOC ": List`1 - %p", klass);
+
+ int32_type = mono_class_get_type (int32_klass);
+
+ ginst = library_helpers->get_generic_inst (1, &int32_type);
+ g_message (G_STRLOC ": ginst - %p", ginst);
+
+ gcontext = library_helpers->get_generic_context (ginst, NULL);
+ g_message (G_STRLOC ": gcontext - %p", gcontext);
+
+ inflated = mono_class_inflate_generic_type (mono_class_get_type (klass), gcontext);
+ g_message (G_STRLOC ": inflated - %p", inflated);
+
+ klass = mono_class_from_mono_type (inflated);
+ g_message (G_STRLOC ": klass - %p");
+
+ mono_class_init (klass);
+
+ return (guint64) (gsize) klass;
+}
diff --git a/backend/mono/library.h b/backend/mono/library.h
new file mode 100644
index 0000000..d91f4d1
--- /dev/null
+++ b/backend/mono/library.h
@@ -0,0 +1,10 @@
+#ifndef __MONO_DEBUGGER_LIBRARY_H__
+#define __MONO_DEBUGGER_LIBRARY_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+G_END_DECLS
+
+#endif
--------------1.5.6--
From 90a1c6de7b4d2401ef2c5de5979a01d88ee0c723 Mon Sep 17 00:00:00 2001
From: Martin Baulig <martin@novell.com>
Date: Wed, 9 Sep 2009 04:39:01 +0200
Subject: [PATCH] Introduce MonoRuntimeTypeHandle.
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------1.5.6"
This is a multi-part message in MIME format.
--------------1.5.6
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit
---
backend/mono/RuntimeTypeHandle.cs | 80 +++++++++++++++++++++++++++++++++++++
1 files changed, 80 insertions(+), 0 deletions(-)
create mode 100644 backend/mono/RuntimeTypeHandle.cs
--------------1.5.6
Content-Type: text/x-patch; name="90a1c6de7b4d2401ef2c5de5979a01d88ee0c723.diff"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline; filename="90a1c6de7b4d2401ef2c5de5979a01d88ee0c723.diff"
diff --git a/backend/mono/RuntimeTypeHandle.cs b/backend/mono/RuntimeTypeHandle.cs
new file mode 100644
index 0000000..96d24e7
--- /dev/null
+++ b/backend/mono/RuntimeTypeHandle.cs
@@ -0,0 +1,80 @@
+using System;
+
+using Mono.Debugger.Languages;
+using Mono.Debugger.Languages.Mono;
+
+namespace Mono.Debugger.Backend.Mono
+{
+ internal interface IMonoType
+ {
+ MonoRuntimeTypeHandle RuntimeTypeHandle {
+ get;
+ }
+ }
+
+ internal class MonoRuntimeTypeHandle : DebuggerMarshalByRefObject
+ {
+ public readonly TargetType Type;
+ public readonly byte[] TypeBlob;
+
+ public MonoRuntimeTypeHandle (TargetType type, byte[] blob)
+ {
+ this.Type = type;
+ this.TypeBlob = blob;
+ }
+
+ internal static MonoRuntimeTypeHandle CreateFundamental (MonoFundamentalType fundamental)
+ {
+ byte blob;
+
+ switch (fundamental.FundamentalKind) {
+ case FundamentalKind.Boolean:
+ blob = (byte) MonoTypeEnum.MONO_TYPE_BOOLEAN;
+ break;
+ case FundamentalKind.Char:
+ blob = (byte) MonoTypeEnum.MONO_TYPE_CHAR;
+ break;
+ case FundamentalKind.SByte:
+ blob = (byte) MonoTypeEnum.MONO_TYPE_I1;
+ break;
+ case FundamentalKind.Byte:
+ blob = (byte) MonoTypeEnum.MONO_TYPE_U1;
+ break;
+ case FundamentalKind.Int16:
+ blob = (byte) MonoTypeEnum.MONO_TYPE_I2;
+ break;
+ case FundamentalKind.UInt16:
+ blob = (byte) MonoTypeEnum.MONO_TYPE_U2;
+ break;
+ case FundamentalKind.Int32:
+ blob = (byte) MonoTypeEnum.MONO_TYPE_I4;
+ break;
+ case FundamentalKind.UInt32:
+ blob = (byte) MonoTypeEnum.MONO_TYPE_U4;
+ break;
+ case FundamentalKind.Int64:
+ blob = (byte) MonoTypeEnum.MONO_TYPE_I8;
+ break;
+ case FundamentalKind.UInt64:
+ blob = (byte) MonoTypeEnum.MONO_TYPE_U8;
+ break;
+ case FundamentalKind.Single:
+ blob = (byte) MonoTypeEnum.MONO_TYPE_R4;
+ break;
+ case FundamentalKind.Double:
+ blob = (byte) MonoTypeEnum.MONO_TYPE_R8;
+ break;
+ case FundamentalKind.IntPtr:
+ blob = (byte) MonoTypeEnum.MONO_TYPE_I;
+ break;
+ case FundamentalKind.UIntPtr:
+ blob = (byte) MonoTypeEnum.MONO_TYPE_U;
+ break;
+ default:
+ return null;
+ }
+
+ return new MonoRuntimeTypeHandle (fundamental, new byte[] { blob });
+ }
+ }
+}
--------------1.5.6--
From 3a1b7b4d3d6ebc49be45d7248fdf07a423e778e1 Mon Sep 17 00:00:00 2001
From: Martin Baulig <martin@novell.com>
Date: Wed, 9 Sep 2009 16:42:41 +0200
Subject: [PATCH] .
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------1.5.6"
This is a multi-part message in MIME format.
--------------1.5.6
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit
---
backend/mono/MonoLanguageBackend.cs | 17 ++++++++++++-----
backend/mono/library.c | 2 +-
frontend/Command.cs | 22 +++++++++++++++++++++-
languages/Language.cs | 2 +-
languages/mono/MonoClassType.cs | 3 ++-
languages/mono/MonoFundamentalType.cs | 11 ++++++++++-
languages/native/NativeLanguage.cs | 2 +-
7 files changed, 48 insertions(+), 11 deletions(-)
--------------1.5.6
Content-Type: text/x-patch; name="3a1b7b4d3d6ebc49be45d7248fdf07a423e778e1.diff"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline; filename="3a1b7b4d3d6ebc49be45d7248fdf07a423e778e1.diff"
diff --git a/backend/mono/MonoLanguageBackend.cs b/backend/mono/MonoLanguageBackend.cs
index 8f8797f..a1644d3 100644
--- a/backend/mono/MonoLanguageBackend.cs
+++ b/backend/mono/MonoLanguageBackend.cs
@@ -1381,15 +1381,12 @@ namespace Mono.Debugger.Languages.Mono
}
}
- public override void Test (Thread thread)
+ public override void Test (Thread thread, TargetType type)
{
- Console.WriteLine ("TEST !!!");
-
var path = Path.Combine (AssemblyInfo.libdir, "libmonodebuggerlibrary.so");
-
TargetAddress test = thread.CallMethod (info.Test, TargetAddress.Null, 0, 0, path);
- Console.WriteLine ("TEST: {0}", test);
+ Console.WriteLine ("TEST: {0} {1}", test, type);
TargetBinaryReader reader = thread.ReadMemory (test, 32).GetReader ();
long magic = reader.ReadAddress ();
@@ -1401,6 +1398,16 @@ namespace Mono.Debugger.Languages.Mono
Console.WriteLine ("TEST: {0:x} {1} {2} - {3}", magic, major, minor, func);
+ var mono_type = type as IMonoType;
+ if (mono_type == null)
+ throw new InvalidOperationException ();
+
+ var handle = mono_type.RuntimeTypeHandle;
+ if (handle == null)
+ throw new InvalidOperationException ();
+
+ Console.WriteLine ("TEST #1: {0}", TargetBinaryReader.HexDump (handle.TypeBlob));
+
TargetAddress ret = thread.CallMethod (func, corlib.MonoImage, 0);
Console.WriteLine ("TEST #2: {0}", ret);
diff --git a/backend/mono/library.c b/backend/mono/library.c
index 6209b37..179619a 100644
--- a/backend/mono/library.c
+++ b/backend/mono/library.c
@@ -69,7 +69,7 @@ debugger_library_test (guint64 image_arg)
g_message (G_STRLOC ": inflated - %p", inflated);
klass = mono_class_from_mono_type (inflated);
- g_message (G_STRLOC ": klass - %p");
+ g_message (G_STRLOC ": klass - %p", klass);
mono_class_init (klass);
diff --git a/frontend/Command.cs b/frontend/Command.cs
index 819f564..37fbfc3 100644
--- a/frontend/Command.cs
+++ b/frontend/Command.cs
@@ -3938,9 +3938,29 @@ namespace Mono.Debugger.Frontend
public class TestCommand : FrameCommand
{
+ Expression expression;
+
+ protected override bool DoResolve (ScriptingContext context)
+ {
+ expression = ParseExpression (context);
+ if (expression == null)
+ return false;
+
+ Expression resolved = expression.TryResolveType (context);
+ if (resolved != null) {
+ expression = resolved;
+ return true;
+ }
+
+ return expression != null;
+ expression = expression.Resolve (context);
+ }
+
protected override object DoExecute (ScriptingContext context)
{
- context.CurrentFrame.Language.Test (context.CurrentThread);
+ TargetType type = expression.EvaluateType (context);
+
+ context.CurrentFrame.Language.Test (context.CurrentThread, type);
return null;
}
}
diff --git a/languages/Language.cs b/languages/Language.cs
index 889719f..0e1c223 100644
--- a/languages/Language.cs
+++ b/languages/Language.cs
@@ -78,6 +78,6 @@ namespace Mono.Debugger.Languages
public abstract bool IsExceptionType (TargetClassType type);
- public abstract void Test (Thread thread);
+ public abstract void Test (Thread thread, TargetType type);
}
}
diff --git a/languages/mono/MonoClassType.cs b/languages/mono/MonoClassType.cs
index 9bf564b..dc9bc2e 100644
--- a/languages/mono/MonoClassType.cs
+++ b/languages/mono/MonoClassType.cs
@@ -7,6 +7,7 @@ using C = Mono.CompilerServices.SymbolWriter;
using Cecil = Mono.Cecil;
using Mono.Debugger.Backend;
+using Mono.Debugger.Backend.Mono;
namespace Mono.Debugger.Languages.Mono
{
@@ -31,7 +32,7 @@ namespace Mono.Debugger.Languages.Mono
MonoFunctionType LookupFunction (Cecil.MethodDefinition mdef);
}
- internal class MonoClassType : TargetClassType, IMonoStructType
+ internal class MonoClassType : TargetClassType, IMonoStructType, IMonoType
{
MonoFieldInfo[] fields;
MonoMethodInfo[] methods;
diff --git a/languages/mono/MonoFundamentalType.cs b/languages/mono/MonoFundamentalType.cs
index 26d1aba..75f83f9 100644
--- a/languages/mono/MonoFundamentalType.cs
+++ b/languages/mono/MonoFundamentalType.cs
@@ -1,21 +1,30 @@
using System;
using System.Runtime.InteropServices;
using Mono.Debugger.Backend;
+using Mono.Debugger.Backend.Mono;
namespace Mono.Debugger.Languages.Mono
{
- internal class MonoFundamentalType : TargetFundamentalType
+ internal class MonoFundamentalType : TargetFundamentalType, IMonoType
{
MonoSymbolFile file;
MonoClassType class_type;
Cecil.TypeDefinition typedef;
+ MonoRuntimeTypeHandle handle;
+
protected MonoFundamentalType (MonoSymbolFile file, Cecil.TypeDefinition typedef,
string name, FundamentalKind kind, int size)
: base (file.Language, name, kind, size)
{
this.file = file;
this.typedef = typedef;
+
+ handle = MonoRuntimeTypeHandle.CreateFundamental (this);
+ }
+
+ MonoRuntimeTypeHandle IMonoType.RuntimeTypeHandle {
+ get { return handle; }
}
public static MonoFundamentalType Create (MonoSymbolFile corlib,
diff --git a/languages/native/NativeLanguage.cs b/languages/native/NativeLanguage.cs
index 2c1f931..806017d 100644
--- a/languages/native/NativeLanguage.cs
+++ b/languages/native/NativeLanguage.cs
@@ -182,7 +182,7 @@ namespace Mono.Debugger.Languages.Native
return false;
}
- public override void Test (Thread thread)
+ public override void Test (Thread thread, TargetType type)
{
throw new NotImplementedException ();
}
--------------1.5.6--
From 0cf9295643f9dec1b1899c65ed3c73e545123338 Mon Sep 17 00:00:00 2001
From: Martin Baulig <martin@novell.com>
Date: Wed, 9 Sep 2009 19:50:13 +0200
Subject: [PATCH] .
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------1.5.6"
This is a multi-part message in MIME format.
--------------1.5.6
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit
---
backend/mono/MonoLanguageBackend.cs | 7 +++++--
backend/mono/RuntimeTypeHandle.cs | 3 +++
backend/mono/library.c | 14 +++++++++++++-
frontend/Command.cs | 2 +-
languages/mono/MonoClassType.cs | 19 +++++++++++++++++++
languages/mono/MonoGenericInstanceType.cs | 28 +++++++++++++++++++++++++++-
6 files changed, 68 insertions(+), 5 deletions(-)
--------------1.5.6
Content-Type: text/x-patch; name="0cf9295643f9dec1b1899c65ed3c73e545123338.diff"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline; filename="0cf9295643f9dec1b1899c65ed3c73e545123338.diff"
diff --git a/backend/mono/MonoLanguageBackend.cs b/backend/mono/MonoLanguageBackend.cs
index a1644d3..8121d41 100644
--- a/backend/mono/MonoLanguageBackend.cs
+++ b/backend/mono/MonoLanguageBackend.cs
@@ -1388,15 +1388,16 @@ namespace Mono.Debugger.Languages.Mono
Console.WriteLine ("TEST: {0} {1}", test, type);
- TargetBinaryReader reader = thread.ReadMemory (test, 32).GetReader ();
+ TargetBinaryReader reader = thread.ReadMemory (test, 40).GetReader ();
long magic = reader.ReadAddress ();
int major = reader.ReadInt32 ();
int minor = reader.ReadInt32 ();
TargetAddress init = new TargetAddress (thread.AddressDomain, reader.ReadAddress ());
TargetAddress func = new TargetAddress (thread.AddressDomain, reader.ReadAddress ());
+ TargetAddress buffer = new TargetAddress (thread.AddressDomain, reader.ReadAddress ());
- Console.WriteLine ("TEST: {0:x} {1} {2} - {3}", magic, major, minor, func);
+ Console.WriteLine ("TEST: {0:x} {1} {2} - {3} {4}", magic, major, minor, func, buffer);
var mono_type = type as IMonoType;
if (mono_type == null)
@@ -1408,6 +1409,8 @@ namespace Mono.Debugger.Languages.Mono
Console.WriteLine ("TEST #1: {0}", TargetBinaryReader.HexDump (handle.TypeBlob));
+ thread.WriteBuffer (buffer, handle.TypeBlob);
+
TargetAddress ret = thread.CallMethod (func, corlib.MonoImage, 0);
Console.WriteLine ("TEST #2: {0}", ret);
diff --git a/backend/mono/RuntimeTypeHandle.cs b/backend/mono/RuntimeTypeHandle.cs
index 96d24e7..f2b7d8b 100644
--- a/backend/mono/RuntimeTypeHandle.cs
+++ b/backend/mono/RuntimeTypeHandle.cs
@@ -70,6 +70,9 @@ namespace Mono.Debugger.Backend.Mono
case FundamentalKind.UIntPtr:
blob = (byte) MonoTypeEnum.MONO_TYPE_U;
break;
+ case FundamentalKind.String:
+ blob = (byte) MonoTypeEnum.MONO_TYPE_STRING;
+ break;
default:
return null;
}
diff --git a/backend/mono/library.c b/backend/mono/library.c
index 179619a..77823bc 100644
--- a/backend/mono/library.c
+++ b/backend/mono/library.c
@@ -1,12 +1,16 @@
#include <library.h>
+#include <mono/metadata/blob.h>
#include <mono/metadata/image.h>
#include <mono/metadata/class.h>
typedef struct _MonoDebuggerLibraryHelpers {
MonoGenericInst * (* get_generic_inst) (int argc, MonoType **type_argv);
MonoGenericContext * (* get_generic_context) (MonoGenericInst *class_inst, MonoGenericInst *method_inst);
+ MonoType * (* parse_type) (guint8 *ptr);
} MonoDebuggerLibraryHelpers;
+static guint8 data_buffer [64536];
+
typedef struct _MartinDebuggerTest {
guint64 magic;
guint32 major_version;
@@ -14,6 +18,8 @@ typedef struct _MartinDebuggerTest {
void (*initialize) (MonoDebuggerLibraryHelpers *helpers);
guint64 (*test) (guint64 argument);
+
+ guint8 *data_buffer;
} MartinDebuggerTest;
static MonoDebuggerLibraryHelpers *library_helpers = NULL;
@@ -29,7 +35,9 @@ MartinDebuggerTest MARTIN_DEBUGGER__test = {
1,
2,
&debugger_initialize,
- &debugger_library_test
+ &debugger_library_test,
+
+ (guint8 *) &data_buffer
};
static void
@@ -48,6 +56,10 @@ debugger_library_test (guint64 image_arg)
MonoGenericContext *gcontext;
MonoType *int32_type;
MonoType *inflated;
+ MonoType *test;
+
+ test = library_helpers->parse_type (data_buffer);
+ g_message (G_STRLOC ": %p", test);
g_message (G_STRLOC ": %p - %s", image, mono_image_get_name (image));
diff --git a/frontend/Command.cs b/frontend/Command.cs
index 37fbfc3..dcc4713 100644
--- a/frontend/Command.cs
+++ b/frontend/Command.cs
@@ -3952,8 +3952,8 @@ namespace Mono.Debugger.Frontend
return true;
}
- return expression != null;
expression = expression.Resolve (context);
+ return expression != null;
}
protected override object DoExecute (ScriptingContext context)
diff --git a/languages/mono/MonoClassType.cs b/languages/mono/MonoClassType.cs
index dc9bc2e..7c1d80e 100644
--- a/languages/mono/MonoClassType.cs
+++ b/languages/mono/MonoClassType.cs
@@ -1,4 +1,5 @@
using System;
+using System.IO;
using System.Text;
using System.Diagnostics;
using System.Collections;
@@ -55,6 +56,8 @@ namespace Mono.Debugger.Languages.Mono
DebuggerTypeProxyAttribute type_proxy;