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
|
unit TTestDebuggerClasses;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, DbgIntfDebuggerBase;
type
{ TTestCallStack }
TTestCallStack = class(TCallStackBase)
private
FList: TList;
protected
procedure Clear; virtual;
function GetCount: Integer; override;
function GetEntryBase(AIndex: Integer): TCallStackEntry; override;
//function GetEntry(AIndex: Integer): TIdeCallStackEntry; virtual;
// procedure AddEntry(AnEntry: TIdeCallStackEntry); virtual; // must be added in correct order
// procedure AssignEntriesTo(AnOther: TTestCallStack); virtual;
// public
// procedure SetCountValidity({%H-}AValidity: TDebuggerDataState); override;
// procedure SetHasAtLeastCountInfo({%H-}AValidity: TDebuggerDataState; {%H-}AMinCount: Integer = - 1); override;
// procedure SetCurrentValidity({%H-}AValidity: TDebuggerDataState); override;
public
constructor Create;
destructor Destroy; override;
// procedure Assign(AnOther: TCallStackBase); override;
// procedure PrepareRange({%H-}AIndex, {%H-}ACount: Integer); override;
// procedure ChangeCurrentIndex(ANewIndex: Integer); virtual;
// function HasAtLeastCount(ARequiredMinCount: Integer): TNullableBool; virtual; // Can be faster than getting the full count
// function CountLimited(ALimit: Integer): Integer; override;
// property Entries[AIndex: Integer]: TIdeCallStackEntry read GetEntry;
end;
{ TTestCallStackList }
TTestCallStackList = class(TCallStackList)
protected
function NewEntryForThread(const AThreadId: Integer): TCallStackBase; override;
end;
{ TTestCallStackMonitor }
TTestCallStackMonitor = class(TCallStackMonitor)
protected
function CreateCallStackList: TCallStackList; override;
end;
TTestThreadsMonitor = class;
{ TTestThreads }
TTestThreads = class(TThreads)
private
FMonitor: TTestThreadsMonitor;
FDataValidity: TDebuggerDataState;
public
constructor Create;
function Count: Integer; override;
procedure Clear; override;
procedure SetValidity(AValidity: TDebuggerDataState); override;
end;
{ TTestThreadsMonitor }
TTestThreadsMonitor = class(TThreadsMonitor)
protected
procedure DoStateEnterPause; override;
function CreateThreads: TThreads; override;
procedure RequestData;
end;
{ TTestWatchValue }
TTestWatchValue = class(TWatchValue)
protected
procedure RequestData;
function GetTypeInfo: TDBGType; override;
function GetValue: String; override;
public
constructor Create(AOwnerWatch: TWatch;
const AThreadId: Integer;
const AStackFrame: Integer
);
constructor Create(AOwnerWatch: TWatch);
end;
{ TTestWatchValueList }
TTestWatchValueList = class(TWatchValueList)
protected
function CopyEntry(AnEntry: TWatchValue): TWatchValue; override;
function CreateEntry(const {%H-}AThreadId: Integer; const {%H-}AStackFrame: Integer): TWatchValue; override;
end;
{ TTestWatch }
TTestWatch = class(TWatch)
function CreateValueList: TWatchValueList; override;
procedure RequestData(AWatchValue: TTestWatchValue);
public
end;
TTestWatchesMonitor = class;
{ TTestWatches }
TTestWatches = class(TWatches)
protected
FMonitor: TTestWatchesMonitor;
function WatchClass: TWatchClass; override;
procedure RequestData(AWatchValue: TWatchValue);
end;
{ TTestWatchesMonitor }
TTestWatchesMonitor = class(TWatchesMonitor)
protected
procedure DoStateChangeEx(const AOldState, ANewState: TDBGState); override;
procedure RequestData(AWatchValue: TWatchValue);
function CreateWatches: TWatches; override;
end;
TTestRegistersMonitor = class;
{ TTestRegisters }
TTestRegisters = class(TRegisters)
private
FMonitor: TTestRegistersMonitor;
protected
procedure DoDataValidityChanged(AnOldValidity: TDebuggerDataState); override;
public
function Count: Integer; reintroduce; override;
end;
{ TTEstRegistersList }
TTestRegistersList = class(TRegistersList)
private
FMonitor: TTestRegistersMonitor;
protected
function CreateEntry(AThreadId, AStackFrame: Integer): TRegisters; override;
end;
{ TTestRegistersMonitor }
TTestRegistersMonitor = class(TRegistersMonitor)
protected
function CreateRegistersList: TRegistersList; override;
procedure RequestData(ARegisters: TRegisters);
procedure DoStateEnterPause; override;
procedure DoStateLeavePause; override;
end;
implementation
{ TTestCallStack }
procedure TTestCallStack.Clear;
var
i: Integer;
begin
for i := 0 to FList.Count - 1 do
TObject(FList[i]).Free;
FList.Clear;
end;
function TTestCallStack.GetCount: Integer;
begin
Result := FList.Count;
end;
function TTestCallStack.GetEntryBase(AIndex: Integer): TCallStackEntry;
begin
Result := TCallStackEntry(FList[AIndex]);
end;
constructor TTestCallStack.Create;
begin
FList := TList.Create;
inherited Create;
end;
destructor TTestCallStack.Destroy;
begin
inherited Destroy;
Clear;
FreeAndNil(FList);
end;
{ TTestThreads }
constructor TTestThreads.Create;
begin
inherited Create;
FDataValidity := ddsUnknown;
end;
function TTestThreads.Count: Integer;
begin
if (FDataValidity = ddsUnknown) then begin
FDataValidity := ddsRequested;
FMonitor.RequestData;
end;
Result := inherited Count;
end;
procedure TTestThreads.Clear;
begin
FDataValidity := ddsUnknown;
inherited Clear;
end;
procedure TTestThreads.SetValidity(AValidity: TDebuggerDataState);
begin
if FDataValidity = AValidity then exit;
FDataValidity := AValidity;
if FDataValidity = ddsUnknown then Clear;
end;
{ TTestThreadsMonitor }
procedure TTestThreadsMonitor.DoStateEnterPause;
begin
inherited DoStateEnterPause;
TTestThreads(Threads).SetValidity(ddsUnknown);
end;
function TTestThreadsMonitor.CreateThreads: TThreads;
begin
Result := TTestThreads.Create;
TTestThreads(Result).FMonitor := Self;
end;
procedure TTestThreadsMonitor.RequestData;
begin
if Supplier <> nil
then Supplier.RequestMasterData;
end;
{ TTestRegistersMonitor }
function TTestRegistersMonitor.CreateRegistersList: TRegistersList;
begin
Result := TTestRegistersList.Create;
TTestRegistersList(Result).FMonitor := Self;
end;
procedure TTestRegistersMonitor.RequestData(ARegisters: TRegisters);
begin
if Supplier <> nil
then Supplier.RequestData(ARegisters)
else ARegisters.DataValidity := ddsInvalid;
end;
procedure TTestRegistersMonitor.DoStateEnterPause;
begin
inherited DoStateEnterPause;
RegistersList.Clear;
end;
procedure TTestRegistersMonitor.DoStateLeavePause;
begin
inherited DoStateLeavePause;
RegistersList.Clear;
end;
{ TTEstRegistersList }
function TTestRegistersList.CreateEntry(AThreadId, AStackFrame: Integer): TRegisters;
begin
Result := TTestRegisters.Create(AThreadId, AStackFrame);
TTestRegisters(Result).FMonitor := FMonitor;
end;
{ TTestRegisters }
procedure TTestRegisters.DoDataValidityChanged(AnOldValidity: TDebuggerDataState);
begin
inherited DoDataValidityChanged(AnOldValidity);
end;
function TTestRegisters.Count: Integer;
begin
case DataValidity of
ddsUnknown: begin
AddReference;
try
Result := 0;
DataValidity := ddsRequested;
FMonitor.RequestData(Self); // Locals can be cleared, if debugger is "run" again
if DataValidity = ddsValid then Result := inherited Count();
finally
ReleaseReference;
end;
end;
ddsRequested, ddsEvaluating: Result := 0;
ddsValid: Result := inherited Count;
ddsInvalid, ddsError: Result := 0;
end;
end;
{ TTestWatches }
function TTestWatches.WatchClass: TWatchClass;
begin
Result := TTestWatch;
end;
procedure TTestWatches.RequestData(AWatchValue: TWatchValue);
begin
TTestWatchesMonitor(FMonitor).RequestData(AWatchValue);
end;
{ TTestWatchesMonitor }
procedure TTestWatchesMonitor.DoStateChangeEx(const AOldState, ANewState: TDBGState);
begin
inherited DoStateChangeEx(AOldState, ANewState);
Watches.ClearValues;
end;
procedure TTestWatchesMonitor.RequestData(AWatchValue: TWatchValue);
begin
if Supplier <> nil
then Supplier.RequestData(AWatchValue)
else AWatchValue.Validity := ddsInvalid;
end;
function TTestWatchesMonitor.CreateWatches: TWatches;
begin
Result := TTestWatches.Create;
TTestWatches(Result).FMonitor := Self;
end;
{ TTestWatchValue }
procedure TTestWatchValue.RequestData;
begin
TTestWatch(Watch).RequestData(self);
end;
function TTestWatchValue.GetTypeInfo: TDBGType;
var
i: Integer;
begin
Result := nil;
if not Watch.Enabled then
exit;
i := DbgStateChangeCounter; // workaround for state changes during TWatchValue.GetValue
if Validity = ddsUnknown then begin
Validity := ddsRequested;
RequestData;
if i <> DbgStateChangeCounter then exit;
end;
case Validity of
ddsRequested,
ddsEvaluating: Result := nil;
ddsValid: Result := inherited GetTypeInfo;
ddsInvalid,
ddsError: Result := nil;
end;
end;
function TTestWatchValue.GetValue: String;
var
i: Integer;
begin
if not Watch.Enabled then begin
Result := '<disabled>';
exit;
end;
i := DbgStateChangeCounter; // workaround for state changes during TWatchValue.GetValue
if Validity = ddsUnknown then begin
Result := '<evaluating>';
Validity := ddsRequested;
RequestData;
if i <> DbgStateChangeCounter then exit; // in case the debugger did run.
// TODO: The watch can also be deleted by the user
end;
case Validity of
ddsRequested, ddsEvaluating: Result := '<evaluating>';
ddsValid: Result := inherited GetValue;
ddsInvalid: Result := '<invalid>';
ddsError: Result := '<Error: '+ (inherited GetValue) +'>';
end;
end;
constructor TTestWatchValue.Create(AOwnerWatch: TWatch; const AThreadId: Integer;
const AStackFrame: Integer);
begin
inherited Create(AOwnerWatch);
Validity := ddsUnknown;
FDisplayFormat := Watch.DisplayFormat;
FEvaluateFlags := Watch.EvaluateFlags;
FRepeatCount := Watch.RepeatCount;
FThreadId := AThreadId;
FStackFrame := AStackFrame;
end;
constructor TTestWatchValue.Create(AOwnerWatch: TWatch);
begin
inherited Create(AOwnerWatch);
Validity := ddsUnknown;
FDisplayFormat := Watch.DisplayFormat;
FEvaluateFlags := Watch.EvaluateFlags;
FRepeatCount := Watch.RepeatCount;
end;
{ TTestWatchValueList }
function TTestWatchValueList.CopyEntry(AnEntry: TWatchValue): TWatchValue;
begin
Result := TTestWatchValue.Create(Watch);
Result.Assign(AnEntry);
end;
function TTestWatchValueList.CreateEntry(const AThreadId: Integer;
const AStackFrame: Integer): TWatchValue;
begin
Result := TTestWatchValue.Create(Watch, AThreadId, AStackFrame);
Add(Result);
end;
{ TTestWatch }
function TTestWatch.CreateValueList: TWatchValueList;
begin
Result := TTestWatchValueList.Create(Self);
end;
procedure TTestWatch.RequestData(AWatchValue: TTestWatchValue);
begin
if Collection <> nil
then TTestWatches(Collection).RequestData(AWatchValue)
else AWatchValue.Validity := ddsInvalid;
end;
{ TTestCallStackMonitor }
function TTestCallStackMonitor.CreateCallStackList: TCallStackList;
begin
Result := TTestCallStackList.Create;
end;
{ TTestCallStackList }
function TTestCallStackList.NewEntryForThread(const AThreadId: Integer): TCallStackBase;
begin
Result := TTestCallStack.Create;
Result.ThreadId := AThreadId;
add(Result);
end;
end.
|