From 45fb709e2b349f92554673bd109097786bfe81e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Sat, 23 Jul 2005 10:43:57 +0000 Subject: [PATCH] Worked on Local variables pad git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@235 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Debugger.AddIn.csproj | 4 + .../Project/Src/Pads/BaseClassItem.cs | 43 ++++++ .../Project/Src/Pads/LocalVarPad.cs | 128 +++++++----------- .../Project/Src/Pads/PlaceHolderItem.cs | 15 ++ .../Project/Src/Pads/VariableItem.cs | 79 +++++++++++ .../Project/Src/Pads/VariableListItem.cs | 69 ++++++++++ .../Src/Debugger/Internal/ManagedCallback.cs | 2 +- .../Project/Src/Debugger/NDebugger.cs | 2 +- .../Project/Src/Variables/ArrayVariable.cs | 5 + .../Project/Src/Variables/BuiltInVariable.cs | 6 + .../Project/Src/Variables/NullRefVariable.cs | 6 + .../Project/Src/Variables/ObjectVariable.cs | 5 + .../Project/Src/Variables/PropertyVariable.cs | 19 ++- .../Project/Src/Variables/UnknownVariable.cs | 6 + .../Project/Src/Variables/Variable.cs | 6 +- .../Src/Variables/VariableCollection.cs | 23 +++- 16 files changed, 329 insertions(+), 89 deletions(-) create mode 100644 src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/BaseClassItem.cs create mode 100644 src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/PlaceHolderItem.cs create mode 100644 src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/VariableItem.cs create mode 100644 src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/VariableListItem.cs diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Debugger.AddIn.csproj b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Debugger.AddIn.csproj index 130b1933fa..a0a26d63f6 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Debugger.AddIn.csproj +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Debugger.AddIn.csproj @@ -41,12 +41,16 @@ Always + + + + Form diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/BaseClassItem.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/BaseClassItem.cs new file mode 100644 index 0000000000..189db4832b --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/BaseClassItem.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Text; +using DebuggerLibrary; + +namespace ICSharpCode.SharpDevelop.Gui.Pads +{ + class BaseClassItem: VariableListItem + { + ObjectVariable variable; + + public override bool IsValid { + get { + return variable != null && + variable.HasBaseClass && + variable.BaseClass.Type != "System.Object"; + } + } + + public BaseClassItem(Variable baseClassOfVariable): base() + { + this.variable = baseClassOfVariable as ObjectVariable; + Refresh(); + } + + public override void Refresh() + { + if (!IsValid) { + return; + } + + SetTexts("", + variable.BaseClass.Value.ToString(), + variable.BaseClass.Type); + + ImageIndex = 0; // Class + + if (variable.BaseClass.MayHaveSubVariables) { // Always true + Items.Add(new PlaceHolderItem()); // Show plus icon + } + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LocalVarPad.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LocalVarPad.cs index 40316ade1c..d1ab5e8f55 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LocalVarPad.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LocalVarPad.cs @@ -16,6 +16,7 @@ using ICSharpCode.Core; using ICSharpCode.SharpDevelop.Services; using DebuggerLibrary; +using System.Collections.Generic; namespace ICSharpCode.SharpDevelop.Gui.Pads { @@ -99,103 +100,72 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads type.Text = "Type"; } - void RefreshList() + private void debuggerService_OnDebuggingPaused(object sender, DebuggingPausedEventArgs e) { - if (debugger.IsDebugging && debugger.IsProcessRunning == false) { - debuggerService_OnDebuggingPaused(this, new DebuggingPausedEventArgs(debuggerCore, PausedReason.StepComplete)); - } + RefreshList(); } - private void debuggerService_OnDebuggingPaused(object sender, DebuggingPausedEventArgs e) + void RefreshList() { - localVarList.BeginUpdate(); - localVarList.Items.Clear(); - - AddVariables(localVarList.Items, debuggerCore.LocalVariables); - - localVarList.EndUpdate(); + if (debugger.IsDebugging && debugger.IsProcessRunning == false) { + UpdateVariables(localVarList.Items, debuggerCore.LocalVariables); + } } private void localVarList_BeforeExpand(object sender, TreeListViewCancelEventArgs e) { - localVarList.BeginUpdate(); - e.Item.Items.Clear(); - - ObjectVariable var = e.Item.Tag as ObjectVariable; - if (var != null && var.HasBaseClass && var.BaseClass.Type != "System.Object") - { - TreeListViewItem newItem = new TreeListViewItem(); - newItem.Text = ""; - newItem.SubItems.Add(var.BaseClass.Value.ToString()); - newItem.SubItems.Add(var.BaseClass.Type); - newItem.Tag = var.BaseClass; - newItem.ImageIndex = 0; // Class - newItem.Items.Add(""); // Show plus icon - e.Item.Items.Add(newItem); + if (debugger.IsDebugging && debugger.IsProcessRunning == false) { + ((VariableListItem)e.Item).PrepareForExpansion(); + } else { + // TODO: Some message telling user that he can not explore variable since + // the debugger has been resumed. + e.Cancel = true; } - AddVariables(e.Item.Items, ((Variable)e.Item.Tag).SubVariables); - - localVarList.EndUpdate(); } - void AddVariables (TreeListViewItemCollection items, VariableCollection vars) + static VariableItem FindVariableItem(TreeListViewItemCollection items, Variable variable) { - foreach (Variable var in vars) { - if (var.Name.StartsWith("CS$")) continue; - TreeListViewItem newItem = new TreeListViewItem(); - newItem.Tag = var; - newItem.Text = var.Name; - newItem.SubItems.Add(var.Value.ToString()); - newItem.SubItems.Add(var.Type); - items.Add(newItem); - RefreshVariable(var); - - if (var is PropertyVariable) { - ((PropertyVariable)var).ValueEvaluated += new EventHandler(PropertyEvaluated); - } - } + foreach (VariableListItem item in items) { + VariableItem variableItem = item as VariableItem; + if (variableItem != null && variableItem.Variable.Name == variable.Name) { + return variableItem; + } + } + return null; } - - void PropertyEvaluated (object sender, DebuggerEventArgs args) - { - RefreshVariable((Variable)sender); - } - void RefreshVariable (Variable var) + public static void UpdateVariables(TreeListViewItemCollection items, VariableCollection variables) { - RefreshVariableInItemConnection(var, localVarList.Items); - } - - void RefreshVariableInItemConnection (Variable var, TreeListViewItemCollection items) - { - foreach (TreeListViewItem item in items) { - // Refresh in sub trees - RefreshVariableInItemConnection(var, item.Items); - - if (item.Tag == var) { - if (item.SubItems[1].Text == null) { - item.SubItems[1].Text = var.Value.ToString(); - } - item.SubItems[2].Text = var.Type; - item.Items.Clear(); - if (var is ObjectVariable && ((ObjectVariable)var).HasBaseClass) { - // It is a class - item.ImageIndex = 0; // Class - item.Items.Add(""); // Show plus icon - - //object devNull = (var as ObjectVariable).SubVariables; // Cache variables TODO: LAME - - } else if (var is PropertyVariable){ - // It is a property - item.ImageIndex = 2; // Property - if ((var as PropertyVariable).IsEvaluated && (var as PropertyVariable).Value is ObjectVariable) { - item.Items.Add(""); // Show plus icon - } - } else { - item.ImageIndex = 1; // Field + // Add new variables and refresh existing ones + foreach (Variable variable in variables) { + VariableItem item = FindVariableItem(items, variable); + if (item != null) { + item.Variable = variable; + item.Refresh(); + } else { + item = new VariableItem(variable); + if (item.IsValid) { + items.Add(item); } } } + + // Delete invalid or removed variables + List toBeRemoved = new List(); + foreach (VariableListItem item in items) { + if (!item.IsValid) { + toBeRemoved.Add(item); + continue; + } + + VariableItem variableItem = item as VariableItem; + if (variableItem != null && !variables.Contains(variableItem.Variable.Name)) { + toBeRemoved.Add(item); + } + } + foreach (VariableListItem item in toBeRemoved) { + item.Remove(); + } } } } diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/PlaceHolderItem.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/PlaceHolderItem.cs new file mode 100644 index 0000000000..e0b57d3ec1 --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/PlaceHolderItem.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ICSharpCode.SharpDevelop.Gui.Pads +{ + class PlaceHolderItem: VariableListItem + { + public override bool IsValid { + get { + return false; + } + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/VariableItem.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/VariableItem.cs new file mode 100644 index 0000000000..21807e6a73 --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/VariableItem.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Text; +using DebuggerLibrary; + +namespace ICSharpCode.SharpDevelop.Gui.Pads +{ + class VariableItem: VariableListItem + { + Variable variable; + + bool baseClassItemAdded = false; + + public Variable Variable { + get { + return variable; + } + set { + variable = value; + } + } + + public override bool IsValid { + get { + return variable != null && + !variable.Name.StartsWith("CS$"); + } + } + + public VariableItem(Variable variable): base() + { + this.variable = variable; + Refresh(); + } + + public override void PrepareForExpansion() + { + UpdateSubVariables(); + } + + public override void Refresh() + { + if (!IsValid) { + return; + } + + SetTexts(variable.Name, + variable.Value.ToString(), + variable.Type); + + if (variable is ObjectVariable) { + ImageIndex = 0; // Class + } else if (variable is PropertyVariable){ + ImageIndex = 2; // Property + } else { + ImageIndex = 1; // Field + } + + if (variable.MayHaveSubVariables && !IsExpanded) { + Items.Add(new PlaceHolderItem()); // Show plus icon + } + + if (IsExpanded) { + UpdateSubVariables(); + } + } + + void UpdateSubVariables() { + if (!baseClassItemAdded) { + VariableListItem baseClassItem = new BaseClassItem(variable); + if (baseClassItem.IsValid) { + this.Items.Add(baseClassItem); + } + baseClassItemAdded = true; + } + LocalVarPad.UpdateVariables(this.Items, Variable.SubVariables); + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/VariableListItem.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/VariableListItem.cs new file mode 100644 index 0000000000..dd0dc6fd15 --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/VariableListItem.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows.Forms; +using System.Drawing; + +namespace ICSharpCode.SharpDevelop.Gui.Pads +{ + abstract class VariableListItem: TreeListViewItem + { + bool textsInitialized; + + public abstract bool IsValid { + get; + } + + public VariableListItem() + { + Reset(); + } + + public virtual void PrepareForExpansion() + { + + } + + public virtual void Reset() + { + SubItems.Clear(); + Text = ""; + SubItems.Add(""); + SubItems.Add(""); + } + + public virtual void Refresh() + { + + } + + protected void SetTexts(string name, string value, string type) + { + if (value == SubItems[1].Text || !textsInitialized) { + // Value has not changed since last setting + if (SubItems[1].ForeColor != Color.Black) { + SubItems[1].ForeColor = Color.Black; + SubItems[1].Font = new Font(SubItems[1].Font, FontStyle.Regular); + } + } else { + // Value has changed since last setting + if (SubItems[1].ForeColor != Color.Blue) { + SubItems[1].ForeColor = Color.Blue; + SubItems[1].Font = new Font(SubItems[1].Font, FontStyle.Bold); + } + } + + if (SubItems[0].Text != name) { + SubItems[0].Text = name; + } + if (SubItems[1].Text != value) { + SubItems[1].Text = value; + } + if (SubItems[2].Text != type) { + SubItems[2].Text = type; + } + + textsInitialized = true; + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs index 7b05de6333..1048f56319 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs @@ -89,8 +89,8 @@ namespace DebuggerLibrary void ExitCallback_Paused(PausedReason reason) { if (reason != PausedReason.EvalComplete) { - debugger.OnDebuggingPaused(reason); debugger.OnIsProcessRunningChanged(); + debugger.OnDebuggingPaused(reason); } handlingCallback = false; } 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 4aa4971061..f5ef5df482 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 @@ -299,7 +299,7 @@ namespace DebuggerLibrary public VariableCollection LocalVariables { get { if (!IsDebugging) return VariableCollection.Empty; - return CurrentProcess.CurrentThread.CurrentFunction.GetLocalVariables(); + return CurrentProcess.CurrentThread.CurrentFunction.GetVariables(); } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ArrayVariable.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ArrayVariable.cs index 3113d8947e..9a44d997dc 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ArrayVariable.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ArrayVariable.cs @@ -105,6 +105,11 @@ namespace DebuggerLibrary } } + public override bool MayHaveSubVariables { + get { + return true; + } + } protected override VariableCollection GetSubVariables() { diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/BuiltInVariable.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/BuiltInVariable.cs index b71d21a59b..75e63e0cda 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/BuiltInVariable.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/BuiltInVariable.cs @@ -72,5 +72,11 @@ namespace DebuggerLibrary internal BuiltInVariable(NDebugger debugger, ICorDebugValue corValue, string name):base(debugger, corValue, name) { } + + public override bool MayHaveSubVariables { + get { + return false; + } + } } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/NullRefVariable.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/NullRefVariable.cs index b4ae8ff246..7c926e09a9 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/NullRefVariable.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/NullRefVariable.cs @@ -40,5 +40,11 @@ namespace DebuggerLibrary { } + + public override bool MayHaveSubVariables { + get { + return false; + } + } } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectVariable.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectVariable.cs index 29452b2c99..865622abad 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectVariable.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectVariable.cs @@ -62,6 +62,11 @@ namespace DebuggerLibrary corModuleSuperclass = corModule; } + public override bool MayHaveSubVariables { + get { + return true; + } + } protected override unsafe VariableCollection GetSubVariables() { diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/PropertyVariable.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/PropertyVariable.cs index d7000a6e0e..ed8b4bd617 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/PropertyVariable.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/PropertyVariable.cs @@ -46,15 +46,24 @@ namespace DebuggerLibrary return currentValue.Type; } } - - public override VariableCollection SubVariables { + + public override bool MayHaveSubVariables { get { - if (!IsEvaluated) { - Evaluate(); + if (IsEvaluated) { + return currentValue.MayHaveSubVariables; + } else { + return true; } - return currentValue.SubVariables; } } + + protected override VariableCollection GetSubVariables() + { + if (!IsEvaluated) { + Evaluate(); + } + return currentValue.SubVariables; + } /// /// Executes evaluation of variable and doesn't return diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/UnknownVariable.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/UnknownVariable.cs index 2799699ea8..8815ed639a 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/UnknownVariable.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/UnknownVariable.cs @@ -30,5 +30,11 @@ namespace DebuggerLibrary { } + + public override bool MayHaveSubVariables { + get { + return false; + } + } } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Variable.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Variable.cs index 913c753e63..bed717a961 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Variable.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Variable.cs @@ -53,7 +53,11 @@ namespace DebuggerLibrary } } - public virtual VariableCollection SubVariables { + public abstract bool MayHaveSubVariables { + get; + } + + public VariableCollection SubVariables { get{ if (subVariables == null) subVariables = GetSubVariables(); return subVariables; diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/VariableCollection.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/VariableCollection.cs index 48c2ee3ce8..a6ace5c4d1 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/VariableCollection.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/VariableCollection.cs @@ -24,6 +24,26 @@ namespace DebuggerLibrary } + public bool Contains(Variable variable) + { + foreach (Variable v in InnerList) { + if (v == variable) { + return true; + } + } + return false; + } + + public bool Contains(string variableName) + { + foreach (Variable v in InnerList) { + if (v.Name == variableName) { + return true; + } + } + return false; + } + static VariableCollection() { Empty = new VariableCollection(); @@ -46,8 +66,7 @@ namespace DebuggerLibrary } } - public Variable this[string variableName] - { + public Variable this[string variableName] { get { foreach (Variable v in InnerList) { if (v.Name == variableName) {