Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
2009-07-08 Martin Baulig <martin@ximian.com>
Browse files Browse the repository at this point in the history
	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
Martin Baulig committed Jul 30, 2009
1 parent 380cca2 commit 53ad566
Show file tree
Hide file tree
Showing 40 changed files with 1,954 additions and 1,409 deletions.
54 changes: 54 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
96 changes: 89 additions & 7 deletions backend/DebuggerServant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace Mono.Debugger.Backend
{
internal class DebuggerServant : DebuggerMarshalByRefObject, IDisposable
internal class DebuggerServant : DebuggerMarshalByRefObject, IOperationHost, IDisposable
{
Debugger client;
DebuggerConfiguration config;
Expand All @@ -33,6 +33,7 @@ internal DebuggerServant (Debugger client, ReportWriter writer,
ObjectCache.Initialize ();
thread_manager = new ThreadManager (this);
process_hash = Hashtable.Synchronized (new Hashtable ());
stopped_event = new ManualResetEvent (false);
}

public Debugger Client {
Expand All @@ -59,6 +60,7 @@ internal void OnModuleUnLoaded (Module module)

internal void OnMainProcessCreatedEvent (ProcessServant process)
{
process_hash.Add (process, process);
client.OnMainProcessCreatedEvent (process.Client);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
//
Expand Down
34 changes: 30 additions & 4 deletions backend/Inferior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public int PID {
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);
Expand Down Expand Up @@ -192,6 +192,9 @@ public int PID {
[DllImport("monodebuggerserver")]
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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 ();
Expand All @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;

Expand Down
8 changes: 5 additions & 3 deletions backend/MonoThreadManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
Loading

0 comments on commit 53ad566

Please sign in to comment.