Changeset 114 for trunk/UTarget.pas


Ignore:
Timestamp:
May 18, 2019, 12:13:44 AM (6 years ago)
Author:
chronos
Message:
  • Modified: Improved stepping through source and target code. Each step has source, program and target index.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UTarget.pas

    r111 r114  
    2222  TDebugStep = class
    2323    SourcePosition: Integer;
     24    ProgramPosition: Integer;
    2425    TargetPosition: Integer;
    2526    Operation: TStepOperation;
     
    3031  TDebugStepList = class(TFPGObjectList<TDebugStep>)
    3132    function SearchBySourcePos(Pos: Integer): TDebugStep;
     33    function SearchByProgramPos(Pos: Integer): TDebugStep;
    3234    function SearchByTargetPos(Pos: Integer): TDebugStep;
     35    function SearchIndexByProgramPos(Pos: Integer): Integer;
    3336    procedure AddStep(SourcePos, TargetPos: Integer; Operation: TStepOperation);
    34     procedure UpdateTargetPos(Old, New: Integer);
     37    procedure UpdateTargetPos(OldProgramFrom, OldProgramTo, NewProgram, NewTarget: Integer);
    3538  end;
    3639
     
    233236end;
    234237
     238function TDebugStepList.SearchByProgramPos(Pos: Integer): TDebugStep;
     239var
     240  I: Integer;
     241begin
     242  I := 0;
     243  while (I < Count) and (TDebugStep(Items[I]).ProgramPosition < Pos) do Inc(I);
     244  if I < Count then Result := TDebugStep(Items[I])
     245    else Result := nil;
     246end;
     247
    235248function TDebugStepList.SearchByTargetPos(Pos: Integer
    236249  ): TDebugStep;
     
    244257end;
    245258
     259function TDebugStepList.SearchIndexByProgramPos(Pos: Integer): Integer;
     260var
     261  I: Integer;
     262begin
     263  I := 0;
     264  while (I < Count) and (TDebugStep(Items[I]).ProgramPosition < Pos) do Inc(I);
     265  if I < Count then Result := I
     266    else Result := -1;
     267end;
     268
    246269procedure TDebugStepList.AddStep(SourcePos, TargetPos: Integer;
    247270  Operation: TStepOperation);
     
    251274  NewItem := TDebugStep.Create;
    252275  NewItem.SourcePosition := SourcePos;
     276  NewItem.ProgramPosition := TargetPos;
    253277  NewItem.TargetPosition := TargetPos;
    254278  NewItem.Operation := Operation;
     
    256280end;
    257281
    258 procedure TDebugStepList.UpdateTargetPos(Old, New: Integer);
    259 var
    260   I: Integer;
    261 begin
    262   I := 0;
    263   while (I < Count) do begin
    264     if TDebugStep(Items[I]).TargetPosition = Old then
    265       TDebugStep(Items[I]).TargetPosition := New;
    266     Inc(I);
    267   end;
     282procedure TDebugStepList.UpdateTargetPos(OldProgramFrom, OldProgramTo, NewProgram, NewTarget: Integer);
     283var
     284  I: Integer;
     285  First: Integer;
     286  Last: Integer;
     287begin
     288  First := SearchIndexByProgramPos(OldProgramFrom);
     289  Last := SearchIndexByProgramPos(OldProgramTo);
     290  for I := Last downto First + 1 do Delete(I);
     291  TDebugStep(Items[First]).ProgramPosition := NewProgram;
     292  TDebugStep(Items[First]).TargetPosition := NewTarget;
    268293end;
    269294
Note: See TracChangeset for help on using the changeset viewer.