Author: martin
Date: 2007-02-16 13:36:06 -0500 (Fri, 16 Feb 2007)
New Revision: 73038

Modified:
   trunk/debugger/ChangeLog
   trunk/debugger/classes/Breakpoint.cs
   trunk/debugger/classes/DebuggerConfiguration.xsd
   trunk/debugger/classes/DebuggerSession.cs
   trunk/debugger/classes/Event.cs
   trunk/debugger/classes/ExceptionCatchPoint.cs
   trunk/debugger/classes/SourceLocation.cs
   trunk/debugger/frontend/Command.cs
   trunk/debugger/frontend/Interpreter.cs
   trunk/debugger/frontend/ScriptingContext.cs
   trunk/debugger/test/testsuite/NUnit.cs
   trunk/debugger/test/testsuite/TestExec.cs
Log:
2007-02-16  Martin Baulig  <[EMAIL PROTECTED]>

        Session changes: keep the `DebuggerSession' in memory between
        different invocations of the same target; this allows us to modify
        breakpoints before starting the target.

        * classes/DebuggerSession.cs
        (DebuggerSession.SessionData): Removed the nested class.

        * classes/Event.cs
        (Event.IsEnabled): Added a setter for this property.

        * classes/SourceLocation.cs
        (SourceLocation): Splitted into `SourceLocation' and
        `DynamicSourceLocation'; the `SourceLocation' can now persist
        across different invocations of the same target.



Modified: trunk/debugger/ChangeLog
===================================================================
--- trunk/debugger/ChangeLog    2007-02-16 18:28:37 UTC (rev 73037)
+++ trunk/debugger/ChangeLog    2007-02-16 18:36:06 UTC (rev 73038)
@@ -1,3 +1,20 @@
+2007-02-16  Martin Baulig  <[EMAIL PROTECTED]>
+
+       Session changes: keep the `DebuggerSession' in memory between
+       different invocations of the same target; this allows us to modify
+       breakpoints before starting the target.
+
+       * classes/DebuggerSession.cs
+       (DebuggerSession.SessionData): Removed the nested class.
+
+       * classes/Event.cs
+       (Event.IsEnabled): Added a setter for this property.
+
+       * classes/SourceLocation.cs
+       (SourceLocation): Splitted into `SourceLocation' and
+       `DynamicSourceLocation'; the `SourceLocation' can now persist
+       across different invocations of the same target.
+
 2007-02-13  Martin Baulig  <[EMAIL PROTECTED]>
 
        * test/testsuite/NUnit.cs: Run the tests in the invariant culture;

Modified: trunk/debugger/classes/Breakpoint.cs
===================================================================
--- trunk/debugger/classes/Breakpoint.cs        2007-02-16 18:28:37 UTC (rev 
73037)
+++ trunk/debugger/classes/Breakpoint.cs        2007-02-16 18:36:06 UTC (rev 
73038)
@@ -19,6 +19,7 @@
        public class Breakpoint : Event
        {
                BreakpointHandle handle;
+               DebuggerSession session;
                SourceLocation location;
                BreakpointType type;
                TargetAddress address = TargetAddress.Null;
@@ -32,10 +33,6 @@
                        get { return location; }
                }
 
-               public override bool IsEnabled {
-                       get { return handle != null; }
-               }
-
                public override void Enable (Thread target)
                {
                        if (handle != null)
@@ -47,7 +44,9 @@
                                        int breakpoint_id = 
target.InsertBreakpoint (this, address);
                                        handle = new SimpleBreakpointHandle 
(this, breakpoint_id);
                                } else if (location != null)
-                                       handle = location.InsertBreakpoint 
(target, this, domain);
+                                       handle = location.InsertBreakpoint 
(session, target, this, domain);
+                               else
+                                       throw new TargetException 
(TargetError.LocationInvalid);
                                break;
 
                        case BreakpointType.WatchRead:
@@ -76,6 +75,8 @@
 
                internal override void OnTargetExited ()
                {
+                       if (location != null)
+                               location.OnTargetExited ();
                        handle = null;
                }
 
@@ -88,7 +89,7 @@
 
                protected virtual Breakpoint Clone ()
                {
-                       return new Breakpoint (GetNextEventIndex (), 
ThreadGroup, location);
+                       return new Breakpoint (session, GetNextEventIndex (), 
ThreadGroup, location);
                }
 
                // <summary>
@@ -132,16 +133,20 @@
                        location.GetSessionData (location_e);
                }               
 
-               internal Breakpoint (int index, ThreadGroup group, 
SourceLocation location)
+               internal Breakpoint (DebuggerSession session, int index, 
ThreadGroup group,
+                                    SourceLocation location)
                        : base (index, location.Name, group)
                {
+                       this.session = session;
                        this.location = location;
                        this.type = BreakpointType.Breakpoint;
                }
 
-               internal Breakpoint (ThreadGroup group, SourceLocation location)
+               internal Breakpoint (DebuggerSession session, ThreadGroup group,
+                                    SourceLocation location)
                        : base (location.Name, group)
                {
+                       this.session = session;
                        this.location = location;
                        this.type = BreakpointType.Breakpoint;
                }

Modified: trunk/debugger/classes/DebuggerConfiguration.xsd
===================================================================
--- trunk/debugger/classes/DebuggerConfiguration.xsd    2007-02-16 18:28:37 UTC 
(rev 73037)
+++ trunk/debugger/classes/DebuggerConfiguration.xsd    2007-02-16 18:36:06 UTC 
(rev 73038)
@@ -61,6 +61,7 @@
   </xs:complexType>
   <xs:complexType name="Location">
     <xs:choice maxOccurs="unbounded">
+      <xs:element name="Name" type="xs:string" minOccurs="1" />
       <xs:element name="Module" type="xs:string" minOccurs="1" />
       <xs:element name="Method" type="xs:string" minOccurs="0" />
       <xs:element name="File" type="xs:string" minOccurs="0" />

Modified: trunk/debugger/classes/DebuggerSession.cs
===================================================================
--- trunk/debugger/classes/DebuggerSession.cs   2007-02-16 18:28:37 UTC (rev 
73037)
+++ trunk/debugger/classes/DebuggerSession.cs   2007-02-16 18:36:06 UTC (rev 
73038)
@@ -23,13 +23,22 @@
                public readonly DebuggerConfiguration Config;
                public readonly DebuggerOptions Options;
 
+               protected readonly Hashtable modules;
+               protected readonly Hashtable events;
+               protected readonly Hashtable thread_groups;
+               protected readonly ThreadGroup main_thread_group;
+
                XmlDocument saved_session;
-               SessionData data;
 
                private DebuggerSession (DebuggerConfiguration config, string 
name)
                {
                        this.Config = config;
                        this.Name = name;
+
+                       modules = Hashtable.Synchronized (new Hashtable ());
+                       events = Hashtable.Synchronized (new Hashtable ());
+                       thread_groups = Hashtable.Synchronized (new Hashtable 
());
+                       main_thread_group = CreateThreadGroup ("main");
                }
 
                public DebuggerSession (DebuggerConfiguration config, 
DebuggerOptions options, string name)
@@ -38,15 +47,6 @@
                        this.Options = options;
                }
 
-               protected SessionData Data {
-                       get {
-                               if (data == null)
-                                       throw new TargetException 
(TargetError.NoTarget);
-
-                               return data;
-                       }
-               }
-
                internal DebuggerSession Clone (DebuggerOptions new_options, 
string new_name)
                {
                        return new DebuggerSession (Config, new_options, 
new_name);
@@ -118,6 +118,8 @@
 
                        XPathNodeIterator options_iter = 
session_iter.Current.Select ("Options/*");
                        Options = new DebuggerOptions (options_iter);
+
+                       LoadSession (nav);
                }
 
                void AddThreadGroup (XmlElement root, ThreadGroup group)
@@ -128,91 +130,10 @@
                        root.AppendChild (element);
                }
 
-               //
-               // Modules.
-               //
-
-               public Module GetModule (string name)
-               {
-                       return Data.GetModule (name);
-               }
-
-               internal Module CreateModule (string name, ModuleGroup group)
-               {
-                       return Data.CreateModule (name, group);
-               }
-
-               internal Module CreateModule (string name, SymbolFile symfile)
-               {
-                       return Data.CreateModule (name, symfile);
-               }
-
-               public Module[] Modules {
-                       get { return Data.Modules; }
-               }
-
-               //
-               // Thread Groups
-               //
-
-               public ThreadGroup CreateThreadGroup (string name)
-               {
-                       return Data.CreateThreadGroup (name);
-               }
-
-               public void DeleteThreadGroup (string name)
-               {
-                       Data.DeleteThreadGroup (name);
-               }
-
-               public bool ThreadGroupExists (string name)
-               {
-                       return Data.ThreadGroupExists (name);
-               }
-
-               public ThreadGroup[] ThreadGroups {
-                       get { return Data.ThreadGroups; }
-               }
-
-               public ThreadGroup ThreadGroupByName (string name)
-               {
-                       return Data.ThreadGroupByName (name);
-               }
-
-               public ThreadGroup MainThreadGroup {
-                       get { return Data.MainThreadGroup; }
-               }
-
-               //
-               // Events
-               //
-
-               public Event[] Events {
-                       get { return Data.Events; }
-               }
-
-               public Event GetEvent (int index)
-               {
-                       return Data.GetEvent (index);
-               }
-
-               internal void AddEvent (Event handle)
-               {
-                       Data.AddEvent (handle);
-               }
-
-               public void DeleteEvent (Thread thread, Event handle)
-               {
-                       Data.DeleteEvent (thread, handle);
-               }
-
-               public Event InsertBreakpoint (Thread target, ThreadGroup 
group, int domain,
+               public Event InsertBreakpoint (Thread target, ThreadGroup group,
                                               SourceLocation location)
                {
-                       if (!location.HasMethod && !location.HasFunction)
-                               throw new TargetException 
(TargetError.LocationInvalid);
-
-                       Event handle = new Breakpoint (group, location);
+                       Event handle = new Breakpoint (this, group, location);
                        AddEvent (handle);
                        return handle;
                }
@@ -225,14 +146,6 @@
                        return handle;
                }
 
-               public Event InsertBreakpoint (Thread target, ThreadGroup group,
-                                              TargetFunctionType func)
-               {
-                       Event handle = new Breakpoint (group, new 
SourceLocation (func));
-                       AddEvent (handle);
-                       return handle;
-               }
-
                public Event InsertExceptionCatchPoint (Thread target, 
ThreadGroup group,
                                                        TargetType exception)
                {
@@ -262,234 +175,205 @@
                //
                public void MainProcessReachedMain (Process process)
                {
-                       if (saved_session == null)
-                               return;
-
-                       data.LoadSession (process, saved_session);
+                       foreach (Event e in events.Values) {
+                               e.Enable (process.MainThread);
+                       }
                }
 
                internal void OnProcessCreated (Process process)
                {
-                       data = new SessionData (this);
                }
 
                internal void OnProcessExited (Process process)
                {
-                       try {
-                               saved_session = SaveSession ();
-                       } finally {
-                               data = null;
+                       foreach (Event e in events.Values) {
+                               e.OnTargetExited ();
                        }
                }
 
-               protected class SessionData
+               protected void LoadSession (XPathNavigator nav)
                {
-                       public readonly DebuggerSession Session;
+                       XPathNodeIterator session_iter = nav.Select (
+                               "/DebuggerConfiguration/[EMAIL PROTECTED]'" + 
Name + "']");
+                       if (!session_iter.MoveNext ())
+                               throw new InternalError ();
 
-                       private readonly Hashtable modules;
-                       private readonly Hashtable events;
-                       private readonly Hashtable thread_groups;
-                       private readonly ThreadGroup main_thread_group;
+                       XPathNodeIterator group_iter = nav.Select (
+                               
"/DebuggerConfiguration/ModuleGroups/ModuleGroup");
+                       while (group_iter.MoveNext ()) {
+                               string name = group_iter.Current.GetAttribute 
("name", "");
+                               ModuleGroup group = Config.CreateModuleGroup 
(name);
 
-                       public SessionData (DebuggerSession session)
-                       {
-                               this.Session = session;
-
-                               modules = Hashtable.Synchronized (new Hashtable 
());
-                               events = Hashtable.Synchronized (new Hashtable 
());
-                               thread_groups = Hashtable.Synchronized (new 
Hashtable ());
-                               main_thread_group = CreateThreadGroup ("main");
+                               group.SetSessionData (group_iter);
                        }
 
-                       public void LoadSession (Process process, XmlDocument 
doc)
-                       {
-                               XPathNavigator nav = doc.CreateNavigator ();
+                       XPathNodeIterator modules_iter = 
session_iter.Current.Select ("Modules/*");
+                       while (modules_iter.MoveNext ()) {
+                               string name = modules_iter.Current.GetAttribute 
("name", "");
+                               string group = 
modules_iter.Current.GetAttribute ("group", "");
 
-                               XPathNodeIterator session_iter = nav.Select (
-                                       "/DebuggerConfiguration/[EMAIL 
PROTECTED]'" + Session.Name + "']");
-                               if (!session_iter.MoveNext ())
-                                       throw new InternalError ();
-
-                               XPathNodeIterator group_iter = nav.Select (
-                                       
"/DebuggerConfiguration/ModuleGroups/ModuleGroup");
-                               while (group_iter.MoveNext ()) {
-                                       string name = 
group_iter.Current.GetAttribute ("name", "");
-                                       ModuleGroup group = 
Session.Config.CreateModuleGroup (name);
-
-                                       group.SetSessionData (group_iter);
+                               Module module = (Module) modules [name];
+                               if (module == null) {
+                                       ModuleGroup mgroup = 
Config.GetModuleGroup (group);
+                                       module = new Module (mgroup, name, 
null);
+                                       modules.Add (name, module);
                                }
 
-                               XPathNodeIterator modules_iter = 
session_iter.Current.Select ("Modules/*");
-                               while (modules_iter.MoveNext ()) {
-                                       string name = 
modules_iter.Current.GetAttribute ("name", "");
-                                       string group = 
modules_iter.Current.GetAttribute ("group", "");
+                               module.SetSessionData (modules_iter);
+                       }
 
-                                       Module module = (Module) modules [name];
-                                       if (module == null) {
-                                               ModuleGroup mgroup = 
Session.Config.GetModuleGroup (group);
-                                               module = new Module (mgroup, 
name, null);
-                                               modules.Add (name, module);
-                                       }
+                       XPathNodeIterator event_iter = 
session_iter.Current.Select ("Events/*");
+                       while (event_iter.MoveNext ()) {
+                               if (event_iter.Current.Name != "Breakpoint")
+                                       throw new InternalError ();
 
-                                       module.SetSessionData (modules_iter);
-                               }
+                               int index = Int32.Parse 
(event_iter.Current.GetAttribute ("index", ""));
+                               bool enabled = Boolean.Parse 
(event_iter.Current.GetAttribute ("enabled", ""));
 
-                               XPathNodeIterator event_iter = 
session_iter.Current.Select ("Events/*");
-                               while (event_iter.MoveNext ()) {
-                                       if (event_iter.Current.Name != 
"Breakpoint")
-                                               throw new InternalError ();
+                               string gname = event_iter.Current.GetAttribute 
("threadgroup", "");
+                               ThreadGroup group;
+                               if (gname == "system")
+                                       group = ThreadGroup.System;
+                               else if (gname == "global")
+                                       group = ThreadGroup.Global;
+                               else
+                                       group = CreateThreadGroup (gname);
 
-                                       string name = 
event_iter.Current.GetAttribute ("name", "");
-                                       int index = Int32.Parse 
(event_iter.Current.GetAttribute ("index", ""));
-                                       bool enabled = Boolean.Parse 
(event_iter.Current.GetAttribute ("enabled", ""));
+                               SourceLocation location = null;
 
-                                       string gname = 
event_iter.Current.GetAttribute ("threadgroup", "");
-                                       ThreadGroup group;
-                                       if (gname == "system")
-                                               group = ThreadGroup.System;
-                                       else if (gname == "global")
-                                               group = ThreadGroup.Global;
+                               XPathNodeIterator children = 
event_iter.Current.SelectChildren (
+                                       XPathNodeType.Element);
+                               while (children.MoveNext ()) {
+                                       if (children.Current.Name == "Location")
+                                               location = new SourceLocation 
(this, children.Current);
                                        else
-                                               group = CreateThreadGroup 
(gname);
-
-                                       SourceLocation location = null;
-
-                                       XPathNodeIterator children = 
event_iter.Current.SelectChildren (
-                                               XPathNodeType.Element);
-                                       while (children.MoveNext ()) {
-                                               if (children.Current.Name == 
"Location")
-                                                       location = new 
SourceLocation (Session, children.Current);
-                                               else
-                                                       throw new InternalError 
();
-                                       }
-
-                                       Breakpoint bpt = new Breakpoint (index, 
group, location);
-                                       AddEvent (bpt);
-                                       if (enabled)
-                                               bpt.Enable (process.MainThread);
+                                               throw new InternalError ();
                                }
-                       }
 
-
-                       //
-                       // Modules.
-                       //
-
-                       public Module GetModule (string name)
-                       {
-                               return (Module) modules [name];
+                               Breakpoint bpt = new Breakpoint (this, index, 
group, location);
+                               bpt.IsEnabled = enabled;
+                               AddEvent (bpt);
                        }
+               }
 
-                       internal Module CreateModule (string name, ModuleGroup 
group)
-                       {
-                               Module module = (Module) modules [name];
-                               if (module != null)
-                                       return module;
+               //
+               // Modules.
+               //
 
-                               module = new Module (group, name, null);
-                               modules.Add (name, module);
+               public Module GetModule (string name)
+               {
+                       return (Module) modules [name];
+               }
 
+               internal Module CreateModule (string name, ModuleGroup group)
+               {
+                       Module module = (Module) modules [name];
+                       if (module != null)
                                return module;
-                       }
 
-                       internal Module CreateModule (string name, SymbolFile 
symfile)
-                       {
-                               if (symfile == null)
-                                       throw new NullReferenceException ();
+                       module = new Module (group, name, null);
+                       modules.Add (name, module);
 
-                               Module module = (Module) modules [name];
-                               if (module != null)
-                                       return module;
+                       return module;
+               }
 
-                               ModuleGroup group = 
Session.Config.GetModuleGroup (symfile);
+               internal Module CreateModule (string name, SymbolFile symfile)
+               {
+                       if (symfile == null)
+                               throw new NullReferenceException ();
 
-                               module = new Module (group, name, symfile);
-                               modules.Add (name, module);
-
+                       Module module = (Module) modules [name];
+                       if (module != null)
                                return module;
-                       }
 
-                       public Module[] Modules {
-                               get {
-                                       Module[] retval = new Module 
[modules.Values.Count];
-                                       modules.Values.CopyTo (retval, 0);
-                                       return retval;
-                               }
-                       }
+                       ModuleGroup group = Config.GetModuleGroup (symfile);
 
-                       //
-                       // Thread Groups
-                       //
+                       module = new Module (group, name, symfile);
+                       modules.Add (name, module);
 
-                       public ThreadGroup CreateThreadGroup (string name)
-                       {
-                               lock (thread_groups) {
-                                       ThreadGroup group = (ThreadGroup) 
thread_groups [name];
-                                       if (group != null)
-                                               return group;
+                       return module;
+               }
 
-                                       group = ThreadGroup.CreateThreadGroup 
(name);
-                                       thread_groups.Add (name, group);
-                                       return group;
-                               }
+               public Module[] Modules {
+                       get {
+                               Module[] retval = new Module 
[modules.Values.Count];
+                               modules.Values.CopyTo (retval, 0);
+                               return retval;
                        }
+               }
 
-                       public void DeleteThreadGroup (string name)
-                       {
-                               thread_groups.Remove (name);
-                       }
+               //
+               // Thread Groups
+               //
 
-                       public bool ThreadGroupExists (string name)
-                       {
-                               return thread_groups.Contains (name);
+               public ThreadGroup CreateThreadGroup (string name)
+               {
+                       lock (thread_groups) {
+                               ThreadGroup group = (ThreadGroup) thread_groups 
[name];
+                               if (group != null)
+                                       return group;
+
+                               group = ThreadGroup.CreateThreadGroup (name);
+                               thread_groups.Add (name, group);
+                               return group;
                        }
+               }
 
-                       public ThreadGroup[] ThreadGroups {
-                               get {
-                                       lock (thread_groups) {
-                                               ThreadGroup[] retval = new 
ThreadGroup [thread_groups.Values.Count];
-                                               thread_groups.Values.CopyTo 
(retval, 0);
-                                               return retval;
-                                       }
+               public void DeleteThreadGroup (string name)
+               {
+                       thread_groups.Remove (name);
+               }
+
+               public bool ThreadGroupExists (string name)
+               {
+                       return thread_groups.Contains (name);
+               }
+
+               public ThreadGroup[] ThreadGroups {
+                       get {
+                               lock (thread_groups) {
+                                       ThreadGroup[] retval = new ThreadGroup 
[thread_groups.Values.Count];
+                                       thread_groups.Values.CopyTo (retval, 0);
+                                       return retval;
                                }
                        }
+               }
 
-                       public ThreadGroup ThreadGroupByName (string name)
-                       {
-                               return (ThreadGroup) thread_groups [name];
-                       }
+               public ThreadGroup ThreadGroupByName (string name)
+               {
+                       return (ThreadGroup) thread_groups [name];
+               }
 
-                       public ThreadGroup MainThreadGroup {
-                               get { return main_thread_group; }
-                       }
+               public ThreadGroup MainThreadGroup {
+                       get { return main_thread_group; }
+               }
 
-                       //
-                       // Events
-                       //
+               //
+               // Events
+               //
 
-                       public Event[] Events {
-                               get {
-                                       Event[] handles = new Event 
[events.Count];
-                                       events.Values.CopyTo (handles, 0);
-                                       return handles;
-                               }
+               public Event[] Events {
+                       get {
+                               Event[] handles = new Event [events.Count];
+                               events.Values.CopyTo (handles, 0);
+                               return handles;
                        }
+               }
 
-                       public Event GetEvent (int index)
-                       {
-                               return (Event) events [index];
-                       }
+               public Event GetEvent (int index)
+               {
+                       return (Event) events [index];
+               }
 
-                       internal void AddEvent (Event handle)
-                       {
-                               events.Add (handle.Index, handle);
-                       }
+               internal void AddEvent (Event handle)
+               {
+                       events.Add (handle.Index, handle);
+               }
 
-                       public void DeleteEvent (Thread thread, Event handle)
-                       {
-                               handle.Remove (thread);
-                               events.Remove (handle.Index);
-                       }
+               public void DeleteEvent (Thread thread, Event handle)
+               {
+                       handle.Remove (thread);
+                       events.Remove (handle.Index);
                }
        }
 }

Modified: trunk/debugger/classes/Event.cs
===================================================================
--- trunk/debugger/classes/Event.cs     2007-02-16 18:28:37 UTC (rev 73037)
+++ trunk/debugger/classes/Event.cs     2007-02-16 18:36:06 UTC (rev 73038)
@@ -49,8 +49,9 @@
                        return false;
                }
 
-               public abstract bool IsEnabled {
-                       get;
+               public bool IsEnabled {
+                       get { return enabled; }
+                       set { enabled = value; }
                }
 
                public abstract void Enable (Thread target);
@@ -86,6 +87,7 @@
 
                int index;
                string name;
+               bool enabled;
                ThreadGroup group;
                static int next_event_index = 0;
 

Modified: trunk/debugger/classes/ExceptionCatchPoint.cs
===================================================================
--- trunk/debugger/classes/ExceptionCatchPoint.cs       2007-02-16 18:28:37 UTC 
(rev 73037)
+++ trunk/debugger/classes/ExceptionCatchPoint.cs       2007-02-16 18:36:06 UTC 
(rev 73038)
@@ -18,10 +18,6 @@
                        this.exception = exception;
                }
 
-               public override bool IsEnabled {
-                       get { return handle > 0; }
-               }
-
                public override void Enable (Thread target)
                {
                        lock (this) {

Modified: trunk/debugger/classes/SourceLocation.cs
===================================================================
--- trunk/debugger/classes/SourceLocation.cs    2007-02-16 18:28:37 UTC (rev 
73037)
+++ trunk/debugger/classes/SourceLocation.cs    2007-02-16 18:36:06 UTC (rev 
73038)
@@ -8,98 +8,180 @@
 
 namespace Mono.Debugger
 {
-       // <summary>
-       //   Represents a location in the source code on which we can insert a 
breakpoint.
-       //   Instances of this class are normally created as the result of a 
user action
-       //   such as a method lookup.
-       // </summary>
-       [Serializable]
        public class SourceLocation
        {
-               Module module;
-               SourceFile file;
-               SourceMethod source;
-               TargetFunctionType function;
-               string method;
-               int line;
+               public readonly string Name;
 
-               public Module Module {
-                       get { return module; }
+               protected readonly string Module;
+               protected readonly string Method;
+
+               public readonly string FileName;
+               public readonly int Line = -1;
+
+               DynamicSourceLocation dynamic;
+
+               private SourceLocation (DynamicSourceLocation dynamic)
+               {
+                       this.dynamic = dynamic;
                }
 
-               public bool HasSourceFile {
-                       get { return file != null; }
+               public SourceLocation (TargetFunctionType function)
+                       : this (new DynamicSourceLocation (function, -1))
+               {
+                       Module = function.Module.Name;
+                       Method = function.DeclaringType.Name + ':' + 
function.Name;
+                       Name = function.FullName;
+
+                       if (function.Source != null) {
+                               FileName = function.Source.SourceFile.FileName;
+                               Line = function.Source.StartRow;
+                       }
                }
 
-               public bool HasMethod {
-                       get { return source != null; }
+               public SourceLocation (SourceMethod source)
+                       : this (source, -1)
+               { }
+
+               public SourceLocation (SourceMethod source, int line)
+                       : this (new DynamicSourceLocation (source, line))
+               {
+                       Module = source.SourceFile.Module.Name;
+                       FileName = source.SourceFile.FileName;
+
+                       if (source.ClassName != null) {
+                               string klass = source.ClassName;
+                               string name = source.Name.Substring 
(klass.Length + 1);
+                               Method = klass + ':' + name;
+                       } else
+                               Method = source.Name;
+
+                       if (line != -1)
+                               Name = source.Name + ':' + line;
+                       else
+                               Name = source.Name;
+
+                       Line = line;
                }
 
-               public bool HasLine {
-                       get { return line != -1; }
+               public SourceLocation (SourceFile file, int line)
+                       : this (new DynamicSourceLocation (file, line))
+               {
+                       Module = file.Module.Name;
+                       FileName = Name = file.Name + ":" + line;
+                       Line = line;
                }
 
-               public bool HasFunction {
-                       get { return function != null; }
+               public void DumpLineNumbers ()
+               {
+                       if (dynamic == null)
+                               throw new TargetException 
(TargetError.LocationInvalid);
+
+                       dynamic.DumpLineNumbers ();
                }
 
-               public SourceFile SourceFile {
-                       get {
-                               if (!HasSourceFile)
-                                       throw new InvalidOperationException ();
+               internal BreakpointHandle InsertBreakpoint (DebuggerSession 
session,
+                                                           Thread target, 
Breakpoint breakpoint,
+                                                           int domain)
+               {
+                       if (dynamic == null) {
+                               if (Method == null)
+                                       throw new TargetException 
(TargetError.LocationInvalid);
 
-                               return file;
+                               Module module = session.GetModule (Module);
+
+                               int pos = Method.IndexOf (':');
+                               if (pos > 0) {
+                                       string class_name = Method.Substring 
(0, pos);
+                                       string method_name = Method.Substring 
(pos + 1);
+
+                                       dynamic = new DynamicSourceLocation (
+                                               module.LookupMethod 
(class_name, method_name), Line);
+                               } else {
+                                       dynamic = new DynamicSourceLocation (
+                                               module.FindMethod (Method), 
Line);
+                               }
                        }
+
+                       return dynamic.InsertBreakpoint (target, breakpoint, 
domain);
                }
 
-               public SourceMethod Method {
-                       get {
-                               if (!HasMethod)
-                                       throw new InvalidOperationException ();
+               internal void OnTargetExited ()
+               {
+                       dynamic = null;
+               }
 
-                               return source;
+               internal void GetSessionData (XmlElement root)
+               {
+                       XmlElement name_e = root.OwnerDocument.CreateElement 
("Name");
+                       name_e.InnerText = Name;
+                       root.AppendChild (name_e);
+
+                       if (Module != null) {
+                               XmlElement module_e = 
root.OwnerDocument.CreateElement ("Module");
+                               module_e.InnerText = Module;
+                               root.AppendChild (module_e);
                        }
-               }
 
-               public TargetFunctionType Function {
-                       get {
-                               if (!HasFunction)
-                                       throw new InvalidOperationException ();
+                       if (Method != null) {
+                               XmlElement method_e = 
root.OwnerDocument.CreateElement ("Method");
+                               method_e.InnerText = Method;
+                               root.AppendChild (method_e);
+                       }
 
-                               return function;
+                       if (FileName != null) {
+                               XmlElement file_e = 
root.OwnerDocument.CreateElement ("File");
+                               file_e.InnerText = FileName;
+                               root.AppendChild (file_e);
                        }
-               }
 
-               public int Line {
-                       get {
-                               if (line == -1)
-                                       return source.StartRow;
-                               else
-                                       return line;
+                       if (Line > 0) {
+                               XmlElement line_e = 
root.OwnerDocument.CreateElement ("Line");
+                               line_e.InnerText = Line.ToString ();
+                               root.AppendChild (line_e);
                        }
                }
 
-               public string Name {
-                       get {
-                               if (function != null)
-                                       return function.FullName;
-                               else if (source != null) {
-                                       if (line != -1)
-                                               return source.Name + ':' + line;
-                                       else
-                                               return source.Name;
-                               } else if (file != null)
-                                       return SourceFile.FileName + ':' + line;
+               internal SourceLocation (DebuggerSession session, 
XPathNavigator navigator)
+               {
+                       this.Line = -1;
+
+                       XPathNodeIterator children = navigator.SelectChildren 
(XPathNodeType.Element);
+                       while (children.MoveNext ()) {
+                               if (children.Current.Name == "Module")
+                                       Module = children.Current.Value;
+                               else if (children.Current.Name == "Method")
+                                       Method = children.Current.Value;
+                               else if (children.Current.Name == "File")
+                                       FileName = children.Current.Value;
+                               else if (children.Current.Name == "Name")
+                                       Name = children.Current.Value;
+                               else if (children.Current.Name == "Line")
+                                       Line = Int32.Parse 
(children.Current.Value);
                                else
-                                       return method;
+                                       throw new InvalidOperationException ();
                        }
                }
+       }
 
-               public SourceLocation (SourceMethod source)
+       // <summary>
+       //   Represents a location in the source code on which we can insert a 
breakpoint.
+       //   Instances of this class are normally created as the result of a 
user action
+       //   such as a method lookup.
+       // </summary>
+       internal class DynamicSourceLocation
+       {
+               Module module;
+               SourceFile file;
+               SourceMethod source;
+               TargetFunctionType function;
+               string method;
+               int line;
+
+               public DynamicSourceLocation (SourceMethod source)
                        : this (source, -1)
                { }
 
-               public SourceLocation (SourceMethod source, int line)
+               public DynamicSourceLocation (SourceMethod source, int line)
                {
                        this.module = source.SourceFile.Module;
                        this.file = source.SourceFile;
@@ -107,14 +189,14 @@
                        this.line = line;
                }
 
-               public SourceLocation (SourceFile file, int line)
+               public DynamicSourceLocation (SourceFile file, int line)
                {
                        this.module = file.Module;
                        this.file = file;
                        this.line = line;
                }
 
-               public SourceLocation (TargetFunctionType function)
+               public DynamicSourceLocation (TargetFunctionType function, int 
line)
                {
                        this.function = function;
                        this.module = function.Module;
@@ -123,24 +205,19 @@
                        if (source != null)
                                file = source.SourceFile;
 
-                       this.line = -1;
+                       this.line = line;
                }
 
-               internal SourceLocation (DebuggerSession session, 
XPathNavigator navigator)
+               internal void DumpLineNumbers ()
                {
-                       this.line = -1;
+                       if (source == null)
+                               throw new TargetException 
(TargetError.LocationInvalid);
 
-                       XPathNodeIterator children = navigator.SelectChildren 
(XPathNodeType.Element);
-                       while (children.MoveNext ()) {
-                               if (children.Current.Name == "Module")
-                                       module = session.GetModule 
(children.Current.Value);
-                               else if (children.Current.Name == "Method")
-                                       method = children.Current.Value;
-                               else if (children.Current.Name == "Line")
-                                       line = Int32.Parse 
(children.Current.Value);
-                               else
-                                       throw new InvalidOperationException ();
-                       }
+                       Method method = source.GetMethod (0);
+                       if ((method == null) || !method.HasSource)
+                               throw new TargetException 
(TargetError.LocationInvalid);
+
+                       method.Source.DumpLineNumbers ();
                }
 
                internal BreakpointHandle InsertBreakpoint (Thread target, 
Breakpoint breakpoint,
@@ -216,71 +293,16 @@
                                return method.StartAddress;
                }
 
-               //
-               // Session handling.
-               //
-
-               internal void GetSessionData (XmlElement root)
-               {
-                       if (function != null) {
-                               XmlElement module = 
root.OwnerDocument.CreateElement ("Module");
-                               module.InnerText = function.Module.Name;
-                               root.AppendChild (module);
-
-                               XmlElement method_e = 
root.OwnerDocument.CreateElement ("Method");
-                               method_e.InnerText = 
function.DeclaringType.Name + ':' + function.Name;
-                               root.AppendChild (method_e);
-                       } else if (source != null) {
-                               XmlElement module = 
root.OwnerDocument.CreateElement ("Module");
-                               module.InnerText = 
source.SourceFile.Module.Name;
-                               root.AppendChild (module);
-
-                               XmlElement method_e = 
root.OwnerDocument.CreateElement ("Method");
-                               root.AppendChild (method_e);
-
-                               if (source.ClassName != null) {
-                                       string klass = source.ClassName;
-                                       string name = source.Name.Substring 
(klass.Length + 1);
-                                       method_e.InnerText = klass + ':' + name;
-                               } else
-                                       method_e.InnerText = source.Name;
-                       } else if (file != null) {
-                               XmlElement module = 
root.OwnerDocument.CreateElement ("Module");
-                               module.InnerText = file.Module.Name;
-                               root.AppendChild (module);
-
-                               XmlElement file_e = 
root.OwnerDocument.CreateElement ("File");
-                               file_e.InnerText = file.Name + ":" + line;
-                               root.AppendChild (file_e);
-                       } else if (method != null) {
-                               XmlElement module = 
root.OwnerDocument.CreateElement ("Module");
-                               module.InnerText = module.Name;
-                               root.AppendChild (module);
-
-                               XmlElement method_e = 
root.OwnerDocument.CreateElement ("Method");
-                               method_e.InnerText = method;
-                               root.AppendChild (method_e);
-                       } else {
-                               throw new InternalError ();
-                       }
-
-                       if (line > 0) {
-                               XmlElement line_e = 
root.OwnerDocument.CreateElement ("Line");
-                               line_e.InnerText = line.ToString ();
-                               root.AppendChild (line_e);
-                       }
-               }
-
                private class ModuleBreakpointHandle : BreakpointHandle
                {
-                       SourceLocation location;
+                       DynamicSourceLocation location;
 
-                       public ModuleBreakpointHandle (Breakpoint bpt, 
SourceLocation location)
+                       public ModuleBreakpointHandle (Breakpoint bpt, 
DynamicSourceLocation location)
                                : base (bpt)
                        {
                                this.location = location;
 
-                               location.Module.ModuleLoadedEvent += 
module_loaded;
+                               location.module.ModuleLoadedEvent += 
module_loaded;
                        }
 
                        void module_loaded (Module module)
@@ -290,7 +312,7 @@
 
                        public override void Remove (Thread target)
                        {
-                               location.Module.ModuleLoadedEvent -= 
module_loaded;
+                               location.module.ModuleLoadedEvent -= 
module_loaded;
                        }
                }
 
@@ -301,14 +323,14 @@
                        int domain;
 
                        public FunctionBreakpointHandle (Thread target, 
Breakpoint bpt, int domain,
-                                                        SourceLocation 
location)
+                                                        DynamicSourceLocation 
location)
 
                                : base (bpt)
                        {
                                this.domain = domain;
 
-                               load_handler = 
location.Module.SymbolFile.RegisterLoadHandler (
-                                       target, location.Method, method_loaded, 
location);
+                               load_handler = 
location.module.SymbolFile.RegisterLoadHandler (
+                                       target, location.source, method_loaded, 
location);
                        }
 
                        public override void Remove (Thread target)
@@ -332,7 +354,7 @@
                        {
                                load_handler = null;
 
-                               SourceLocation location = (SourceLocation) data;
+                               DynamicSourceLocation location = 
(DynamicSourceLocation) data;
                                TargetAddress address = location.GetAddress 
(domain);
                                if (address.IsNull)
                                        return;
@@ -340,10 +362,5 @@
                                index = target.InsertBreakpoint (Breakpoint, 
address);
                        }
                }
-
-               public override string ToString ()
-               {
-                       return String.Format ("SourceLocation ({0})", Name);
-               }
        }
 }

Modified: trunk/debugger/frontend/Command.cs
===================================================================
--- trunk/debugger/frontend/Command.cs  2007-02-16 18:28:37 UTC (rev 73037)
+++ trunk/debugger/frontend/Command.cs  2007-02-16 18:36:06 UTC (rev 73038)
@@ -2266,21 +2266,18 @@
                        if (!Repeating) {
                                SourceBuffer buffer;
 
-                               if (Location.HasSourceFile) {
-                                       string filename = 
Location.SourceFile.FileName;
-                                       buffer = context.FindFile (filename);
+                               if (Location.FileName != null) {
+                                       buffer = context.FindFile 
(Location.FileName);
                                        if (buffer == null)
                                                throw new ScriptingException (
-                                                       "Cannot find source 
file `{0}'", filename);
+                                                       "Cannot find source 
file `{0}'",
+                                                       Location.FileName);
                                } else
                                        throw new ScriptingException (
                                                "Current location doesn't have 
any source code.");
 
                                source_code = buffer.Contents;
 
-                               if (Location.HasMethod && !Location.HasLine)
-                                       count = Location.Method.EndRow - 
Location.Method.StartRow + 4;
-
                                if (count < 0)
                                        last_line = System.Math.Max 
(Location.Line + 2, 0);
                                else 
@@ -2411,21 +2408,16 @@
                                        context.CurrentThread, tgroup, address);
                                context.Print ("Breakpoint {0} at {1}", index, 
address);
                                return index;
-                       } else if (Location.HasFunction) {
+                       } else {
                                if (domain != 0)
                                        throw new ScriptingException (
-                                               "Can't insert function 
breakpoints in " +
+                                               "Can't insert breakpoints in " +
                                                "other application domains.");
 
                                int index = 
context.Interpreter.InsertBreakpoint (
-                                       context.CurrentThread, tgroup, 
Location.Function);
+                                       context.CurrentThread, tgroup, 
Location);
                                context.Print ("Breakpoint {0} at {1}", index, 
Location.Name);
                                return index;
-                       } else {
-                               int index = 
context.Interpreter.InsertBreakpoint (
-                                       context.CurrentThread, tgroup, domain, 
Location);
-                               context.Print ("Breakpoint {0} at {1}", index, 
Location.Name);
-                               return index;
                        }
                }
 
@@ -2602,19 +2594,12 @@
                                if (!resolved)
                                        throw new ScriptingException ("No such 
method: `{0}'", Argument);
 
-                               if (!Location.HasSourceFile)
-                                       throw new ScriptingException ("Location 
invalid.");
-
                                return true;
                        }
 
                        protected override object DoExecute (ScriptingContext 
context)
                        {
-                               Method method = Location.Method.GetMethod (0);
-                               if ((method == null) || !method.HasSource)
-                                       throw new ScriptingException ("Location 
invalid.");
-
-                               method.Source.DumpLineNumbers ();
+                               Location.DumpLineNumbers ();
                                return null;
                        }
 

Modified: trunk/debugger/frontend/Interpreter.cs
===================================================================
--- trunk/debugger/frontend/Interpreter.cs      2007-02-16 18:28:37 UTC (rev 
73037)
+++ trunk/debugger/frontend/Interpreter.cs      2007-02-16 18:36:06 UTC (rev 
73038)
@@ -814,11 +814,10 @@
                                group.RemoveThread (thread.ID);
                }
 
-               public int InsertBreakpoint (Thread target, ThreadGroup group, 
int domain,
+               public int InsertBreakpoint (Thread target, ThreadGroup group,
                                             SourceLocation location)
                {
-                       Event handle = target.Process.Session.InsertBreakpoint (
-                               target, group, domain, location);
+                       Event handle = target.Process.Session.InsertBreakpoint 
(target, group, location);
                        handle.Enable (target);
                        return handle.Index;
                }
@@ -832,14 +831,6 @@
                        return handle.Index;
                }
 
-               public int InsertBreakpoint (Thread target, ThreadGroup group,
-                                            TargetFunctionType func)
-               {
-                       Event handle = target.Process.Session.InsertBreakpoint 
(target, group, func);
-                       handle.Enable (target);
-                       return handle.Index;
-               }
-
                public int InsertExceptionCatchPoint (Thread target, 
ThreadGroup group,
                                                      TargetType exception)
                {

Modified: trunk/debugger/frontend/ScriptingContext.cs
===================================================================
--- trunk/debugger/frontend/ScriptingContext.cs 2007-02-16 18:28:37 UTC (rev 
73037)
+++ trunk/debugger/frontend/ScriptingContext.cs 2007-02-16 18:36:06 UTC (rev 
73038)
@@ -342,10 +342,10 @@
 
                public SourceLocation FindLocation (SourceLocation location, 
int line)
                {
-                       if (!location.HasSourceFile)
+                       if (location.FileName == null)
                                throw new ScriptingException ("Location doesn't 
have any source code.");
 
-                       return FindLocation (location.SourceFile.FileName, 
line);
+                       return FindLocation (location.FileName, line);
                }
 
                public SourceLocation FindMethod (string name)

Modified: trunk/debugger/test/testsuite/NUnit.cs
===================================================================
--- trunk/debugger/test/testsuite/NUnit.cs      2007-02-16 18:28:37 UTC (rev 
73037)
+++ trunk/debugger/test/testsuite/NUnit.cs      2007-02-16 18:36:06 UTC (rev 
73038)
@@ -347,13 +347,20 @@
                                                 frame.Level, level);
                                if (frame.SourceAddress == null)
                                        Assert.Fail ("Current frame `{0}' has 
no source code.", frame);
+
                                SourceLocation location = 
frame.SourceAddress.Location;
-                               Assert.AreEqual (function, location.Method.Name,
+
+                               string name = location.Name;
+                               int pos = name.IndexOf (':');
+                               if (pos > 0)
+                                       name = name.Substring (0, pos);
+
+                               Assert.AreEqual (function, name,
                                                 "Target stopped in method 
`{0}', but expected `{1}'.",
-                                                function, 
location.Method.Name);
+                                                function, name);
                                Assert.AreEqual (line, location.Line,
                                                 "Target stopped at line {0}, 
but expected {1}.",
-                                                location.Name, line);
+                                                location.Line, line);
                        } catch (TargetException ex) {
                                Assert.Fail ("Cannot get current frame: {0}.", 
ex.Message);
                        }

Modified: trunk/debugger/test/testsuite/TestExec.cs
===================================================================
--- trunk/debugger/test/testsuite/TestExec.cs   2007-02-16 18:28:37 UTC (rev 
73037)
+++ trunk/debugger/test/testsuite/TestExec.cs   2007-02-16 18:36:06 UTC (rev 
73038)
@@ -123,6 +123,8 @@
                               !child_exited || !thread_exited) {
                                DebuggerEvent e = AssertEvent ();
 
+                               Report.Debug (DebugFlags.Threads, "EXEC EVENT: 
{0}", e);
+
                                if (e.Type == DebuggerEventType.ProcessExited) {
                                        if ((Process) e.Data == child.Process) {
                                                child_exited = true;

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

Reply via email to