Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
fix refresh bugs in CallStackPad
Browse files Browse the repository at this point in the history
  • Loading branch information
siegfriedpammer committed Mar 6, 2012
1 parent 070efb3 commit f5e1507
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 15 deletions.
25 changes: 11 additions & 14 deletions src/AddIns/Debugger/Debugger.AddIn/Pads/CallStackPad.xaml.cs
Expand Up @@ -3,12 +3,12 @@


using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;

using Debugger; using Debugger;
using Debugger.AddIn.TreeModel; using Debugger.AddIn.TreeModel;
using ICSharpCode.Core; using ICSharpCode.Core;
Expand Down Expand Up @@ -147,24 +147,21 @@ internal void RefreshPad()
return; return;
} }


List<CallStackItem> items = new List<CallStackItem>(); var items = new ObservableCollection<CallStackItem>();
using(new PrintTimes("Callstack refresh")) { using(new PrintTimes("Callstack refresh")) {
bool showExternalMethods = DebuggingOptions.Instance.ShowExternalMethods; bool showExternalMethods = DebuggingOptions.Instance.ShowExternalMethods;
bool lastItemIsExternalMethod = false; bool previousItemIsExternalMethod = false;


foreach (StackFrame frame in debuggedProcess.SelectedThread.GetCallstack(100)) { debuggedProcess.EnqueueForEach(
StackFrame f = frame;
debuggedProcess.EnqueueWork(
Dispatcher, Dispatcher,
delegate { debuggedProcess.SelectedThread.GetCallstack(100),
items.AddIfNotNull(CreateItem(f, showExternalMethods, ref lastItemIsExternalMethod)); f => items.AddIfNotNull(CreateItem(f, showExternalMethods, ref previousItemIsExternalMethod))
}); );
}
} }
view.ItemsSource = items; view.ItemsSource = items;
} }


CallStackItem CreateItem(StackFrame frame, bool showExternalMethods, ref bool lastItemIsExternalMethod) CallStackItem CreateItem(StackFrame frame, bool showExternalMethods, ref bool previousItemIsExternalMethod)
{ {
CallStackItem item; CallStackItem item;


Expand All @@ -187,16 +184,16 @@ CallStackItem CreateItem(StackFrame frame, bool showExternalMethods, ref bool la
item = new CallStackItem() { item = new CallStackItem() {
Name = GetFullName(frame), Language = "", Line = lineNumber, ModuleName = moduleName Name = GetFullName(frame), Language = "", Line = lineNumber, ModuleName = moduleName
}; };
lastItemIsExternalMethod = false; previousItemIsExternalMethod = false;
item.Frame = frame; item.Frame = frame;
} else { } else {
// Show [External methods] in the list // Show [External methods] in the list
if (lastItemIsExternalMethod) return null; if (previousItemIsExternalMethod) return null;
item = new CallStackItem() { item = new CallStackItem() {
Name = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.ExternalMethods"), Name = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.ExternalMethods"),
Language = "" Language = ""
}; };
lastItemIsExternalMethod = true; previousItemIsExternalMethod = true;
} }


return item; return item;
Expand Down
46 changes: 45 additions & 1 deletion src/AddIns/Debugger/Debugger.AddIn/TreeModel/Utils.cs
Expand Up @@ -2,10 +2,11 @@
// This code is distributed under the BSD license (for details please see \src\AddIns\Debugger\Debugger.AddIn\license.txt) // This code is distributed under the BSD license (for details please see \src\AddIns\Debugger\Debugger.AddIn\license.txt)


using System; using System;
using System.Collections; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using System.Windows.Forms; using System.Windows.Forms;
using System.Windows.Threading; using System.Windows.Threading;

using Debugger.AddIn.Pads.Controls; using Debugger.AddIn.Pads.Controls;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.NRefactory.Ast; using ICSharpCode.NRefactory.Ast;
Expand Down Expand Up @@ -40,6 +41,49 @@ public static void EnqueueWork(this Process process, Dispatcher dispatcher, Acti
} }
); );
} }

public static void EnqueueForEach<T>(this Process process, Dispatcher dispatcher, IList<T> items, Action<T> work)
{
DebuggeeState debuggeeStateWhenEnqueued = process.DebuggeeState;

dispatcher.BeginInvoke(
DispatcherPriority.Normal,
(Action)delegate { ProcessItems(process, dispatcher, 0, items, work, debuggeeStateWhenEnqueued); }
);
}

static void ProcessItems<T>(Process process, Dispatcher dispatcher, int startIndex, IList<T> items, Action<T> work, DebuggeeState debuggeeStateWhenEnqueued)
{
var watch = new System.Diagnostics.Stopwatch();
watch.Start();

for (int i = startIndex; i < items.Count; i++) {
int index = i;
if (process.IsPaused && debuggeeStateWhenEnqueued == process.DebuggeeState) {
try {
// Do the work, this may recursively enqueue more work
work(items[index]);
} catch (System.Exception ex) {
if (process == null || process.HasExited) {
// Process unexpectedly exited - silently ignore
} else {
MessageService.ShowException(ex);
}
break;
}
}

// if we are too slow move to background
if (watch.ElapsedMilliseconds > 100) {
dispatcher.BeginInvoke(
DispatcherPriority.Background,
(Action)delegate { ProcessItems(process, dispatcher, index, items, work, debuggeeStateWhenEnqueued); }
);
break;
}
}
}

} }


public class AbortedBecauseDebuggeeResumedException: System.Exception public class AbortedBecauseDebuggeeResumedException: System.Exception
Expand Down

0 comments on commit f5e1507

Please sign in to comment.