Skip to content
This repository
Browse code

fix refresh bugs in CallStackPad

  • Loading branch information...
commit f5e15070885e8d92db8d70b4e42a5e8f2dec1afc 1 parent 070efb3
Siegfried Pammer siegfriedpammer authored
25 src/AddIns/Debugger/Debugger.AddIn/Pads/CallStackPad.xaml.cs
@@ -3,12 +3,12 @@
3 3
4 4 using System;
5 5 using System.Collections.Generic;
  6 +using System.Collections.ObjectModel;
6 7 using System.Linq;
7 8 using System.Text;
8 9 using System.Windows.Controls;
9 10 using System.Windows.Input;
10 11 using System.Windows.Media;
11   -
12 12 using Debugger;
13 13 using Debugger.AddIn.TreeModel;
14 14 using ICSharpCode.Core;
@@ -147,24 +147,21 @@ internal void RefreshPad()
147 147 return;
148 148 }
149 149
150   - List<CallStackItem> items = new List<CallStackItem>();
  150 + var items = new ObservableCollection<CallStackItem>();
151 151 using(new PrintTimes("Callstack refresh")) {
152 152 bool showExternalMethods = DebuggingOptions.Instance.ShowExternalMethods;
153   - bool lastItemIsExternalMethod = false;
  153 + bool previousItemIsExternalMethod = false;
154 154
155   - foreach (StackFrame frame in debuggedProcess.SelectedThread.GetCallstack(100)) {
156   - StackFrame f = frame;
157   - debuggedProcess.EnqueueWork(
  155 + debuggedProcess.EnqueueForEach(
158 156 Dispatcher,
159   - delegate {
160   - items.AddIfNotNull(CreateItem(f, showExternalMethods, ref lastItemIsExternalMethod));
161   - });
162   - }
  157 + debuggedProcess.SelectedThread.GetCallstack(100),
  158 + f => items.AddIfNotNull(CreateItem(f, showExternalMethods, ref previousItemIsExternalMethod))
  159 + );
163 160 }
164 161 view.ItemsSource = items;
165 162 }
166 163
167   - CallStackItem CreateItem(StackFrame frame, bool showExternalMethods, ref bool lastItemIsExternalMethod)
  164 + CallStackItem CreateItem(StackFrame frame, bool showExternalMethods, ref bool previousItemIsExternalMethod)
168 165 {
169 166 CallStackItem item;
170 167
@@ -187,16 +184,16 @@ CallStackItem CreateItem(StackFrame frame, bool showExternalMethods, ref bool la
187 184 item = new CallStackItem() {
188 185 Name = GetFullName(frame), Language = "", Line = lineNumber, ModuleName = moduleName
189 186 };
190   - lastItemIsExternalMethod = false;
  187 + previousItemIsExternalMethod = false;
191 188 item.Frame = frame;
192 189 } else {
193 190 // Show [External methods] in the list
194   - if (lastItemIsExternalMethod) return null;
  191 + if (previousItemIsExternalMethod) return null;
195 192 item = new CallStackItem() {
196 193 Name = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.ExternalMethods"),
197 194 Language = ""
198 195 };
199   - lastItemIsExternalMethod = true;
  196 + previousItemIsExternalMethod = true;
200 197 }
201 198
202 199 return item;
46 src/AddIns/Debugger/Debugger.AddIn/TreeModel/Utils.cs
@@ -2,10 +2,11 @@
2 2 // This code is distributed under the BSD license (for details please see \src\AddIns\Debugger\Debugger.AddIn\license.txt)
3 3
4 4 using System;
5   -using System.Collections;
  5 +using System.Collections.Generic;
6 6 using System.Reflection;
7 7 using System.Windows.Forms;
8 8 using System.Windows.Threading;
  9 +
9 10 using Debugger.AddIn.Pads.Controls;
10 11 using ICSharpCode.Core;
11 12 using ICSharpCode.NRefactory.Ast;
@@ -40,6 +41,49 @@ public static void EnqueueWork(this Process process, Dispatcher dispatcher, Acti
40 41 }
41 42 );
42 43 }
  44 +
  45 + public static void EnqueueForEach<T>(this Process process, Dispatcher dispatcher, IList<T> items, Action<T> work)
  46 + {
  47 + DebuggeeState debuggeeStateWhenEnqueued = process.DebuggeeState;
  48 +
  49 + dispatcher.BeginInvoke(
  50 + DispatcherPriority.Normal,
  51 + (Action)delegate { ProcessItems(process, dispatcher, 0, items, work, debuggeeStateWhenEnqueued); }
  52 + );
  53 + }
  54 +
  55 + static void ProcessItems<T>(Process process, Dispatcher dispatcher, int startIndex, IList<T> items, Action<T> work, DebuggeeState debuggeeStateWhenEnqueued)
  56 + {
  57 + var watch = new System.Diagnostics.Stopwatch();
  58 + watch.Start();
  59 +
  60 + for (int i = startIndex; i < items.Count; i++) {
  61 + int index = i;
  62 + if (process.IsPaused && debuggeeStateWhenEnqueued == process.DebuggeeState) {
  63 + try {
  64 + // Do the work, this may recursively enqueue more work
  65 + work(items[index]);
  66 + } catch (System.Exception ex) {
  67 + if (process == null || process.HasExited) {
  68 + // Process unexpectedly exited - silently ignore
  69 + } else {
  70 + MessageService.ShowException(ex);
  71 + }
  72 + break;
  73 + }
  74 + }
  75 +
  76 + // if we are too slow move to background
  77 + if (watch.ElapsedMilliseconds > 100) {
  78 + dispatcher.BeginInvoke(
  79 + DispatcherPriority.Background,
  80 + (Action)delegate { ProcessItems(process, dispatcher, index, items, work, debuggeeStateWhenEnqueued); }
  81 + );
  82 + break;
  83 + }
  84 + }
  85 + }
  86 +
43 87 }
44 88
45 89 public class AbortedBecauseDebuggeeResumedException: System.Exception

0 comments on commit f5e1507

Please sign in to comment.
Something went wrong with that request. Please try again.