File: testwatches.pas

package info (click to toggle)
lazarus 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 214,460 kB
  • sloc: pascal: 1,862,622; xml: 265,709; cpp: 56,595; sh: 3,008; java: 609; makefile: 535; perl: 297; sql: 222; ansic: 137
file content (1163 lines) | stat: -rw-r--r-- 46,093 bytes parent folder | download | duplicates (3)
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
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
unit TestWatches;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, strutils, fpcunit, testutils, testregistry, RegExpr,
  DbgIntfBaseTypes, DbgIntfDebuggerBase, TestBase, FpGdbmiDebugger, LCLProc,
  TestWatchUtils, GDBMIDebugger, FpErrorMessages, TestDbgControl, TestDbgConfig,
  TTestDbgExecuteables, TestDbgTestSuites;

const
  BREAK_COUNT_TestWatchesUnitSimple = 17;
  BL_TW1  = 413; // Test1Sub
  BL_TW2  = 418; // Simple_NoneNested
  BL_TW3  = 708; // Test1Method
  BL_TW4  = 576; // Test1Method Nested1
  BL_TW5  = 738; // Test2Method
  BL_TW6  = 719; // Test2Method Nested2a
  BL_TW7  = 729; // Test2Method Nested2b
  BL_TW8  = 725; // Test2Method Nested2c
  BL_TW9  = 429; // Test0Method
  BL_TW10 = 426; // Test0Method Nested0
  BREAK_LINE_TestWatchesUnitSimple: array [1..BREAK_COUNT_TestWatchesUnitSimple] of Integer =
    ( BL_TW1,  // 1:  Test1Sub
      BL_TW3,  // 2:  Class1.Test1Method
      BL_TW4,  // 3:  Class1.Test1Method > Nested1
      BL_TW2,  // 4:  Class1.Test1Method > Nested1 > Simple_NoneNested
      BL_TW2,  // 5:  Class1.Test1Method > Simple_NoneNested
      BL_TW9,  // 6:  Class1.Test1Method > Test0Method
      BL_TW10, // 7:  Class1.Test1Method > Test0Method > Nested0
      BL_TW5,  // 8:  Class2.Test2Method
      BL_TW6,  // 9:  Class2.Test2Method > Nested2a
      BL_TW7,  // 10: Class2.Test2Method > Nested2b
      BL_TW7,  // 11: Class2.Test2Method > Nested2b > Nested2b
      BL_TW8,  // 12: Class2.Test2Method > Nested2b > Nested2b > Nested2c
      BL_TW6,  // 13: Class2.Test2Method > Nested2b > Nested2b > Nested2c > Nested2a
      BL_TW9,  // 14: Class2.Test0Method

      BL_TW10, // 15: Class2.Test0Method > Nested0
      BL_TW9,  // 16: Class0.Test0Method
      BL_TW10  // 17: Class0.Test0Method > Nested0
    );

  BREAK_LINE_TestWatchesUnitArray = 931;

type

  { TTestWatches }

  TTestWatches = class(TTestWatchesBase)
  private
    FWatches: TWatches;

    ExpectBreakSimple: array [1..BREAK_COUNT_TestWatchesUnitSimple] of TWatchExpectationArray;

    ExpectBreakArray_1: TWatchExpectationArray;

    FCurrentExpect: PWatchExpectationArray; // currently added to
    FLastAddedExp: PWatchExpectation;

    FDbgOutPut: String;
    FDbgOutPutEnable: Boolean;

    procedure DoDbgOutput(Sender: TObject; const AText: String); override;
    procedure ClearAllTestArrays;
    function  HasTestArraysData: Boolean;

    // Add to FLastAddedExp
    function Add(AnExpr:  string; AFmt: TWatchDisplayFormat; AMtch: string;
                 AKind: TDBGSymbolKind; ATpNm: string; AFlgs: TWatchExpectationFlags): PWatchExpectation;
    function Add(AnExpr:  string; AFmt: TWatchDisplayFormat; AEvalFlags: TDBGEvaluateFlags; AMtch: string;
                 AKind: TDBGSymbolKind; ATpNm: string; AFlgs: TWatchExpectationFlags): PWatchExpectation;
    //
    function AddFmtDef        (AnExpr: string;
                               AMtch: string; AKind: TDBGSymbolKind; ATpNm: string; AFlgs: TWatchExpectationFlags=[]): PWatchExpectation;
    function AddFmtDef        (AnExpr: string; AnFormatParam: array of const;
                               AMtch: string; AKind: TDBGSymbolKind; ATpNm: string; AFlgs: TWatchExpectationFlags=[]): PWatchExpectation;
    //function AddFmtDef        (AnExpr: String; AEvalFlags: TDBGEvaluateFlags;
    //                           AMtch: string; AKind: TDBGSymbolKind; ATpNm: string; AFlgs: TWatchExpectationFlags=[]): PWatchExpectation;
    function AddFmtDef        (AnExpr: String; AnFormatParam: array of const; AEvalFlags: TDBGEvaluateFlags;
                               AMtch: string; AKind: TDBGSymbolKind; ATpNm: string; AFlgs: TWatchExpectationFlags=[]): PWatchExpectation;

    procedure JoinExpectsForHexReplace; // Join the lat 2 additions
    procedure LastExpectsToPtrReplace(AReplacePtrExpr: String);
    function Sp2RegEx(s: String): String;

    function AddError         (AnExpr: String; AnErrorCode: Integer = 0; AMtch: string = ''): PWatchExpectation;
    function AddError         (AnExpr: String; AnFormatParam: array of const; AnErrorCode: Integer = 0; AMtch: string = ''): PWatchExpectation;
    function AddExpInt(AnExpr: string; AMtch: Int64; ATpNm: string): PWatchExpectation;
    function AddExpInt(AnExpr: string; AnFormatParam: array of const; AMtch: Int64; ATpNm: string): PWatchExpectation;
    function AddExpUInt(AnExpr: string; AMtch: QWord; ATpNm: string): PWatchExpectation;
    function AddExpUInt(AnExpr: string; AnFormatParam: array of const; AMtch: QWord; ATpNm: string): PWatchExpectation;
    function AddExpPtr(AnExpr: string): PWatchExpectation;
    function AddExpPtr(AnExpr: string; AnFormatParam: array of const): PWatchExpectation;

    procedure AdjustExpectToAddress(AWatchExp: PWatchExpectation); // only ExpectBreakSimple_1
    procedure AdjustArrayExpectToAddress(AWatchExp: PWatchExpectation); // only ExpectBreakSimple_1

    procedure AddExpectSimple;
    procedure AddExpectArray_1;
    procedure RunTestWatches(NamePreFix: String;
                             TestExeName, ExtraOpts: String;
                             UsedUnits: array of TUsesDir
                            );
  published
    procedure TestWatches;
  end;

  { TTestFpErrorHandler }

  TTestFpErrorHandler = class(TFpErrorHandler)
  public
    function ErrorAsString(AnErrorCode: TFpErrorCode; AData: array of const): string; override;
  end;

implementation

var
  ControlTTestWatches: Pointer;

const
  RNoPreQuote  = '(^|[^''])'; // No open qoute (Either at start, or other char)
  RNoPostQuote = '($|[^''])'; // No close qoute (Either at end, or other char)
  Match_Pointer = '\$[0-9A-F]+';
  M_Int = 'Integer|LongInt';

  {%region    * Classes * }
  // _vptr$TOBJECt on older gdb e.g. mac 6.3.50
  Match_ArgTFoo = '<TFoo> = \{.*?(<|vptr\$)TObject>?.+ValueInt = -11';
  Match_ArgTFoo1 = '<TFoo> = \{.*?(<|vptr\$)TObject>?.+ValueInt = 31';
  {%ebdregion    * Classes * }
  // Todo: Dwarf fails with dereferenced var pointer types

function MatchPointer(TypeName: String=''): String;
begin
  if TypeName = ''
  then Result := '\$[0-9A-F]+'
  else Result := TypeName+'\(\$[0-9A-F]+';
end;

function MatchRecord(TypeName: String; AContent: String = ''): String;
begin
  Result := 'record '+TypeName+' .+'+AContent;
end;
function MatchRecord(TypeName: String; AValInt: integer; AValFoo: String = ''): String;
begin
  Result := 'record '+TypeName+' .+ valint = '+IntToStr(AValInt);
  If AValFoo <> '' then Result := Result + ',.*? valfoo = '+AValFoo;
end;

function MatchClass(TypeName: String; AContent: String = ''): String;
begin
  Result := '<'+TypeName+'> = \{.*?(vptr\$|<TObject>).+'+AContent;
end;

function MatchClassNil(TypeName: String): String;
begin
  Result := '<'+TypeName+'> = nil';
end;

{ TTestFpErrorHandler }

function TTestFpErrorHandler.ErrorAsString(AnErrorCode: TFpErrorCode;
  AData: array of const): string;
begin
  Result := inherited ErrorAsString(AnErrorCode, AData);
  Result := 'Error ' + IntToStr(AnErrorCode) + ': ' + Result;
end;


{ TTestWatches }

procedure TTestWatches.AdjustExpectToAddress(AWatchExp: PWatchExpectation);
var
  OtherWatchExp: TWatchExpectation;
  s: String;
  st: TSymbolType;
  OtherList: PWatchExpectationArray;
begin
  OtherList := PWatchExpectationArray(AWatchExp^.UserData2);
  OtherWatchExp := OtherList^[PtrUInt(AWatchExp^.UserData)];
  if OtherWatchExp.TheWatch = nil then begin
    debugln(['SKIPPING watch update']);
    exit;
  end;
  s := OtherWatchExp.TheWatch.Values[1,0].Value;
  delete(s, 1, pos('$', s) - 1); delete(s, pos(')', s), 99);
  for st := low(TSymbolType) to high(TSymbolType) do
    AWatchExp^.Result[st].ExpMatch := '\'+s;
end;

procedure TTestWatches.AdjustArrayExpectToAddress(AWatchExp: PWatchExpectation);
var
  OtherWatchExp: TWatchExpectation;
  s: String;
  st: TSymbolType;
  OtherList: PWatchExpectationArray;
begin
  OtherList := PWatchExpectationArray(AWatchExp^.UserData2);
  //OtherWatchExp := OtherList^[PtrUInt(AWatchExp^.UserData)];
  OtherWatchExp := ExpectBreakArray_1[PtrUInt(AWatchExp^.UserData)];
  if OtherWatchExp.TheWatch = nil then begin
    debugln(['SKIPPING watch update']);
    exit;
  end;
  s := OtherWatchExp.TheWatch.Values[1,0].Value;
  delete(s, 1, pos('$', s) - 1); delete(s, pos(')', s), 99);
  for st := low(TSymbolType) to high(TSymbolType) do begin
    AWatchExp^.Result[st].ExpMatch := AnsiReplaceText(AWatchExp^.Result[st].ExpMatch, 'REPLACEME', s);
  end;
  AWatchExp^.TestName := AnsiReplaceText(AWatchExp^.TestName, 'REPLACEME', 'REPLACEME='+s);
  AWatchExp^.Expression := AnsiReplaceText(AWatchExp^.Expression, 'REPLACEME', s);
  AWatchExp^.TheWatch.Expression := AWatchExp^.Expression;
end;

procedure TTestWatches.DoDbgOutput(Sender: TObject; const AText: String);
begin
  inherited DoDbgOutput(Sender, AText);
  if FDbgOutPutEnable then
    FDbgOutPut := FDbgOutPut + AText;
end;

procedure TTestWatches.ClearAllTestArrays;
var
  i: Integer;
begin
  for i := 1 to BREAK_COUNT_TestWatchesUnitSimple do
    SetLength(ExpectBreakSimple[i], 0);
  SetLength(ExpectBreakArray_1, 0);
end;

function TTestWatches.HasTestArraysData: Boolean;
var
  i: Integer;
begin
  Result :=
    (Length(ExpectBreakArray_1) > 0);
  for i := 1 to BREAK_COUNT_TestWatchesUnitSimple do
    Result := Result or (Length(ExpectBreakSimple[i]) > 0);
end;

function TTestWatches.Add(AnExpr: string; AFmt: TWatchDisplayFormat; AMtch: string;
  AKind: TDBGSymbolKind; ATpNm: string; AFlgs: TWatchExpectationFlags): PWatchExpectation;
begin
  Result := AddWatchExp(FCurrentExpect^, AnExpr, AFmt, AMtch, AKind, ATpNm, AFlgs );
  FLastAddedExp := Result;
end;

function TTestWatches.Add(AnExpr: string; AFmt: TWatchDisplayFormat;
  AEvalFlags: TDBGEvaluateFlags; AMtch: string; AKind: TDBGSymbolKind; ATpNm: string;
  AFlgs: TWatchExpectationFlags): PWatchExpectation;
begin
  Result := AddWatchExp(FCurrentExpect^, AnExpr, AFmt, AEvalFlags, AMtch, AKind, ATpNm, AFlgs );
  FLastAddedExp := Result;
end;

function TTestWatches.AddFmtDef(AnExpr: string; AMtch: string; AKind: TDBGSymbolKind;
  ATpNm: string; AFlgs: TWatchExpectationFlags): PWatchExpectation;
begin
  Result := Add(AnExpr, wdfDefault, AMtch, AKind, ATpNm, AFlgs );
end;

function TTestWatches.AddFmtDef(AnExpr: string; AnFormatParam: array of const; AMtch: string;
  AKind: TDBGSymbolKind; ATpNm: string; AFlgs: TWatchExpectationFlags): PWatchExpectation;
begin
  Result := AddFmtDef(Format(AnExpr, AnFormatParam), AMtch, AKind, ATpNm, AFlgs);
end;

//function TTestWatches.AddFmtDef(AnExpr: String; AEvalFlags: TDBGEvaluateFlags; AMtch: string;
//  AKind: TDBGSymbolKind; ATpNm: string; AFlgs: TWatchExpectationFlags): PWatchExpectation;
//begin
//  Result := Add(AnExpr, wdfDefault, AEvalFlags, AMtch, AKind, ATpNm, AFlgs );
//end;

function TTestWatches.AddFmtDef(AnExpr: String; AnFormatParam: array of const;
  AEvalFlags: TDBGEvaluateFlags; AMtch: string; AKind: TDBGSymbolKind; ATpNm: string;
  AFlgs: TWatchExpectationFlags): PWatchExpectation;
begin
  Result := Add(Format(AnExpr, AnFormatParam), wdfDefault, AEvalFlags, AMtch, AKind, ATpNm, AFlgs );
end;

procedure TTestWatches.JoinExpectsForHexReplace;
var
  i: Integer;
begin
  assert(Length(FCurrentExpect^) >= 2, 'TTestWatches.JoinExpectsForHexReplace: Length(FCurrentExpect) >= 2');
  i := Length(FCurrentExpect^) - 1;

  FCurrentExpect^[i-1].OnBeforeTest := @AdjustArrayExpectToAddress;
  FCurrentExpect^[i-1].UserData := pointer(ptruint(i));
  FCurrentExpect^[i-1].UserData2 := FCurrentExpect;
end;

procedure TTestWatches.LastExpectsToPtrReplace(AReplacePtrExpr: String);
begin
  AddExpPtr(AReplacePtrExpr);
  JoinExpectsForHexReplace;
end;

function TTestWatches.Sp2RegEx(s: String): String;
begin
  Result := AnsiReplaceText(s, ' ', '[ \r\n]');
end;

function TTestWatches.AddError(AnExpr: String; AnErrorCode: Integer;
  AMtch: string): PWatchExpectation;
var
  s: String;
begin
  if AnErrorCode > 0 then
    s := 'Error '+IntToStr(AnErrorCode) + ': ' + AMtch
  else
    s := 'Error ' + AMtch;
  AddFmtDef(AnExpr, s, skNone, '', [fTpMtch, IgnKind, fTExpectError]); // ERROR
end;

function TTestWatches.AddError(AnExpr: String; AnFormatParam: array of const;
  AnErrorCode: Integer; AMtch: string): PWatchExpectation;
begin
  Result := AddError(Format(AnExpr, AnFormatParam), AnErrorCode, AMtch);
end;

function TTestWatches.AddExpInt(AnExpr: string; AMtch: Int64;
  ATpNm: string): PWatchExpectation;
begin
  Result := AddFmtDef(AnExpr, '^'+IntToStr(AMtch), skSimple, ATpNm, [fTpMtch]);
end;

function TTestWatches.AddExpInt(AnExpr: string; AnFormatParam: array of const; AMtch: Int64;
  ATpNm: string): PWatchExpectation;
begin
  Result := AddExpInt(Format(AnExpr, AnFormatParam), AMtch, ATpNm);
end;

function TTestWatches.AddExpUInt(AnExpr: string; AMtch: QWord;
  ATpNm: string): PWatchExpectation;
begin
  Result := AddFmtDef(AnExpr, '^'+IntToStr(AMtch), skSimple, ATpNm, [fTpMtch]);
end;

function TTestWatches.AddExpUInt(AnExpr: string; AnFormatParam: array of const; AMtch: QWord;
  ATpNm: string): PWatchExpectation;
begin
  Result := AddExpUInt(Format(AnExpr, AnFormatParam), AMtch, ATpNm);
end;

function TTestWatches.AddExpPtr(AnExpr: string): PWatchExpectation;
begin
  Result := AddFmtDef(AnExpr, '\$[0-9A-F]', skPointer, '', [fTpMtch]);
end;

function TTestWatches.AddExpPtr(AnExpr: string;
  AnFormatParam: array of const): PWatchExpectation;
begin
  Result := AddExpPtr(Format(AnExpr, AnFormatParam));
end;

procedure TTestWatches.AddExpectSimple;
  procedure AddExpectSimple_Test1Sub;
  var
    i, j: Integer;
    s, s2, s2def: String;
    r: PWatchExpectation;
  begin
    {%region Int/Cardinal types}
    for i := 0 to 3 do begin
      s2def := '';
      case i of
        0: s := '%s';
        1: s := '(@%s)^';
        2: s := 'Int64(%s)';
        3: s := 'QWord(%s)';
      end;
      case i of
        2: s2def := 'Int64';
        3: s2def := 'QWord';
      end;


      s2 := s2def;
      if s2 = '' then s2 := 'ShortInt';
      if not(i in [3]) then begin
        AddExpInt(s, ['SimpleArg_Short1'],   -92, s2);
        AddExpInt(s, ['SimpleVArg_Short1'],  -91, s2);
      end else begin
        AddExpUInt(s, ['SimpleArg_Short1'],   QWord(-92), s2);
        AddExpUInt(s, ['SimpleVArg_Short1'],  QWord(-91), s2);
      end;
      AddExpInt(s, ['Local_Short1'], 39, s2);
      AddExpInt(s, ['SimpleGlob_Short1 '], 29, s2);
      AddExpInt(s, ['SimpleGlob_Short2'],  0, s2);
      if not(i in [3]) then begin
        AddExpInt(s, ['SimpleGlob_Short3'],  -1, s2);
      end;
      AddExpInt(s, ['SimpleGlob_Short4'],  high(ShortInt), s2);
      if not(i in [3]) then begin
        AddExpInt(s, ['SimpleGlob_Short5'],  low(ShortInt), s2);
      end;

      s2 := s2def;
      if s2 = '' then s2 := 'SmallInt';
      if not(i in [3]) then begin
        AddExpInt(s, ['SimpleArg_Small1'],    -192, s2);
        AddExpInt(s, ['SimpleVArg_Small1'],   -191, s2);
      end;
      AddExpInt(s, ['Local_Small1'], 391, s2);
      AddExpInt(s, ['SimpleGlob_Small1 '], 291, s2);
      AddExpInt(s, ['SimpleGlob_Small2'], 0, s2);
      if not(i in [3]) then begin
        AddExpInt(s, ['SimpleGlob_Small3'], -1, s2);
      end;
      AddExpInt(s, ['SimpleGlob_Small4'], high(SmallInt), s2);
      if not(i in [3]) then begin
        AddExpInt(s, ['SimpleGlob_Small5'], low(SmallInt), s2);
      end;

      s2 := s2def;
      if s2 = '' then s2 := M_Int;
      if not(i in [3]) then begin
        AddExpInt(s, ['SimpleArg_Int1'],    -1902, s2);
        AddExpInt(s, ['SimpleVArg_Int1'],   -1901, s2);
      end;
      AddExpInt(s, ['Local_Int1'],  3901, s2);
      AddExpInt(s, ['SimpleGlob_Int1'],   2901, s2);
      AddExpInt(s, ['SimpleGlob_Int2'],   0, s2);
      if not(i in [3]) then begin
        AddExpInt(s, ['SimpleGlob_Int3'],   -1, s2);
      end;
      AddExpInt(s, ['SimpleGlob_Int4'],   2147483647, s2);
      if not(i in [3]) then begin
        AddExpInt(s, ['SimpleGlob_Int5'],   -2147483648, s2);
      end;

      s2 := s2def;
      if s2 = '' then s2 := 'Int64';
      if not(i in [3]) then begin
        AddExpInt(s, ['SimpleArg_QInt1'],    -190000000000002, s2);
        AddExpInt(s, ['SimpleVArg_QInt1'],   -190000000000001, s2);
      end;
      AddExpInt(s, ['Local_QInt1'], 39001, s2);
      AddExpInt(s, ['SimpleGlob_QInt1 '], 29001, s2);
      AddExpInt(s, ['SimpleGlob_QInt2'], 0, s2);
      if not(i in [3]) then begin
        AddExpInt(s, ['SimpleGlob_QInt3'], -1, s2);
      end;
      AddExpInt(s, ['SimpleGlob_QInt4'], high(Int64), s2);
      if not(i in [3]) then begin
        AddExpInt(s, ['SimpleGlob_QInt5'], low(Int64), s2);
      end;

      s2 := s2def;
      if s2 = '' then s2 := 'Byte';
      AddExpUInt(s, ['Local_Byte1'], 59, s2);
      AddExpUInt(s, ['SimpleGlob_Byte1 '], 49, s2);
      AddExpUInt(s, ['SimpleGlob_Byte2'], $7f, s2);
      AddExpUInt(s, ['SimpleGlob_Byte3'], $80, s2);
      AddExpUInt(s, ['SimpleGlob_Byte4'], high(Byte), s2);
      AddExpUInt(s, ['SimpleGlob_Byte5'], low(Byte), s2);

      s2 := s2def;
      if s2 = '' then s2 := 'Word';
      AddExpUInt(s, ['Local_Word1'], 591, s2);
      AddExpUInt(s, ['SimpleGlob_Word1 '], 491, s2);
      AddExpUInt(s, ['SimpleGlob_Word2'], $7fff, s2);
      AddExpUInt(s, ['SimpleGlob_Word3'], $8000, s2);
      AddExpUInt(s, ['SimpleGlob_Word4'], high(Word), s2);
      AddExpUInt(s, ['SimpleGlob_Word5'], low(Word), s2);

      s2 := s2def;
      if s2 = '' then s2 := 'LongWord';
      AddExpUInt(s, ['Local_DWord1'], 5901, s2);
      AddExpUInt(s, ['SimpleGlob_DWord1 '], 4901, s2);
      AddExpUInt(s, ['SimpleGlob_DWord2'], $7fffffff, s2);
      AddExpUInt(s, ['SimpleGlob_DWord3'], $80000000, s2);
      AddExpUInt(s, ['SimpleGlob_DWord4'], high(LongWord), s2);
      AddExpUInt(s, ['SimpleGlob_DWord5'], low(LongWord), s2);

      s2 := s2def;
      if s2 = '' then s2 := 'QWord';
      if not(i in [2]) then begin
        AddExpUInt(s, ['Local_QWord1'], 59001, s2);
        AddExpUInt(s, ['SimpleGlob_QWord1 '], 49001, s2);
        AddExpUInt(s, ['SimpleGlob_QWord2'], $7fffffffffffffff, s2);
        AddExpUInt(s, ['SimpleGlob_QWord3'], qword($8000000000000000), s2);
        AddExpUInt(s, ['SimpleGlob_QWord4'], high(QWord), s2);
        AddExpUInt(s, ['SimpleGlob_QWord5'], low(QWord), s2);
      end;

    end;


    s2 := 'Byte';
    s := 'Byte(%s)';
    AddExpInt(s, ['SimpleArg_Int1'],    Byte(-1902), s2);
    AddExpInt(s, ['SimpleVArg_Int1'],   Byte(-1901), s2);
    AddExpInt(s, ['Local_Int1'],  Byte(3901), s2);
    AddExpInt(s, ['SimpleGlob_Int1'],   Byte(2901), s2);
    AddExpInt(s, ['SimpleGlob_Int2'],   Byte(0), s2);
    AddExpInt(s, ['SimpleGlob_Int3'],   Byte(-1), s2);
    AddExpInt(s, ['SimpleGlob_Int4'],   Byte(2147483647), s2);
    AddExpInt(s, ['SimpleGlob_Int5'],   Byte(-2147483648), s2);


    for i := 0 to 3 do begin
      case i of
        0: s := 'SimpleArg_Class1.%s';
        1: s := 'SimpleVArg_Class1.%s';
        2: s := 'SimpleArg_Class2.%s';
        3: s := 'SimpleVArg_Class2.%s';
      end;
      j := 0;
      if i in [2,3] then j := 100;

      AddExpInt(s, ['Field_Short1'],   j+11, 'ShortInt');
      AddExpInt(s, ['Field_Small1'],   j+12, 'SmallInt');
      AddExpInt(s, ['Field_Int1'],     j+13, 'LongInt');
      AddExpInt(s, ['Field_QInt1'],    j+14, 'Int64');

      AddExpInt(s, ['Field_Byte1'],     j+15, 'Byte');
      AddExpInt(s, ['Field_Word1'],     j+16, 'Word');
      AddExpInt(s, ['Field_DWord1'],    j+17, 'LongWord');
      AddExpInt(s, ['Field_QWord1'],    j+18, 'QWord');
    end;
    {%endregion}

    s := '%s';
    AddFmtDef(s, ['SimpleGlob_Single1'],   '^99\.(2|19)',  skSimple, '', [fTpMtch]);
    AddFmtDef(s, ['SimpleGlob_Double1'],   '^199\.(3|29)', skSimple, '', [fTpMtch]);
    AddFmtDef(s, ['SimpleGlob_Ext1'],      '^299\.(4|39)', skSimple, '', [fTpMtch]);
    AddExpInt(s, ['SimpleGlob_Comp1'],    -2, '');

    {%region AddressOf / Var param, hidden pointer}
      //SimplePArg_Int1, SimplePVArg_Int1, SimplePLocal_Int1, SimplePGlob_Int1: PLongInt;
      r := AddFmtDef('@SimpleArg_Int1',    'replaceme', skPointer, '');
      r^.OnBeforeTest := @AdjustExpectToAddress;
      r^.UserData := pointer(ptruint(Length(FCurrentExpect^)));
      r^.UserData2 := FCurrentExpect;
      AddFmtDef('SimplePArg_Int1',    '\$[0-9A-F]', skPointer, '');

      r := AddFmtDef('@SimpleVArg_Int1',    'replaceme', skPointer, '');
      UpdResMinFpc(r, stSymAll, 020600);
      r^.OnBeforeTest := @AdjustExpectToAddress;
      r^.UserData := pointer(PtrUInt(Length(FCurrentExpect^)));
      r^.UserData2 := FCurrentExpect;
      AddFmtDef('SimplePVArg_Int1',    '\$[0-9A-F]', skPointer, '');

      r := AddFmtDef('@Local_Int1',    'replaceme', skPointer, '');
      r^.OnBeforeTest := @AdjustExpectToAddress;
      r^.UserData := pointer(PtrUInt(Length(FCurrentExpect^)));
      r^.UserData2 := FCurrentExpect;
      AddFmtDef('SimplePLocal_Int1',    '\$[0-9A-F]', skPointer, '');

      r := AddFmtDef('@SimpleGlob_Int1',    'replaceme', skPointer, '');
      r^.OnBeforeTest := @AdjustExpectToAddress;
      r^.UserData := pointer(PtrUInt(Length(FCurrentExpect^)));
      r^.UserData2 := FCurrentExpect;
      AddFmtDef('SimplePGlob_Int1',    '\$[0-9A-F]', skPointer, '');

    {%endregion}
  end;
var
  BrkIdx, i, i2, j: Integer;
  s, s1, s2, s2def: String;
  r: PWatchExpectation;
  ErrCodeNotFound: TFpErrorCode;
begin
  for BrkIdx := 1 to BREAK_COUNT_TestWatchesUnitSimple do begin
    FCurrentExpect := @ExpectBreakSimple[BrkIdx];

    if BrkIdx in [1] then begin // Test1Sub
      AddExpectSimple_Test1Sub;
      continue;
    end;

    {%region  Fields / Glob / ... }
    for i := 0 to 7 do begin

      case i of
        0: s := 'Field_';
        1: s := 'SimpleGlob_';
        2: s := 'Arg_';
        3: s := 'VArg_';
        4: s := 'Local_';
        5: s := 'self.Field_';
        6: s := 'TSimpleClass1(self).Field_';
        7: s := 'TSimpleClass2(self).Field_';
        //8: s := 'TSimpleClass0(self).Field_';
        // 6: passed in object / var arg object
        // unit.glob
      end;
      if (i in [5..7]) and not(BrkIdx in [4, 5]) then
        ErrCodeNotFound := fpErrNoMemberWithName
      else
        ErrCodeNotFound := fpErrSymbolNotFound;


      if i in [0, 5] then begin
        // Some Expressions that will always fail
        s1 := s;
        s2 := '';
        for j := 0 to 9 do begin
          case j of
            0: s1 := s;
            1: s2 := '[1]';
            2: s2 := '[-1]';
            3: s2 := '[0]';
            4: s2 := '[$7fffffff]';
            5: s2 := '^';
            6: s1 := '@' + s;
            7: s2 := '()';
            8: s2 := '(1)';
            9: begin s1 := 'TSimpleClass1(' + s; s2 := ')'; end;
          end;

          AddError(Format('%sIDoNotExist%1:s', [s1,s2]), ErrCodeNotFound); // ERROR
          // procedures
          AddError(Format('%sInitFields%1:s', [s1,s2]),  ErrCodeNotFound); // ERROR
          AddError(Format('%sSimple_NoneNested%1:s', [s1,s2]),  ErrCodeNotFound); // ERROR
          // type
          AddError(Format('%sTSimpleClass1%1:s', [s1,s2]),  ErrCodeNotFound); // ERROR
          // unit
          AddError(Format('%sTestWatchesUnitSimple%1:s', [s1,s2]),  ErrCodeNotFound); // ERROR
        end;
      end;

      if ( (BrkIdx in [6, 7]) and (i in [7]) ) or          // Class1.Test0Method
         ( (BrkIdx in [16,17]) and (i in [6,7]) )          // Class0.Test0Method
      then
        continue; // typecast to unrelated class. May fail or succeed
        // TODO check there is no crash

      if
        ( (BrkIdx in [4, 5]) and             // Class1:Simple_NoneNested
          ( not (i in [1]) ) ) or
        ( (BrkIdx in [6..7]) and             // Class1.Test0Method
          ( not (i in [1, 6]) ) ) or
        ( (BrkIdx in [8..13]) and            // Class2.Test2Method
          ( not (i in [0..1, 5..8]) ) ) or
        ( (BrkIdx in [14..15]) and           // Class2.Test0Method
          ( not (i in [1, 6..7]) ) ) or
        ( (BrkIdx in [16..17]) and           // Class0.Test0Method
          ( not (i in [1]) ) )
      then begin
        // Not Found
        for i2 := 0 to 1 do begin
          s2 := '';
          if i2 = 1 then begin
            s := s + 'P';
            s2 := '^';
          end;

          AddError(Format('%sShort1%1:s', [s,s2]), ErrCodeNotFound); // ERROR
          AddError(Format('%sInt1%1:s',   [s,s2]), ErrCodeNotFound); // ERROR
        end;

        continue;
      end;


      {%region  address of }
      //r := AddFmtDef(Format('@%sDynInt1', [s]), '\REPLACEME', skPointer, '', [fTpMtch]);
      //if i = 3 then UpdResMinFpc(r, stSymAll, 020600);
      //r^.OnBeforeTest := @AdjustArrayExpectToAddress;
      //r^.UserData := pointer(ptruint(Length(FCurrentExpect^)));
      //r^.UserData2 := FCurrentExpect;
      //AddFmtDef(Format('%sPDynInt1', [s]), '\$[0-9A-F]', skPointer, '', [fTpMtch]);

      {%endregion  address of }


      for i2 := 0 to 1 do begin
        s2 := '';
        if i2 = 1 then begin
          s := s + 'P';
          s2 := '^';
        end;

        AddExpInt(Format('%sShort1%1:s', [s,s2]),   11, 'ShortInt');
        AddExpInt(Format('%sSmall1%1:s', [s,s2]),   112, 'SmallInt');
        AddExpInt(Format('%sInt1%1:s', [s,s2]),     1123, 'LongInt');
        AddExpInt(Format('%sQInt1%1:s', [s,s2]),    11234, 'Int64');

        AddExpInt(Format('%sByte1%1:s', [s,s2]),    22, 'Byte');
        AddExpInt(Format('%sWord1%1:s', [s,s2]),    223, 'Word');
        AddExpInt(Format('%sDWord1%1:s', [s,s2]),   2234, 'LongWord');
        AddExpInt(Format('%sQWord1%1:s', [s,s2]),   22345, 'QWord');

        AddFmtDef(Format('%sSingle1%1:s', [s,s2]),  '^0.(5|49)',  skSimple, '', [fTpMtch]);
        AddFmtDef(Format('%sDouble1%1:s', [s,s2]),  '^0.2(5|49)',  skSimple, '', [fTpMtch]);
        AddFmtDef(Format('%sExt1%1:s', [s,s2]),     '^0.7(5|49)',  skSimple, '', [fTpMtch]);
        AddFmtDef(Format('%sComp1%1:s', [s,s2]),    '^-9',  skSimple, '', [fTpMtch]);

        AddFmtDef(Format('%sBool1%1:s', [s,s2]),     '^True', skSimple, '', [fTpMtch]);
        AddFmtDef(Format('%sBool2%1:s', [s,s2]),     '^False', skSimple, '', [fTpMtch]);
        AddFmtDef(Format('%sEnum1%1:s', [s,s2]),    '^eval2', skSimple, '', [fTpMtch]);
        AddFmtDef(Format('%sEnum2%1:s', [s,s2]),    '^eval1', skSimple, '', [fTpMtch]);
        r := AddFmtDef(Format('%sSet1%1:s', [s,s2]),     '^\[eval2\]', skSimple, '', [fTpMtch]);
        UpdExpRes(r, stDwarf, '', skSimple); // no sets in dwarf2
        r := AddFmtDef(Format('%sSet2%1:s', [s,s2]),     '^\[\]', skSimple, '', [fTpMtch]);
        UpdExpRes(r, stDwarf, '', skSimple); // no sets in dwarf2

        AddError(Format('%sByte1%1:s^', [s,s2]), fpErrCannotDereferenceType); // ERROR
    end; // i2

    end; // i
    {%endregion  Fields }


  end;
end;

procedure TTestWatches.AddExpectArray_1;
var
  i, i2: Integer;
  s, s2: String;
  SkipParamArgs: Boolean;
begin
  FCurrentExpect := @ExpectBreakArray_1;


  {%region  Fields / Glob / ... }
  for i := 0 to 5 do begin
    case i of
      0: s := 'Field_';
      1: s := 'ArrayGlob_';
      2: s := 'Arg_';
      3: s := 'VArg_';
      4: s := 'Local_';
      5: s := 'self.Field_';
      // 6: passed in object / var arg object
    end;

    {%region  address of }
    AddFmtDef('@%sDynInt1', [s], '\REPLACEME', skPointer, '', [fTpMtch]);
    if i = 3 then UpdResMinFpc(FLastAddedExp, stSymAll, 020600);
    LastExpectsToPtrReplace(Format('%sPDynInt1', [s]));

    AddFmtDef('@%sStatInt1', [s], '\REPLACEME', skPointer, '', [fTpMtch]);
    if i = 3 then UpdResMinFpc(FLastAddedExp, stSymAll, 020600);
    LastExpectsToPtrReplace(Format('%sPStatInt1', [s]));
    {%endregion  address of }


    for i2 := 0 to 1 do begin
      s2 := '';
      if i2 = 1 then begin
        s := s + 'P';
        s2 := '^';
      end;

      SkipParamArgs := (i in [2,3]);

      // Test: Simple Array of int
      if not SkipParamArgs then begin
        AddFmtDef('%sDynAInt1%1:s', [s,s2], '^[\(L].*?100, 101, 102, 103, 104\)', skArray, '', [fTpMtch]);
        // RepeatCount
        AddFmtDef('%sDynAInt1%1:s', [s,s2], '^[\(L].*?100, 101, 102, 103, 104,', skArray, '', [fTpMtch]);
        FLastAddedExp^.RepeatCount := 6;
      end;
      if (not SkipParamArgs) or (i2=0) then begin // open array / not valid, pointer is pointer to dyn array
        AddExpInt('%sDynAInt1%1:s[0]', [s,s2],    100, M_Int);
        AddExpInt('%sDynAInt1%1:s[1]', [s,s2],    101, M_Int);
        AddError ('%sDynAInt1%1:s[0][0]', [s,s2], fpErrTypeHasNoIndex); // ERROR
      end;


      AddFmtDef('%sStatAInt1%1:s', [s,s2], '^[\(L].*?6600, 6601, 6602, 6603, 6604, 6699\)', skArray, '', [fTpMtch]);
      // RepeatCount
      AddFmtDef('%sStatAInt1%1:s', [s,s2], '^[\(L].*?6600, 6601, 6602, 6603, 6604, 6699,', skArray, '', [fTpMtch]);
      FLastAddedExp^.RepeatCount := 7;
      AddExpInt('%sStatAInt1%1:s[4]', [s,s2],    6600, M_Int);
      AddExpInt('%sStatAInt1%1:s[9]', [s,s2],    6699, M_Int);
      AddFmtDef('%sStatAInt1%1:s[3]', [s,s2], '', skSimple, M_Int, [fTpMtch]); // Just do not crash
      AddFmtDef('%sStatAInt1%1:s[10]', [s,s2], '', skSimple, M_Int, [fTpMtch]); // Just do not crash
      AddFmtDef('%sStatAInt1%1:s[-1]', [s,s2], '', skSimple, M_Int, [fTpMtch]); // Just do not crash
      AddError ('%sStatAInt1%1:s[0][0]', [s,s2], fpErrTypeHasNoIndex); // ERROR


      AddFmtDef('%sStatAInt2%1:s', [s,s2], '^[\(L].*?3300, 3301, 3302', skArray, '', [fTpMtch]);
      AddExpInt('%sStatAInt2%1:s[-4]', [s,s2],    3300, M_Int);
      AddExpInt('%sStatAInt2%1:s[0]', [s,s2],    3304, M_Int);


      AddFmtDef('%sDynInt1%1:s', [s,s2], '^[\(L].*?5511, 5512, 5513, 5514, -5511', skArray, '', [fTpMtch]);
      AddExpInt('%sDynInt1%1:s[0]', [s,s2],    5511, M_Int);
      AddExpInt('%sDynInt1%1:s[19]', [s,s2],    5500, M_Int);

      // Test: wdfMemDump
//TODO: DynArray.Size / check for end after last element.
      if not SkipParamArgs then begin
        // 5511 = $1587 / -5511=$FFFFEA79 / 5500=$157c
        AddFmtDef('%sDynInt1%1:s', [s,s2], Sp2RegEx('^\$?[0-9A-F]+: *(00 00 )?((15 87)|(87 15)) +00 00 +([0-9A-F][0-9A-F] +)*00 ((15 7C)|(7C 15))'), skArray, '', [fTpMtch]);
        FLastAddedExp^.DspFormat := wdfMemDump;
        AddFmtDef('%sDynInt1%1:s[1]', [s,s2], Sp2RegEx('^\$?[0-9A-F]+: *((00 00 15 88)|(88 15 00 00)) *$'), skArray, '', [fTpMtch]);
        FLastAddedExp^.DspFormat := wdfMemDump;
        AddFmtDef('%sDynInt1%1:s[1]', [s,s2], Sp2RegEx('^\$?[0-9A-F]+: *((00 00 15 88)|(88 15 00 00)) +[0-9A-F][0-9A-F]'), skArray, '', [fTpMtch]);
        FLastAddedExp^.DspFormat := wdfMemDump;
        FLastAddedExp^.RepeatCount := 5;
      end;

      // 6600 = $19C8 / 6699=$1A2B
      AddFmtDef('%sStatAInt1%1:s', [s,s2], Sp2RegEx('^\$?[0-9A-F]+: *(00 00 )?((19 C8)|(C8 19)) +00 00 +([0-9A-F][0-9A-F] +)*00 ((1A 2B)|(2B 1A))'), skArray, '', [fTpMtch]);
      FLastAddedExp^.DspFormat := wdfMemDump;
      AddFmtDef('%sStatAInt1%1:s[5]', [s,s2], Sp2RegEx('^\$?[0-9A-F]+: *((00 00 19 C9)|(C9 19 00 00)) *$'), skArray, '', [fTpMtch]);
      FLastAddedExp^.DspFormat := wdfMemDump;
      AddFmtDef('%sStatAInt1%1:s[5]', [s,s2], Sp2RegEx('^\$?[0-9A-F]+: *((00 00 19 C9)|(C9 19 00 00)) +[0-9A-F][0-9A-F]'), skArray, '', [fTpMtch]);
      FLastAddedExp^.DspFormat := wdfMemDump;
      FLastAddedExp^.RepeatCount := 5;

      // Test: typecast dynarray to dynarray
      AddFmtDef('TArrayDynInt(%sDynInt1%1:s)', [s,s2], '^[\(L].*?5511, 5512, 5513, 5514, -5511', skArray, '', [fTpMtch]);
      if i in [3] then UpdResMinFpc(FLastAddedExp, stSymAll, 020600);
      AddExpInt('TArrayDynInt(%sDynInt1%1:s)[0]', [s,s2],    5511, M_Int);
      if i in [3] then UpdResMinFpc(FLastAddedExp, stSymAll, 020600);
      // typecast for dynarray
      AddFmtDef('TArrayDynInt(Pointer(%sDynInt1%1:s))', [s,s2], '^[\(L].*?5511, 5512, 5513, 5514, -5511',
                skArray, '', [fTpMtch]);
      if i in [3] then UpdResMinFpc(FLastAddedExp, stSymAll, 020600);
      AddExpInt('TArrayDynInt(Pointer(%sDynInt1%1:s))[0]', [s,s2],    5511, M_Int);
      if i in [3] then UpdResMinFpc(FLastAddedExp, stSymAll, 020600);
      // typecast for dynarray
      AddFmtDef('TArrayDynInt(QWord(%sDynInt1%1:s))', [s,s2], '^[\(L].*?5511, 5512, 5513, 5514, -5511',
                skArray, '', [fTpMtch]);
      if i in [3] then UpdResMinFpc(FLastAddedExp, stSymAll, 020600);
      AddExpInt('TArrayDynInt(QWord(%sDynInt1%1:s))[0]', [s,s2],    5511, M_Int);
      if i in [3] then UpdResMinFpc(FLastAddedExp, stSymAll, 020600);

      // Test: typecast Address to array
      if (i2 = 0) and (i <> 3) then begin
        AddFmtDef('TArrayDynInt(REPLACEME)', [s,s2], '^[\(L].*?5511, 5512, 5513, 5514, -5511',
                  skArray, '', [fTpMtch]);
        //      if i in [3] then UpdResMinFpc(FLastAddedExp, stSymAll, 020600);
        LastExpectsToPtrReplace(Format('Pointer(%sDynInt1%1:s)', [s,s2]));

        AddExpInt('TArrayDynInt(REPLACEME)[0]', [s,s2],    5511, M_Int);
        //if i in [3] then UpdResMinFpc(FLastAddedExp, stSymAll, 020600);
        LastExpectsToPtrReplace(Format('Pointer(%sDynInt1%1:s)', [s,s2]));

        //AddError('TArrayStatInt(REPLACEME)', [s,s2]);
        //LastExpectsToPtrReplace(Format('Pointer(@%sStatInt1%1:s[-2])', [s,s2]));
        //AddError('TArrayStatInt(REPLACEME)[0]', [s,s2]);
        //LastExpectsToPtrReplace(Format('Pointer(@%sStatInt1%1:s[-2])', [s,s2]));
      end;


      // Test: Empty DynArray = nil
      AddFmtDef('%sDynInt2%1:s', [s,s2], '^nil', skArray, '', [fTpMtch]);
      AddFmtDef('TArrayDynInt(%sDynInt2%1:s)', [s,s2], '^nil', skArray, '', [fTpMtch]);
      if i in [3] then UpdResMinFpc(FLastAddedExp, stSymAll, 020600);
      AddExpInt('QWord(%sDynInt2%1:s)', [s,s2],   0, 'QWord');
      if i in [3] then UpdResMinFpc(FLastAddedExp, stSymAll, 020600);


      // Test: Array of structure // nested array
      AddFmtDef('%sDynClass1%1:s', [s,s2], '^[\(L].*?'+
        '\(.*?Field_INT1 = 98700;.*?Field_INT2 = 98701;.*?Field_DYNAINT1 = \(9900, 9901\);.*?\), ' +
        '\(.*?Field_INT1 = 88700;.*?Field_INT2 = 88701;.*?Field_DYNAINT1 = \(8900, 8901\);.*?\), ' +
        '\(.*?Field_INT1 = 78700;.*?Field_INT2 = 78701;.*?Field_DYNAINT1 = \(7900, 7901, 7902\);.*?\)',
        skArray, '', [fTpMtch]);
      AddFmtDef(Format('%sDynClass1%1:s[0]', [s,s2]),
        '\(.*?Field_INT1 = 98700;.*?Field_INT2 = 98701;.*?Field_DYNAINT1 = \(9900, 9901\);.*?\), ',
        skClass, 'TArrayClass1', [fTpMtch]);
      AddFmtDef(Format('%sDynClass1%1:s[1]', [s,s2]),
        '\(.*?Field_INT1 = 88700;.*?Field_INT2 = 88701;.*?Field_DYNAINT1 = \(8900, 8901\);.*?\), ',
        skClass, 'TArrayClass1', [fTpMtch]);
      AddExpInt('%sDynClass1%1:s[0].Field_INT1', [s,s2],  98700, M_Int);


      AddFmtDef('%sDynRec1%1:s', [s,s2], '^[\(L].*?'+
        '\(.*?FieldINT1 = 200;.*?FieldINT2 = 201;.*?\), ' +
        '\(.*?FieldINT1 = 210;.*?FieldINT2 = 211;.*?\), ' +
        '\(.*?FieldINT1 = 220;.*?FieldINT2 = 221;.*?\)',
      skArray, '', [fTpMtch]);

      if not SkipParamArgs then // open array / TODO
        AddFmtDef('%sDynRec2%1:s', [s,s2], '^[\(L].*?'+
          '\(.*?FieldByte1 = 200;.*?FieldByte2 = 201;.*?\), ' +
          '\(.*?FieldByte1 = 210;.*?FieldByte2 = 211;.*?\), ' +
          '\(.*?FieldByte1 = 220;.*?FieldByte2 = 221;.*?\)',
        skArray, '', [fTpMtch]);

      // Test: Nested Array
      // 1st nested has diff len
      AddFmtDef('%sDynDynInt1%1:s', [s,s2], '^[\(L].*?'+
        '\(1000, 1001\), ' +    '\(1010, 1011, 1012\), ' +    '\(1020, 1021, 1022\)',
      skArray, '', [fTpMtch]);
      AddExpInt('%sDynDynInt1%1:s[0][0]', [s,s2],    1000, M_Int);
      AddExpInt('%sDynDynInt1%1:s[0,0]', [s,s2],    1000, M_Int);
      AddExpInt('%0:sDynDynInt1%1:s[%0:sDynDynInt1%1:s[3,0], %0:sDynDynInt1%1:s[3,1]]', [s,s2],    1012, M_Int);
      AddExpInt('%0:sDynDynInt1%1:s[%0:sDynDynInt1%1:s[3,0]][%0:sDynDynInt1%1:s[3,1]]', [s,s2],    1012, M_Int);

      AddError('%0:sDynDynInt1%1:s[FooNoExistFoo, %0:sDynDynInt1%1:s[3,1]]', [s,s2], fpErrSymbolNotFound); // ERROR
      AddError('%0:sDynDynInt1%1:s[%0:sDynDynInt1%1:s[3,0].NoMember, %0:sDynDynInt1%1:s[3,1]]', [s,s2], fpErrorNotAStructure); // ERROR


      AddFmtDef('%sDynDynClass1%1:s', [s,s2], '^[^\(G]*?\('+ // not GDB:
        '\(\(.*?Field_INT1 = 5000;.*?\), \(.*?Field_INT1 = 5001;.*?\)\), ' +
        '\(nil, \(.*?Field_INT1 = 5011;.*?\)\), ' +
        '\(nil, nil\)',
      skArray, '', [fTpMtch]);


      ////
      AddFmtDef('%sStatStatInt1%1:s', [s,s2], '^[\(L].*?'+
        '\(4091, 4092, 4093\), ' +    '\(4081, 4082, 4083\), ' +    '\(4071, 4072, 4073\), ',
      skArray, '', [fTpMtch]);
      AddExpInt('%sStatStatInt1%1:s[-9,1]', [s,s2],    4091, M_Int);
      AddFmtDef('TArrayStatStatInt(%sStatStatInt1%1:s)', [s,s2], '^[\(L].*?'+
        '\(4091, 4092, 4093\), ' +    '\(4081, 4082, 4083\), ' +    '\(4071, 4072, 4073\), ',
      skArray, '', [fTpMtch]);
      if i in [3] then UpdResMinFpc(FLastAddedExp, stSymAll, 020600);
      AddExpInt('TArrayStatStatInt(%sStatStatInt1%1:s)[-9,1]', [s,s2],    4091, M_Int);
      if i in [3] then UpdResMinFpc(FLastAddedExp, stSymAll, 020600);

      {%region  Pointer }
      AddExpInt('(%sIntPointer%1:s-2)^',    [s,s2],    5511, M_Int);
      AddExpInt('(%sIntPointer%1:s+(-2))^', [s,s2],    5511, M_Int);
      AddExpInt('(%sIntPointer%1:s+ArraySub2)^', [s,s2],    5511, M_Int);
      AddExpInt('(%sIntPointer%1:s-ArrayAdd2)^', [s,s2],    5511, M_Int);
      AddExpInt('(ArraySub2+%sIntPointer%1:s)^', [s,s2],    5511, M_Int);
      AddExpInt('(-2+%sIntPointer%1:s)^',   [s,s2],    5511, M_Int);
      AddExpInt('(-1+%sIntPointer%1:s-1)^', [s,s2],    5511, M_Int);

      AddExpInt('(%sIntPointer%1:s-1)^',    [s,s2],    5512, M_Int);
      AddExpInt('(%sIntPointer%1:s+(-1))^', [s,s2],    5512, M_Int);
      AddExpInt('%sIntPointer%1:s^',        [s,s2],    5513, M_Int);
      AddExpInt('(%sIntPointer%1:s)^',      [s,s2],    5513, M_Int);
      AddExpInt('(%sIntPointer%1:s+0)^',    [s,s2],    5513, M_Int);
      AddExpInt('(%sIntPointer%1:s-0)^',    [s,s2],    5513, M_Int);
      AddExpInt('(%sIntPointer%1:s+1)^',    [s,s2],    5514, M_Int);
      AddExpInt('(%sIntPointer%1:s+2)^',    [s,s2],   -5511, M_Int);

      AddExpInt('%sIntPointer%1:s[-2]', [s,s2],    5511, M_Int);
      AddExpInt('%sIntPointer%1:s[ArraySub2]', [s,s2],    5511, M_Int);
      AddExpInt('%sIntPointer%1:s[-ArrayAdd2]', [s,s2],    5511, M_Int);
      AddExpInt('%sIntPointer%1:s[-1]', [s,s2],    5512, M_Int);
      AddExpInt('%sIntPointer%1:s[0]',  [s,s2],    5513, M_Int);
      AddExpInt('%sIntPointer%1:s[1]',  [s,s2],    5514, M_Int);
      AddExpInt('%sIntPointer%1:s[2]',  [s,s2],   -5511, M_Int);

      AddExpInt('(PInteger(@%sIntPointer%1:s[-1])-1)^', [s,s2],    5511, M_Int);
      AddExpInt('(%sIntPointer%1:s-1)[-1]',    [s,s2],    5511, M_Int);
      AddExpInt('(PInteger(@Pointer(%sIntPointer%1:s)[-4])-1)^', [s,s2],    5511, M_Int);
      AddExpInt('(PInteger(@Pointer(%sIntPointer%1:s)[-2]-6))^', [s,s2],    5511, M_Int);

      // add 2 each for word pointer
      AddExpInt('PInteger(%sWordPointer%1:s)^',     [s,s2],    5513, M_Int);
      AddExpInt('PInteger(%sWordPointer%1:s+0)^',   [s,s2],    5513, M_Int);
      AddExpInt('PInteger(%sWordPointer%1:s+2)^',   [s,s2],    5514, M_Int);
      AddExpInt('PInteger(%sWordPointer%1:s+ArrayAdd2)^',   [s,s2],    5514, M_Int);
      AddExpInt('PInteger(%sWordPointer%1:s-ArraySub2)^',   [s,s2],    5514, M_Int);

      // add 4 each for pointer
      AddExpInt('PInteger(%sPointer%1:s)^',     [s,s2],    5513, M_Int);
      AddExpInt('PInteger(%sPointer%1:s+0)^',   [s,s2],    5513, M_Int);
      AddExpInt('PInteger(%sPointer%1:s+4)^',   [s,s2],    5514, M_Int);

      // deref generic: error
      //AddFmtDef('%sPointer%1:s^', [s,s2], 'GDB|Error', skNone, '', [fTpMtch, IgnKind, fTExpectError]); // ERROR
      //AddFmtDef('(%sPointer%1:s)^', [s,s2], 'GDB|Error', skNone, '', [fTpMtch, IgnKind, fTExpectError]); // ERROR
      //AddFmtDef('(%sPointer%1:s+0)^', [s,s2], 'GDB|Error', skNone, '', [fTpMtch, IgnKind, fTExpectError]); // ERROR
      //AddFmtDef('(%sPointer%1:s+4)^', [s,s2], 'GDB|Error', skNone, '', [fTpMtch, IgnKind, fTExpectError]); // ERROR
      //AddFmtDef('(%sPointer%1:s-4)^', [s,s2], 'GDB|Error', skNone, '', [fTpMtch, IgnKind, fTExpectError]); // ERROR


      if i2 = 0 then begin
        {%region  address of }
        AddFmtDef('%sIntPointer', [s], '\REPLACEME', skPointer, '', [fTpMtch]);
        if i = 3 then UpdResMinFpc(FLastAddedExp, stSymAll, 020600);
        LastExpectsToPtrReplace(Format('@%sDynInt1[2]', [s]));

        AddFmtDef('(%sIntPointer+0)', [s], '\REPLACEME', skPointer, '', [fTpMtch]);
        if i = 3 then UpdResMinFpc(FLastAddedExp, stSymAll, 020600);
        LastExpectsToPtrReplace(Format('@%sDynInt1[2]', [s]));

        AddFmtDef('@(%sIntPointer^)', [s], '\REPLACEME', skPointer, '', [fTpMtch]);
        if i = 3 then UpdResMinFpc(FLastAddedExp, stSymAll, 020600);
        LastExpectsToPtrReplace(Format('@%sDynInt1[2]', [s]));

        AddFmtDef('(%sIntPointer+1)', [s], '\REPLACEME', skPointer, '', [fTpMtch]);
        if i = 3 then UpdResMinFpc(FLastAddedExp, stSymAll, 020600);
        LastExpectsToPtrReplace(Format('@%sDynInt1[3]', [s]));

        AddFmtDef('(%sIntPointer-1)', [s], '\REPLACEME', skPointer, '', [fTpMtch]);
        if i = 3 then UpdResMinFpc(FLastAddedExp, stSymAll, 020600);
        LastExpectsToPtrReplace(Format('@%sDynInt1[1]', [s]));

        // Add/SUb to word pointer
        AddFmtDef('(%sWordPointer+2)', [s], '\REPLACEME', skPointer, '', [fTpMtch]);
        if i = 3 then UpdResMinFpc(FLastAddedExp, stSymAll, 020600);
        LastExpectsToPtrReplace(Format('@%sDynInt1[3]', [s]));

        // Add/SUb to generic pointer
        AddFmtDef('%sPointer', [s], '\REPLACEME', skPointer, '', [fTpMtch]);
        if i = 3 then UpdResMinFpc(FLastAddedExp, stSymAll, 020600);
        LastExpectsToPtrReplace(Format('@%sDynInt1[2]', [s]));

        AddFmtDef('%sPointer+4', [s], '\REPLACEME', skPointer, '', [fTpMtch]);
        if i = 3 then UpdResMinFpc(FLastAddedExp, stSymAll, 020600);
        LastExpectsToPtrReplace(Format('@%sDynInt1[3]', [s]));

        AddFmtDef('%sPointer-4', [s], '\REPLACEME', skPointer, '', [fTpMtch]);
        if i = 3 then UpdResMinFpc(FLastAddedExp, stSymAll, 020600);
        LastExpectsToPtrReplace(Format('@%sDynInt1[1]', [s]));

        {%endregion  address of }
      end;

      {%endregion  Pointer }
    end; // i2

  end; // i
  {%endregion  Fields }

//TODO
  AddExpInt('PInteger(Field_DynInt1)[0]',  5511, M_Int);
  AddExpInt('PInteger(Field_DynInt1)[1]',  5512, M_Int);
  AddExpInt('PInteger(Field_DynInt1)[2]',  5513, M_Int);

  AddExpInt('^LongInt(Field_DynInt1)[0]',  5511, M_Int);
  AddExpInt('^LongInt(Field_DynInt1)[1]',  5512, M_Int);
  AddExpInt('^LongInt(Field_DynInt1)[2]',  5513, M_Int);

end;

procedure TTestWatches.RunTestWatches(NamePreFix: String; TestExeName, ExtraOpts: String;
  UsedUnits: array of TUsesDir);

var
  dbg: TGDBMIDebugger;
  Only: Integer;
  OnlyName, OnlyNamePart: String;

  procedure SetBreak(AFileName: String; ALineNum: Integer);
  begin
    with dbg.BreakPoints.Add(AFileName, ALineNum) do begin
      InitialEnabled := True;
      Enabled := True;
    end;
  end;

var
  i: Integer;
  st: TSymbolType;
  s: String;

begin
  TestBaseName := NamePreFix;
  if not HasTestArraysData then exit;
  Only := StrToIntDef(TestControlGetTestPattern, -1);
  OnlyNamePart := '';OnlyName := '';
  if Only < 0
  then begin
    OnlyName := TestControlGetTestPattern;
    if (OnlyName <> '') and (OnlyName[1]='*') then begin
      OnlyNamePart := copy(OnlyName, 2, length(OnlyName));
      OnlyName := '';
    end;
  end;


  try
    TestCompile(AppDir + 'TestWatchesProg.pas', TestExeName, UsedUnits, '', ExtraOpts);
  except
    on e: Exception do begin
      TestTrue('Compile error: ' + e.Message, False);
      exit;
    end;
  end;

  try
    dbg := StartGDB(AppDir, TestExeName);
    FWatches := Watches.Watches;

    for i := 1 to BREAK_COUNT_TestWatchesUnitSimple do
      SetBreak('TestWatchesUnitSimple.pas', BREAK_LINE_TestWatchesUnitSimple[i]);
    SetBreak('TestWatchesUnitArray.pas', BREAK_LINE_TestWatchesUnitArray);

    if dbg.State = dsError then
      Fail(' Failed Init');

    for i := 1 to BREAK_COUNT_TestWatchesUnitSimple do
      AddWatches(ExpectBreakSimple[i], FWatches, Only, OnlyName, OnlyNamePart);
    AddWatches(ExpectBreakArray_1,  FWatches, Only, OnlyName, OnlyNamePart);

    (* Start debugging *)
    dbg.ShowConsole := True;
    dbg.Run;


    for i := 1 to BREAK_COUNT_TestWatchesUnitSimple do begin
      if not TestTrue('State=Pause', dbg.State = dsPause) then begin
        TestTrue('Hit BREAK_LINE_TestWatchesUnitSimple_'+IntToStr(i), False);
        exit;
      end;
      AssertTrue('in simple', pos('simple', LowerCase(dbg.GetLocation.SrcFile)) > 0);
      (* Hit first breakpoint:  *)
      TestWatchList('Simple'+IntToStr(i), ExpectBreakSimple[i], dbg, Only, OnlyName, OnlyNamePart);

      dbg.Run;
    end;


    // array


   if not TestTrue('State=Pause', dbg.State = dsPause) then begin
      TestTrue('Hit BREAK_LINE_TestWatchesUnitArray', False);
      exit;
    end;
    AssertTrue('reached array', pos('array', LowerCase(dbg.GetLocation.SrcFile)) > 0);

    (* Hit 11st Array breakpoint: *)
    TestWatchList('Array1',ExpectBreakArray_1, dbg, Only, OnlyName, OnlyNamePart);

//    dbg.Run;





    dbg.Stop;
  except
    on e: Exception do begin
      TestTrue('Error: ' + e.Message, False);
      exit;
    end;
  end;
  dbg.Done;
  CleanGdb;
  dbg.Free;
end;

procedure TTestWatches.TestWatches;
var
  TestExeName: string;
begin
  if SkipTest then exit;
  if not TestControlCanTest(ControlTTestWatches) then exit;

  ClearTestErrors;

  // Floating point tests assume that decimal separator is a '.' so make sure that's what we get.
  FormatSettings.DecimalSeparator := '.';
  ClearAllTestArrays;
  AddExpectSimple;
  AddExpectArray_1;

  RunTestWatches('', TestExeName,  '', []);

  AssertTestErrors;
end;

initialization

  ErrorHandler := TTestFpErrorHandler.Create;
  RegisterDbgTest(TTestWatches);
  ControlTTestWatches := TestControlRegisterTest('TTestWatches');

end.