Author: martin
Date: 2007-07-04 21:46:19 -0400 (Wed, 04 Jul 2007)
New Revision: 81365

Modified:
   branches/martin/debugger-dublin/debugger/backend/MonoThreadManager.cs
   branches/martin/debugger-dublin/debugger/backend/SingleSteppingEngine.cs
   branches/martin/debugger-dublin/debugger/backend/arch/Bfd.cs
   branches/martin/debugger-dublin/debugger/backend/arch/DwarfReader.cs
   branches/martin/debugger-dublin/debugger/classes/MethodSource.cs
   branches/martin/debugger-dublin/debugger/classes/Module.cs
   branches/martin/debugger-dublin/debugger/classes/SourceLocation.cs
   branches/martin/debugger-dublin/debugger/classes/StackFrame.cs
   branches/martin/debugger-dublin/debugger/frontend/Command.cs
   branches/martin/debugger-dublin/debugger/frontend/Expression.cs
   
branches/martin/debugger-dublin/debugger/languages/mono/MonoLanguageBackend.cs
   branches/martin/debugger-dublin/debugger/languages/mono/MonoSymbolFile.cs
Log:
Daily backup July 4th.

Modified: branches/martin/debugger-dublin/debugger/backend/MonoThreadManager.cs
===================================================================
--- branches/martin/debugger-dublin/debugger/backend/MonoThreadManager.cs       
2007-07-05 01:46:04 UTC (rev 81364)
+++ branches/martin/debugger-dublin/debugger/backend/MonoThreadManager.cs       
2007-07-05 01:46:19 UTC (rev 81365)
@@ -80,6 +80,8 @@
                        notification_address = inferior.ReadAddress 
(debugger_info.NotificationAddress);
                        inferior.SetNotificationAddress (notification_address);
 
+                       inferior.WriteInteger (debugger_info.DebuggerVersion, 
2);
+
                        if (notification_bpt > 0) {
                                inferior.BreakpointManager.RemoveBreakpoint 
(inferior, notification_bpt);
                                notification_bpt = -1;

Modified: 
branches/martin/debugger-dublin/debugger/backend/SingleSteppingEngine.cs
===================================================================
--- branches/martin/debugger-dublin/debugger/backend/SingleSteppingEngine.cs    
2007-07-05 01:46:04 UTC (rev 81364)
+++ branches/martin/debugger-dublin/debugger/backend/SingleSteppingEngine.cs    
2007-07-05 01:46:19 UTC (rev 81365)
@@ -983,9 +983,14 @@
                                                return new_operation;
                                }
 
-                               update_current_frame (new StackFrame (
-                                       thread, iframe.Address, 
iframe.StackPointer,
-                                       iframe.FrameAddress, registers, 
current_method, source));
+                               if (source != null)
+                                       update_current_frame (new StackFrame (
+                                               thread, iframe.Address, 
iframe.StackPointer,
+                                               iframe.FrameAddress, registers, 
current_method, source));
+                               else
+                                       update_current_frame (new StackFrame (
+                                               thread, iframe.Address, 
iframe.StackPointer,
+                                               iframe.FrameAddress, registers, 
current_method));
                        } else {
                                if (!same_method && (current_method != null)) {
                                        Operation new_operation = 
check_method_operation (
@@ -2052,11 +2057,12 @@
                                MethodSource source = 
main.MonoClass.File.GetMethodByToken (main.Token);
                                if (source != null) {
                                        SourceLocation location = new 
SourceLocation (source);
-                                       Method method = source.GetMethod (0);
+                                       // Method method = source.GetMethod (0);
+                                       Method method = null;
 
                                        main_frame = new StackFrame (
                                                sse.thread, iframe.Address, 
iframe.StackPointer,
-                                               iframe.FrameAddress, registers, 
method, location);
+                                               iframe.FrameAddress, registers, 
main, location);
                                } else {
                                        main_frame = new StackFrame (
                                                sse.thread, iframe.Address, 
iframe.StackPointer,

Modified: branches/martin/debugger-dublin/debugger/backend/arch/Bfd.cs
===================================================================
--- branches/martin/debugger-dublin/debugger/backend/arch/Bfd.cs        
2007-07-05 01:46:04 UTC (rev 81364)
+++ branches/martin/debugger-dublin/debugger/backend/arch/Bfd.cs        
2007-07-05 01:46:19 UTC (rev 81365)
@@ -557,6 +557,7 @@
                        throw new InvalidOperationException ();
                }
 
+#if FIXME
                public override Method GetMethod (int domain, long handle)
                {
                        if (dwarf != null)
@@ -564,6 +565,7 @@
 
                        throw new InvalidOperationException ();
                }
+#endif
 
                public override MethodSource FindMethod (string name)
                {

Modified: branches/martin/debugger-dublin/debugger/backend/arch/DwarfReader.cs
===================================================================
--- branches/martin/debugger-dublin/debugger/backend/arch/DwarfReader.cs        
2007-07-05 01:46:04 UTC (rev 81364)
+++ branches/martin/debugger-dublin/debugger/backend/arch/DwarfReader.cs        
2007-07-05 01:46:19 UTC (rev 81365)
@@ -2468,9 +2468,8 @@
                                get { return end_row; }
                        }
 
-                       public override Method GetMethod (int domain)
-                       {
-                               return subprog.Method;
+                       public override Method NativeMethod {
+                               get {return subprog.Method; }
                        }
                }
 

Modified: branches/martin/debugger-dublin/debugger/classes/MethodSource.cs
===================================================================
--- branches/martin/debugger-dublin/debugger/classes/MethodSource.cs    
2007-07-05 01:46:04 UTC (rev 81364)
+++ branches/martin/debugger-dublin/debugger/classes/MethodSource.cs    
2007-07-05 01:46:19 UTC (rev 81365)
@@ -41,6 +41,8 @@
                        get;
                }
 
-               public abstract Method GetMethod (int domain);
+               public abstract Method NativeMethod {
+                       get;
+               }
        }
 }

Modified: branches/martin/debugger-dublin/debugger/classes/Module.cs
===================================================================
--- branches/martin/debugger-dublin/debugger/classes/Module.cs  2007-07-05 
01:46:04 UTC (rev 81364)
+++ branches/martin/debugger-dublin/debugger/classes/Module.cs  2007-07-05 
01:46:19 UTC (rev 81365)
@@ -59,7 +59,7 @@
 
                public abstract MethodSource[] GetMethods (SourceFile file);
 
-               public abstract Method GetMethod (int domain, long handle);
+               // public abstract Method GetMethod (int domain, long handle);
 
                public abstract MethodSource FindMethod (string name);
 
@@ -418,10 +418,12 @@
                        return SymbolFile.GetMethods (file);
                }
 
+#if FIXME
                public Method GetMethod (int domain, long handle)
                {
                        return SymbolFile.GetMethod (domain, handle);
                }
+#endif
 
                // <summary>
                //   Find method @name, which must be a full method name 
including the

Modified: branches/martin/debugger-dublin/debugger/classes/SourceLocation.cs
===================================================================
--- branches/martin/debugger-dublin/debugger/classes/SourceLocation.cs  
2007-07-05 01:46:04 UTC (rev 81364)
+++ branches/martin/debugger-dublin/debugger/classes/SourceLocation.cs  
2007-07-05 01:46:19 UTC (rev 81365)
@@ -232,6 +232,7 @@
 
                internal void DumpLineNumbers ()
                {
+#if FIXME
                        if (source == null)
                                throw new TargetException 
(TargetError.LocationInvalid);
 
@@ -240,6 +241,7 @@
                                throw new TargetException 
(TargetError.LocationInvalid);
 
                        method.LineNumberTable.DumpLineNumbers ();
+#endif
                }
 
                internal BreakpointHandle ResolveBreakpoint (Breakpoint 
breakpoint, int domain)
@@ -260,22 +262,22 @@
                        if (function != null)
                                return new FunctionBreakpointHandle 
(breakpoint, domain, function, line);
 
-                       if (source == null)
+                       if ((source == null) || source.IsManaged)
                                throw new TargetException 
(TargetError.LocationInvalid);
 
-                       TargetAddress address = GetAddress (domain);
+                       TargetAddress address = GetAddress ();
                        if (!address.IsNull)
                                return new AddressBreakpointHandle (breakpoint, 
address);
 
                        return null;
                }
 
-               protected TargetAddress GetAddress (int domain)
+               protected TargetAddress GetAddress ()
                {
-                       if (source == null)
+                       if ((source == null) || source.IsManaged)
                                return TargetAddress.Null;
 
-                       Method method = source.GetMethod (domain);
+                       Method method = source.NativeMethod;
                        if (method == null)
                                return TargetAddress.Null;
 

Modified: branches/martin/debugger-dublin/debugger/classes/StackFrame.cs
===================================================================
--- branches/martin/debugger-dublin/debugger/classes/StackFrame.cs      
2007-07-05 01:46:04 UTC (rev 81364)
+++ branches/martin/debugger-dublin/debugger/classes/StackFrame.cs      
2007-07-05 01:46:19 UTC (rev 81365)
@@ -192,6 +192,7 @@
                StackFrame parent_frame;
                TargetObject exc_object;
                SourceLocation location;
+               TargetFunctionType function;
                Language language;
                bool has_source;
                Symbol name;
@@ -230,6 +231,17 @@
 
                internal StackFrame (Thread thread, TargetAddress address, 
TargetAddress stack_ptr,
                                     TargetAddress frame_address, Registers 
registers,
+                                    TargetFunctionType function, 
SourceLocation location)
+                       : this (thread, address, stack_ptr, frame_address, 
registers)
+               {
+                       this.function = function;
+                       this.language = function.DeclaringType.Language;
+                       this.name = new Symbol (function.FullName, address, 0);
+                       this.location = location;
+               }
+
+               internal StackFrame (Thread thread, TargetAddress address, 
TargetAddress stack_ptr,
+                                    TargetAddress frame_address, Registers 
registers,
                                     Method method, SourceLocation location)
                        : this (thread, address, stack_ptr, frame_address, 
registers, method)
                {
@@ -294,6 +306,10 @@
                        get { return method; }
                }
 
+               public TargetFunctionType Function {
+                       get { return function; }
+               }
+
                public Symbol Name {
                        get { return name; }
                }

Modified: branches/martin/debugger-dublin/debugger/frontend/Command.cs
===================================================================
--- branches/martin/debugger-dublin/debugger/frontend/Command.cs        
2007-07-05 01:46:04 UTC (rev 81364)
+++ branches/martin/debugger-dublin/debugger/frontend/Command.cs        
2007-07-05 01:46:19 UTC (rev 81365)
@@ -2607,7 +2607,9 @@
        public abstract class SourceCommand : FrameCommand
        {
                LocationType type = LocationType.Method;
-               SourceLocation location;
+               protected SourceLocation location;
+               protected SourceAddress address;
+               int line;
 
                public bool Ctor {
                        get { return type == LocationType.Constructor; }
@@ -2646,9 +2648,16 @@
 
                                return location;
                        }
+               }
 
-                       set {
-                               location = value;
+               public int Line {
+                       get {
+                               if (location != null)
+                                       return location.Line;
+                               else if (address != null)
+                                       return address.Row;
+                               else
+                                       throw new ScriptingException ("Location 
is invalid.");
                        }
                }
 
@@ -2679,8 +2688,16 @@
                        }
 
                        if (Argument == "") {
-                               location = context.CurrentLocation;
-                               return location != null;
+                               StackFrame frame = context.CurrentFrame;
+                               if (frame.SourceAddress == null)
+                                       return false;
+
+                               if (frame.SourceAddress.Location != null)
+                                       location = frame.SourceAddress.Location;
+                               else
+                                       address = frame.SourceAddress;
+
+                               return true;
                        }
 
                        try {
@@ -2729,35 +2746,47 @@
                protected override bool DoResolve (ScriptingContext context)
                {
                        if (Argument == "-"){
-                               Location = context.CurrentLocation;
                                reverse = true;
-                               return true;
-                       }
+                               location = context.CurrentLocation;
+                               if (location == null)
+                                       return false;
+                       } else if (!base.DoResolve (context))
+                               return false;
 
-                       return base.DoResolve (context);
-               }
-
-               protected override object DoExecute (ScriptingContext context)
-               {
-                       int count = Lines * (reverse ? -1 : 1);
-                       if (!Repeating) {
-                               SourceBuffer buffer;
-
-                               if (Location.FileName == null) 
+                       SourceBuffer buffer;
+                       if (location != null) {
+                               if (location.FileName == null) 
                                        throw new ScriptingException (
                                                "Current location doesn't have 
any source code.");
 
-                               buffer = context.Interpreter.ReadFile 
(Location.FileName);
+                               buffer = context.Interpreter.ReadFile 
(location.FileName);
                                if (buffer == null)
                                        throw new ScriptingException (
-                                               "Cannot read source file 
`{0}'", Location.FileName);
+                                               "Cannot read source file 
`{0}'", location.FileName);
+                       } else if (address != null) {
+                               LineNumberTable lnt = address.LineNumberTable;
 
-                               source_code = buffer.Contents;
+                               if ((lnt == null) || !lnt.IsDynamic)
+                                       throw new ScriptingException (
+                                               "Current location doesn't have 
any source code.");
 
+                               buffer = lnt.SourceBuffer;
+                       } else
+                               throw new ScriptingException (
+                                       "Current location doesn't have any 
source code.");
+
+                       source_code = buffer.Contents;
+                       return true;
+               }
+
+               protected override object DoExecute (ScriptingContext context)
+               {
+                       int count = Lines * (reverse ? -1 : 1);
+                       if (!Repeating) {
                                if (count < 0)
-                                       last_line = System.Math.Max 
(Location.Line + 2, 0);
+                                       last_line = System.Math.Max (Line + 2, 
0);
                                else 
-                                       last_line = System.Math.Max 
(Location.Line - 2, 0);
+                                       last_line = System.Math.Max (Line - 2, 
0);
                        }
 
                        int start;

Modified: branches/martin/debugger-dublin/debugger/frontend/Expression.cs
===================================================================
--- branches/martin/debugger-dublin/debugger/frontend/Expression.cs     
2007-07-05 01:46:04 UTC (rev 81364)
+++ branches/martin/debugger-dublin/debugger/frontend/Expression.cs     
2007-07-05 01:46:19 UTC (rev 81365)
@@ -865,6 +865,17 @@
                MemberExpression LookupMember (ScriptingContext context, 
StackFrame frame,
                                               string full_name)
                {
+                       MemberExpression member;
+
+                       TargetFunctionType function = frame.Function;
+                       if (function != null) {
+                               member = StructAccessExpression.FindMember (
+                                       frame.Thread, function.DeclaringType, 
null,
+                                       full_name, true, true);
+                               if (member != null)
+                                       return member;
+                       }
+
                        Method method = frame.Method;
                        if ((method == null) || (method.DeclaringType == null))
                                return null;
@@ -873,7 +884,7 @@
                        if (method.HasThis)
                                instance = (TargetClassObject) 
method.This.GetObject (frame);
 
-                       MemberExpression member = 
StructAccessExpression.FindMember (
+                       member = StructAccessExpression.FindMember (
                                frame.Thread, method.DeclaringType, instance, 
full_name, true, true);
                        if (member == null)
                                return null;

Modified: 
branches/martin/debugger-dublin/debugger/languages/mono/MonoLanguageBackend.cs
===================================================================
--- 
branches/martin/debugger-dublin/debugger/languages/mono/MonoLanguageBackend.cs  
    2007-07-05 01:46:04 UTC (rev 81364)
+++ 
branches/martin/debugger-dublin/debugger/languages/mono/MonoLanguageBackend.cs  
    2007-07-05 01:46:19 UTC (rev 81365)
@@ -535,9 +535,10 @@
 
                private enum DataItemType {
                        Unknown         = 0,
-                       Method,
+                       OldMethod,
                        Class,
-                       Wrapper
+                       OldWrapper,
+                       Method
                }
 
                void read_data_items (TargetMemoryAccess memory, TargetAddress 
address, int start, int end)
@@ -562,23 +563,22 @@
 
                                switch (item_type) {
                                case DataItemType.Method:
-                                       read_range_entry (reader);
+                                       read_range_entry (memory, reader);
                                        break;
 
                                case DataItemType.Class:
                                        read_class_entry (memory, reader);
                                        break;
 
-                               case DataItemType.Wrapper:
-                                       read_wrapper_entry (memory, reader);
-                                       break;
+                               default:
+                                       throw new InternalError ("Got unknown 
data item: {0}", item_type);
                                }
 
                                reader.BinaryReader.Position = pos + item_size;
                        }
                }
 
-               void read_range_entry (TargetReader reader)
+               void read_range_entry (TargetMemoryAccess memory, TargetReader 
reader)
                {
                        int size = reader.BinaryReader.PeekInt32 ();
                        byte[] contents = reader.BinaryReader.PeekBuffer (size);
@@ -588,7 +588,7 @@
                                      size, file_idx);
                        MonoSymbolFile file = (MonoSymbolFile) symbol_files 
[file_idx];
                        if (file != null)
-                               file.AddRangeEntry (reader, contents);
+                               file.AddRangeEntry (memory, reader, contents);
                }
 
                void read_class_entry (TargetMemoryAccess memory, TargetReader 
reader)
@@ -607,13 +607,20 @@
                        GetClassInfo (memory, klass_address);
                }
 
+#if FIXME
                void read_wrapper_entry (TargetMemoryAccess memory, 
TargetReader reader)
                {
                        int size = reader.BinaryReader.PeekInt32 ();
                        byte[] contents = reader.BinaryReader.PeekBuffer (size);
                        reader.BinaryReader.ReadInt32 ();
-                       corlib.AddWrapperEntry (memory, reader, contents);
+                       int file_idx = reader.BinaryReader.ReadInt32 ();
+                       Report.Debug (DebugFlags.JitSymtab, "READ WRAPPER ITEM: 
{0} {1}",
+                                     size, file_idx);
+                       MonoSymbolFile file = (MonoSymbolFile) symbol_files 
[file_idx];
+                       if (file != null)
+                               file.AddWrapperEntry (memory, reader, contents);
                }
+#endif
 
                internal MonoClassInfo GetClassInfo (TargetMemoryAccess memory, 
TargetAddress klass_address)
                {
@@ -668,7 +675,18 @@
 
                Method method_from_jit_info (TargetMemoryAccess target, 
TargetAddress data)
                {
-                       return process.SymbolTableManager.Lookup (data);
+                       int size = target.ReadInteger (data);
+                       TargetReader reader = new TargetReader 
(target.ReadMemory (data, size));
+                       byte[] contents = reader.BinaryReader.PeekBuffer (size);
+
+                       reader.BinaryReader.ReadInt32 ();
+                       int file_idx = reader.BinaryReader.ReadInt32 ();
+                       int domain_id = reader.BinaryReader.ReadInt32 ();
+                       int index = reader.BinaryReader.ReadInt32 ();
+                       TargetAddress method_addr = reader.ReadAddress ();
+                       MonoSymbolFile file = (MonoSymbolFile) symbol_files 
[file_idx];
+
+                       return file.GetMonoMethod (method_addr, domain_id, 
index, contents);
                }
 
                internal int RegisterMethodLoadHandler (Thread target, 
TargetAddress method_address,
@@ -952,7 +970,7 @@
                                break;
 
                        case NotificationType.ReloadSymtabs:
-                               do_update_symbol_table (inferior);
+                               // do_update_symbol_table (inferior);
                                break;
 
                        case NotificationType.JitBreakpoint:

Modified: 
branches/martin/debugger-dublin/debugger/languages/mono/MonoSymbolFile.cs
===================================================================
--- branches/martin/debugger-dublin/debugger/languages/mono/MonoSymbolFile.cs   
2007-07-05 01:46:04 UTC (rev 81364)
+++ branches/martin/debugger-dublin/debugger/languages/mono/MonoSymbolFile.cs   
2007-07-05 01:46:19 UTC (rev 81365)
@@ -126,19 +126,19 @@
                                return TargetAddress.Null;
                }
 
-               public MethodAddress (C.MethodEntry entry, TargetBinaryReader 
reader,
+               public MethodAddress (TargetBinaryReader reader,
                                      AddressDomain domain, Architecture arch)
                {
                        // here we read the MonoDebugMethodAddress structure
                        // as written out in mono_debug_add_method.
                        reader.Position = 16;
-                       int code_size = reader.ReadInt32 ();
-                       reader.Position += 4;
+                       ReadAddress (reader, domain); // method
                        StartAddress = ReadAddress (reader, domain);
-                       EndAddress = StartAddress + code_size;
                        WrapperAddress = ReadAddress (reader, domain);
-                       ReadAddress (reader, domain);
+                       int code_size = reader.ReadInt32 ();
 
+                       EndAddress = StartAddress + code_size;
+
                        MethodStartAddress = StartAddress + reader.ReadLeb128 
();
                        MethodEndAddress = StartAddress + reader.ReadLeb128 ();
 
@@ -347,21 +347,24 @@
                        get { return File != null; }
                }
 
-               internal void AddRangeEntry (TargetReader reader, byte[] 
contents)
+               internal void AddRangeEntry (TargetMemoryAccess memory, 
TargetReader reader,
+                                            byte[] contents)
                {
-                       MethodRangeEntry range = MethodRangeEntry.Create (this, 
reader, contents);
-                       if (!range_hash.Contains (range.Index)) {
-                               range_hash.Add (range.Index, range);
+                       RangeEntry range = RangeEntry.Create (this, memory, 
reader, contents);
+                       if (!range_hash.Contains (range.Hash)) {
+                               range_hash.Add (range.Hash, range);
                                ranges.Add (range);
                        }
                }
 
+#if FIXME
                internal void AddWrapperEntry (TargetMemoryAccess memory, 
TargetReader reader,
                                               byte[] contents)
                {
                        WrapperEntry wrapper = WrapperEntry.Create (this, 
memory, reader, contents);
                        wrappers.Add (wrapper);
                }
+#endif
 
                public TargetType LookupMonoType (Cecil.TypeReference type)
                {
@@ -419,7 +422,7 @@
 
                public override Symbol SimpleLookup (TargetAddress address, 
bool exact_match)
                {
-                       foreach (MethodRangeEntry range in ranges) {
+                       foreach (RangeEntry range in ranges) {
                                if ((address < range.StartAddress) || (address 
> range.EndAddress))
                                        continue;
 
@@ -432,6 +435,7 @@
                                        method.Name, range.StartAddress, (int) 
offset);
                        }
 
+#if FIXME
                        foreach (WrapperEntry wrapper in wrappers) {
                                if ((address < wrapper.StartAddress) || 
(address > wrapper.EndAddress))
                                        continue;
@@ -443,6 +447,7 @@
                                return new Symbol (
                                        wrapper.Name, wrapper.StartAddress, 
(int) offset);
                        }
+#endif
 
                        return null;
                }
@@ -546,8 +551,10 @@
                        return GetMethodSource (entry.Index);
                }
 
-               Hashtable method_hash = new Hashtable ();
+               Hashtable method_hash = Hashtable.Synchronized (new Hashtable 
());
+               Hashtable wrapper_hash = Hashtable.Synchronized (new Hashtable 
());
 
+#if FIXME
                public override Method GetMethod (int domain, long handle)
                {
                        MethodHashEntry index = new MethodHashEntry (domain, 
(int) handle);
@@ -557,6 +564,7 @@
 
                        return entry.GetMethod ();
                }
+#endif
 
                public override MethodSource[] GetMethods (SourceFile file)
                {
@@ -679,6 +687,7 @@
                        return GetMethodByToken (token);
                }
 
+#if FIXME
                internal Method GetMonoMethod (MethodSource source, int domain)
                {
                        return GetMonoMethod ((MonoMethodSource) source, 
domain);
@@ -706,15 +715,22 @@
                        method.Load (reader, TargetInfo.AddressDomain);
                        return method;
                }
+#endif
 
-               protected MonoMethod GetMonoMethod (MethodHashEntry index, 
byte[] contents)
+               public Method GetMonoMethod (TargetAddress method, int domain, 
int index, byte[] contents)
                {
+                       MethodHashEntry hash = new MethodHashEntry (method, 
domain);
+                       return GetMonoMethod (hash, index, contents);
+               }
+
+               protected MonoMethod GetMonoMethod (MethodHashEntry hash, int 
index, byte[] contents)
+               {
                        ensure_sources ();
-                       MonoMethod method = (MonoMethod) method_hash [index];
+                       MonoMethod method = (MonoMethod) method_hash [hash];
                        if (method == null) {
-                               MonoMethodSource source = GetMethodSource 
(index.Index);
+                               MonoMethodSource source = GetMethodSource 
(index);
                                method = new MonoMethod (this, source, 
source.Entry, source.Method);
-                               method_hash.Add (index, method);
+                               method_hash.Add (hash, method);
                        }
 
                        if (!method.IsLoaded) {
@@ -725,6 +741,23 @@
                        return method;
                }
 
+               protected WrapperMethod GetWrapperMethod (MethodHashEntry hash, 
WrapperEntry wrapper,
+                                                         byte[] contents)
+               {
+                       WrapperMethod method = (WrapperMethod) wrapper_hash 
[hash];
+                       if (method == null) {
+                               method = new WrapperMethod (this, wrapper);
+                               wrapper_hash.Add (hash, method);
+                       }
+
+                       if (!method.IsLoaded) {
+                               TargetBinaryReader reader = new 
TargetBinaryReader (contents, TargetInfo);
+                               method.Load (reader, TargetInfo.AddressDomain);
+                       }
+
+                       return method;
+               }
+
                internal MonoFunctionType GetFunctionType (string class_name, 
int token)
                {
                        MonoClassType klass = null;
@@ -838,9 +871,8 @@
                                get { return mdef; }
                        }
 
-                       public override Method GetMethod (int domain)
-                       {
-                               return file.GetMonoMethod (this, domain);
+                       public override Method NativeMethod {
+                               get { throw new InvalidOperationException (); }
                        }
                }
 
@@ -899,7 +931,7 @@
                                is_loaded = true;
 
                                address = new MethodAddress (
-                                       method, dynamic_reader, domain, 
file.Architecture);
+                                       dynamic_reader, domain, 
file.Architecture);
 
                                SetAddresses (address.StartAddress, 
address.EndAddress);
                                SetMethodBounds (address.MethodStartAddress, 
address.MethodEndAddress);
@@ -1150,62 +1182,90 @@
 
                private struct MethodHashEntry
                {
+                       public readonly TargetAddress Method;
                        public readonly int Domain;
-                       public readonly int Index;
 
-                       public MethodHashEntry (int domain, int index)
+                       public MethodHashEntry (TargetAddress method, int 
domain)
                        {
+                               this.Method = method;
                                this.Domain = domain;
-                               this.Index = index;
                        }
 
                        public override string ToString ()
                        {
-                               return String.Format ("MethodHashEntry 
({0}:{1:x})", Domain, Index);
+                               return String.Format ("MethodHashEntry 
({0}:{1})", Method, Domain);
                        }
                }
 
-               private class MethodRangeEntry : SymbolRangeEntry
+               private class RangeEntry : SymbolRangeEntry
                {
                        public readonly MonoSymbolFile File;
-                       public readonly MethodHashEntry Index;
-                       public readonly TargetAddress WrapperAddress;
+                       public readonly MethodHashEntry Hash;
+                       public readonly int Index;
+                       public readonly WrapperEntry Wrapper;
                        public readonly byte[] Contents;
 
-                       private MethodRangeEntry (MonoSymbolFile file, int 
domain, int index,
-                                                 TargetAddress start_address, 
TargetAddress end_address,
-                                                 TargetAddress 
wrapper_address, byte[] contents)
+                       private RangeEntry (MonoSymbolFile file, int domain, 
int index,
+                                           WrapperEntry wrapper, TargetAddress 
method,
+                                           TargetAddress start_address, 
TargetAddress end_address,
+                                           byte[] contents)
                                : base (start_address, end_address)
                        {
                                this.File = file;
-                               this.Index = new MethodHashEntry (domain, 
index);
-                               this.WrapperAddress = wrapper_address;
+                               this.Index = index;
+                               this.Hash = new MethodHashEntry (method, 
domain);
+                               this.Wrapper = wrapper;
                                this.Contents = contents;
                        }
 
-                       public static MethodRangeEntry Create (MonoSymbolFile 
file, TargetReader reader,
-                                                              byte[] contents)
+                       public static RangeEntry Create (MonoSymbolFile file, 
TargetMemoryAccess memory,
+                                                        TargetReader reader, 
byte[] contents)
                        {
                                int domain = reader.BinaryReader.ReadInt32 ();
                                int index = reader.BinaryReader.ReadInt32 ();
-                               int size = reader.BinaryReader.ReadInt32 ();
-                               reader.BinaryReader.ReadInt32 (); /* dummy */
-                               TargetAddress start = reader.ReadAddress ();
-                               TargetAddress end = start + size;
-                               TargetAddress wrapper = reader.ReadAddress ();
 
-                               return new MethodRangeEntry (
-                                       file, domain, index, start, end, 
wrapper, contents);
+                               TargetAddress method = reader.ReadAddress ();
+                               TargetAddress code_start = reader.ReadAddress 
();
+                               TargetAddress wrapper_data = reader.ReadAddress 
();
+                               int code_size = reader.BinaryReader.ReadInt32 
();
+
+                               WrapperEntry wrapper = null;
+
+                               if (!wrapper_data.IsNull) {
+                                       int wrapper_size = 4 + 3 * 
memory.TargetInfo.TargetAddressSize;
+
+                                       TargetReader wrapper_reader = new 
TargetReader (
+                                               memory.ReadMemory 
(wrapper_data, wrapper_size));
+
+                                       TargetAddress wrapper_addr = 
wrapper_reader.ReadAddress ();
+                                       TargetAddress name_address = 
wrapper_reader.ReadAddress ();
+                                       TargetAddress cil_address = 
wrapper_reader.ReadAddress ();
+
+                                       string name = "<" + memory.ReadString 
(name_address) + ">";
+                                       string cil_code = memory.ReadString 
(cil_address);
+
+                                       int wrapper_type = 
reader.BinaryReader.ReadInt32 ();
+
+                                       wrapper = new WrapperEntry (
+                                               wrapper_addr, (WrapperType) 
wrapper_type, name, cil_code);
+                               }
+
+                               return new RangeEntry (
+                                       file, domain, index, wrapper, method,
+                                       code_start, code_start + code_size, 
contents);
                        }
 
                        internal Method GetMethod ()
                        {
-                               return File.GetMonoMethod (Index, Contents);
+                               if (Wrapper != null)
+                                       return File.GetWrapperMethod (Hash, 
Wrapper, Contents);
+                               else
+                                       return File.GetMonoMethod (Hash, Index, 
Contents);
                        }
 
                        protected override ISymbolLookup GetSymbolLookup ()
                        {
-                               return File.GetMonoMethod (Index, Contents);
+                               return GetMethod ();
                        }
 
                        public override string ToString ()
@@ -1215,96 +1275,41 @@
                        }
                }
 
-               private class WrapperEntry : SymbolRangeEntry
+               private class WrapperEntry
                {
-                       public readonly MonoSymbolFile File;
                        public readonly TargetAddress WrapperMethod;
-                       public readonly TargetAddress MethodStartAddress;
-                       public readonly TargetAddress MethodEndAddress;
                        public readonly WrapperType WrapperType;
                        public readonly string Name;
                        public readonly string CILCode;
-                       public readonly JitLineNumberEntry[] LineNumbers;
                        WrapperMethod method;
 
-                       private WrapperEntry (MonoSymbolFile file, 
TargetAddress method, string name,
-                                             TargetAddress code_start, int 
code_size,
-                                             TargetAddress prologue_end, 
TargetAddress epilogue_begin,
-                                             WrapperType wrapper_type, string 
cil_code,
-                                             JitLineNumberEntry[] line_numbers)
-                               : base (code_start, code_start + code_size)
+                       public WrapperEntry (TargetAddress wrapper_method, 
WrapperType wrapper_type,
+                                            string name, string cil_code)
                        {
-                               this.File = file;
-                               this.WrapperMethod = method;
-                               this.MethodStartAddress = prologue_end;
-                               this.MethodEndAddress = epilogue_begin;
+                               this.WrapperMethod = wrapper_method;
                                this.WrapperType = wrapper_type;
                                this.Name = name;
                                this.CILCode = cil_code;
-                               this.LineNumbers = line_numbers;
                        }
-
-                       public static WrapperEntry Create (MonoSymbolFile file, 
TargetMemoryAccess memory,
-                                                          TargetReader reader, 
byte[] contents)
-                       {
-                               int size = reader.BinaryReader.ReadInt32 ();
-                               TargetAddress wrapper = reader.ReadAddress ();
-                               TargetAddress code = reader.ReadAddress ();
-
-                               TargetAddress name_address = reader.ReadAddress 
();
-                               TargetAddress cil_address = reader.ReadAddress 
();
-
-                               string name = "<" + memory.ReadString 
(name_address) + ">";
-                               string cil_code = memory.ReadString 
(cil_address);
-
-                               TargetAddress prologue_end = code + 
reader.BinaryReader.ReadLeb128 ();
-                               TargetAddress epilogue_begin = code + 
reader.BinaryReader.ReadLeb128 ();
-
-                               int num_line_numbers = 
reader.BinaryReader.ReadLeb128 ();
-                               JitLineNumberEntry[] lines = new 
JitLineNumberEntry [num_line_numbers];
-
-                               int il_offset = 0, native_offset = 0;
-                               for (int i = 0; i < num_line_numbers; i++) {
-                                       il_offset += 
reader.BinaryReader.ReadSLeb128 ();
-                                       native_offset += 
reader.BinaryReader.ReadSLeb128 ();
-
-                                       lines [i] = new JitLineNumberEntry 
(il_offset, native_offset);
-                               }
-
-                               int wrapper_type = 
reader.BinaryReader.ReadLeb128 ();
-
-                               return new WrapperEntry (
-                                       file, wrapper, name, code, size, 
prologue_end, epilogue_begin,
-                                       (WrapperType) wrapper_type, cil_code, 
lines);
-                       }
-
-                       protected override ISymbolLookup GetSymbolLookup ()
-                       {
-                               if (method != null)
-                                       return method;
-
-                               method = new WrapperMethod (this);
-                               return method;
-                       }
-
                        public override string ToString ()
                        {
-                               return String.Format ("WrapperEntry 
[{0:x}:{3}:{1:x}:{2:x}]",
-                                                     WrapperMethod, 
StartAddress, EndAddress, Name);
+                               return String.Format ("WrapperEntry 
[{0:x}:{1}:{2}:{3}]",
+                                                     WrapperMethod, 
WrapperType, Name, CILCode);
                        }
                }
 
                protected class WrapperMethod : Method
                {
+                       public readonly MonoSymbolFile File;
                        public readonly WrapperEntry Entry;
+                       bool is_loaded;
+                       MethodAddress address;
 
-                       public WrapperMethod (WrapperEntry entry)
-                               : base (entry.Name, entry.File.ImageFile, 
entry.File.Module,
-                                       entry.StartAddress, entry.EndAddress)
+                       public WrapperMethod (MonoSymbolFile file, WrapperEntry 
entry)
+                               : base (entry.Name, file.ImageFile, file.Module)
                        {
+                               this.File = file;
                                this.Entry = entry;
-                               SetMethodBounds (entry.MethodStartAddress, 
entry.MethodEndAddress);
-                               SetLineNumbers (new WrapperLineNumberTable 
(this));
                                SetWrapperType (entry.WrapperType);
                        }
 
@@ -1348,21 +1353,38 @@
                                get { return null; }
                        }
 
+                       public void Load (TargetBinaryReader dynamic_reader, 
AddressDomain domain)
+                       {
+                               if (is_loaded)
+                                       throw new InternalError ();
+
+                               is_loaded = true;
+
+                               address = new MethodAddress (
+                                       dynamic_reader, domain, 
File.Architecture);
+
+                               SetAddresses (address.StartAddress, 
address.EndAddress);
+                               SetMethodBounds (address.MethodStartAddress, 
address.MethodEndAddress);
+                               SetLineNumbers (new WrapperLineNumberTable 
(this, address));
+                       }
+
                        internal override MethodSource GetTrampoline 
(TargetMemoryAccess memory,
                                                                      
TargetAddress address)
                        {
-                               return Entry.File.LanguageBackend.GetTrampoline 
(memory, address);
+                               return File.LanguageBackend.GetTrampoline 
(memory, address);
                        }
                }
 
                protected class WrapperLineNumberTable : LineNumberTable
                {
                        WrapperMethod wrapper;
+                       MethodAddress address;
 
-                       public WrapperLineNumberTable (WrapperMethod wrapper)
+                       public WrapperLineNumberTable (WrapperMethod wrapper, 
MethodAddress address)
                                : base (wrapper, true)
                        {
                                this.wrapper = wrapper;
+                               this.address = address;
                        }
 
                        void generate_line_number (ArrayList lines, 
TargetAddress address, int offset,
@@ -1388,7 +1410,7 @@
                                ArrayList lines = new ArrayList ();
                                int last_line = -1;
 
-                               JitLineNumberEntry[] line_numbers = 
wrapper.Entry.LineNumbers;
+                               JitLineNumberEntry[] line_numbers = 
address.LineNumbers;
 
                                string[] cil_code = wrapper.Entry.CILCode.Split 
('\n');
                                SourceBuffer buffer = new SourceBuffer 
(wrapper.Name, cil_code);
@@ -1421,9 +1443,8 @@
 
                                return new LineNumberTableData (
                                        1, cil_code.Length, addresses, null, 
buffer,
-                                       wrapper.Entry.File.Module);
+                                       wrapper.File.Module);
                        }
-
                }
 
                protected struct TypeHashEntry

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to