From b0f39002604b261ddf92b5f6009beeadadb441d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Mon, 25 Jul 2005 09:38:42 +0000 Subject: [PATCH] Exception dialog uses TextBox and is bit more informative git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@248 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Src/Service/ExceptionForm.cs | 42 +++++++++++++------ .../Project/Src/Service/WindowsDebugger.cs | 17 ++++---- .../Project/Src/Debugger/NDebugger.cs | 2 +- .../Project/Src/Threads/Exception.cs | 20 ++++++++- 4 files changed, 58 insertions(+), 23 deletions(-) diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/ExceptionForm.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/ExceptionForm.cs index 2cebc8caa5..56f5019b24 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/ExceptionForm.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/ExceptionForm.cs @@ -7,6 +7,8 @@ using System; using System.Windows.Forms; +using ICSharpCode.Core; +using DebuggerLibrary; namespace ICSharpCode.SharpDevelop.Services { @@ -14,20 +16,33 @@ namespace ICSharpCode.SharpDevelop.Services { public enum Result {Break, Continue, Ignore}; - public Result result = Result.Continue; + private Result result = Result.Continue; - public System.Windows.Forms.Label label; + private System.Windows.Forms.TextBox textBox; private System.Windows.Forms.Button buttonContinue; private System.Windows.Forms.Button buttonIgnore; - public System.Windows.Forms.PictureBox pictureBox; + private System.Windows.Forms.PictureBox pictureBox; private System.Windows.Forms.Button buttonBreak; - public ExceptionForm() + private ExceptionForm() { InitializeComponent(); } + public static Result Show(DebuggerLibrary.Exception exception) + { + ExceptionForm form = new ExceptionForm(); + form.textBox.Text = "Exception " + + exception.Type + + " was thrown in debugee:\r\n" + + exception.Message + "\r\n\r\n" + + exception.Callstack.Replace("\n","\r\n"); + form.pictureBox.Image = ResourceService.GetBitmap((exception.ExceptionType != ExceptionType.DEBUG_EXCEPTION_UNHANDLED)?"Icons.32x32.Warning":"Icons.32x32.Error"); + form.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainForm); + return form.result; + } + #region Windows Forms Designer generated code /// /// This method is required for Windows Forms designer support. @@ -39,7 +54,7 @@ namespace ICSharpCode.SharpDevelop.Services this.pictureBox = new System.Windows.Forms.PictureBox(); this.buttonIgnore = new System.Windows.Forms.Button(); this.buttonContinue = new System.Windows.Forms.Button(); - this.label = new System.Windows.Forms.Label(); + this.textBox = new System.Windows.Forms.TextBox(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); this.SuspendLayout(); // @@ -85,19 +100,22 @@ namespace ICSharpCode.SharpDevelop.Services // // label // - this.label.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + this.textBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.label.Location = new System.Drawing.Point(91, 16); - this.label.Name = "label"; - this.label.Size = new System.Drawing.Size(528, 144); - this.label.TabIndex = 4; - this.label.Text = "label"; + this.textBox.Location = new System.Drawing.Point(91, 16); + this.textBox.Name = "textBox"; + this.textBox.Multiline = true; + this.textBox.WordWrap = false; + this.textBox.ReadOnly = true; + this.textBox.Size = new System.Drawing.Size(528, 138); + this.textBox.TabIndex = 4; + this.textBox.Text = ""; // // ExceptionForm // this.ClientSize = new System.Drawing.Size(638, 203); - this.Controls.Add(this.label); + this.Controls.Add(this.textBox); this.Controls.Add(this.pictureBox); this.Controls.Add(this.buttonIgnore); this.Controls.Add(this.buttonContinue); 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 804deedcaa..f54c96bbe7 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 @@ -246,6 +246,7 @@ namespace ICSharpCode.SharpDevelop.Services debugger = new NDebugger(); debugger.LogMessage += new EventHandler(LogMessage); + debugger.DebuggerTraceMessage += new EventHandler(TraceMessage); debugger.ProcessStarted += new EventHandler(ProcessStarted); debugger.ProcessExited += new EventHandler(ProcessExited); debugger.DebuggingPaused += new EventHandler(DebuggingPaused); @@ -313,7 +314,12 @@ namespace ICSharpCode.SharpDevelop.Services void LogMessage(object sender, MessageEventArgs e) { - DebuggerService.PrintDebugMessage(e.Message); + DebuggerService.PrintDebugMessage(">" + e.Message); + } + + void TraceMessage(object sender, MessageEventArgs e) + { + DebuggerService.PrintDebugMessage(e.Message + "\n"); } void ProcessStarted(object sender, ProcessEventArgs e) @@ -349,14 +355,7 @@ namespace ICSharpCode.SharpDevelop.Services JumpToCurrentLine(); - ExceptionForm form = new ExceptionForm(); - form.label.Text = "Exception " + - debugger.CurrentThread.CurrentException.Type + - " was thrown in debugee:\n" + - debugger.CurrentThread.CurrentException.Message; - form.pictureBox.Image = ResourceService.GetBitmap((debugger.CurrentThread.CurrentException.ExceptionType != ExceptionType.DEBUG_EXCEPTION_UNHANDLED)?"Icons.32x32.Warning":"Icons.32x32.Error"); - form.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainForm); - switch (form.result) { + switch (ExceptionForm.Show(debugger.CurrentThread.CurrentException)) { case ExceptionForm.Result.Break: break; case ExceptionForm.Result.Continue: 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 3122f20462..abc5657e4b 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 @@ -144,7 +144,7 @@ namespace DebuggerLibrary protected internal virtual void OnLogMessage(string message) { - TraceMessage ("Debugger event: OnLogMessage(\"" + message + "\")"); + TraceMessage ("Debugger event: OnLogMessage"); if (LogMessage != null) { LogMessage(this, new MessageEventArgs(this, message)); } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Exception.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Exception.cs index a7772c1317..45db581294 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Exception.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Exception.cs @@ -6,6 +6,7 @@ // using System; +using System.Collections.Generic; using System.Runtime.InteropServices; using System.Threading; @@ -24,6 +25,7 @@ namespace DebuggerLibrary ExceptionType exceptionType; SourcecodeSegment location; DateTime creationTime; + string callstack; string type; string message; @@ -47,7 +49,17 @@ namespace DebuggerLibrary message = runtimeVariableException.SubVariables["_message"].Value.ToString(); } - location = thread.CurrentFunction.NextStatement; + location = thread.LastFunctionWithLoadedSymbols.NextStatement; + callstack = ""; + foreach(Function function in thread.Callstack) { + SourcecodeSegment loc = function.NextStatement; + callstack += function.Name + "()"; + if (loc != null) { + callstack += " - " + loc.SourceFullFilename + ":" + loc.StartLine + "," + loc.StartColumn; + } + callstack += "\n"; + } + type = runtimeVariable.Type; } @@ -68,6 +80,12 @@ namespace DebuggerLibrary return message; } } + + public string Callstack { + get { + return callstack; + } + } public ExceptionType ExceptionType{ get {