Author: martin
Date: 2006-04-03 12:45:21 -0400 (Mon, 03 Apr 2006)
New Revision: 58959

Modified:
   trunk/debugger/ChangeLog
   trunk/debugger/backends/Debugger.cs
   trunk/debugger/backends/Process.cs
   trunk/debugger/backends/ThreadManager.cs
   trunk/debugger/frontend/Command.cs
   trunk/debugger/frontend/Interpreter.cs
Log:
2006-04-03  Martin Baulig  <[EMAIL PROTECTED]>

        * frontend/Interpreter.cs
        (Interpreter.MainProcess): Removed.
        (Interpreter.CurrentProcess): New public property.

        * backends/Debugger.cs
        (Debugger.TargetExitedEvent): New public event.
        (Debugger.OnProcessExitedEvent): Kill all other processes if the
        main process exited.
        (Debugger.Kill): New public method.



Modified: trunk/debugger/ChangeLog
===================================================================
--- trunk/debugger/ChangeLog    2006-04-03 16:11:43 UTC (rev 58958)
+++ trunk/debugger/ChangeLog    2006-04-03 16:45:21 UTC (rev 58959)
@@ -1,5 +1,17 @@
 2006-04-03  Martin Baulig  <[EMAIL PROTECTED]>
 
+       * frontend/Interpreter.cs
+       (Interpreter.MainProcess): Removed.
+       (Interpreter.CurrentProcess): New public property.
+
+       * backends/Debugger.cs
+       (Debugger.TargetExitedEvent): New public event.
+       (Debugger.OnProcessExitedEvent): Kill all other processes if the
+       main process exited.
+       (Debugger.Kill): New public method.
+
+2006-04-03  Martin Baulig  <[EMAIL PROTECTED]>
+
        * backends/Process.cs
        (Process.Initialize): Set `main_thread' and `main_engine' here.
 

Modified: trunk/debugger/backends/Debugger.cs
===================================================================
--- trunk/debugger/backends/Debugger.cs 2006-04-03 16:11:43 UTC (rev 58958)
+++ trunk/debugger/backends/Debugger.cs 2006-04-03 16:45:21 UTC (rev 58959)
@@ -16,6 +16,7 @@
 
 namespace Mono.Debugger
 {
+       public delegate void DebuggerEventHandler (Debugger debugger);
        public delegate void ThreadEventHandler (Debugger debugger, Thread 
thread);
        public delegate void ProcessEventHandler (Debugger debugger, Process 
process);
 
@@ -24,6 +25,7 @@
                ThreadManager thread_manager;
                DebuggerSession session;
                Hashtable process_hash;
+               Process main_process;
 
                public Debugger ()
                {
@@ -47,6 +49,7 @@
                public event ProcessEventHandler ProcessCreatedEvent;
                public event ProcessEventHandler ProcessReachedMainEvent;
                public event ProcessEventHandler ProcessExitedEvent;
+               public event DebuggerEventHandler TargetExitedEvent;
                public event TargetEventHandler TargetEvent;
                public event SymbolTableChangedHandler SymbolTableChanged;
 
@@ -63,27 +66,62 @@
                                ProcessReachedMainEvent (this, process);
                }
 
+               protected void OnTargetExitedEvent ()
+               {
+                       if (TargetExitedEvent != null)
+                               TargetExitedEvent (this);
+               }
+
                internal void OnProcessExitedEvent (Process process)
                {
                        process_hash.Remove (process);
                        if (ProcessExitedEvent != null)
                                ProcessExitedEvent (this, process);
+
+                       if (process == main_process) {
+                               Kill ();
+                       }
                }
 
+               public void Kill ()
+               {
+                       main_process = null;
+
+                       Process[] procs;
+                       lock (process_hash.SyncRoot) {
+                               procs = new Process [process_hash.Count];
+                               process_hash.Values.CopyTo (procs, 0);
+                       }
+
+                       foreach (Process proc in procs) {
+                               proc.Kill ();
+                       }
+
+                       OnTargetExitedEvent ();
+               }
+
                public Process Run (DebuggerOptions options)
                {
                        check_disposed ();
 
+                       if (main_process != null)
+                               throw new TargetException 
(TargetError.AlreadyHaveTarget);
+
                        ProcessStart start = new ProcessStart (options);
-                       return thread_manager.StartApplication (start);
+                       main_process = thread_manager.StartApplication (start);
+                       return main_process;
                }
 
                public Process Attach (DebuggerOptions options, int pid)
                {
                        check_disposed ();
 
+                       if (main_process != null)
+                               throw new TargetException 
(TargetError.AlreadyHaveTarget);
+
                        ProcessStart start = new ProcessStart (options, pid);
-                       return thread_manager.StartApplication (start);
+                       main_process = thread_manager.StartApplication (start);
+                       return main_process;
                }
 
                public Process OpenCoreFile (DebuggerOptions options, string 
core_file,
@@ -91,8 +129,12 @@
                {
                        check_disposed ();
 
+                       if (main_process != null)
+                               throw new TargetException 
(TargetError.AlreadyHaveTarget);
+
                        ProcessStart start = new ProcessStart (options, 
core_file);
-                       return thread_manager.OpenCoreFile (start, out threads);
+                       main_process = thread_manager.OpenCoreFile (start, out 
threads);
+                       return main_process;
                }
 
                internal void OnThreadCreatedEvent (Thread new_process)

Modified: trunk/debugger/backends/Process.cs
===================================================================
--- trunk/debugger/backends/Process.cs  2006-04-03 16:11:43 UTC (rev 58958)
+++ trunk/debugger/backends/Process.cs  2006-04-03 16:45:21 UTC (rev 58959)
@@ -346,7 +346,7 @@
                        Dispose ();
                }
 
-               internal void KillThread (SingleSteppingEngine engine)
+               internal void Kill (SingleSteppingEngine engine)
                {
                        if (engine == main_engine) {
                                Kill ();

Modified: trunk/debugger/backends/ThreadManager.cs
===================================================================
--- trunk/debugger/backends/ThreadManager.cs    2006-04-03 16:11:43 UTC (rev 
58958)
+++ trunk/debugger/backends/ThreadManager.cs    2006-04-03 16:45:21 UTC (rev 
58959)
@@ -234,7 +234,7 @@
                             (cevent.Type == 
Inferior.ChildEventType.CHILD_SIGNALED)) {
                                thread_hash.Remove (engine.PID);
                                engine_hash.Remove (engine.ID);
-                               engine.Process.KillThread (engine);
+                               engine.Process.Kill (engine);
                                return false;
                        }
 

Modified: trunk/debugger/frontend/Command.cs
===================================================================
--- trunk/debugger/frontend/Command.cs  2006-04-03 16:11:43 UTC (rev 58958)
+++ trunk/debugger/frontend/Command.cs  2006-04-03 16:45:21 UTC (rev 58959)
@@ -1326,7 +1326,7 @@
                        {
                                bool printed_something = false;
                                foreach (Process process in 
context.Interpreter.Processes) {
-                                       string prefix = process == 
context.Interpreter.MainProcess ?
+                                       string prefix = process == 
context.Interpreter.CurrentProcess ?
                                                "(*)" : "   ";
 
                                        context.Print ("{0} {1}", prefix, 
PrintProcess (process));

Modified: trunk/debugger/frontend/Interpreter.cs
===================================================================
--- trunk/debugger/frontend/Interpreter.cs      2006-04-03 16:11:43 UTC (rev 
58958)
+++ trunk/debugger/frontend/Interpreter.cs      2006-04-03 16:45:21 UTC (rev 
58959)
@@ -25,7 +25,7 @@
 
                Debugger debugger;
                Process main_process;
-               Thread main_thread;
+               Process current_process;
 
                Hashtable styles;
                StyleBase current_style;
@@ -109,12 +109,12 @@
                        }
                }
 
-               public Process MainProcess {
+               public Process CurrentProcess {
                        get {
-                               if (main_process == null)
+                               if (current_process == null)
                                        throw new ScriptingException ("No 
target.");
 
-                               return main_process;
+                               return current_process;
                        }
                }
 
@@ -295,13 +295,13 @@
 
                public bool HasTarget {
                        get {
-                               return main_process != null;
+                               return debugger != null;
                        }
                }
 
                public Process Start ()
                {
-                       if (debugger != null)
+                       if ((debugger != null) || (main_process != null))
                                throw new ScriptingException ("Program already 
started.");
 
                        Console.WriteLine ("Starting program: {0}",
@@ -315,13 +315,12 @@
 
                                session = debugger.Session;
 
-                               main_process = debugger.Run (options);
+                               current_process = main_process = debugger.Run 
(options);
 
-                               main_thread = main_process.MainThread;
-                               CurrentThread = main_thread;
-                               Wait (main_thread);
+                               current_thread = current_process.MainThread;
+                               Wait (current_thread);
 
-                               return main_process;
+                               return current_process;
                        } catch (TargetException e) {
                                Kill ();
                                throw new ScriptingException (e.Message);
@@ -330,7 +329,7 @@
 
                public Process Attach (int pid)
                {
-                       if (debugger != null)
+                       if ((debugger != null) || (main_process != null))
                                throw new ScriptingException ("Program already 
started.");
 
                        Console.WriteLine ("Attaching to {0}", pid);
@@ -343,13 +342,12 @@
 
                                session = debugger.Session;
 
-                               main_process = debugger.Attach (options, pid);
+                               current_process = main_process = 
debugger.Attach (options, pid);
 
-                               main_thread = main_process.MainThread;
-                               CurrentThread = main_thread;
-                               Wait (main_thread);
+                               current_thread = current_process.MainThread;
+                               Wait (current_thread);
 
-                               return main_process;
+                               return current_process;
                        } catch (TargetException e) {
                                Kill ();
                                throw new ScriptingException (e.Message);
@@ -358,7 +356,7 @@
 
                public Process OpenCoreFile (string core_file)
                {
-                       if (debugger != null)
+                       if ((debugger != null) || (main_process != null))
                                throw new ScriptingException ("Program already 
started.");
 
                        Console.WriteLine ("Loading core file {0}", core_file);
@@ -372,12 +370,12 @@
                                session = debugger.Session;
 
                                Thread[] threads;
-                               main_process = debugger.OpenCoreFile (options, 
core_file, out threads);
-                               main_thread = main_process.MainThread;
+                               current_process = main_process = 
debugger.OpenCoreFile (
+                                       options, core_file, out threads);
 
-                               CurrentThread = main_thread;
+                               current_thread = current_process.MainThread;
 
-                               return main_process;
+                               return current_process;
                        } catch (TargetException e) {
                                Kill ();
                                throw new ScriptingException (e.Message);
@@ -393,7 +391,7 @@
 
                public Process LoadSession (Stream stream)
                {
-                       if (debugger != null)
+                       if ((debugger != null) || (main_process != null))
                                throw new ScriptingException ("Program already 
started.");
 
                        try {
@@ -404,17 +402,15 @@
                                new InterpreterEventSink (this, debugger);
                                new ThreadEventSink (this, debugger);
 
-                               Process process = debugger.Run (options);
+                               current_process = main_process = debugger.Run 
(options);
 
                                session = DebuggerSession.Load (debugger, 
stream);
 
-                               session.InsertBreakpoints (main_thread);
+                               current_thread = current_process.MainThread;
+                               session.InsertBreakpoints (current_thread);
+                               Wait (current_thread);
 
-                               main_thread = process.MainThread;
-                               CurrentThread = main_thread;
-                               Wait (main_thread);
-
-                               return process;
+                               return current_process;
                        } catch (TargetException e) {
                                Kill ();
                                throw new ScriptingException (e.Message);
@@ -498,25 +494,18 @@
 
                protected void ThreadExited (Thread thread)
                {
-                       if (thread == main_thread) {
-                               TargetExited ();
-                               CurrentThread = null;
-                       }
+                       if (thread == current_thread)
+                               current_thread = null;
                }
 
-               protected void TargetExited ()
+               protected void ProcessExited (Process process)
                {
-                       if (main_process != null) {
-                               if ((main_thread != null) &&
-                                   (main_thread.Process == main_process)) {
-                                       main_thread = null;
-                                       main_process = null;
-                                       CurrentThread = null;
-                               }
-                       } else {
-                               CurrentThread = null;
-                               main_thread = null;
-                               main_process = null;
+                       if (process == main_process) {
+                               current_process = main_process = null;
+                               current_thread = null;
+                       } else if (process == current_process) {
+                               current_process = main_process;
+                               current_thread = main_process.MainThread;
                        }
                }
 
@@ -528,7 +517,10 @@
                                return current_thread;
                        }
 
-                       set { current_thread = value; }
+                       set {
+                               current_thread = value;
+                               current_process = value.Process;
+                       }
                }
 
                public Thread GetThread (int number)
@@ -536,9 +528,11 @@
                        if (number == -1)
                                return CurrentThread;
 
-                       foreach (Thread proc in MainProcess.Threads)
-                               if (proc.ID == number)
-                                       return proc;
+                       foreach (Process process in Processes) {
+                               foreach (Thread thread in process.Threads)
+                                       if (thread.ID == number)
+                                               return thread;
+                       }
 
                        throw new ScriptingException ("No such thread: {0}", 
number);
                }
@@ -555,7 +549,7 @@
 
                public void ShowThreadGroups ()
                {
-                       foreach (ThreadGroup group in MainProcess.ThreadGroups) 
{
+                       foreach (ThreadGroup group in 
CurrentProcess.ThreadGroups) {
                                if (group.Name.StartsWith ("@"))
                                        continue;
                                StringBuilder ids = new StringBuilder ();
@@ -569,18 +563,18 @@
 
                public void CreateThreadGroup (string name)
                {
-                       if (MainProcess.ThreadGroupExists (name))
+                       if (CurrentProcess.ThreadGroupExists (name))
                                throw new ScriptingException ("A thread group 
with that name already exists.");
 
-                       MainProcess.CreateThreadGroup (name);
+                       CurrentProcess.CreateThreadGroup (name);
                }
 
                public void DeleteThreadGroup (string name)
                {
-                       if (!MainProcess.ThreadGroupExists (name))
+                       if (!CurrentProcess.ThreadGroupExists (name))
                                throw new ScriptingException ("No such thread 
group.");
 
-                       MainProcess.DeleteThreadGroup (name);
+                       CurrentProcess.DeleteThreadGroup (name);
                }
 
                public ThreadGroup GetThreadGroup (string name, bool writable)
@@ -589,10 +583,10 @@
                                name = "global";
                        if (name.StartsWith ("@"))
                                throw new ScriptingException ("No such thread 
group.");
-                       if (!MainProcess.ThreadGroupExists (name))
+                       if (!CurrentProcess.ThreadGroupExists (name))
                                throw new ScriptingException ("No such thread 
group.");
 
-                       ThreadGroup group = MainProcess.CreateThreadGroup 
(name);
+                       ThreadGroup group = CurrentProcess.CreateThreadGroup 
(name);
 
                        if (writable && group.IsSystem)
                                throw new ScriptingException ("Cannot modify 
system-created thread group.");
@@ -655,18 +649,30 @@
                public void Kill ()
                {
                        if (debugger != null) {
+                               debugger.Kill ();
                                debugger.Dispose ();
                                debugger = null;
                        }
-                       TargetExited ();
                }
 
+               protected void TargetExited ()
+               {
+                       if (debugger != null) {
+                               debugger.Dispose ();
+                               debugger = null;
+                       }
+
+                       main_process = current_process = null;
+                       current_thread = null;
+               }
+
                public string GetFullPathByFilename (string filename)
                {
+                       Process process = CurrentProcess;
                        try {
-                               main_process.ModuleManager.Lock ();
+                               process.ModuleManager.Lock ();
 
-                               Module[] modules = main_process.Modules;
+                               Module[] modules = process.Modules;
 
                                foreach (Module module in modules) {
                                        if (!module.SymbolsLoaded)
@@ -678,7 +684,7 @@
                                        }
                                }
                        } finally {
-                               main_process.ModuleManager.UnLock ();
+                               process.ModuleManager.UnLock ();
                        }
 
                        return null;
@@ -715,6 +721,7 @@
                        {
                                this.interpreter = interpreter;
 
+                               backend.TargetExitedEvent += target_exited;
                                backend.ThreadCreatedEvent += thread_created;
                                backend.ProcessReachedMainEvent += 
process_reached_main;
                                backend.ProcessExitedEvent += process_exited;
@@ -732,6 +739,11 @@
 
                        public void process_exited (Debugger debugger, Process 
process)
                        {
+                               interpreter.ProcessExited (process);
+                       }
+
+                       public void target_exited (Debugger debugger)
+                       {
                                interpreter.TargetExited ();
                        }
 

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

Reply via email to