File: testwatchutils.pas

package info (click to toggle)
lazarus 4.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 275,760 kB
  • sloc: pascal: 2,341,904; xml: 509,420; makefile: 348,726; cpp: 93,608; sh: 3,387; java: 609; perl: 297; sql: 222; ansic: 137
file content (658 lines) | stat: -rw-r--r-- 24,862 bytes parent folder | download
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
unit TestWatchUtils;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, RegExpr, TestBase, LazLoggerBase, DbgIntfBaseTypes,
  DbgIntfDebuggerBase, TestDbgConfig, TTestDebuggerClasses, IdeDebuggerBase,
  IdeDebuggerWatchResult, IdeDebuggerWatchResPrinter, LazDebuggerIntf,
  LazDebuggerIntfBaseTypes, IdeDebuggerWatchValueIntf;

type

  TWatchExpectationFlag =
    (IgnDwrf,            // ignore error for dwarf at all
     IgnDwrf2,           // ignore error for dwarf 2
     IgnDwrf2IfNoSet,    // ignore error for dwarf2 (-gw) without set
     IgnDwrf3,           // ignore error for dwarf 3
     IgnStabs,
     //IgnDwrfSet,   // no dwarf2 with set // no dwarf3

     IgnData,           // Ignore the data part
     IgnDataDw,         // Ignore the data part, if dwarf
     IgnDataDw2,        // Ignore the data part, if dwarf 2
     IgnDataDw3,        // Ignore the data part, if dwarf 3
     IgnDataSt,         // Ignore the data part, if Stabs

     IgnKind,           // Ignore skSimple, ....
     IgnKindDw,
     IgnKindDw2,
     IgnKindDw3,
     IgnKindSt,
     acceptSkSimple, // also accept skSimple

     IgnKindPtr,           // Ignore skSimple, ONLY if got kind=skPointer
     IgnKindPtrDw,
     IgnKindPtrDw2,
     IgnKindPtrDw3,
     IgnKindPtrSt,

     IgnTpName,           // Ignore the typename
     IgnTpNameDw,
     IgnTpNameDw2,
     IgnTpNameDw3,
     IgnTpNameSt,

     fTstSkip,       // Do not run test
     fTstSkipDwarf3,
     fTpMtch,
     fTExpectNotFound,
     fTExpectError
    );
  TWatchExpectationFlags = set of TWatchExpectationFlag;

const
  WatchExpFlagMask: array[TSymbolType] of TWatchExpectationFlags
  = ( {stNone}     [],
      {stStabs}    [IgnStabs,
                    IgnData,    IgnDataSt,
                    IgnKind,    IgnKindSt,
                    IgnKindPtr, IgnKindPtrSt,
                    IgnTpName,  IgnTpNameSt
                   ],
      {stDwarf}    [IgnDwrf, IgnDwrf2, IgnDwrf2IfNoSet,
                    IgnData,    IgnDataDw, IgnDataDw2,
                    IgnKind,    IgnKindDw, IgnKindDw2,
                    IgnKindPtr, IgnKindPtrDw, IgnKindPtrDw2,
                    IgnTpName,  IgnTpNameDw, IgnTpNameDw2
                   ],
      {stDwarfSet} [IgnDwrf, IgnDwrf2,
                    IgnData,    IgnDataDw, IgnDataDw2,
                    IgnKind,    IgnKindDw, IgnKindDw2,
                    IgnKindPtr, IgnKindPtrDw, IgnKindPtrDw2,
                    IgnTpName,  IgnTpNameDw, IgnTpNameDw2
                   ],
      {stDwarf3}   [IgnDwrf, IgnDwrf3,
                    IgnData,    IgnDataDw, IgnDataDw3,
                    IgnKind,    IgnKindDw, IgnKindDw3,
                    IgnKindPtr, IgnKindPtrDw, IgnKindPtrDw3,
                    IgnTpName,  IgnTpNameDw, IgnTpNameDw3
                   ],
                   []
    );

  WatchExpFlagSIgnAll     = [IgnStabs, IgnDwrf, IgnDwrf2, IgnDwrf2IfNoSet, IgnDwrf3];
  WatchExpFlagSIgnData    = [IgnStabs, IgnDwrf, IgnDwrf2, IgnDwrf2IfNoSet, IgnDwrf3,  IgnData,    IgnDataDw, IgnDataDw2, IgnDataDw3, IgnDataSt];
  WatchExpFlagSIgnKind    = [IgnStabs, IgnDwrf, IgnDwrf2, IgnDwrf2IfNoSet, IgnDwrf3,  IgnKind,    IgnKindDw, IgnKindDw2, IgnKindDw3, IgnKindSt];
  WatchExpFlagSIgnKindPtr = [IgnStabs, IgnDwrf, IgnDwrf2, IgnDwrf2IfNoSet, IgnDwrf3,  IgnKindPtr, IgnKindPtrDw, IgnKindPtrDw2, IgnKindPtrDw3, IgnKindPtrSt];
  WatchExpFlagSIgnTpName  = [IgnStabs, IgnDwrf, IgnDwrf2, IgnDwrf2IfNoSet, IgnDwrf3,  IgnTpName,  IgnTpNameDw, IgnTpNameDw2, IgnTpNameDw3, IgnTpNameSt];

type
  PWatchExpectation= ^TWatchExpectation;
  TWatchExpectOnBeforeTest = procedure(AWatchExp: PWatchExpectation) of object;

  TFullTypeMemberExpectationResult = record
    Name: string;
    ExpTypeName: string;
    ExpKind: TDbgSymbolKind;
    Flgs: TWatchExpectationFlags;
  end;
  TFullTypeMemberExpectationResultArray = array of TFullTypeMemberExpectationResult;

  TWatchExpectationResult = record
    ExpMatch: string;
    ExpKind: TDBGSymbolKind;
    ExpTypeName: string;
    Flgs: TWatchExpectationFlags;
    MinGdb, MinFpc: Integer;
    FullTypesExpect: TFullTypeMemberExpectationResultArray;
  end;

  TWatchExpectation = record
    TestName: String;
    Expression:  string;
    RepeatCount: Integer;
    EvaluateFlags: TWatcheEvaluateFlags;
    StackFrame: Integer;
    Result: Array [TSymbolType] of TWatchExpectationResult;

    TheWatch: TTestWatch;
    UserData, UserData2: Pointer;
    OnBeforeTest: TWatchExpectOnBeforeTest;
  end;
  TWatchExpectationArray = array of TWatchExpectation;
  PWatchExpectationArray = ^TWatchExpectationArray;

  { TTestWatchesBase }

  TTestWatchesBase = class(TGDBTestCase)
  protected
    procedure TestWatch(Name: String; ADbg: TDebuggerIntf;
                        AWatch: TTestWatch; Data: TWatchExpectation; WatchValue: String = '');
    procedure AddWatches(ExpectList: TWatchExpectationArray;
                         AWatches: TWatches;
                         Only: Integer; const OnlyName, OnlyNamePart: String);
    procedure TestWatchList(const AName: String; ExpectList: TWatchExpectationArray;
                          ADbg: TDebuggerIntf;
                          Only: Integer; OnlyName, OnlyNamePart: String);
  end;


function AddWatchExp(var ExpArray: TWatchExpectationArray;
  const AnExpr:  string;
  const AMtch: string; AKind: TDBGSymbolKind; const ATpNm: string;
  AFlgs: TWatchExpectationFlags = [];
  AStackFrame: Integer = 0;
  AMinGdb: Integer = 0; AMinFpc: Integer = 0
): PWatchExpectation;
function AddWatchExp(var ExpArray: TWatchExpectationArray;
  const AnExpr:  string; AEvaluateFlags: TWatcheEvaluateFlags;
  const AMtch: string; AKind: TDBGSymbolKind; const ATpNm: string;
  AFlgs: TWatchExpectationFlags = [];
  AStackFrame: Integer = 0;
  AMinGdb: Integer = 0; AMinFpc: Integer = 0
): PWatchExpectation;
function AddWatchExp(var ExpArray: TWatchExpectationArray; ATestName: String;
  const AnExpr:  string;
  const AMtch: string; AKind: TDBGSymbolKind; const ATpNm: string;
  AFlgs: TWatchExpectationFlags = [];
  AStackFrame: Integer = 0;
  AMinGdb: Integer = 0; AMinFpc: Integer = 0
): PWatchExpectation;
function AddWatchExp(var ExpArray: TWatchExpectationArray; ATestName: String;
  const AnExpr:  string; AEvaluateFlags: TWatcheEvaluateFlags;
  const AMtch: string; AKind: TDBGSymbolKind; const ATpNm: string;
  AFlgs: TWatchExpectationFlags = [];
  AStackFrame: Integer = 0;
  AMinGdb: Integer = 0; AMinFpc: Integer = 0
): PWatchExpectation;

procedure UpdExpRes(AWatchExp: PWatchExpectation; ASymbolType: TSymbolType;
  const AMtch: string; AKind: TDBGSymbolKind; const ATpNm: string; AFlgs: TWatchExpectationFlags;
  AMinGdb: Integer; AMinFpc: Integer
);
procedure UpdExpRes(AWatchExp: PWatchExpectation; ASymbolType: TSymbolType;
  const AMtch: string; AKind: TDBGSymbolKind; const ATpNm: string; AFlgs: TWatchExpectationFlags = []
);
procedure UpdExpRes(AWatchExp: PWatchExpectation; ASymbolType: TSymbolType;
  const AMtch: string; AKind: TDBGSymbolKind
);
procedure UpdExpRes(AWatchExp: PWatchExpectation; ASymbolType: TSymbolType;
  AKind: TDBGSymbolKind
);
procedure UpdExpRes(AWatchExp: PWatchExpectation; ASymbolType: TSymbolType;
  const ATpNm: string; AFlgs: TWatchExpectationFlags
);
procedure UpdResMinGdb(AWatchExp: PWatchExpectation; ASymbolType: TSymbolType; AMinGdb: Integer);
procedure UpdResMinFpc(AWatchExp: PWatchExpectation; ASymbolType: TSymbolType; AMinFpc: Integer);

procedure UpdExpRes(AWatchExp: PWatchExpectation; ASymbolTypes: TSymbolTypes;
  const ATpNm: string; AFlgs: TWatchExpectationFlags
);
procedure UpdResMinGdb(AWatchExp: PWatchExpectation; ASymbolTypes: TSymbolTypes; AMinGdb: Integer);
procedure UpdResMinFpc(AWatchExp: PWatchExpectation; ASymbolTypes: TSymbolTypes; AMinFpc: Integer);

procedure AddMemberExpect(AWatchExp: PWatchExpectation;
  const AName, ATpNm: string; AFlgs: TWatchExpectationFlags; AnExpKind: TDBGSymbolKind;
  ASymbolTypes: TSymbolTypes = stSymAll
);

implementation

function AddWatchExp(var ExpArray: TWatchExpectationArray;
  const AnExpr: string; const AMtch: string;
  AKind: TDBGSymbolKind; const ATpNm: string; AFlgs: TWatchExpectationFlags;
  AStackFrame: Integer; AMinGdb: Integer; AMinFpc: Integer): PWatchExpectation;
begin
  Result := AddWatchExp(ExpArray,
    AnExpr + ' []',
    AnExpr, [], AMtch, AKind, ATpNm, AFlgs, AStackFrame, AMinGdb, AMinFpc);
end;

function AddWatchExp(var ExpArray: TWatchExpectationArray;
  const AnExpr: string;
  AEvaluateFlags: TWatcheEvaluateFlags; const AMtch: string;
  AKind: TDBGSymbolKind; const ATpNm: string; AFlgs: TWatchExpectationFlags;
  AStackFrame: Integer; AMinGdb: Integer; AMinFpc: Integer): PWatchExpectation;
begin
  Result := AddWatchExp(ExpArray,
    AnExpr + ' (' + dbgs(AEvaluateFlags) + ')',
    AnExpr, AEvaluateFlags, AMtch, AKind, ATpNm, AFlgs, AStackFrame, AMinGdb, AMinFpc);
end;

function AddWatchExp(var ExpArray: TWatchExpectationArray; ATestName: String;
  const AnExpr: string; const AMtch: string;
  AKind: TDBGSymbolKind; const ATpNm: string; AFlgs: TWatchExpectationFlags;
  AStackFrame: Integer; AMinGdb: Integer; AMinFpc: Integer): PWatchExpectation;
begin
  Result := AddWatchExp(ExpArray, ATestName, AnExpr, [], AMtch, AKind, ATpNm,
    AFlgs, AStackFrame, AMinGdb, AMinFpc);
end;

function AddWatchExp(var ExpArray: TWatchExpectationArray; ATestName: String;
  const AnExpr: string;
  AEvaluateFlags: TWatcheEvaluateFlags; const AMtch: string;
  AKind: TDBGSymbolKind; const ATpNm: string; AFlgs: TWatchExpectationFlags;
  AStackFrame: Integer; AMinGdb: Integer; AMinFpc: Integer): PWatchExpectation;
var
  i: TSymbolType;
begin
  SetLength(ExpArray, Length(ExpArray)+1);
  with ExpArray[Length(ExpArray)-1] do begin
    TestName     := ATestName;
    Expression   := AnExpr;
    RepeatCount  := 0;
    EvaluateFlags := AEvaluateFlags;
    TheWatch := nil;
    OnBeforeTest := nil;
    UserData := nil;
    for i := low(TSymbolType) to high(TSymbolType) do begin
      Result[i].ExpMatch     := AMtch;
      Result[i].ExpKind      := AKind;
      Result[i].ExpTypeName  := ATpNm;
      Result[i].Flgs         := AFlgs;
      Result[i].MinGdb := AMinGdb;
      Result[i].MinFpc := AMinFpc;
    end;
    StackFrame   := AStackFrame;
  end;
  Result := @ExpArray[Length(ExpArray)-1];
end;

procedure UpdExpRes(AWatchExp: PWatchExpectation; ASymbolType: TSymbolType;
  const AMtch: string; AKind: TDBGSymbolKind; const ATpNm: string;
  AFlgs: TWatchExpectationFlags; AMinGdb: Integer; AMinFpc: Integer);
begin
  with AWatchExp^ do begin
    Result[ASymbolType].ExpMatch     := AMtch;
    Result[ASymbolType].ExpKind      := AKind;
    Result[ASymbolType].ExpTypeName  := ATpNm;
    Result[ASymbolType].Flgs         := AFlgs;
    Result[ASymbolType].MinGdb := AMinGdb;
    Result[ASymbolType].MinFpc := AMinFpc;
  end;
end;

procedure UpdExpRes(AWatchExp: PWatchExpectation; ASymbolType: TSymbolType;
  const AMtch: string; AKind: TDBGSymbolKind; const ATpNm: string;
  AFlgs: TWatchExpectationFlags);
begin
  with AWatchExp^ do begin
    Result[ASymbolType].ExpMatch     := AMtch;
    Result[ASymbolType].ExpKind      := AKind;
    Result[ASymbolType].ExpTypeName  := ATpNm;
    Result[ASymbolType].Flgs         := AFlgs;
  end;
end;

procedure UpdExpRes(AWatchExp: PWatchExpectation; ASymbolType: TSymbolType;
  const AMtch: string; AKind: TDBGSymbolKind);
begin
  with AWatchExp^ do begin
    Result[ASymbolType].ExpMatch     := AMtch;
    Result[ASymbolType].ExpKind      := AKind;
  end;
end;

procedure UpdExpRes(AWatchExp: PWatchExpectation; ASymbolType: TSymbolType;
  AKind: TDBGSymbolKind);
begin
  with AWatchExp^ do begin
    Result[ASymbolType].ExpKind      := AKind;
  end;
end;

procedure UpdExpRes(AWatchExp: PWatchExpectation; ASymbolType: TSymbolType;
  const ATpNm: string; AFlgs: TWatchExpectationFlags);
begin
  with AWatchExp^ do begin
    Result[ASymbolType].ExpTypeName  := ATpNm;
    Result[ASymbolType].Flgs         := AFlgs;
  end;
end;

procedure UpdExpRes(AWatchExp: PWatchExpectation; ASymbolTypes: TSymbolTypes;
  const ATpNm: string; AFlgs: TWatchExpectationFlags);
var
  i: TSymbolType;
begin
  for i := low(TSymbolType) to high(TSymbolType) do
    if i in ASymbolTypes then
      UpdExpRes(AWatchExp, i, ATpNm, AFlgs);
end;

procedure UpdResMinGdb(AWatchExp: PWatchExpectation; ASymbolTypes: TSymbolTypes;
  AMinGdb: Integer);
var
  i: TSymbolType;
begin
  for i := low(TSymbolType) to high(TSymbolType) do
    if i in ASymbolTypes then
      UpdResMinGdb(AWatchExp, i, AMinGdb);
end;

procedure UpdResMinFpc(AWatchExp: PWatchExpectation; ASymbolTypes: TSymbolTypes;
  AMinFpc: Integer);
var
  i: TSymbolType;
begin
  for i := low(TSymbolType) to high(TSymbolType) do
    if i in ASymbolTypes then
      UpdResMinFpc(AWatchExp, i, AMinFpc);
end;

procedure AddMemberExpect(AWatchExp: PWatchExpectation; const AName,
  ATpNm: string; AFlgs: TWatchExpectationFlags; AnExpKind: TDBGSymbolKind;
  ASymbolTypes: TSymbolTypes);
var
  i: TSymbolType;
  l: Integer;
begin
  for i := low(TSymbolType) to high(TSymbolType) do
    if i in ASymbolTypes then begin
      l := length(AWatchExp^.Result[i].FullTypesExpect);
      SetLength(AWatchExp^.Result[i].FullTypesExpect, l + 1);
      AWatchExp^.Result[i].FullTypesExpect[l].Name := AName;
      AWatchExp^.Result[i].FullTypesExpect[l].ExpTypeName := ATpNm;
      AWatchExp^.Result[i].FullTypesExpect[l].ExpKind := AnExpKind;
      AWatchExp^.Result[i].FullTypesExpect[l].Flgs := AFlgs;
    end;
end;

procedure UpdResMinGdb(AWatchExp: PWatchExpectation; ASymbolType: TSymbolType;
  AMinGdb: Integer);
begin
  with AWatchExp^ do begin
    Result[ASymbolType].MinGdb := AMinGdb;
  end;
end;

procedure UpdResMinFpc(AWatchExp: PWatchExpectation; ASymbolType: TSymbolType;
  AMinFpc: Integer);
begin
  with AWatchExp^ do begin
    Result[ASymbolType].MinFpc := AMinFpc;
  end;
end;


var
  Frx: TRegExpr;
  TheWatchPrinter: TWatchResultPrinter;

{ TTestWatchesBase }

procedure TTestWatchesBase.TestWatch(Name: String; ADbg: TDebuggerIntf;
  AWatch: TTestWatch; Data: TWatchExpectation; WatchValue: String);
var
  rx: TRegExpr;
  s, s2: String;
  flag, IsValid, HasTpInfo, f2: Boolean;
  WV: TWatchValue;
  Stack: Integer;
  n: String;
  DataRes: TWatchExpectationResult;
  IgnoreFlags: TWatchExpectationFlags;
  IgnoreAll, IgnoreData, IgnoreKind, IgnoreKindPtr, IgnoreTpName: boolean;
  IgnoreText: String;
  i, j: Integer;
  fld: TDBGField;
  MemberTests: TFullTypeMemberExpectationResultArray;

  function CmpNames(const TestName, Exp: String; Got: String; Match: Boolean): Boolean;
  begin
    if Match then begin
      if Frx = nil then Frx := TRegExpr.Create;
      Frx.ModifierI := true;
      Frx.Expression := Exp;
      TestTrue(TestName + ' matches '+Exp+' but was '+Got,  Frx.Exec(Got), DataRes.MinGdb, DataRes.MinFpc, IgnoreText);
     end
     else begin
       if LowerCase(Got) = 'ansichar' then Got := 'char'; // 3.3.1 returns ansichar
       TestEquals(TestName + ' equals ',  LowerCase(Exp), LowerCase(Got), DataRes.MinGdb, DataRes.MinFpc, IgnoreText);
     end;
  end;

begin
  StartTestBlock;
  try
    if not TestTrue('Dbg did NOT enter dsError', ADbg.State <> dsError) then exit;
    if Data.OnBeforeTest <> nil then Data.OnBeforeTest(@Data);

    rx := nil;
    Stack := Data.StackFrame;
    DataRes := Data.Result[SymbolType];
    IgnoreFlags := DataRes.Flgs * WatchExpFlagMask[SymbolType];
    IgnoreAll     := IgnoreFlags * WatchExpFlagSIgnAll <> [];
    IgnoreData    := IgnoreFlags * WatchExpFlagSIgnData <> [];
    IgnoreKind    := IgnoreFlags * WatchExpFlagSIgnKind <> [];
    IgnoreKindPtr := IgnoreFlags * WatchExpFlagSIgnKindPtr <> [];
    IgnoreTpName  := IgnoreFlags * WatchExpFlagSIgnTpName <> [];

    // Get Value
    n := Data.TestName;
    if n = '' then n := Data.Expression + ' (' + dbgs(Data.EvaluateFlags) + ' RepCnt=' + dbgs(Data.RepeatCount) + ')';
    Name := Name + ' ' + n + ' ::: '+adbg.GetLocation.SrcFile+' '+IntToStr(ADbg.GetLocation.SrcLine);
    LogToFile('###### ' + Name + '###### '+LineEnding);
    flag := AWatch <> nil; // test for typeinfo/kind  // Awatch=nil > direct gdb command
    IsValid := True;
    HasTpInfo := True;
    if flag then begin
      WV := AWatch.Values[1, Stack];// trigger read
      // read did not enter error?
      if not TestTrue('Dbg did NOT enter dsError', ADbg.State <> dsError) then
        exit;
      WV.Value;
      // read did not enter error?
      if not TestTrue('Dbg did NOT enter dsError', ADbg.State <> dsError) then
        exit;

      s := TheWatchPrinter.PrintWatchValue(WV.ResultData, AWatch.DisplayFormat, '');
      IsValid := WV.Validity = ddsValid;
      HasTpInfo := IsValid and (
        (WV.TypeInfo <> nil) or
        (not (WV.ResultData.ValueKind in [rdkError, rdkPrePrinted, rdkUnknown]))
      );
  //      flag := flag and IsValid;
    end
    else
      s := WatchValue;

    if not TestTrue('ADbg did NOT enter dsError', ADbg.State <> dsError) then exit;

    // Check Data
    f2 := True;
    IgnoreText := '';    if IgnoreData then IgnoreText := 'Ignored by flag';
    if IsValid = not(fTExpectError in DataRes.Flgs) then begin
      rx := TRegExpr.Create;
      rx.ModifierI := true;
      rx.Expression := DataRes.ExpMatch;
      if DataRes.ExpMatch <> ''
      then f2 := TestTrue(Name + ' Matches "'+DataRes.ExpMatch + '", but was "' + s + '"', rx.Exec(s), DataRes.MinGdb, DataRes.MinFpc, IgnoreText);
      FreeAndNil(rx);
    end else begin
       f2 := TestTrue(Name + ' Matches "'+DataRes.ExpMatch + '", but STATE was <'+dbgs(WV.Validity)+'> Val="'+s+'"', False, DataRes.MinGdb, DataRes.MinFpc, IgnoreText);
       //exit; // failed Data, do not list others as potential unexpected success
    end;

    if (not f2) and IgnoreAll then exit; // failed Data, do not list others as potential unexpected success

    // TypeInfo checks ?
    if (not flag) or (DataRes.ExpTypeName = '') then exit;

    // Check TypeInfo
    s:='';
    if HasTpInfo then begin
      if (WV.TypeInfo <> nil) then
        WriteStr(s, WV.TypeInfo.Kind)
      else
      case wv.ResultData.ValueKind of
        rdkString:         s := 'skString';
        rdkChar:           s := 'skChar';
        rdkWideString:     s := 'skWideString';
        rdkSignedNumVal:   s := 'skSimple';  // 'skInteger'
        rdkUnsignedNumVal: s := 'skSimple';
        rdkPointerVal:     s := 'skPointer';
        rdkFloatVal:       s := 'skFloat';
        rdkEnum:           s := 'skEnum';
        rdkEnumVal:        s := 'skEnumValue';
        rdkBool:           s := 'skBoolean';
      end;
    end;
    WriteStr(s2, DataRes.ExpKind);
    if (acceptSkSimple in DataRes.Flgs) and (s = 'skSimple') then s2 := 'skSimple';
    IgnoreText := '';    if IgnoreKind then IgnoreText := 'Ignored by flag';
    if IsValid and HasTpInfo then begin
      if (not IgnoreKind) and IgnoreKindPtr and (WV.TypeInfo.Kind = skPointer) then IgnoreText := 'Ignored by flag (Kind may be Ptr)';
      f2 := TestEquals(Name + ' Kind',  s2, s, DataRes.MinGdb, DataRes.MinFpc, IgnoreText);
      if ((s2='skClass') and (s = 'skRecord')) or ((s='skClass') and (s2 = 'skRecord')) then begin
        TotalClassVsRecord := TotalClassVsRecord + 1;
      end;
    end else begin
      f2 := TestTrue(Name + ' Kind is "'+s2+'", failed: STATE was <'+dbgs(WV.Validity)+'>, HasTypeInfo='+dbgs(HasTpInfo)+' Val="'+s+'"', False, DataRes.MinGdb, DataRes.MinFpc, IgnoreText);
    end;

    if (not f2) and IgnoreAll then exit; // failed Data, do not list others as potential unexpected success

    // Check TypeName
    IgnoreText := '';    if IgnoreTpName then IgnoreText := 'Ignored by flag';
    if IsValid and HasTpInfo then begin
      s := '';
      if WV.ResultData <> nil then
        s := WV.ResultData.TypeName;
      if (WV.TypeInfo <> nil) then begin
        if s = '' then
          s := WV.TypeInfo.TypeName
        else
          TestEquals(Name+' TypeName ResData=TpInfo ', WV.TypeInfo.TypeName, s, False);
      end;
      CmpNames(Name+' TypeName', DataRes.ExpTypeName, s, fTpMtch  in DataRes.Flgs);
      //if fTpMtch  in DataRes.Flgs
      //then begin
      //  rx := TRegExpr.Create;
      //  rx.ModifierI := true;
      //  rx.Expression := DataRes.ExpTypeName;
      //  TestTrue(Name + ' TypeName matches '+DataRes.ExpTypeName+' but was '+s,  rx.Exec(s), DataRes.MinGdb, DataRes.MinFpc, IgnoreText);
      //  FreeAndNil(rx);
      // end
      // else TestEquals(Name + ' TypeName',  LowerCase(DataRes.ExpTypeName), LowerCase(s), DataRes.MinGdb, DataRes.MinFpc, IgnoreText);
    end else begin
        TestTrue(Name + ' TypeName matches '+DataRes.ExpTypeName+' but STATE was <'+dbgs(WV.Validity)+'> HasTypeInfo='+dbgs(HasTpInfo)+' Val="'+s+'"',  False, DataRes.MinGdb, DataRes.MinFpc, IgnoreText);
    end;


    MemberTests := DataRes.FullTypesExpect;
    if Length(MemberTests) > 0 then begin
      if HasTpInfo then begin
        TestTrue('has field type info', WV.TypeInfo <> nil, DataRes.MinGdb, DataRes.MinFpc, IgnoreText);
        if WV.TypeInfo <> nil then begin
          for i := 0 to Length(MemberTests) - 1 do begin
            j := WV.TypeInfo.Fields.Count - 1;
            while (j >= 0) and (CompareText(WV.TypeInfo.Fields[j].Name, MemberTests[i].Name) <> 0) do dec(j);
            TestTrue(Name + ' no members with name ' +  MemberTests[i].Name,
                     (fTExpectNotFOund  in MemberTests[i].Flgs) <> (j >= 0),
                     DataRes.MinGdb, DataRes.MinFpc, IgnoreText);
            if j >= 0 then begin
              fld := WV.TypeInfo.Fields[j];
              WriteStr(s, MemberTests[i].ExpKind);
              WriteStr(s2, fld.DBGType.Kind);
              if fld.DBGType <> nil then begin
                TestTrue(Name + ' members with name ' +  MemberTests[i].Name + ' type='
                + s + ' but was ' + s2,
                    MemberTests[i].ExpKind = fld.DBGType.Kind, DataRes.MinGdb, DataRes.MinFpc, IgnoreText);;
                CmpNames(Name + ' members with name ' +  MemberTests[i].Name + 'TypeName',
                         MemberTests[i].ExpTypeName, fld.DBGType.TypeName, fTpMtch  in MemberTests[i].Flgs);
              end
              else
                TestTrue(Name + ' no dbgtype for members with name' +  MemberTests[i].Name, False, DataRes.MinGdb, DataRes.MinFpc, IgnoreText);;
            end;
          end;
        end;
      end
      else
        TestTrue(Name + ' no typeinfo for members' , False, DataRes.MinGdb, DataRes.MinFpc, IgnoreText);
    end;

  finally
    EndTestBlock;
  end;
end;

procedure TTestWatchesBase.AddWatches(ExpectList: TWatchExpectationArray;
  AWatches: TWatches; Only: Integer; const OnlyName, OnlyNamePart: String);

  function SkipTest(const Data: TWatchExpectation): Boolean;
  begin
    Result := True;
    if Data.Result[SymbolType].Flgs * [fTstSkip, fTstSkipDwarf3] <> [] then exit;
    Result := False;
  end;

  function MatchOnly(const Data: TWatchExpectation; Idx: Integer): Boolean;
  begin
    Result := True;
    if ((Only >=0) and (Only <> Idx)) or
       ((OnlyName<>'') and (OnlyName <> Data.TestName)) or
       ((OnlyNamePart<>'') and (pos(OnlyNamePart, Data.TestName)<1))
    then Result := False;
  end;
var
  i: Integer;
begin
  for i := low(ExpectList) to high(ExpectList) do begin
    ExpectList[i].TheWatch := nil;
    if not MatchOnly(ExpectList[i], i) then continue;
    if not SkipTest(ExpectList[i]) then begin
      ExpectList[i].TheWatch := TTestWatch.Create(AWatches);
      ExpectList[i].TheWatch.Expression := ExpectList[i].Expression;
      ExpectList[i].TheWatch.RepeatCount := ExpectList[i].RepeatCount;
      ExpectList[i].TheWatch.EvaluateFlags:= ExpectList[i].EvaluateFlags;
      ExpectList[i].TheWatch.enabled := True;
    end;
  end;
end;

procedure TTestWatchesBase.TestWatchList(const AName: String;
  ExpectList: TWatchExpectationArray; ADbg: TDebuggerIntf; Only: Integer;
  OnlyName, OnlyNamePart: String);

  function SkipTest(const Data: TWatchExpectation): Boolean;
  begin
    Result := True;
    if Data.Result[SymbolType].Flgs * [fTstSkip, fTstSkipDwarf3] <> [] then exit;
    Result := False;
  end;

  function MatchOnly(const Data: TWatchExpectation; Idx: Integer): Boolean;
  begin
    Result := True;
    if ((Only >=0) and (Only <> Idx)) or
       ((OnlyName<>'') and (OnlyName <> Data.TestName)) or
       ((OnlyNamePart<>'') and (pos(OnlyNamePart, Data.TestName)<1))
    then Result := False;
  end;
var
  i: Integer;
begin
  for i := low(ExpectList) to high(ExpectList) do begin
    if not MatchOnly(ExpectList[i], i) then continue;
    if ExpectList[i].TheWatch = nil then continue;
    if not SkipTest(ExpectList[i]) then
      TestWatch(AName + ' '+IntToStr(i)+' ', ADbg, ExpectList[i].TheWatch, ExpectList[i]);
  end;

end;


initialization
  TheWatchPrinter := TWatchResultPrinter.Create;
  TheWatchPrinter.FormatFlags := [];

finalization
  FreeAndNil(Frx);
  FreeAndNil(TheWatchPrinter);

end.