Permalink
Browse files

2009-07-08 Martin Baulig <martin@ximian.com>

	Martin's new Threading Model.

	* classes/GUIManager.cs
	(GUIManager): Made this obsolete, it's now just a tiny wrapper
	around the new API.

	* classes/Operation.cs: New file.
	(ThreadingModel): New public enum.
	(CommandResult): New public abstract class.
	(OperationHost): New internal interface.
	(OperationCommandResult): New public class.

	* backend/ThreadServant.cs
	(ThreadServant.StepInstruction): Removed, use the new Step() API.
	(ThreadServant.StepNativeInstruction): Likewise.
	(ThreadServant.NextInstruction): Likewise.
	(ThreadServant.StepLine): Likewise.
	(ThreadServant.NextLine): Likewise.
	(ThreadServant.Finish): Removed, use the new Step() API.

	* backend/SingleSteppingEngine.cs
	(SSE.OperationStep): Add support for `StepMode.Run'; this
	obsoletes `OperationRun'.
	(SSE.OperationRun): Removed; use `OperationStep' with `StepMode.Run'.
	(SSE.OperationFinish): Removed; use `OperationStep' with
	`StepMode.Finish' or `StepMode.FinishNative'.

	* backend/StepFrame.cs: Moved to ../classes/StepFrame.cs.

	* classes/StepFrame.cs
	(StepMode): Made this public.
	(StepFrame): Make this public and [Serializable].
	(StepMode.Run): Added.
	(StepMode.FinishNative): Added.
	(StepFrame.Until): New public property; only valid in`
	StepMode.Run'.

	* classes/Thread.cs
	(Thread.Step): New public function.
	(Thread.StepInstruction): Obsolete, use the new Step() API.
	(Thread.StepNativeInstruction): Likewise.
	(Thread.NextInstruction): Likewise.
	(Thread.StepLine): Likewise.
	(Thread.NextLine): Likewise.
	(Thread.Continue): Use `Step (StepMode.Run)'.
	(Thread.Background): Obsolete; this was never implemented and
	always the same as Continue().
	(Thread.Finish): Obsolete, use the new Step() API.

	* backend/ThreadServant.cs
	(ThreadServant.Step): New public function.

svn path=/trunk/debugger/; revision=139051
  • Loading branch information...
1 parent 380cca2 commit 53ad566fcea1bfd49c1dd053dfeb2332fbfafa0c Martin Baulig committed Jul 30, 2009
Showing with 1,954 additions and 1,409 deletions.
  1. +54 −0 ChangeLog
  2. +89 −7 backend/DebuggerServant.cs
  3. +30 −4 backend/Inferior.cs
  4. +5 −3 backend/MonoThreadManager.cs
  5. +231 −30 backend/ProcessServant.cs
  6. +489 −430 backend/SingleSteppingEngine.cs
  7. +9 −6 backend/ThreadManager.cs
  8. +7 −47 backend/ThreadServant.cs
  9. +9 −29 backend/arch/CoreFile.cs
  10. +13 −0 backend/server/i386-arch.c
  11. +11 −2 backend/server/library.c
  12. +9 −2 backend/server/server.h
  13. +20 −18 backend/server/x86-linux-ptrace.c
  14. +4 −3 backend/server/x86-ptrace.c
  15. +13 −0 backend/server/x86_64-arch.c
  16. +27 −2 classes/Debugger.cs
  17. +104 −33 classes/DebuggerConfiguration.cs
  18. +9 −0 classes/DebuggerConfiguration.xsd
  19. +46 −8 classes/DebuggerSession.cs
  20. +42 −329 classes/GUIManager.cs
  21. +108 −0 classes/Operation.cs
  22. +8 −18 classes/Process.cs
  23. +29 −8 {backend → classes}/StepFrame.cs
  24. +102 −104 classes/Thread.cs
  25. +135 −76 frontend/Command.cs
  26. +19 −6 frontend/Expression.cs
  27. +39 −197 frontend/Interpreter.cs
  28. +18 −16 frontend/Main.cs
  29. +0 −1 frontend/ScriptingContext.cs
  30. +1 −0 test/framework/DebuggerTestFixture.cs
  31. +2 −0 test/src/TestChild.cs
  32. +1 −1 test/src/TestMultiThread.cs
  33. +5 −4 test/testsuite/TestAbort.cs
  34. +1 −2 test/testsuite/TestActivateBreakpoints2.cs
  35. +1 −2 test/testsuite/TestAppDomain-Module.cs
  36. +1 −2 test/testsuite/TestAppDomain.cs
  37. +247 −4 test/testsuite/TestExec.cs
  38. +11 −9 test/testsuite/TestMultiThread.cs
  39. +2 −3 test/testsuite/testnativeexec.cs
  40. +3 −3 test/testsuite/testnativefork.cs
View
@@ -1,3 +1,57 @@
+2009-07-08 Martin Baulig <martin@ximian.com>
+
+ Martin's new Threading Model.
+
+ * classes/GUIManager.cs
+ (GUIManager): Made this obsolete, it's now just a tiny wrapper
+ around the new API.
+
+ * classes/Operation.cs: New file.
+ (ThreadingModel): New public enum.
+ (CommandResult): New public abstract class.
+ (OperationHost): New internal interface.
+ (OperationCommandResult): New public class.
+
+ * backend/ThreadServant.cs
+ (ThreadServant.StepInstruction): Removed, use the new Step() API.
+ (ThreadServant.StepNativeInstruction): Likewise.
+ (ThreadServant.NextInstruction): Likewise.
+ (ThreadServant.StepLine): Likewise.
+ (ThreadServant.NextLine): Likewise.
+ (ThreadServant.Finish): Removed, use the new Step() API.
+
+ * backend/SingleSteppingEngine.cs
+ (SSE.OperationStep): Add support for `StepMode.Run'; this
+ obsoletes `OperationRun'.
+ (SSE.OperationRun): Removed; use `OperationStep' with `StepMode.Run'.
+ (SSE.OperationFinish): Removed; use `OperationStep' with
+ `StepMode.Finish' or `StepMode.FinishNative'.
+
+ * backend/StepFrame.cs: Moved to ../classes/StepFrame.cs.
+
+ * classes/StepFrame.cs
+ (StepMode): Made this public.
+ (StepFrame): Make this public and [Serializable].
+ (StepMode.Run): Added.
+ (StepMode.FinishNative): Added.
+ (StepFrame.Until): New public property; only valid in`
+ StepMode.Run'.
+
+ * classes/Thread.cs
+ (Thread.Step): New public function.
+ (Thread.StepInstruction): Obsolete, use the new Step() API.
+ (Thread.StepNativeInstruction): Likewise.
+ (Thread.NextInstruction): Likewise.
+ (Thread.StepLine): Likewise.
+ (Thread.NextLine): Likewise.
+ (Thread.Continue): Use `Step (StepMode.Run)'.
+ (Thread.Background): Obsolete; this was never implemented and
+ always the same as Continue().
+ (Thread.Finish): Obsolete, use the new Step() API.
+
+ * backend/ThreadServant.cs
+ (ThreadServant.Step): New public function.
+
2009-07-13 Jonathan Chambers <joncham@gmail.com>
* backend/Inferior.cs: Add and handle WINDOWS server type.
@@ -16,7 +16,7 @@
namespace Mono.Debugger.Backend
{
- internal class DebuggerServant : DebuggerMarshalByRefObject, IDisposable
+ internal class DebuggerServant : DebuggerMarshalByRefObject, IOperationHost, IDisposable
{
Debugger client;
DebuggerConfiguration config;
@@ -33,6 +33,7 @@ internal class DebuggerServant : DebuggerMarshalByRefObject, IDisposable
ObjectCache.Initialize ();
thread_manager = new ThreadManager (this);
process_hash = Hashtable.Synchronized (new Hashtable ());
+ stopped_event = new ManualResetEvent (false);
}
public Debugger Client {
@@ -59,6 +60,7 @@ internal void OnModuleUnLoaded (Module module)
internal void OnMainProcessCreatedEvent (ProcessServant process)
{
+ process_hash.Add (process, process);
client.OnMainProcessCreatedEvent (process.Client);
}
@@ -107,6 +109,16 @@ internal void SendTargetEvent (SingleSteppingEngine sse, TargetEventArgs args)
}
}
+ internal void OnEnterNestedBreakState (SingleSteppingEngine sse)
+ {
+ client.OnEnterNestedBreakState (sse.Thread);
+ }
+
+ internal void OnLeaveNestedBreakState (SingleSteppingEngine sse)
+ {
+ client.OnLeaveNestedBreakState (sse.Thread);
+ }
+
public void Kill ()
{
main_process = null;
@@ -140,29 +152,27 @@ public void Detach ()
}
}
- public Process Run (DebuggerSession session)
+ public Process Run (DebuggerSession session, out CommandResult result)
{
check_disposed ();
if (main_process != null)
throw new TargetException (TargetError.AlreadyHaveTarget);
ProcessStart start = new ProcessStart (session);
- main_process = thread_manager.StartApplication (start);
- process_hash.Add (main_process, main_process);
+ main_process = thread_manager.StartApplication (start, out result);
return main_process.Client;
}
- public Process Attach (DebuggerSession session, int pid)
+ public Process Attach (DebuggerSession session, int pid, out CommandResult result)
{
check_disposed ();
if (main_process != null)
throw new TargetException (TargetError.AlreadyHaveTarget);
ProcessStart start = new ProcessStart (session, pid);
- main_process = thread_manager.StartApplication (start);
- process_hash.Add (main_process, main_process);
+ main_process = thread_manager.StartApplication (start, out result);
return main_process.Client;
}
@@ -200,6 +210,78 @@ public void Error (string message, params object[] args)
Console.WriteLine ("ERROR: " + String.Format (message, args));
}
+#region Global Threading Model
+
+ ManualResetEvent stopped_event;
+ OperationCommandResult current_operation;
+
+ internal WaitHandle WaitHandle {
+ get { return stopped_event; }
+ }
+
+ internal CommandResult StartOperation (ThreadingModel model, SingleSteppingEngine caller)
+ {
+ if (!ThreadManager.InBackgroundThread)
+ throw new InternalError ();
+
+ if ((model & ThreadingModel.ThreadingMode) == ThreadingModel.Default) {
+ if (Inferior.HasThreadEvents)
+ model |= ThreadingModel.Single;
+ else
+ model |= ThreadingModel.Process;
+ }
+
+ if ((model & ThreadingModel.ThreadingMode) != ThreadingModel.Global)
+ return caller.Process.StartOperation (model, caller);
+
+ if (current_operation != null)
+ throw new TargetException (TargetError.NotStopped);
+
+ lock (this) {
+ stopped_event.Reset ();
+ current_operation = new OperationCommandResult (this, model);
+ }
+
+ foreach (ProcessServant process in process_hash.Values) {
+ process.StartGlobalOperation (model, caller, current_operation);
+ }
+
+ return current_operation;
+ }
+
+ public void OperationCompleted (SingleSteppingEngine caller, TargetEventArgs result, ThreadingModel model)
+ {
+ if (!ThreadManager.InBackgroundThread)
+ throw new InternalError ();
+
+ foreach (ProcessServant process in process_hash.Values) {
+ process.OperationCompleted (caller, result, model);
+ }
+
+ lock (this) {
+ current_operation = null;
+ stopped_event.Set ();
+ }
+ }
+
+ WaitHandle IOperationHost.WaitHandle {
+ get { return stopped_event; }
+ }
+
+ void IOperationHost.SendResult (SingleSteppingEngine sse, TargetEventArgs args)
+ {
+ SendTargetEvent (sse, args);
+ }
+
+ void IOperationHost.Abort ()
+ {
+ foreach (ProcessServant process in process_hash.Values) {
+ process.Stop ();
+ }
+ }
+
+#endregion
+
//
// IDisposable
//
View
@@ -65,7 +65,7 @@ internal class Inferior : TargetAccess, ITargetNotification, IDisposable
static extern TargetError mono_debugger_server_initialize_process (IntPtr handle);
[DllImport("monodebuggerserver")]
- static extern TargetError mono_debugger_server_initialize_thread (IntPtr handle, int child_pid);
+ static extern TargetError mono_debugger_server_initialize_thread (IntPtr handle, int child_pid, bool wait);
[DllImport("monodebuggerserver")]
static extern TargetError mono_debugger_server_io_thread_main (IntPtr io_data, ChildOutputHandler output_handler);
@@ -193,6 +193,9 @@ internal class Inferior : TargetAccess, ITargetNotification, IDisposable
static extern TargetError mono_debugger_server_get_callback_frame (IntPtr handle, long stack_pointer, bool exact_match, IntPtr info);
[DllImport("monodebuggerserver")]
+ static extern TargetError mono_debugger_server_restart_notification (IntPtr handle);
+
+ [DllImport("monodebuggerserver")]
static extern void mono_debugger_server_set_runtime_info (IntPtr handle, IntPtr mono_runtime_info);
[DllImport("monodebuggerserver")]
@@ -603,6 +606,11 @@ public void DisableBreakpoint (int breakpoint)
server_handle, breakpoint));
}
+ public void RestartNotification ()
+ {
+ check_error (mono_debugger_server_restart_notification (server_handle));
+ }
+
public ProcessStart ProcessStart {
get {
return start;
@@ -668,7 +676,22 @@ public void InitializeThread (int pid)
initialized = true;
- check_error (mono_debugger_server_initialize_thread (server_handle, pid));
+ check_error (mono_debugger_server_initialize_thread (server_handle, pid, true));
+ this.child_pid = pid;
+
+ SetupInferior ();
+
+ change_target_state (TargetState.Stopped, 0);
+ }
+
+ public void InitializeAfterExec (int pid)
+ {
+ if (initialized)
+ throw new TargetException (TargetError.AlreadyHaveTarget);
+
+ initialized = true;
+
+ check_error (mono_debugger_server_initialize_thread (server_handle, pid, false));
this.child_pid = pid;
SetupInferior ();
@@ -678,7 +701,7 @@ public void InitializeThread (int pid)
public void Attach (int pid)
{
- if (has_target)
+ if (has_target || initialized)
throw new TargetException (TargetError.AlreadyHaveTarget);
has_target = true;
@@ -692,7 +715,9 @@ public void Attach (int pid)
start.SetupApplication (exe_file, cwd, cmdline_args);
- InitializeThread (pid);
+ initialized = true;
+
+ SetupInferior ();
change_target_state (TargetState.Stopped, 0);
}
@@ -732,6 +757,7 @@ public ChildEvent ProcessEvent (int status)
case ChildEventType.CHILD_STOPPED:
case ChildEventType.CHILD_INTERRUPTED:
case ChildEventType.CHILD_HIT_BREAKPOINT:
+ case ChildEventType.CHILD_NOTIFICATION:
change_target_state (TargetState.Stopped);
break;
@@ -239,18 +239,20 @@ internal void ThreadCreated (SingleSteppingEngine sse)
sse.Inferior.SetRuntimeInfo (mono_runtime_info);
if (!MonoDebuggerInfo.CheckRuntimeVersion (81, 3) && !process.IsAttached) {
if (++index < 3)
- sse.SetDaemon ();
+ sse.Thread.ThreadFlags |= Thread.Flags.Daemon | Thread.Flags.Immutable;
} else {
- sse.SetDaemon ();
+ sse.Thread.ThreadFlags |= Thread.Flags.Daemon | Thread.Flags.Immutable;
}
}
void check_thread_flags (SingleSteppingEngine engine, ThreadFlags flags)
{
if ((flags & (ThreadFlags.Internal | ThreadFlags.ThreadPool)) != ThreadFlags.Internal) {
- engine.SetManaged ();
+ engine.Thread.ThreadFlags &= ~(Thread.Flags.Daemon | Thread.Flags.Immutable);
if (engine != process.MainThread)
process.Debugger.Client.OnManagedThreadCreatedEvent (engine.Thread);
+ } else if ((flags & ThreadFlags.ThreadPool) != 0) {
+ engine.Thread.ThreadFlags &= ~Thread.Flags.Immutable;
}
}
Oops, something went wrong.

0 comments on commit 53ad566

Please sign in to comment.