From 48adfe8ff3ca8d7c3a2264f1bc77b0f334d9af78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Sun, 2 Apr 2006 22:42:20 +0000 Subject: [PATCH] Fixed callstack browsing; Moved some exception history code git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1255 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Src/Pads/CallStackPad.cs | 1 + .../Project/Src/Pads/ExceptionHistoryPad.cs | 27 ++++---- .../Project/Src/Pads/RunningThreadsPad.cs | 1 + .../Project/Src/Service/WindowsDebugger.cs | 69 ++++--------------- .../Src/Debugger/NDebugger-StateControl.cs | 18 ++--- 5 files changed, 38 insertions(+), 78 deletions(-) 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 082822c851..e4f2583788 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 @@ -72,6 +72,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads if (f.HasSymbols) { if (debuggerCore.SelectedThread != null) { debuggerCore.SelectedThread.SelectedFunction = f; + debuggerCore.OnDebuggeeStateChanged(); // Force refresh of pads } } else { MessageBox.Show("You can not switch to function without symbols", "Function switch"); diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/ExceptionHistoryPad.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/ExceptionHistoryPad.cs index 2ac8227057..e245e4212d 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/ExceptionHistoryPad.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/ExceptionHistoryPad.cs @@ -10,6 +10,7 @@ using System.Windows.Forms; using System.Drawing; using System.CodeDom.Compiler; using System.Collections; +using System.Collections.Generic; using System.IO; using System.Diagnostics; using ICSharpCode.Core; @@ -23,6 +24,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads { ListView exceptionHistoryList; + List exceptions = new List(); + ColumnHeader time = new ColumnHeader(); ColumnHeader exception = new ColumnHeader(); ColumnHeader location = new ColumnHeader(); @@ -62,7 +65,16 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads protected override void RegisterDebuggerEvents() { - debugger.ExceptionHistoryModified += delegate { RefreshPad(); }; + debuggerCore.ProcessExited += delegate { + exceptions.Clear(); + RefreshPad(); + }; + debuggerCore.DebuggingPaused += delegate (object sender, DebuggingPausedEventArgs e) { + if (e.Reason == PausedReason.Exception) { + exceptions.Add(debuggerCore.SelectedThread.CurrentException); + RefreshPad(); + } + }; } void ExceptionHistoryListItemActivate(object sender, EventArgs e) @@ -81,17 +93,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads if (content is IPositionable) { ((IPositionable)content).JumpTo((int)nextStatement.StartLine - 1, (int)nextStatement.StartColumn - 1); } - - /*if (content.Control is TextEditorControl) { - IDocument document = ((TextEditorControl)content.Control).Document; - LineSegment line = document.GetLineSegment((int)nextStatement.StartLine - 1); - int offset = line.Offset + (int)nextStatement.StartColumn; - currentLineMarker = new TextMarker(offset, (int)nextStatement.EndColumn - (int)nextStatement.StartColumn, TextMarkerType.SolidBlock, Color.Yellow); - currentLineMarkerParent = document; - currentLineMarkerParent.MarkerStrategy.TextMarker.Add(currentLineMarker); - document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea)); - document.CommitUpdate(); - }*/ } } @@ -100,7 +101,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads exceptionHistoryList.BeginUpdate(); exceptionHistoryList.Items.Clear(); - foreach(Debugger.Exception exception in debugger.ExceptionHistory) { + foreach(Debugger.Exception exception in exceptions) { string location; if (exception.Location != null) { location = exception.Location.SourceFilename + ":" + exception.Location.StartLine; 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 25512651a5..0c81bb734a 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 @@ -94,6 +94,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads if (debuggerCore.IsPaused) { if (debuggerCore.SelectedProcess != null) { debuggerCore.SelectedProcess.SelectedThread = (Thread)(runningThreadsList.SelectedItems[0].Tag); + debuggerCore.OnDebuggeeStateChanged(); // Force refresh of pads } } else { MessageBox.Show("You can not switch threads while the debugger is running.", "Thread switch"); 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 257e2d7744..f5056e6f1b 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 @@ -39,21 +39,8 @@ namespace ICSharpCode.SharpDevelop.Services Properties properties; - bool isDebuggingCache = false; - bool isProcessRunningCache = false; bool serviceInitialized = false; - - List exceptionHistory = new List(); - - public event EventHandler ExceptionHistoryModified; - - protected virtual void OnExceptionHistoryModified() - { - if (ExceptionHistoryModified != null) { - ExceptionHistoryModified(this, EventArgs.Empty); - } - } - + public NDebugger DebuggerCore { get { return debugger; @@ -71,12 +58,6 @@ namespace ICSharpCode.SharpDevelop.Services return serviceInitialized; } } - - public IList ExceptionHistory { - get { - return exceptionHistory.AsReadOnly(); - } - } public WindowsDebugger() { @@ -87,13 +68,13 @@ namespace ICSharpCode.SharpDevelop.Services public bool IsDebugging { get { - return isDebuggingCache; + return serviceInitialized && (debugger.Processes.Count > 0); } } public bool IsProcessRunning { get { - return isProcessRunningCache; + return IsDebugging && debugger.IsRunning; } } @@ -164,15 +145,7 @@ namespace ICSharpCode.SharpDevelop.Services } public event EventHandler DebugStarted; - - protected virtual void OnDebugStarted(EventArgs e) - { - if (DebugStarted != null) { - DebugStarted(this, e); - } - } - - + public event EventHandler DebugStopped; public event EventHandler IsProcessRunningChanged; protected virtual void OnIsProcessRunningChanged(EventArgs e) @@ -181,16 +154,6 @@ namespace ICSharpCode.SharpDevelop.Services IsProcessRunningChanged(this, e); } } - - - public event EventHandler DebugStopped; - - protected virtual void OnDebugStopped(EventArgs e) - { - if (DebugStopped != null) { - DebugStopped(this, e); - } - } /// /// Gets variable of given name. @@ -296,9 +259,6 @@ namespace ICSharpCode.SharpDevelop.Services foreach (BreakpointBookmark b in DebuggerService.Breakpoints) { AddBreakpoint(b); } - - isDebuggingCache = false; - isProcessRunningCache = true; if (Initialize != null) { Initialize(this, null); @@ -346,30 +306,26 @@ namespace ICSharpCode.SharpDevelop.Services void ProcessStarted(object sender, ProcessEventArgs e) { if (debugger.Processes.Count == 1) { - OnDebugStarted(EventArgs.Empty); - isDebuggingCache = true; - isProcessRunningCache = true; + if (DebugStarted != null) { + DebugStarted(this, EventArgs.Empty); + } } } void ProcessExited(object sender, ProcessEventArgs e) { if (debugger.Processes.Count == 0) { - exceptionHistory.Clear(); - OnDebugStopped(EventArgs.Empty); - isDebuggingCache = false; - isProcessRunningCache = false; + if (DebugStopped != null) { + DebugStopped(this, e); + } } } void DebuggingPaused(object sender, DebuggingPausedEventArgs e) { - isProcessRunningCache = false; OnIsProcessRunningChanged(EventArgs.Empty); if (e.Reason == PausedReason.Exception) { - exceptionHistory.Add(debugger.SelectedThread.CurrentException); - OnExceptionHistoryModified(); if (debugger.SelectedThread.CurrentException.ExceptionType != ExceptionType.DEBUG_EXCEPTION_UNHANDLED) { // Ignore the exception e.ResumeDebuggingAfterEvent(); @@ -398,7 +354,6 @@ namespace ICSharpCode.SharpDevelop.Services void DebuggingResumed(object sender, DebuggerEventArgs e) { - isProcessRunningCache = true; if (!debugger.Evaluating) { DebuggerService.RemoveCurrentLineMarker(); } @@ -410,9 +365,9 @@ namespace ICSharpCode.SharpDevelop.Services SourcecodeSegment nextStatement = debugger.NextStatement; if (nextStatement == null) { DebuggerService.RemoveCurrentLineMarker(); - return; + } else { + DebuggerService.JumpToCurrentLine(nextStatement.SourceFullFilename, nextStatement.StartLine, nextStatement.StartColumn, nextStatement.EndLine, nextStatement.EndColumn); } - DebuggerService.JumpToCurrentLine(nextStatement.SourceFullFilename, nextStatement.StartLine, nextStatement.StartColumn, nextStatement.EndLine, nextStatement.EndColumn); } } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger-StateControl.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger-StateControl.cs index 0028c4f671..a8e2d64959 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger-StateControl.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger-StateControl.cs @@ -59,7 +59,8 @@ namespace Debugger } } - protected virtual void OnDebuggeeStateChanged() + // HACK: should not be public + public virtual void OnDebuggeeStateChanged() { TraceMessage ("Debugger event: OnDebuggeeStateChanged (" + PausedReason.ToString() + ")"); if (DebuggeeStateChanged != null) { @@ -115,6 +116,10 @@ namespace Debugger get { return debugeeState; } + private set { + debugeeState = value; + OnDebuggeeStateChanged(); + } } public void AssertPaused() @@ -156,17 +161,14 @@ namespace Debugger internal void Pause() { + if (PausedReason != PausedReason.EvalComplete) { + DebugeeState = new DebugeeState(); + } + OnDebuggingPaused(); // Debugger state is unknown after calling OnDebuggingPaused (it may be resumed) - if (IsPaused) { - if (PausedReason != PausedReason.EvalComplete) { - debugeeState = new DebugeeState(); - OnDebuggeeStateChanged(); - } - } - if (IsPaused) { pausedHandle.Set(); }