-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathamScript.Debugger.Frame.Stack.pas
More file actions
526 lines (455 loc) · 14.9 KB
/
Copy pathamScript.Debugger.Frame.Stack.pas
File metadata and controls
526 lines (455 loc) · 14.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
unit amScript.Debugger.Frame.Stack;
(*
* Copyright © 2011 Brian Frost
* Copyright © 2019 Anders Melander
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*)
interface
uses
Generics.Collections,
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls, ImgList, Menus, ActnList, System.Actions,
cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters, dxSkinsCore,
cxContainer, cxEdit, cxCustomData, cxStyles, cxTL, cxTextEdit, cxTLdxBarBuiltInMenu, cxInplaceContainer,
cxClasses, cxTLData, dxSkinsdxBarPainter, dxBar, cxFilter, dxScrollbarAnnotations,
dwsUtils,
dwsExprs,
dwsSymbols,
dwsErrors,
dwsInfo,
amScript.Debugger.API;
type
TFrame = TScriptDebuggerFrame;
TScriptDebuggerStackFrame = class(TFrame)
TreeListStack: TcxTreeList;
cxTreeList1Column1: TcxTreeListColumn;
cxTreeList1Column2: TcxTreeListColumn;
cxTreeList1Column3: TcxTreeListColumn;
cxStyleRepository1: TcxStyleRepository;
StyleBackground: TcxStyle;
dxBarPopupMenu1: TdxBarPopupMenu;
dxBarManager1: TdxBarManager;
dxBarSeparator1: TdxBarSeparator;
MenuItemScopePublished: TdxBarButton;
MenuItemScopePublic: TdxBarButton;
MenuItemScopeProtected: TdxBarButton;
MenuItemScopePrivate: TdxBarButton;
dxBarSeparator2: TdxBarSeparator;
MenuItemMembersInherited: TdxBarButton;
MenuItemMembersProperties: TdxBarButton;
MenuItemMembersFields: TdxBarButton;
MenuItemItemWatch: TdxBarButton;
MenuItemItemModify: TdxBarButton;
ActionList1: TActionList;
ActionItemWatch: TAction;
ActionItemModify: TAction;
MenuItemMembersPropertyGetters: TdxBarButton;
ActionViewMemberFields: TAction;
ActionViewMemberProperties: TAction;
ActionViewMemberPropertySideEffects: TAction;
ActionViewMemberInherited: TAction;
ActionViewScopePublished: TAction;
ActionViewScopePublic: TAction;
ActionViewScopeProtected: TAction;
ActionViewScopePrivate: TAction;
procedure TreeListStackDeletion(Sender: TcxCustomTreeList; ANode: TcxTreeListNode);
procedure TreeListStackExpanding(Sender: TcxCustomTreeList; ANode: TcxTreeListNode; var Allow: Boolean);
procedure TreeListStackCanFocusNode(Sender: TcxCustomTreeList; ANode: TcxTreeListNode; var Allow: Boolean);
strict private
FLoading: boolean;
strict private
procedure LoadNode(Node: TcxTreeListNode); overload;
procedure LoadNode(Node: TcxTreeListNode; const Info: IInfo; TypeSym: TSymbol = nil); overload;
procedure LoadMemberNodes(Node: TcxTreeListNode; const Info: IInfo; TypeSym: TCompositeTypeSymbol);
function FindNode(const AName: string; ParentNode: TcxTreeListNode): TcxTreeListNode;
function GetDisplayValue(const Info: IInfo; TypeSym: TSymbol): string;
procedure UpdateInfo;
strict protected
// IScriptDebuggerWindow
procedure Initialize(const ADebugger: IScriptDebugger; AImageList, AImageListSymbols: TCustomImageList); override;
strict protected
// IScriptDebuggerWindow
procedure ScriptDebuggerNotification(Notification: TScriptDebuggerNotification); override;
public
end;
implementation
{$R *.dfm}
uses
dwsDebugger,
dwsInfoClasses,
dwsCompiler,
dwsDataContext,
dwsSuggestions,
amScript.IDE.Settings;
{ TDwsIdeLocalVariablesFrame }
procedure TScriptDebuggerStackFrame.Initialize(const ADebugger: IScriptDebugger; AImageList, AImageListSymbols: TCustomImageList);
begin
inherited Initialize(ADebugger, AImageList, AImageListSymbols);
TreeListStack.Images := AImageListSymbols;
ActionItemWatch.Visible := ScriptSettings.Features.ViewWatches;
UpdateInfo;
end;
procedure TScriptDebuggerStackFrame.ScriptDebuggerNotification(Notification: TScriptDebuggerNotification);
begin
inherited;
case Notification of
dnDebugSuspended:
UpdateInfo;
else
TreeListStack.Clear;
end;
end;
function TScriptDebuggerStackFrame.FindNode(const AName: string; ParentNode: TcxTreeListNode): TcxTreeListNode;
begin
if (ParentNode = nil) then
ParentNode := TreeListStack.Root;
Result := ParentNode.getFirstChild;
while (Result <> nil) do
begin
if (Result.Texts[0] = AName) then
break;
Result := Result.getNextSibling;
end;
end;
procedure TScriptDebuggerStackFrame.LoadNode(Node: TcxTreeListNode);
var
Info: IInfo;
begin
if (Node.Data = nil) then
exit;
pointer(Info) := Node.Data;
Node.Data := nil;
LoadNode(Node, Info);
end;
procedure TScriptDebuggerStackFrame.LoadMemberNodes(Node: TcxTreeListNode; const Info: IInfo; TypeSym: TCompositeTypeSymbol);
var
RefreshedNodes: TList<TcxTreeListNode>;
procedure DoLoadMemberNodes(Node: TcxTreeListNode; TypeSym: TCompositeTypeSymbol);
var
i: integer;
Symbol: TSymbol;
MemberInfo, NewInfo: IInfo;
MemberNode: TcxTreeListNode;
Data: TData;
begin
(*
if (FShowMembersInherited) and (TypeSym.Parent <> nil) then
begin
DoLoadMemberNodes(Node, TypeSym.Parent);
end;
*)
for i := 0 to TypeSym.Members.Count-1 do
begin
Symbol := TypeSym.Members[i];
if (Symbol is TFieldSymbol) or (Symbol is TPropertySymbol) then
begin
if (Symbol is TPropertySymbol) then
begin
continue;
(*
if (not FShowMembersProperty) then
continue;
if (not (TPropertySymbol(Symbol).Visibility in FVisibilities)) then
continue;
*)
end else
begin
(*
if (not FShowMembersField) then
continue;
if (not (TFieldSymbol(Symbol).Visibility in FVisibilities)) then
continue;
*)
end;
MemberNode := FindNode(Symbol.Name, Node);
if (MemberNode = nil) then
MemberNode := Node.AddChild;
RefreshedNodes.Add(MemberNode);
MemberNode.Texts[0] := Symbol.Name;
if (Symbol is TPropertySymbol) then
begin
if (TPropertySymbol(Symbol).ArrayIndices <> nil) and (TPropertySymbol(Symbol).ArrayIndices.Count > 0) then
begin
MemberNode.Texts[1] := '[...]';
MemberNode.Texts[2] := Symbol.Typ.Name;
MemberNode.ImageIndex := DebuggerSymbolImageIndexArray;
if (MemberNode.StateIndex = -1) then
begin
MemberNode.OverlayIndex := DebuggerSymbolImageIndexOverlayAdd;
MemberNode.StateIndex := 0;
end else
MemberNode.OverlayIndex := -1;
continue;
end;
end;
MemberNode.ImageIndex := Debugger.SymbolToImageIndex(Symbol);
try
if (Symbol is TPropertySymbol) then
// We're not using Info.Member[] for properties since it uses the symbol lookup (see TInfoClassObj.GetMember)
// of the wrapped script object and the object might actually be an instance that's shared between
// multiple objects.
// E.g. TLayoutItem and TLayoutItem.Items:TLayoutItemList both wrap the same object, so a lookup on
// the Info.Members on TLayoutItem.Items will only find the symbols of TLayoutItem.
if (TPropertySymbol(Symbol).ReadSym = nil) then
begin
MemberNode.Texts[1] := '(not readable)';
MemberNode.Texts[2] := Symbol.Typ.Name;
MemberNode.OverlayIndex := DebuggerSymbolImageIndexOverlayWarning;
continue;
end else
if (TPropertySymbol(Symbol).ReadSym is TFuncSymbol) then//and (not FShowMembersPropertySideEffects) then
begin
MemberNode.Texts[1] := '(getter is method)';
MemberNode.Texts[2] := Symbol.Typ.Name;
MemberNode.OverlayIndex := DebuggerSymbolImageIndexOverlayWarning;
continue;
end else
{$ifdef OLD_DWSCRIPT}
MemberInfo := TInfoProperty.Create(Info.Exec.Info, Symbol.Typ, Info.Exec.Info.Execution.DataContext_Nil, TPropertySymbol(Symbol), Info.ScriptObj)
{$else OLD_DWSCRIPT}
MemberInfo := Info.Member[Symbol.Name] // TODO : OLD_DWSCRIPT - see comment above
{$endif OLD_DWSCRIPT}
else
MemberInfo := Info.Member[Symbol.Name];
except
MemberNode.Texts[1] := '(failed)';
MemberNode.Texts[2] := Symbol.Typ.Name;
MemberNode.OverlayIndex := DebuggerSymbolImageIndexOverlayWarning;
continue;
end;
try
Data := MemberInfo.Data;
except
MemberNode.Texts[1] := '(unavailable)';
MemberNode.Texts[2] := Symbol.Typ.Name;
MemberNode.OverlayIndex := DebuggerSymbolImageIndexOverlayWarning;
continue;
end;
CreateInfoOnSymbol(NewInfo, Debugger.GetDebugger.Execution.Info, Symbol.Typ, Data, 0);
if (Node.Expanded) then
LoadNode(MemberNode, NewInfo, Symbol.Typ)
else
begin
if (MemberNode.Count > 0) then
MemberNode.DeleteChildren;
MemberNode.Data := pointer(NewInfo);
pointer(NewInfo) := nil;
end;
end;
end;
end;
var
MemberNode, NextNode: TcxTreeListNode;
begin
RefreshedNodes := TList<TcxTreeListNode>.Create;
try
DoLoadMemberNodes(Node, TypeSym);
MemberNode := Node.getFirstChild;
while (MemberNode <> nil) do
begin
NextNode := MemberNode.getNextSibling;
if (not RefreshedNodes.Contains(MemberNode)) then
MemberNode.Free;
MemberNode := NextNode;
end;
finally
RefreshedNodes.Free;
end;
end;
function TScriptDebuggerStackFrame.GetDisplayValue(const Info: IInfo; TypeSym: TSymbol): string;
var
ElementSymbol: TElementSymbol;
BaseType: TTypeSymbol;
n, i: integer;
begin
if (TypeSym is TEnumerationSymbol) then
begin
ElementSymbol := TEnumerationSymbol(TypeSym).ElementByValue(Info.ValueAsInteger);
if (ElementSymbol <> nil) then
Result := ElementSymbol.Name
else
Result := Format('(%d)', [Info.ValueAsInteger]);
end else
if (TypeSym is TSetOfSymbol) then
begin
BaseType := TSetOfSymbol(TypeSym).Typ;
Result := '';
n := Info.ValueAsInteger;
if (BaseType is TEnumerationSymbol) then
begin
i := 0;
while (n > 0) do
begin
if (n and 1 <> 0) then
begin
if (Result <> '') then
Result := Result + ',';
ElementSymbol := TEnumerationSymbol(BaseType).ElementByValue(i);
if (ElementSymbol <> nil) then
Result := Result + ElementSymbol.Name
else
Result := Result + Format('(%d)', [i]);
end;
n := n shr 1;
inc(i);
end;
end else
begin
i := 0;
while (n > 0) do
begin
if (n and 1 <> 0) then
begin
if (Result <> '') then
Result := Result + ',';
Result := Result + IntToStr(i);
end;
n := n shr 1;
inc(i);
end;
end;
Result := '[' + Result + ']';
end else
begin
Result := Info.ValueAsString;
if (TypeSym is TBaseStringSymbol) then
Result := '''' + Result + '''';
end;
end;
procedure TScriptDebuggerStackFrame.LoadNode(Node: TcxTreeListNode; const Info: IInfo; TypeSym: TSymbol);
var
s: string;
begin
// Note: The TypeSym parameter isn't really necessary. This works just as well without it (i.e. using Info.TypeSym).
if (TypeSym = nil) then
TypeSym := Info.TypeSym;
s := GetDisplayValue(Info, TypeSym);
(*
if (Node.StateIndex = -1) then
begin
Node.OverlayIndex := DebuggerSymbolImageIndexOverlayAdd;
Node.StateIndex := 0;
end else
begin
if (Node.Texts[1] <> s) then
Node.OverlayIndex := DebuggerSymbolImageIndexOverlayChanged
else
Node.OverlayIndex := -1;
end;
*)
Node.Texts[1] := s;
Node.Texts[2] := TypeSym.Name;
if (TypeSym is TCompositeTypeSymbol) then
begin
Node.ImageIndex := Debugger.SymbolToImageIndex(TypeSym);
if (Info is TInfoClassObj) and (Info.ValueIsEmpty) then
begin
if (Node.HasChildren) then
Node.DeleteChildren;
exit;
end;
LoadMemberNodes(Node, Info, TCompositeTypeSymbol(TypeSym));
end else
begin
if (Node.HasChildren) then
Node.DeleteChildren;
end;
end;
procedure TScriptDebuggerStackFrame.TreeListStackCanFocusNode(Sender: TcxCustomTreeList; ANode: TcxTreeListNode; var Allow: Boolean);
begin
Allow := FLoading;
end;
procedure TScriptDebuggerStackFrame.TreeListStackDeletion(Sender: TcxCustomTreeList; ANode: TcxTreeListNode);
var
Info: IInfo;
begin
if (ANode.Data = nil) then
exit;
pointer(Info) := ANode.Data;
ANode.Data := nil;
Info := nil;
end;
procedure TScriptDebuggerStackFrame.TreeListStackExpanding(Sender: TcxCustomTreeList; ANode: TcxTreeListNode; var Allow: Boolean);
var
ChildNode: TcxTreeListNode;
begin
ChildNode := ANode.getFirstChild;
while (ChildNode <> nil) do
begin
if (ChildNode.Data <> nil) then
LoadNode(ChildNode);
ChildNode := ChildNode.getNextSibling;
end;
end;
procedure TScriptDebuggerStackFrame.UpdateInfo;
var
ProgramExecution : TdwsProgramExecution;
Node: TcxTreeListNode;
i: integer;
ValueInfo: IInfo;
Data: Variant;
ScriptObj: TScriptObjInstance;
s: string;
begin
FLoading := True;
TreeListStack.BeginUpdate;
try
TreeListStack.Clear;
ProgramExecution := TdwsProgramExecution(Debugger.GetDebugger.Execution);
if (ProgramExecution = nil) or (ProgramExecution.Debugger = nil) then
exit;
for i := ProgramExecution.Stack.StackPointer-1 downto 0 do
begin
Node := TreeListStack.Add;
Node.Values[0] := IntToStr(i);
Node.ImageIndex := -1;
Node.OverlayIndex := -1;
Node.StateIndex := -1;
ProgramExecution.Stack.ReadValue(i, Data);
try
if (VarType(Data) = varUnknown) then
begin
ScriptObj := TScriptObjInstance(IUnknown(Data));
if (ScriptObj <> nil) then
begin
CreateInfoOnSymbol(ValueInfo, ProgramExecution.ProgramInfo, ScriptObj.ClassSym, ProgramExecution.Stack.Data, i);
LoadNode(Node, ValueInfo, ScriptObj.ClassSym);
if (ProgramExecution.SelfScriptObject <> nil) and (TScriptObjInstance(ProgramExecution.SelfScriptObject^) = ScriptObj) then
Node.OverlayIndex := 20;
end else
Node.Values[1] := '(nil)';
end else
begin
try
Node.Values[1] := VarToStr(Data);
except
on E: Exception do
begin
Node.Values[1] := '('+E.Message+')';
end;
end;
s := VarTypeAsText(VarType(Data));
Node.Values[2] := s;
end;
finally
Data := Unassigned;
end;
if (i = ProgramExecution.Stack.BasePointer) then
begin
Node.Selected := True;
Node.Focused := True;
Node.StateIndex := 20;
end;
end;
finally
TreeListStack.EndUpdate;
FLoading := False;
end;
end;
initialization
RegisterClass(TScriptDebuggerStackFrame);
finalization
end.