Author: martin
Date: 2006-04-25 08:35:31 -0400 (Tue, 25 Apr 2006)
New Revision: 59850

Modified:
   trunk/debugger/ChangeLog
   trunk/debugger/backends/DebuggerServant.cs
   trunk/debugger/backends/ProcessServant.cs
   trunk/debugger/backends/SingleSteppingEngine.cs
   trunk/debugger/backends/TargetReader.cs
   trunk/debugger/backends/ThreadManager.cs
   trunk/debugger/backends/ThreadServant.cs
Log:
2006-04-25  Martin Baulig  <[EMAIL PROTECTED]>

        * backends/SingleSteppingEngine.cs
        (SingleSteppingEngine.StartThread): Added `do_attach' argument.
        (SingleSteppingEngine.GetThreadID): Removed.
        (SingleSteppingEngine.Attached): Removed.
        (SingleSteppingEngine.Attach): Removed.
        (SingleSteppingEngine.Detach): When detaching from a managed
        application, start an `OperationDetach'.
        (OperationDetach): New operation.
        (OperationGetThreadId): Renamed into `OperationGetCurrentThread'.

        * backends/ThreadServant.cs
        (ThreadServant.DetachThread): New internal abstract method.



Modified: trunk/debugger/ChangeLog
===================================================================
--- trunk/debugger/ChangeLog    2006-04-25 12:30:43 UTC (rev 59849)
+++ trunk/debugger/ChangeLog    2006-04-25 12:35:31 UTC (rev 59850)
@@ -1,5 +1,20 @@
 2006-04-25  Martin Baulig  <[EMAIL PROTECTED]>
 
+       * backends/SingleSteppingEngine.cs
+       (SingleSteppingEngine.StartThread): Added `do_attach' argument.
+       (SingleSteppingEngine.GetThreadID): Removed.
+       (SingleSteppingEngine.Attached): Removed.
+       (SingleSteppingEngine.Attach): Removed.
+       (SingleSteppingEngine.Detach): When detaching from a managed
+       application, start an `OperationDetach'.
+       (OperationDetach): New operation.
+       (OperationGetThreadId): Renamed into `OperationGetCurrentThread'.
+
+       * backends/ThreadServant.cs
+       (ThreadServant.DetachThread): New internal abstract method.
+
+2006-04-25  Martin Baulig  <[EMAIL PROTECTED]>
+
        * backends/BreakpointManager.cs
        (BreakpointManager.RemoveAllBreakpoints): New public method.
 

Modified: trunk/debugger/backends/DebuggerServant.cs
===================================================================
--- trunk/debugger/backends/DebuggerServant.cs  2006-04-25 12:30:43 UTC (rev 
59849)
+++ trunk/debugger/backends/DebuggerServant.cs  2006-04-25 12:35:31 UTC (rev 
59850)
@@ -104,6 +104,7 @@
                        }
 
                        OnTargetExitedEvent ();
+                       Dispose ();
                }
 
                public void Detach ()
@@ -113,8 +114,6 @@
                        else if (!main_process.IsAttached)
                                throw new TargetException 
(TargetError.CannotDetach);
 
-                       main_process = null;
-
                        ProcessServant[] procs;
                        lock (process_hash.SyncRoot) {
                                procs = new ProcessServant [process_hash.Count];
@@ -124,8 +123,6 @@
                        foreach (ProcessServant proc in procs) {
                                proc.Detach ();
                        }
-
-                       OnTargetExitedEvent ();
                }
 
                public Process Run (DebuggerOptions options)

Modified: trunk/debugger/backends/ProcessServant.cs
===================================================================
--- trunk/debugger/backends/ProcessServant.cs   2006-04-25 12:30:43 UTC (rev 
59849)
+++ trunk/debugger/backends/ProcessServant.cs   2006-04-25 12:35:31 UTC (rev 
59850)
@@ -229,7 +229,7 @@
                        // Order is important: first add the new engine to the 
manager's hash table,
                        //                     then call inferior.Initialize() 
/ inferior.Attach().
                        manager.AddEngine (new_thread);
-                       new_thread.StartThread ();
+                       new_thread.StartThread (do_attach);
 
                        if ((mono_manager != null) && !do_attach)
                                mono_manager.ThreadCreated (new_thread);
@@ -254,7 +254,7 @@
                        // Order is important: first add the new engine to the 
manager's hash table,
                        //                     then call inferior.Initialize() 
/ inferior.Attach().
                        manager.AddEngine (new_thread);
-                       new_thread.StartThread ();
+                       new_thread.StartThread (false);
 
                        new_inferior.InitializeAfterFork ();
 
@@ -314,7 +314,7 @@
                        thread_hash [inferior.PID] = new_thread;
 
                        manager.ProcessExecd (new_thread);
-                       new_thread.StartThread ();
+                       new_thread.StartThread (false);
 
                        manager.Debugger.OnProcessExecdEvent (this);
                        manager.Debugger.OnThreadCreatedEvent 
(new_thread.Thread);
@@ -343,11 +343,11 @@
                        initialized_event.WaitOne ();
                }
 
-               internal bool Initialize (SingleSteppingEngine engine, Inferior 
inferior,
+               internal void Initialize (SingleSteppingEngine engine, Inferior 
inferior,
                                          bool is_exec)
                {
                        if (initialized)
-                               return true;
+                               return;
 
                        if (!is_exec)
                                inferior.InitializeProcess ();
@@ -373,18 +373,9 @@
                                                continue;
                                        ThreadCreated (inferior, thread, true);
                                }
-
-                               if (mono_manager == null) {
-                                       ReachedMain ();
-                                       inferior.InitializeModules ();
-                                       engine.Attached ();
-                                       initialized_event.Set ();
-                                       return false;
-                               }
                        }
 
                        initialized_event.Set ();
-                       return true;
                }
 
                public void Kill ()
@@ -407,16 +398,12 @@
                                throw new TargetException 
(TargetError.CannotDetach);
 
                        main_thread.Detach ();
-
-                       manager.Debugger.OnProcessExitedEvent (this);
-
-                       Dispose ();
                }
 
                internal void KillThread (SingleSteppingEngine engine)
                {
                        if (engine == main_thread) {
-                               manager.Debugger.OnProcessExitedEvent 
(main_thread.ProcessServant);
+                               manager.Debugger.OnProcessExitedEvent (this);
                                Kill ();
                        } else {
                                thread_hash.Remove (engine.PID);
@@ -425,6 +412,12 @@
                        }
                }
 
+               internal void OnTargetDetached ()
+               {
+                       manager.Debugger.OnProcessExitedEvent (this);
+                       Dispose ();
+               }
+
                // XXX This desperately needs to be renamed.
                internal ILanguageBackend CreateDebuggerHandler 
(MonoDebuggerInfo info)
                {
@@ -499,6 +492,17 @@
                        return null;
                }
 
+               internal ThreadServant[] ThreadServants {
+                       get {
+                               lock (thread_hash.SyncRoot) {
+                                       int count = thread_hash.Count;
+                                       ThreadServant[] servants = new 
ThreadServant [count];
+                                       thread_hash.Values.CopyTo (servants, 0);
+                                       return servants;
+                               }
+                       }
+               }
+
                public Thread[] Threads {
                        get {
                                lock (thread_hash.SyncRoot) {

Modified: trunk/debugger/backends/SingleSteppingEngine.cs
===================================================================
--- trunk/debugger/backends/SingleSteppingEngine.cs     2006-04-25 12:30:43 UTC 
(rev 59849)
+++ trunk/debugger/backends/SingleSteppingEngine.cs     2006-04-25 12:35:31 UTC 
(rev 59850)
@@ -95,14 +95,15 @@
                        : this (manager, process, start)
                {
                        inferior = Inferior.CreateInferior (manager, process, 
start);
+                       inferior.TargetOutput += new TargetOutputHandler 
(inferior_output_handler);
 
                        is_main = true;
                        if (start.PID != 0) {
                                this.pid = start.PID;
                                inferior.Attach (pid);
-                       } else
+                       } else {
                                pid = inferior.Run (true);
-                       inferior.TargetOutput += new TargetOutputHandler 
(inferior_output_handler);
+                       }
 
                        result = new Thread.StepCommandResult (thread);
                        current_operation = new OperationStart (result);
@@ -116,12 +117,18 @@
                        this.pid = pid;
                }
 
-               public CommandResult StartThread ()
+               public CommandResult StartThread (bool do_attach)
                {
-                       inferior.InitializeThread (pid);
+                       if (do_attach)
+                               inferior.Attach (pid);
+                       else
+                               inferior.InitializeThread (pid);
 
                        CommandResult result = new Thread.StepCommandResult 
(thread);
-                       current_operation = new OperationRun 
(TargetAddress.Null, true, result);
+                       if (do_attach)
+                               current_operation = new OperationInitialize 
(result);
+                       else
+                               current_operation = new OperationRun (result);
                        return result;
                }
 
@@ -480,12 +487,6 @@
                        }
                }
 
-               internal void Attached ()
-               {
-                       frame_changed (inferior.CurrentFrame, null);
-                       engine_stopped = true;
-               }
-
                internal void ReachedManagedMain (TargetAddress method)
                {
                        if (!method.IsNull) {
@@ -497,14 +498,6 @@
                        }
                }
 
-               internal void Attach (MonoDebuggerInfo info)
-               {
-                       CommandResult result = new Thread.StepCommandResult 
(thread);
-
-                       this.is_main = true;
-                       StartOperation (new OperationAttach (info, result));
-               }
-
                internal void OnManagedThreadCreated (long tid, TargetAddress 
end_stack_address)
                {
                        this.tid = tid;
@@ -516,14 +509,6 @@
                        this.end_stack_address = TargetAddress.Null;
                }
 
-               internal CommandResult GetThreadID (MonoThreadManager manager, 
MonoDebuggerInfo info)
-               {
-                       CommandResult result = new SimpleCommandResult ();
-                       current_operation = new OperationGetThreadId (manager, 
info, result);
-                       current_operation.Execute (this);
-                       return result;
-               }
-
                void set_registers (Registers registers)
                {
                        if (!registers.FromCurrentFrame)
@@ -724,17 +709,43 @@
                                        throw new TargetException 
(TargetError.NotStopped);
                                }
 
-                               lock (this) {
-                                       if (inferior != null) {
-                                               inferior.Detach ();
-                                               inferior.Dispose ();
-                                               inferior = null;
-                                       }
+                               process.AcquireGlobalThreadLock (this);
+                               process.BreakpointManager.RemoveAllBreakpoints 
(inferior);
+
+                               if (process.MonoManager != null) {
+                                       CommandResult result = new 
Thread.StepCommandResult (thread);
+                                       StartOperation (new OperationDetach 
(result));
+                               } else {
+                                       DoDetach ();
                                }
                                return null;
                        });
                }
 
+               protected void DoDetach ()
+               {
+                       foreach (ThreadServant servant in 
process.ThreadServants) {
+                               if (servant == this)
+                                       continue;
+
+                               servant.DetachThread ();
+                       }
+
+                       inferior.Detach ();
+                       inferior = null;
+
+                       process.OnTargetDetached ();
+               }
+
+               internal override void DetachThread ()
+               {
+                       if (inferior != null) {
+                               inferior.Detach ();
+                               inferior.Dispose ();
+                               inferior = null;
+                       }
+               }
+
                public override void Stop ()
                {
                        lock (this) {
@@ -1928,13 +1939,24 @@
                                                               out 
TargetEventArgs args)
                {
                        Report.Debug (DebugFlags.SSE,
-                                     "{0} start: {1}", sse, cevent);
+                                     "{0} start: {1} {2}", sse, cevent,
+                                     sse.ProcessServant.IsAttached);
 
                        args = null;
                        if (cevent.Type != 
Inferior.ChildEventType.CHILD_STOPPED)
                                return EventResult.Completed;
 
+                       if (sse.Architecture.IsSyscallInstruction (inferior, 
inferior.CurrentFrame)) {
+                               inferior.Step ();
+                               return EventResult.Running;
+                       }
+
                        if (sse.ProcessServant.MonoManager != null) {
+                               if (sse.ProcessServant.IsAttached) {
+                                       sse.PushOperation (new OperationAttach 
(null));
+                                       return EventResult.Running;
+                               }
+
                                if (!initialized) {
                                        initialized = true;
                                        inferior.Continue ();
@@ -1943,6 +1965,9 @@
                                        return EventResult.Completed;
                        }
 
+                       if (sse.ProcessServant.IsAttached)
+                               return EventResult.Completed;
+
                        sse.PushOperation (new OperationRun 
(inferior.MainMethodAddress, true, Result));
                        return EventResult.Running;
                }
@@ -1967,26 +1992,29 @@
                                                               out 
TargetEventArgs args)
                {
                        Report.Debug (DebugFlags.SSE,
-                                     "{0} initialize ({1})", this,
+                                     "{0} initialize ({1})", sse,
                                      DebuggerWaitHandle.CurrentThread);
 
                        args = null;
+                       if (sse.Architecture.IsSyscallInstruction (inferior, 
inferior.CurrentFrame)) {
+                               inferior.Step ();
+                               return EventResult.Running;
+                       }
+
+                       if (sse.ProcessServant.MonoManager != null) {
+                               sse.PushOperation (new 
OperationGetCurrentThread (null));
+                               return EventResult.Running;
+                       }
+
                        return EventResult.Completed;
                }
        }
 
-       protected class OperationGetThreadId : OperationCallback
+       protected class OperationGetCurrentThread : OperationCallback
        {
-               MonoThreadManager manager;
-               MonoDebuggerInfo info;
-
-               public OperationGetThreadId (MonoThreadManager manager, 
MonoDebuggerInfo info,
-                                            CommandResult result)
+               public OperationGetCurrentThread (CommandResult result)
                        : base (result)
-               {
-                       this.manager = manager;
-                       this.info = info;
-               }
+               { }
 
                public override bool IsSourceOperation {
                        get { return false; }
@@ -1994,7 +2022,8 @@
 
                protected override void DoExecute (SingleSteppingEngine sse)
                {
-                       sse.inferior.CallMethod (info.GetThreadId, 0, 0, ID);
+                       MonoDebuggerInfo info = 
sse.ProcessServant.MonoManager.MonoDebuggerInfo;
+                       sse.inferior.CallMethod (info.GetCurrentThread, 0, 0, 
ID);
                }
 
                protected override bool CallbackCompleted (SingleSteppingEngine 
sse,
@@ -2002,25 +2031,34 @@
                                                           long data1, long 
data2)
                {
                        Report.Debug (DebugFlags.SSE,
-                                     "{0} get thread ID: {1:x} {2:x} {3}",
+                                     "{0} get current thread: {1:x} {2:x} {3}",
                                      sse, data1, data2, Result);
 
-                       sse.tid = data1;
-                       // sse.SetTID (data1);
-                       // manager.SetThreadId (sse);
+                       RestoreStack (sse);
+
+                       if (data1 == 0) {
+                               sse.PushOperation (new OperationRun (null));
+                               return false;
+                       }
+
+                       TargetAddress thread = new TargetAddress 
(inferior.AddressDomain, data1);
+                       MonoMetadataInfo info = 
sse.ProcessServant.MonoManager.MonoMetadataInfo;
+                       TargetReader reader = new TargetReader (
+                               inferior.ReadMemory (thread, info.ThreadSize));
+
+                       reader.Offset = info.ThreadTidOffset;
+                       long tid = reader.BinaryReader.ReadInt64 ();
+
+                       sse.OnManagedThreadCreated (tid, thread + 
info.ThreadEndStackOffset);
                        return true;
                }
        }
 
        protected class OperationAttach : OperationCallback
        {
-               MonoDebuggerInfo info;
-
-               public OperationAttach (MonoDebuggerInfo info, CommandResult 
result)
+               public OperationAttach (CommandResult result)
                        : base (result)
-               {
-                       this.info = info;
-               }
+               { }
 
                public override bool IsSourceOperation {
                        get { return false; }
@@ -2028,6 +2066,7 @@
 
                protected override void DoExecute (SingleSteppingEngine sse)
                {
+                       MonoDebuggerInfo info = 
sse.ProcessServant.MonoManager.MonoDebuggerInfo;
                        sse.inferior.CallMethod (info.Attach, 0, 0, ID);
                }
 
@@ -2046,6 +2085,46 @@
                }
        }
 
+       protected class OperationDetach : OperationCallback
+       {
+               public OperationDetach (CommandResult result)
+                       : base (result)
+               { }
+
+               public override bool IsSourceOperation {
+                       get { return false; }
+               }
+
+               protected override void DoExecute (SingleSteppingEngine sse)
+               {
+                       MonoDebuggerInfo info = 
sse.ProcessServant.MonoManager.MonoDebuggerInfo;
+                       sse.inferior.CallMethod (info.Detach, 0, 0, ID);
+               }
+
+               protected override bool CallbackCompleted (SingleSteppingEngine 
sse,
+                                                          Inferior inferior,
+                                                          Inferior.ChildEvent 
cevent,
+                                                          out TargetEventArgs 
args,
+                                                          out EventResult 
result)
+               {
+                       Report.Debug (DebugFlags.SSE, "{0} detach done: {1} 
{2}",
+                                     sse, cevent, Result);
+
+                       sse.DoDetach ();
+
+                       args = new TargetEventArgs 
(TargetEventType.TargetExited, 0);
+                       result = EventResult.Completed;
+                       return true;
+               }
+
+               protected override bool CallbackCompleted (SingleSteppingEngine 
sse,
+                                                          Inferior inferior,
+                                                          long data1, long 
data2)
+               {
+                       throw new InternalError ();
+               }
+       }
+
        protected class OperationStepOverBreakpoint : Operation
        {
                TargetAddress until;
@@ -2456,6 +2535,15 @@
                        this.in_background = in_background;
                }
 
+               public OperationRun (bool in_background, CommandResult result)
+                       : this (TargetAddress.Null, in_background, result)
+               { }
+
+               public OperationRun (CommandResult result)
+                       : this (TargetAddress.Null, true, result)
+               { }
+
+
                public bool InBackground {
                        get { return in_background; }
                }
@@ -2632,8 +2720,9 @@
                                goto out_frame_changed;
                        }
 
-                       if (!CallbackCompleted (sse, inferior, cevent.Data1, 
cevent.Data2))
-                               return EventResult.Running;
+                       EventResult result;
+                       if (CallbackCompleted (sse, inferior, cevent, out args, 
out result))
+                               return result;
 
                        if (stack_data != null) {
                                sse.restore_stack (stack_data);
@@ -2647,6 +2736,23 @@
                        return EventResult.Completed;
                }
 
+               protected virtual bool CallbackCompleted (SingleSteppingEngine 
sse,
+                                                         Inferior inferior,
+                                                         Inferior.ChildEvent 
cevent,
+                                                         out TargetEventArgs 
args,
+                                                         out EventResult 
result)
+               {
+                       if (!CallbackCompleted (sse, inferior, cevent.Data1, 
cevent.Data2)) {
+                               args = null;
+                               result = EventResult.Running;
+                               return true;
+                       }
+
+                       args = null;
+                       result = EventResult.CompletedCallback;
+                       return false;
+               }
+
                protected abstract bool CallbackCompleted (SingleSteppingEngine 
sse,
                                                           Inferior inferior,
                                                           long data1, long 
data2);

Modified: trunk/debugger/backends/TargetReader.cs
===================================================================
--- trunk/debugger/backends/TargetReader.cs     2006-04-25 12:30:43 UTC (rev 
59849)
+++ trunk/debugger/backends/TargetReader.cs     2006-04-25 12:35:31 UTC (rev 
59850)
@@ -22,8 +22,8 @@
                        this.data = data;
                }
 
-               internal TargetReader (TargetBlob data, TargetInfo info)
-                       : this (data.Contents, info)
+               internal TargetReader (TargetBlob data)
+                       : this (data.Contents, data.TargetInfo)
                { }
 
                public long Offset {

Modified: trunk/debugger/backends/ThreadManager.cs
===================================================================
--- trunk/debugger/backends/ThreadManager.cs    2006-04-25 12:30:43 UTC (rev 
59849)
+++ trunk/debugger/backends/ThreadManager.cs    2006-04-25 12:35:31 UTC (rev 
59850)
@@ -158,16 +158,8 @@
                                return true;
                        }
 
-                       if (!inferior.Process.Initialize (engine, inferior, 
false)) {
-                               if ((cevent.Type != 
Inferior.ChildEventType.CHILD_STOPPED) ||
-                                   (cevent.Argument != 0))
-                                       throw new InternalError (
-                                               "Received unexpected initial 
child event {0}",
-                                               cevent);
+                       inferior.Process.Initialize (engine, inferior, false);
 
-                               return true;
-                       }
-
                        if (cevent.Type == 
Inferior.ChildEventType.CHILD_CREATED_THREAD) {
                                inferior.Process.ThreadCreated (inferior, (int) 
cevent.Argument, false);
                                inferior.Continue ();

Modified: trunk/debugger/backends/ThreadServant.cs
===================================================================
--- trunk/debugger/backends/ThreadServant.cs    2006-04-25 12:30:43 UTC (rev 
59849)
+++ trunk/debugger/backends/ThreadServant.cs    2006-04-25 12:35:31 UTC (rev 
59850)
@@ -145,6 +145,8 @@
 
                public abstract void Detach ();
 
+               internal abstract void DetachThread ();
+
                public abstract void Stop ();
 
                internal abstract object Invoke (TargetAccessDelegate func, 
object data);

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

Reply via email to