From d94907f1da75c31ed515e4d8baa56702f1e62724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Wed, 2 Nov 2005 15:07:49 +0000 Subject: [PATCH] Fixed SD2-505: Debugger freezes on StackOverflowException git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@667 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Src/Pads/CallStackPad.cs | 3 ++ .../Project/Src/Threads/Exception.cs | 7 +++ .../Project/Src/Threads/Thread.cs | 44 +++++++++---------- 3 files changed, 32 insertions(+), 22 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 4764ddf5a8..15b659e486 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 @@ -196,6 +196,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads bool showArgumentValues = ShowArgumentValues; bool showExternalMethods = ShowExternalMethods; bool lastItemIsExternalMethod = false; + int callstackItems = 0; callStackList.BeginUpdate(); callStackList.Items.Clear(); @@ -253,6 +254,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads item.Tag = f; item.ForeColor = f.HasSymbols ? Color.Black : Color.Gray; callStackList.Items.Add(item); + callstackItems++; + if (callstackItems >= 100) break; } } callStackList.EndUpdate(); 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 456f25753e..3cf37fe37e 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 @@ -54,13 +54,20 @@ namespace DebuggerLibrary } callstack = ""; + int callstackItems = 0; foreach(Function function in thread.Callstack) { + if (callstackItems >= 100) { + callstack += "...\n"; + break; + } + SourcecodeSegment loc = function.NextStatement; callstack += function.Name + "()"; if (loc != null) { callstack += " - " + loc.SourceFullFilename + ":" + loc.StartLine + "," + loc.StartColumn; } callstack += "\n"; + callstackItems++; } type = runtimeVariable.Type; 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 a1032814d2..2f8e3c2897 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 @@ -185,15 +185,13 @@ namespace DebuggerLibrary } } - public unsafe List Callstack { + public IEnumerable Callstack { get { - List callstack = new List(); - - if (process.IsRunning) return callstack; - + if (process.IsRunning) yield break; + ICorDebugChainEnum corChainEnum; corThread.EnumerateChains(out corChainEnum); - + while (true) { uint chainsFetched; ICorDebugChain[] corChains = new ICorDebugChain[1]; // One at time @@ -203,27 +201,27 @@ namespace DebuggerLibrary int isManaged; corChains[0].IsManaged(out isManaged); if (isManaged == 0) continue; // Only managed ones - + ICorDebugFrameEnum corFrameEnum; corChains[0].EnumerateFrames(out corFrameEnum); - - for(;;) - { + + while (true) { uint framesFetched; ICorDebugFrame[] corFrames = new ICorDebugFrame[1]; // Only one at time corFrameEnum.Next(1, corFrames, out framesFetched); if (framesFetched == 0) break; // We are done - - try { + + Function function = null; + try { if (corFrames[0] is ICorDebugILFrame) { - callstack.Add(new Function(debugger, (ICorDebugILFrame)corFrames[0])); + function = new Function(debugger, (ICorDebugILFrame)corFrames[0]); } - } catch (COMException) { + } catch (COMException) { // TODO }; + yield return function; } - } // for(;;) - return callstack; + } } // get } // End of public FunctionCollection Callstack @@ -267,15 +265,17 @@ namespace DebuggerLibrary return null; } } - + + /// + /// Returns the most recent function on callstack. + /// Returns null if callstack is empty. + /// public Function LastFunction { get { - List callstack = Callstack; - if (callstack.Count > 0) { - return Callstack[0]; - } else { - return null; + foreach(Function function in Callstack) { + return function; } + return null; } } }