diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.cs index 20b2552dff..86a0596846 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.cs @@ -121,7 +121,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads public override void RefreshPad() { - if (debuggedProcess == null) { + if (debuggedProcess == null || debuggedProcess.IsRunning) { runningThreadsList.Items.Clear(); return; } @@ -161,7 +161,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads { runningThreadsList.Items.Add(new ListViewItem(thread.ID.ToString())); RefreshThread(thread); - thread.StateChanged += delegate { + thread.NameChanged += delegate { RefreshThread(thread); }; thread.Expired += delegate { diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Thread.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Thread.cs index 5a31b39bd2..f5525a047a 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Thread.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Thread.cs @@ -19,21 +19,16 @@ namespace Debugger { Process process; + uint id; ICorDebugThread corThread; + List steppers = new List(); + Exception currentException; DebuggeeState currentException_DebuggeeState; ExceptionType currentExceptionType; bool currentExceptionIsUnhandled; - List steppers = new List(); - - uint id; - bool lastSuspendedState = false; - ThreadPriority lastPriority = ThreadPriority.Normal; - string lastName = string.Empty; - bool hasBeenLoaded = false; - bool hasExpired = false; bool nativeThreadExited = false; @@ -41,6 +36,7 @@ namespace Debugger public event EventHandler Expired; public event EventHandler NativeThreadExited; + public event EventHandler NameChanged; public bool HasExpired { get { @@ -55,16 +51,6 @@ namespace Debugger } } - internal bool HasBeenLoaded { - get { - return hasBeenLoaded; - } - set { - hasBeenLoaded = value; - OnStateChanged(); - } - } - [Debugger.Tests.Ignore] public uint ID { get{ @@ -72,22 +58,7 @@ namespace Debugger } } - /// If the thread is not at safe point, it is not posible to evaluate - /// on it - /// Returns false is the thread is in invalid state - public bool IsAtSafePoint { - get { - if (IsInValidState) { - return CorThread.UserState != CorDebugUserState.USER_UNSAFE_POINT; - } else { - return false; - } - } - } - - /// - /// From time to time the thread may be in invalid state. - /// + /// From time to time the thread may be in invalid state. public bool IsInValidState { get { try { @@ -153,53 +124,81 @@ namespace Debugger } } + /// If the thread is not at safe point, it is not posible to evaluate + /// on it + /// Returns false if the thread is in invalid state + public bool IsAtSafePoint { + get { + process.AssertPaused(); + + if (!IsInValidState) return false; + + return CorThread.UserState != CorDebugUserState.USER_UNSAFE_POINT; + } + } + + /// Returns false if the thread is in invalid state public bool Suspended { get { - if (process.IsRunning) return lastSuspendedState; + process.AssertPaused(); + + if (!IsInValidState) return false; - lastSuspendedState = (CorThread.DebugState == CorDebugThreadState.THREAD_SUSPEND); - return lastSuspendedState; + return (CorThread.DebugState == CorDebugThreadState.Suspend); } set { - CorThread.SetDebugState((value==true)?CorDebugThreadState.THREAD_SUSPEND:CorDebugThreadState.THREAD_RUN); + CorThread.SetDebugState((value==true) ? CorDebugThreadState.Suspend : CorDebugThreadState.Run); } } + /// Returns Normal if the thread is in invalid state public ThreadPriority Priority { get { - if (!HasBeenLoaded) return lastPriority; - if (process.IsRunning) return lastPriority; + process.AssertPaused(); + + if (!IsInValidState) return ThreadPriority.Normal; Value runTimeValue = RuntimeValue; if (runTimeValue.IsNull) return ThreadPriority.Normal; - lastPriority = (ThreadPriority)(int)runTimeValue.GetMemberValue("m_Priority").PrimitiveValue; - return lastPriority; + return (ThreadPriority)(int)runTimeValue.GetMemberValue("m_Priority").PrimitiveValue; } } - + + // NB: The value is null during the CreateThread callback public Value RuntimeValue { get { - // TODO: It may have started - rework - if (!HasBeenLoaded) throw new DebuggerException("Thread has not started jet"); process.AssertPaused(); return new Value(process, CorThread.Object); } } + /// Returns empty string if the thread is in invalid state public string Name { get { - if (!HasBeenLoaded) return lastName; - if (process.IsRunning) return lastName; - Value runtimeValue = RuntimeValue; - if (runtimeValue.IsNull) return lastName; + process.AssertPaused(); + + if (!IsInValidState) return string.Empty; + Value runtimeValue = RuntimeValue; + if (runtimeValue.IsNull) return string.Empty; Value runtimeName = runtimeValue.GetMemberValue("m_Name"); if (runtimeName.IsNull) return string.Empty; - lastName = runtimeName.AsString.ToString(); - return lastName; + return runtimeName.AsString.ToString(); } } + protected virtual void OnNameChanged(ThreadEventArgs e) + { + if (NameChanged != null) { + NameChanged(this, e); + } + } + + internal void NotifyNameChanged() + { + OnNameChanged(new ThreadEventArgs(this)); + } + public Exception CurrentException { get { if (currentException_DebuggeeState == this.Process.DebuggeeState) { @@ -269,16 +268,6 @@ namespace Debugger } } - public event EventHandler StateChanged; - - protected void OnStateChanged() - { - if (StateChanged != null) { - StateChanged(this, new ThreadEventArgs(this)); - } - } - - public override string ToString() { return String.Format("Thread Name = {1} Suspended = {2}", ID, Name, Suspended); diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallback.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallback.cs index e909335324..24cd9cd013 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallback.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallback.cs @@ -351,7 +351,7 @@ namespace Debugger EnterCallback(PausedReason.Other, "NameChange: pThread", pThread); Thread thread = process.GetThread(pThread); - thread.HasBeenLoaded = true; + thread.NotifyNameChanged(); ExitCallback(); diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorDebug/Autogenerated/CorDebugThreadState.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorDebug/Autogenerated/CorDebugThreadState.cs index bba55bb2b7..0cf8aafaa9 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorDebug/Autogenerated/CorDebugThreadState.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorDebug/Autogenerated/CorDebugThreadState.cs @@ -1,4 +1,4 @@ -// +// // // // @@ -16,10 +16,8 @@ namespace Debugger.Wrappers.CorDebug public enum CorDebugThreadState : int { - - THREAD_RUN = 0, - - THREAD_SUSPEND = 1, + Run = 0, + Suspend = 1, } }