Отладчик: Окно "Локальные переменные"

This commit is contained in:
Ivan Bondarev 2023-06-08 14:39:56 +02:00
parent 3275eb311c
commit dbffb4ba80
5 changed files with 67 additions and 92 deletions

View file

@ -547,6 +547,7 @@ namespace VisualPascalABC
}
private delegate void EndDebuggerSessionDelegate();
public void EndDebuggerSession()
{
@ -596,9 +597,10 @@ namespace VisualPascalABC
monoDebuggerSession = new Mono.Debugging.Soft.SoftDebuggerSession();
}
private void Process_Exited(object sender, EventArgs e)
{
EndDebuggerSession();
VisualPABCSingleton.MainForm.Invoke(new EndDebuggerSessionDelegate(EndDebuggerSession));
}
@ -613,6 +615,7 @@ namespace VisualPascalABC
stackFrame = e.Thread.Backtrace.GetFrame(0);
JumpToCurrentLine();
workbench.WidgetController.SetStartDebugEnabled();
WorkbenchServiceFactory.DebuggerOperationsService.RefreshPad(new FunctionItem(stackFrame).SubItems);
}
private void MonoDebuggerSession_TargetStarted(object sender, EventArgs e)

View file

@ -141,32 +141,15 @@ namespace VisualPascalABC
public class ModuleItem : ListItem
{
private NamedValue val;
private string ns_name;
private Function func;
private List<DebugType> types;
private Mono.Debugging.Client.StackFrame frame;
private List<Mono.Debugging.Evaluation.TypeValueReference> monoTypes;
/*public ModuleItem(NamedValue val, Function func)
public ModuleItem(List<Mono.Debugging.Evaluation.TypeValueReference> monoTypes, Mono.Debugging.Client.StackFrame frame)
{
this.val = val;
ns_name = val.Type.FullName.Substring(0, val.Type.FullName.LastIndexOf('.'));
this.func = func;
this.func.Process.DebuggeeStateChanged += delegate
{
this.OnChanged(new ListItemEventArgs(this));
};
}*/
public ModuleItem(List<DebugType> types, Function func)
{
//this.val = val;
//ns_name = val.Type.FullName.Substring(0, val.Type.FullName.LastIndexOf('.'));
this.types = types;
this.func = func;
this.func.Process.DebuggeeStateChanged += delegate
{
this.OnChanged(new ListItemEventArgs(this));
};
this.monoTypes = monoTypes;
this.frame = frame;
}
public override int ImageIndex
@ -228,12 +211,12 @@ namespace VisualPascalABC
get
{
List<IListItem> ret = new List<IListItem>();
foreach (DebugType dt in types)
foreach (var tr in monoTypes)
{
//IList<FieldInfo> fis = val.Type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
IList<FieldInfo> fis = dt.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
foreach (FieldInfo fi in fis)
if (!fi.Name.Contains("$")) ret.Add(new ValueItem(fi.GetValue(null),fi.DeclaringType));
var fields = tr.GetChildReferences(Mono.Debugging.Client.EvaluationOptions.DefaultOptions);
foreach (var fi in fields)
if (!fi.Name.Contains("$"))
ret.Add(new ValueItem(fi.CreateObjectValue(false, Mono.Debugging.Client.EvaluationOptions.DefaultOptions)));
}
return ret;
}
@ -242,15 +225,8 @@ namespace VisualPascalABC
public class FunctionItem : ListItem
{
Function function;
Mono.Debugging.Client.StackFrame frame;
public Function Function
{
get
{
return function;
}
}
public override bool IsLiteral
{
@ -271,7 +247,7 @@ namespace VisualPascalABC
{
get
{
return function.Name;
return frame.SourceLocation.MethodName;
}
}
@ -314,45 +290,42 @@ namespace VisualPascalABC
{
List<IListItem> ret = new List<IListItem>();
Hashtable ht = new Hashtable(StringComparer.CurrentCultureIgnoreCase);
foreach (NamedValue val in function.LocalVariables)
foreach (var val in frame.GetAllLocals())
{
if (val.Name.Contains("$class_var") /*&& !val.Type.FullName.Contains("$")*/)
if (val.Name.Contains("$class_var"))
{
//IList<FieldInfo> fis = val.Type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
//if (fis.Count != 0)
List<DebugType> types = new List<DebugType>();
List<Mono.Debugging.Evaluation.TypeValueReference> types = new List<Mono.Debugging.Evaluation.TypeValueReference>();
try
{
if (val.Type.FullName.Contains(PascalABCCompiler.TreeConverter.compiler_string_consts.ImplementationSectionNamespaceName))
if (val.TypeName.Contains(PascalABCCompiler.TreeConverter.compiler_string_consts.ImplementationSectionNamespaceName))
{
string interf_name = val.Type.FullName.Substring(0, val.Type.FullName.IndexOf(PascalABCCompiler.TreeConverter.compiler_string_consts.ImplementationSectionNamespaceName));
string interf_name = val.TypeName.Substring(0, val.TypeName.IndexOf(PascalABCCompiler.TreeConverter.compiler_string_consts.ImplementationSectionNamespaceName));
Type t = AssemblyHelper.GetTypeForStatic(interf_name);
DebugType dt = DebugUtils.GetDebugType(t);
types.Add(dt);
var tr = new Mono.Debugging.Evaluation.TypeValueReference(frame.SourceBacktrace.GetEvaluationContext(frame.Index, Mono.Debugging.Client.EvaluationOptions.DefaultOptions),
(frame.DebuggerSession as Mono.Debugging.Soft.SoftDebuggerSession).GetType(t.FullName));
types.Add(tr);
}
types.Add(val.Type);
var valtr = new Mono.Debugging.Evaluation.TypeValueReference(frame.SourceBacktrace.GetEvaluationContext(frame.Index, Mono.Debugging.Client.EvaluationOptions.DefaultOptions),
(frame.DebuggerSession as Mono.Debugging.Soft.SoftDebuggerSession).GetType(val.TypeName));
types.Add(valtr);
}
catch (System.Exception e)
{
Console.WriteLine(e.Message + " " + e.StackTrace);
}
ret.Add(new ModuleItem(types, function));
//foreach (FieldInfo fi in fis)
// if (!fi.Name.Contains("$")) ret.Add(new ValueItem(fi.GetValue(val)));
ret.Add(new ModuleItem(types, frame));
}
}
foreach (NamedValue val in function.LocalVariables)
foreach (var val in frame.GetAllLocals())
{
//if (val.IsObject)
if (!val.Name.Contains("$"))
ret.Add(new ValueItem(val,null));
ret.Add(new ValueItem(val));
else if (val.Name.Contains("$rv"))
{
ret.Add(new ValueItem(val,null));
ret.Add(new ValueItem(val));
}
else if (val.Name == "$disp$")
/*else if (val.Name == "$disp$")
{
IList<FieldInfo> fields = val.Type.GetFields(BindingFlags.All);
foreach (FieldInfo fi in fields)
@ -361,15 +334,15 @@ namespace VisualPascalABC
ret.Add(new ValueItem(fi.GetValue(val),fi.DeclaringType));
ht[fi.Name] = fi.Name;
}
}
}*/
}
NamedValue self_nv = null;
Mono.Debugging.Client.ObjectValue self_nv = null;
try
{
foreach (NamedValue val in function.Arguments)
foreach (var val in frame.GetParameters())
{
if (!val.Name.Contains("$") && !ht.ContainsKey(val.Name))
ret.Add(new ValueItem(val, null));
ret.Add(new ValueItem(val));
else if (val.Name == "$obj$")
self_nv = val;
}
@ -377,26 +350,17 @@ namespace VisualPascalABC
catch
{
}
if (!function.IsStatic) ret.Add(new ValueItem(function.ThisValue,null));
if (frame.GetThisReference() != null)
ret.Add(new ValueItem(frame.GetThisReference()));
else if (self_nv != null)
ret.Add(new ValueItem(self_nv,"self",null));
/*foreach (NamedValue val in function.ContaingClassVariables)
{
if (!val.Name.Contains("$"))
ret.Add(new ValueItem(val));
}*/
ret.Add(new ValueItem(self_nv));
return ret.AsReadOnly();
}
}
public FunctionItem(Function function)
public FunctionItem(Mono.Debugging.Client.StackFrame frame)
{
this.function = function;
this.function.Process.DebuggeeStateChanged += delegate
{
this.OnChanged(new ListItemEventArgs(this));
};
this.frame = frame;
}
}

View file

@ -489,7 +489,7 @@ namespace AdvancedDataGridView
private void Update()
{
DateTime start = Debugger.Util.HighPrecisionTimer.Now;
//DateTime start = Debugger.Util.HighPrecisionTimer.Now;
updated = false;
//this.HasChildren = Content.HasSubItems;
//this._image = content.Image;
@ -513,7 +513,7 @@ namespace AdvancedDataGridView
if (this.Cells[2].Value == null)
this.Cells[2].Value = this.type;
//this.Cells[2].Value = this.type;
DateTime end = Debugger.Util.HighPrecisionTimer.Now;
//DateTime end = Debugger.Util.HighPrecisionTimer.Now;
//LoggingService.InfoFormatted("Updated node {0} ({1} ms)", FullName, (end - start).TotalMilliseconds);

View file

@ -633,11 +633,9 @@ namespace VisualPascalABC
private bool watch_vis = false;
public void SetDebugTabsVisible(bool flag)
{
if (DebugWatchListWindow == null)
return;
if (flag)
{
if (!DebugWatchListWindow.IsHidden)
if (DebugWatchListWindow != null && !DebugWatchListWindow.IsHidden)
{
watch_vis = true;
}
@ -645,14 +643,15 @@ namespace VisualPascalABC
{
if (!BottomTabsVisible)
BottomTabsVisible = true;
ShowContent(DebugWatchListWindow, false);
if (DebugWatchListWindow != null)
ShowContent(DebugWatchListWindow, false);
ShowContent(DebugVariablesListWindow, false);
}
}
else
{
//HideContent(DebugWatchListWindow);
if (!watch_vis)
if (!watch_vis && DebugWatchListWindow != null)
{
HideContent(DebugWatchListWindow);
}

View file

@ -341,9 +341,10 @@ namespace VisualPascalABC
AddDisassemblyWindow(); // Это нельзя убирать - почему то оболочка закрывается при запуске программы!!!
HideContent(FindSymbolsResultWindow);
HideContent(DisassemblyWindow);
AddDebugVariablesListWindow();
HideContent(DebugVariablesListWindow);
/*AddImmediateWindow();
//AddDebugVariablesListWindow();
//AddDebugWatchListWindow();
if (!Tools.IsUnix())
{
@ -355,7 +356,7 @@ namespace VisualPascalABC
// SelectContent(ProjectExplorerWindow, false);
//HideContent(ImmediateWindow);
//HideContent(DebugVariablesListWindow);
//HideContent(DebugWatchListWindow);
if (!Tools.IsUnix())
@ -685,19 +686,27 @@ namespace VisualPascalABC
DebugVariablesListWindow.ClearAllSubTrees();
}
public void RefreshPad(IList<IListItem> items)
private delegate void RefreshPadDelegate(IList<IListItem> items);
private void RefreshPadInvoke(IList<IListItem> items)
{
try
{
DebugWatchListWindow.RefreshWatch();
if (DebugWatchListWindow != null)
DebugWatchListWindow.RefreshWatch();
AdvancedDataGridView.TreeGridNode.UpdateNodesForLocalList(DebugVariablesListWindow.watchList, DebugVariablesListWindow.watchList.Nodes, items);
}
catch (System.Exception)
catch (System.Exception ex)
{
Console.WriteLine(ex.Message + " " + ex.StackTrace);
}
}
public void RefreshPad(IList<IListItem> items)
{
Invoke(new RefreshPadDelegate(RefreshPadInvoke), items);
}
public void GotoWatch()
{
BottomTabsVisible = true;