diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs index b6b4e73474..eb34851777 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs @@ -86,7 +86,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads void CallStackListItemActivate(object sender, EventArgs e) { - if (!debuggerCore.IsProcessRunning) { + if (!debuggerCore.IsCurrentProcessSafeForInspection) { debuggerCore.CurrentThread.CurrentFunction = (Function)(callStackList.SelectedItems[0].Tag); } } @@ -105,7 +105,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads { callStackList.BeginUpdate(); callStackList.Items.Clear(); - if (debugger.IsProcessRunning == false && debuggerCore.CurrentThread != null) { + if (debuggerCore.IsCurrentProcessSafeForInspection) { foreach (Function f in debuggerCore.CurrentThread.Callstack) { ListViewItem item = new ListViewItem(new string[] { f.Name, "" }); item.Tag = f; diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LocalVarPad.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LocalVarPad.cs index 0a542f8fbc..e84e8a90b9 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LocalVarPad.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LocalVarPad.cs @@ -107,14 +107,14 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads void RefreshList() { - if (debugger.IsDebugging && debugger.IsProcessRunning == false) { + if (debuggerCore.IsCurrentProcessSafeForInspection) { UpdateVariables(localVarList.Items, debuggerCore.LocalVariables); } } private void localVarList_BeforeExpand(object sender, TreeListViewCancelEventArgs e) { - if (debugger.IsDebugging && debugger.IsProcessRunning == false) { + if (debuggerCore.IsCurrentProcessSafeForInspection) { ((VariableListItem)e.Item).PrepareForExpansion(); } else { // TODO: Some message telling user that he can not explore variable since 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 5534ed88a7..11ed9619a3 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 @@ -97,7 +97,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads void RunningThreadsListItemActivate(object sender, EventArgs e) { - if (!debugger.IsProcessRunning) { + if (debuggerCore.IsCurrentProcessSafeForInspection) { debuggerCore.CurrentThread = (Thread)(runningThreadsList.SelectedItems[0].Tag); } } diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs index b60fcf6075..087f2cdbe6 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs @@ -208,7 +208,7 @@ namespace ICSharpCode.SharpDevelop.Services /// public string GetValueAsString(string variableName) { - if (debugger == null || !debugger.IsDebugging || debugger.IsProcessRunning) return null; + if (debugger == null || !debugger.IsCurrentProcessSafeForInspection) return null; VariableCollection collection = debugger.LocalVariables; if (collection == null) return null; @@ -267,8 +267,8 @@ namespace ICSharpCode.SharpDevelop.Services RestoreNDebuggerBreakpoints(); - isDebuggingCache = debugger.IsDebugging; - isProcessRunningCache = debugger.IsProcessRunning; + isDebuggingCache = false; + isProcessRunningCache = true; if (Initialize != null) { Initialize(this, null); diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs index ef82074628..e45f5858a7 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs @@ -53,8 +53,6 @@ namespace DebuggerLibrary } } - #region Basic functions - public NDebugger() { requiredApartmentState = System.Threading.Thread.CurrentThread.GetApartmentState(); @@ -79,7 +77,6 @@ namespace DebuggerLibrary NativeMethods.CreateDebuggingInterfaceFromVersion(3, sb.ToString(), out corDebug); - //corDebug = new CorDebugClass(); managedCallback = new ManagedCallback(this); managedCallbackProxy = new ManagedCallbackProxy(this, managedCallback); @@ -104,8 +101,6 @@ namespace DebuggerLibrary TraceMessage("Reset done"); } - #endregion - #region Public events public event EventHandler DebuggingPaused; @@ -167,8 +162,6 @@ namespace DebuggerLibrary #endregion - #region Execution control - public void StartWithoutDebugging(System.Diagnostics.ProcessStartInfo psi) { System.Diagnostics.Process process; @@ -183,56 +176,28 @@ namespace DebuggerLibrary AddProcess(process); } - - #endregion - - public void ToggleBreakpointAt(string fileName, int line, int column) - { - // Check if there is breakpoint on that line - foreach (Breakpoint breakpoint in Breakpoints) { - // TODO check filename too - if (breakpoint.SourcecodeSegment.StartLine == line) { - RemoveBreakpoint(breakpoint); - return; - } - } - - // Add the breakpoint - Breakpoint addedBreakpoint = AddBreakpoint(new SourcecodeSegment(fileName, line), true); - - // Check if it wasn't forced to move to different line with breakpoint - foreach (Breakpoint breakpoint in Breakpoints) { - if (breakpoint != addedBreakpoint) { // Only the old ones - if (breakpoint.SourcecodeSegment.StartLine == addedBreakpoint.SourcecodeSegment.StartLine) { - // Whops! We have two breakpoint on signle line, delete one - RemoveBreakpoint(addedBreakpoint); - return; - } - } - } - } - - - public bool IsProcessRunning { + public bool IsCurrentProcessSafeForInspection { get { - if (!IsDebugging) return false; - return CurrentProcess.IsProcessRunning; - } - set { - if (CurrentProcess == null) return; - CurrentProcess.IsProcessRunning = value; + if (CurrentProcess == null) { + return false; + } else { + return CurrentProcess.IsProcessSafeForInspection; + } } } - public bool IsDebugging { - get { - return (CurrentProcess != null); + internal void CheckThatCurrentProcessIsSafeForInspection() + { + if (CurrentProcess == null) { + throw new DebuggerException("There is no process being debugged."); + } else { + CurrentProcess.CheckThatProcessIsSafeForInspection(); } } public Thread CurrentThread { get { - if (!IsDebugging) return null; + if (CurrentProcess == null) return null; return CurrentProcess.CurrentThread; } set { @@ -242,7 +207,7 @@ namespace DebuggerLibrary public SourcecodeSegment NextStatement { get { - if (!IsDebugging) return null; + if (!IsCurrentProcessSafeForInspection) return null; if (CurrentProcess.CurrentThread.CurrentFunction == null) { return null; } else { @@ -253,7 +218,7 @@ namespace DebuggerLibrary public VariableCollection LocalVariables { get { - if (!IsDebugging) return VariableCollection.Empty; + if (!IsCurrentProcessSafeForInspection) return VariableCollection.Empty; return CurrentProcess.CurrentThread.CurrentFunction.GetVariables(); } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs index 0f33b87828..9b37179555 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs @@ -38,14 +38,13 @@ namespace DebuggerLibrary public Thread CurrentThread { get { - if (IsProcessRunning) throw new DebuggerException("Process must not be running"); if (currentThread != null) return currentThread; IList threads = Threads; if (currentThread == null && threads.Count > 0) { currentThread = threads[0]; return currentThread; } - throw new DebuggerException("No current thread"); + return null; } set { currentThread = value; @@ -120,7 +119,7 @@ namespace DebuggerLibrary public void Break() { - if (!IsProcessRunning) { + if (!isProcessRunning) { throw new DebuggerException("Invalid operation"); } @@ -132,7 +131,7 @@ namespace DebuggerLibrary public void Continue() { - if (IsProcessRunning) { + if (isProcessRunning) { throw new DebuggerException("Invalid operation"); } @@ -165,5 +164,27 @@ namespace DebuggerLibrary isProcessRunning = value; } } + + public bool IsProcessSafeForInspection { + get { + if (isProcessRunning) return false; + if (CurrentThread == null) return false; + + return true; + } + } + + internal void CheckThatProcessIsSafeForInspection() + { + if (!IsProcessSafeForInspection) { + if (isProcessRunning) { + throw new DebuggerException("Process is not safe for inspection because it is running."); + } else if (CurrentThread == null){ + throw new DebuggerException("Process is not safe for inspection because it has no thread."); + } else { + throw new DebuggerException("Process is not safe for inspection."); + } + } + } } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Thread.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Thread.cs index e749176f66..64b78ec41a 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Thread.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Thread.cs @@ -84,7 +84,7 @@ namespace DebuggerLibrary public bool Suspended { get { - if (debugger.IsProcessRunning) return lastSuspendedState; + if (!process.IsProcessSafeForInspection) return lastSuspendedState; CorDebugThreadState state; corThread.GetDebugState(out state); @@ -99,7 +99,7 @@ namespace DebuggerLibrary public ThreadPriority Priority { get { if (!HasBeenLoaded) return lastPriority; - if (debugger.IsProcessRunning) return lastPriority; + if (!process.IsProcessSafeForInspection) return lastPriority; Variable runTimeVar = RuntimeVariable; if (runTimeVar is NullRefVariable) return ThreadPriority.Normal; @@ -111,7 +111,8 @@ namespace DebuggerLibrary public Variable RuntimeVariable { get { if (!HasBeenLoaded) throw new DebuggerException("Thread has not started jet"); - if (debugger.IsProcessRunning) throw new DebuggerException("Process is running"); + process.CheckThatProcessIsSafeForInspection(); + ICorDebugValue corValue; corThread.GetObject(out corValue); return VariableFactory.CreateVariable(debugger, corValue, "Thread" + ID); @@ -121,7 +122,7 @@ namespace DebuggerLibrary public string Name { get { if (!HasBeenLoaded) return lastName; - if (debugger.IsProcessRunning) return lastName; + if (!process.IsProcessSafeForInspection) return lastName; Variable runtimeVar = RuntimeVariable; if (runtimeVar is NullRefVariable) return lastName; Variable runtimeName = runtimeVar.SubVariables["m_Name"]; @@ -180,8 +181,7 @@ namespace DebuggerLibrary get { List callstack = new List(); - if (!debugger.IsDebugging) return callstack; - if (debugger.IsProcessRunning) return callstack; + if (!process.IsProcessSafeForInspection) return callstack; ICorDebugChainEnum corChainEnum; corThread.EnumerateChains(out corChainEnum); @@ -219,7 +219,8 @@ namespace DebuggerLibrary public Function CurrentFunction { get { - if (debugger.IsProcessRunning) throw new DebuggerException("Process must not be running"); + process.CheckThatProcessIsSafeForInspection(); + return currentFunction; } set { diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/Eval.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/Eval.cs index e6d3847909..da769e6378 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/Eval.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/Eval.cs @@ -58,9 +58,7 @@ namespace DebuggerLibrary /// public void AsyncPerformEval() { - if (debugger.IsProcessRunning) { - throw new DebuggerException("Debugger must be paused"); - } + debugger.CheckThatCurrentProcessIsSafeForInspection(); debugger.CurrentThread.CorThread.CreateEval(out corEval);