Author: martin
Date: 2007-05-16 12:07:41 -0400 (Wed, 16 May 2007)
New Revision: 77486

Modified:
   trunk/debugger/ChangeLog
   trunk/debugger/backend/BreakpointHandle.cs
   trunk/debugger/classes/AddressBreakpoint.cs
   trunk/debugger/classes/Breakpoint.cs
   trunk/debugger/classes/DebuggerSession.cs
   trunk/debugger/classes/ExpressionBreakpoint.cs
   trunk/debugger/classes/SourceBreakpoint.cs
   trunk/debugger/classes/SourceLocation.cs
Log:
2007-05-16  Martin Baulig  <[EMAIL PROTECTED]>

        * classes/Breakpoint.cs
        (Breakpoint.Resolve): New abstract internal method.

        * classes/SourceLocation.cs
        (SourceLocation.InsertBreakpoint): Renamed into
        ResolveBreakpoint(); don't take a `Thread' argument.  You need to
        call Insert() on the returned `BreakpointHandle' to actually
        insert the breakpoint.

        * backend/BreakpointHandle.cs
        (BreakpointHandle.Insert): New public abstract method; we need to
        call this to actually insert the breakpoint.
        (AddressBreakpointHandle): New internal class.



Modified: trunk/debugger/ChangeLog
===================================================================
--- trunk/debugger/ChangeLog    2007-05-16 15:41:03 UTC (rev 77485)
+++ trunk/debugger/ChangeLog    2007-05-16 16:07:41 UTC (rev 77486)
@@ -1,3 +1,19 @@
+2007-05-16  Martin Baulig  <[EMAIL PROTECTED]>
+
+       * classes/Breakpoint.cs
+       (Breakpoint.Resolve): New abstract internal method.
+
+       * classes/SourceLocation.cs
+       (SourceLocation.InsertBreakpoint): Renamed into
+       ResolveBreakpoint(); don't take a `Thread' argument.  You need to
+       call Insert() on the returned `BreakpointHandle' to actually
+       insert the breakpoint.
+
+       * backend/BreakpointHandle.cs
+       (BreakpointHandle.Insert): New public abstract method; we need to
+       call this to actually insert the breakpoint.
+       (AddressBreakpointHandle): New internal class.
+
 2007-05-09  Martin Baulig  <[EMAIL PROTECTED]>
 
        Released version 0.50 "Dublin" of the Mono Debugger :-)

Modified: trunk/debugger/backend/BreakpointHandle.cs
===================================================================
--- trunk/debugger/backend/BreakpointHandle.cs  2007-05-16 15:41:03 UTC (rev 
77485)
+++ trunk/debugger/backend/BreakpointHandle.cs  2007-05-16 16:07:41 UTC (rev 
77486)
@@ -11,6 +11,8 @@
                        this.Breakpoint = breakpoint;
                }
 
+               public abstract void Insert (Thread target);
+
                public abstract void Remove (Thread target);
        }
 
@@ -24,6 +26,11 @@
                        this.index = index;
                }
 
+               public override void Insert (Thread target)
+               {
+                       throw new InternalError ();
+               }
+
                public override void Remove (Thread target)
                {
                        if (index > 0)
@@ -31,4 +38,28 @@
                        index = -1;
                }
        }
+
+       internal class AddressBreakpointHandle : BreakpointHandle
+       {
+               public readonly TargetAddress Address;
+               int index = -1;
+
+               public AddressBreakpointHandle (Breakpoint breakpoint, 
TargetAddress address)
+                       : base (breakpoint)
+               {
+                       this.Address = address;
+               }
+
+               public override void Insert (Thread target)
+               {
+                       index = target.InsertBreakpoint (Breakpoint, Address);
+               }
+
+               public override void Remove (Thread target)
+               {
+                       if (index > 0)
+                               target.RemoveBreakpoint (index);
+                       index = -1;
+               }
+       }
 }

Modified: trunk/debugger/classes/AddressBreakpoint.cs
===================================================================
--- trunk/debugger/classes/AddressBreakpoint.cs 2007-05-16 15:41:03 UTC (rev 
77485)
+++ trunk/debugger/classes/AddressBreakpoint.cs 2007-05-16 16:07:41 UTC (rev 
77486)
@@ -34,6 +34,28 @@
                        get { return handle != null; }
                }
 
+               internal override BreakpointHandle Resolve (Thread target)
+               {
+                       if (handle != null)
+                               return handle;
+
+                       switch (Type) {
+                       case EventType.Breakpoint:
+                               handle = new AddressBreakpointHandle (this, 
address);
+                               break;
+
+                       case EventType.WatchRead:
+                       case EventType.WatchWrite:
+                               handle = new AddressBreakpointHandle (this, 
address);
+                               break;
+
+                       default:
+                               throw new InternalError ();
+                       }
+
+                       return handle;
+               }
+
                public override void Activate (Thread target)
                {
                        if (handle != null)

Modified: trunk/debugger/classes/Breakpoint.cs
===================================================================
--- trunk/debugger/classes/Breakpoint.cs        2007-05-16 15:41:03 UTC (rev 
77485)
+++ trunk/debugger/classes/Breakpoint.cs        2007-05-16 16:07:41 UTC (rev 
77486)
@@ -17,6 +17,8 @@
        // </summary>
        public abstract class Breakpoint : Event
        {
+               internal abstract BreakpointHandle Resolve (Thread target);
+
                public override void Remove (Thread target)
                {
                        Deactivate (target);

Modified: trunk/debugger/classes/DebuggerSession.cs
===================================================================
--- trunk/debugger/classes/DebuggerSession.cs   2007-05-16 15:41:03 UTC (rev 
77485)
+++ trunk/debugger/classes/DebuggerSession.cs   2007-05-16 16:07:41 UTC (rev 
77486)
@@ -207,6 +207,14 @@
                        return parser.Parse (target, type, name);
                }
 
+               public SourceFile FindFile (string name)
+               {
+                       if (main_process == null)
+                               return null;
+
+                       return main_process.FindFile (name);
+               }
+
                //
                // Session management.
                //

Modified: trunk/debugger/classes/ExpressionBreakpoint.cs
===================================================================
--- trunk/debugger/classes/ExpressionBreakpoint.cs      2007-05-16 15:41:03 UTC 
(rev 77485)
+++ trunk/debugger/classes/ExpressionBreakpoint.cs      2007-05-16 16:07:41 UTC 
(rev 77486)
@@ -19,18 +19,27 @@
                        get { return handle != null; }
                }
 
-               public override void Activate (Thread target)
+               internal override BreakpointHandle Resolve (Thread target)
                {
                        if (handle != null)
-                               return;
+                               return handle;
 
                        SourceLocation location = Session.ParseLocation 
(target, LocationType, Name);
                        if (location == null)
                                throw new TargetException 
(TargetError.LocationInvalid);
 
-                       handle = location.InsertBreakpoint (Session, target, 
this, domain);
+                       handle = location.ResolveBreakpoint (Session, this, 
domain);
+                       return handle;
                }
 
+               public override void Activate (Thread target)
+               {
+                       Resolve (target);
+                       if (handle == null)
+                               throw new TargetException 
(TargetError.LocationInvalid);
+                       handle.Insert (target);
+               }
+
                public override void Deactivate (Thread target)
                {
                        if (handle != null) {
@@ -44,14 +53,6 @@
                        handle = null;
                }
 
-               internal Breakpoint Clone (int breakpoint_id)
-               {
-                       ExpressionBreakpoint new_bpt = new ExpressionBreakpoint 
(
-                               Session, GetNextEventIndex (), ThreadGroup, 
LocationType, Name);
-                       new_bpt.handle = new SimpleBreakpointHandle (new_bpt, 
breakpoint_id);
-                       return new_bpt;
-               }
-
                protected override void GetSessionData (XmlElement root, 
XmlElement element)
                {
                        XmlElement location_e = 
root.OwnerDocument.CreateElement ("Expression");

Modified: trunk/debugger/classes/SourceBreakpoint.cs
===================================================================
--- trunk/debugger/classes/SourceBreakpoint.cs  2007-05-16 15:41:03 UTC (rev 
77485)
+++ trunk/debugger/classes/SourceBreakpoint.cs  2007-05-16 16:07:41 UTC (rev 
77486)
@@ -56,14 +56,23 @@
                        get { return handle != null; }
                }
 
-               public override void Activate (Thread target)
+               internal override BreakpointHandle Resolve (Thread target)
                {
                        if (handle != null)
-                               return;
+                               return handle;
 
-                       handle = location.InsertBreakpoint (session, target, 
this, domain);
+                       handle = location.ResolveBreakpoint (session, this, 
domain);
+                       return handle;
                }
 
+               public override void Activate (Thread target)
+               {
+                       Resolve (target);
+                       if (handle == null)
+                               throw new TargetException 
(TargetError.LocationInvalid);
+                       handle.Insert (target);
+               }
+
                public override void Deactivate (Thread target)
                {
                        if (handle != null) {

Modified: trunk/debugger/classes/SourceLocation.cs
===================================================================
--- trunk/debugger/classes/SourceLocation.cs    2007-05-16 15:41:03 UTC (rev 
77485)
+++ trunk/debugger/classes/SourceLocation.cs    2007-05-16 16:07:41 UTC (rev 
77486)
@@ -85,7 +85,7 @@
                        dynamic.DumpLineNumbers ();
                }
 
-               protected bool Resolve (DebuggerSession session, Thread target)
+               protected bool Resolve (DebuggerSession session)
                {
                        if (dynamic != null)
                                return true;
@@ -115,7 +115,7 @@
 
                                string filename = FileName.Substring (0, pos);
 
-                               SourceFile file = target.Process.FindFile 
(filename);
+                               SourceFile file = session.FindFile (filename);
                                if (file == null)
                                        return false;
 
@@ -126,14 +126,13 @@
                        return false;
                }
 
-               internal BreakpointHandle InsertBreakpoint (DebuggerSession 
session,
-                                                           Thread target, 
Breakpoint breakpoint,
-                                                           int domain)
+               internal BreakpointHandle ResolveBreakpoint (DebuggerSession 
session,
+                                                            Breakpoint 
breakpoint, int domain)
                {
-                       if (!Resolve (session, target))
+                       if (!Resolve (session))
                                throw new TargetException 
(TargetError.LocationInvalid);
 
-                       return dynamic.InsertBreakpoint (target, breakpoint, 
domain);
+                       return dynamic.ResolveBreakpoint (breakpoint, domain);
                }
 
                internal void OnTargetExited ()
@@ -251,11 +250,10 @@
                        method.Source.DumpLineNumbers ();
                }
 
-               internal BreakpointHandle InsertBreakpoint (Thread target, 
Breakpoint breakpoint,
-                                                           int domain)
+               internal BreakpointHandle ResolveBreakpoint (Breakpoint 
breakpoint, int domain)
                {
                        if (!module.IsLoaded)
-                               return new ModuleBreakpointHandle (breakpoint, 
this);
+                               return new ModuleBreakpointHandle (breakpoint, 
module);
 
                        if ((function == null) && (source == null)) {
                                if (method != null) {
@@ -279,12 +277,10 @@
                                if (line > 0)
                                        source = function.Source;
                                else if (function.IsLoaded) {
-                                       int index = target.InsertBreakpoint 
(breakpoint, function);
-                                       return new SimpleBreakpointHandle 
(breakpoint, index);
+                                       return new FunctionBreakpointHandle 
(breakpoint, domain, this);
                                } else {
                                        source = function.Source;
-                                       return new FunctionBreakpointHandle (
-                                               target, breakpoint, domain, 
this);
+                                       return new FunctionBreakpointHandle 
(breakpoint, domain, this);
                                }
                        }
 
@@ -293,15 +289,13 @@
 
                        TargetAddress address = GetAddress (domain);
                        if (!address.IsNull) {
-                               int index = target.InsertBreakpoint 
(breakpoint, address);
-                               return new SimpleBreakpointHandle (breakpoint, 
index);
+                               return new AddressBreakpointHandle (breakpoint, 
address);
                        } else if (source.IsDynamic) {
                                // A dynamic method is a method which may emit a
                                // callback when it's loaded.  We register this
                                // callback here and do the actual insertion 
when
                                // the method is loaded.
-                               return new FunctionBreakpointHandle (
-                                       target, breakpoint, domain, this);
+                               return new FunctionBreakpointHandle 
(breakpoint, domain, this);
                        }
 
                        return null;
@@ -327,44 +321,58 @@
                                return method.StartAddress;
                }
 
-               private class ModuleBreakpointHandle : BreakpointHandle
+               class ModuleBreakpointHandle : BreakpointHandle
                {
-                       DynamicSourceLocation location;
+                       Module module;
 
-                       public ModuleBreakpointHandle (Breakpoint bpt, 
DynamicSourceLocation location)
+                       public ModuleBreakpointHandle (Breakpoint bpt, Module 
module)
                                : base (bpt)
                        {
-                               this.location = location;
-
-                               location.module.ModuleLoadedEvent += 
module_loaded;
+                               this.module = module;
                        }
 
                        void module_loaded (Module module)
                        {
-                               Console.WriteLine ("MODULE LOADED: {0} {1}", 
module, location);
+                               Console.WriteLine ("MODULE LOADED: {0} {1}", 
module);
                        }
 
+                       public override void Insert (Thread target)
+                       {
+                               module.ModuleLoadedEvent += module_loaded;
+                       }
+
                        public override void Remove (Thread target)
                        {
-                               location.module.ModuleLoadedEvent -= 
module_loaded;
+                               module.ModuleLoadedEvent -= module_loaded;
                        }
                }
 
-               private class FunctionBreakpointHandle : BreakpointHandle
+               class FunctionBreakpointHandle : BreakpointHandle
                {
+                       DynamicSourceLocation location;
                        ILoadHandler load_handler;
                        int index = -1;
                        int domain;
 
-                       public FunctionBreakpointHandle (Thread target, 
Breakpoint bpt, int domain,
+                       public FunctionBreakpointHandle (Breakpoint bpt, int 
domain,
                                                         DynamicSourceLocation 
location)
 
                                : base (bpt)
                        {
+                               this.location = location;
                                this.domain = domain;
+                       }
 
-                               load_handler = 
location.module.SymbolFile.RegisterLoadHandler (
-                                       target, location.source, method_loaded, 
location);
+                       public override void Insert (Thread target)
+                       {
+                               if ((load_handler != null) || (index > 0))
+                                       return;
+
+                               if ((location.function != null) && 
location.function.IsLoaded)
+                                       index = target.InsertBreakpoint 
(Breakpoint, location.function);
+                               else
+                                       load_handler = 
location.module.SymbolFile.RegisterLoadHandler (
+                                               target, location.source, 
method_loaded, location);
                        }
 
                        public override void Remove (Thread target)

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

Reply via email to