Changeset 36 for trunk/Target


Ignore:
Timestamp:
Feb 19, 2012, 9:44:58 AM (13 years ago)
Author:
chronos
Message:
  • Modified: Redone brakepoint system for system stepping breakpoints. Now system breakpoint are managed using BreakPoints filed in TTarget.
  • Added: Program can be started using Step in, Step over and Run to cursor actions.
Location:
trunk/Target
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Target/UTarget.pas

    r35 r36  
    3232    function SearchByTargetPos(Pos: Integer): TDebugStep;
    3333    procedure AddStep(SourcePos, TargetPos: Integer; Operation: TStepOperation);
     34  end;
     35
     36  TBreakPoint = class
     37    TargetAddress: Integer;
     38    System: Boolean;
     39  end;
     40
     41  { TBreakPointList }
     42
     43  TBreakPointList = class(TListObject)
     44    procedure AddItem(TargetAddress: Integer);
     45    procedure SetSystem(TargetAddress: Integer);
     46    procedure ClearSystem;
     47    function SearchByTargetPos(Pos: Integer): TBreakPoint;
    3448  end;
    3549
     
    5064    function LongFileName(FileName: string): string;
    5165    function GetExecutionPosition: Integer; virtual;
     66    procedure SetState(AValue: TRunState); virtual;
    5267  public
    5368    Name: string;
     
    5974    ProjectFileName: string;
    6075    Capabilities: TTargetCapabilities;
    61     BreakPoints: TListInteger;
     76    BreakPoints: TBreakPointList;
    6277    DebugSteps: TDebugStepList;
    6378    constructor Create; virtual;
     
    7590    procedure LoadFromRegistry(Root: HKEY; Key: string); virtual;
    7691    procedure SaveToRegistry(Root: HKEY; Key: string); virtual;
    77     property State: TRunState read FState;
     92    property State: TRunState read FState write SetState;
    7893    property OnChangeState: TNotifyEvent read FOnChangeState write FOnChangeState;
    7994    property SourceCode: string write SetSourceCode;
     
    98113
    99114implementation
     115
     116{ TBreakPointList }
     117
     118procedure TBreakPointList.AddItem(TargetAddress: Integer);
     119var
     120  NewItem: TBreakPoint;
     121begin
     122  NewItem := TBreakPoint.Create;
     123  NewItem.TargetAddress := TargetAddress;
     124  Add(NewItem);
     125end;
     126
     127procedure TBreakPointList.SetSystem(TargetAddress: Integer);
     128var
     129  NewItem: TBreakPoint;
     130begin
     131  ClearSystem;
     132  NewItem := TBreakPoint.Create;
     133  NewItem.TargetAddress := TargetAddress;
     134  NewItem.System := True;
     135  Add(NewItem);
     136end;
     137
     138procedure TBreakPointList.ClearSystem;
     139var
     140  I: Integer;
     141begin
     142  for I := Count - 1 downto 0 do
     143    if TBreakPoint(Items[I]).System then Delete(I);
     144end;
     145
     146function TBreakPointList.SearchByTargetPos(Pos: Integer): TBreakPoint;
     147var
     148  I: Integer;
     149begin
     150  I := 0;
     151  while (I < Count) and (TBreakPoint(Items[I]).TargetAddress < Pos) do Inc(I);
     152  if I < Count then Result := TBreakPoint(Items[I])
     153    else Result := nil;
     154end;
    100155
    101156{ TDebugStepList }
     
    191246begin
    192247
     248end;
     249
     250procedure TTarget.SetState(AValue: TRunState);
     251begin
     252  if FState = AValue then Exit;
     253  FState := AValue;
    193254end;
    194255
     
    218279  inherited;
    219280  Optimization := coNormal;
    220   BreakPoints := TListInteger.Create;
     281  BreakPoints := TBreakPointList.Create;
    221282  DebugSteps := TDebugStepList.Create;
    222283end;
  • trunk/Target/UTargetInterpretter.pas

    r35 r36  
    3434    function GetMemorySize: Integer;
    3535    procedure SetMemorySize(AValue: Integer);
    36     procedure SetState(AValue: TRunState);
    3736    procedure SetThread(State: Boolean);
    3837    procedure PrepareJumpTable;
     
    4847    procedure PrepareBreakPoints;
    4948  protected
     49    procedure SetState(AValue: TRunState); override;
    5050    function GetTargetCode: string; override;
    5151    function GetExecutionPosition: Integer; override;
     
    9393  SJumpTableColision = 'Jump table colision';
    9494  SMemoryCellOutOfRange = 'Memory cell %s value out of range';
     95  SProgramNotRunning = 'Program not running';
    9596
    9697{ TTargetInterpretterThread }
     
    104105        if FProgramBreakpoints[SourcePosition] then begin
    105106          FProgramBreakpoints[SourcePosition] := False;
    106           SetState(rsPaused);
     107          State := rsPaused;
    107108        end else begin
    108109          FCommandTable[FProgram[SourcePosition]];
     
    113114      if State = rsPaused then Sleep(1);
    114115    end;
    115     SetState(rsStopped);
     116    State := rsStopped;
    116117  until Terminated or (State = rsStopped);
    117118end;
     
    295296    Memory[I] := 0;
    296297  FStepCount := 0;
     298  PrepareBreakPoints;
    297299end;
    298300
     
    305307    FProgramBreakpoints[I] := False;
    306308  for I := 0 to BreakPoints.Count - 1 do
    307     FProgramBreakpoints[BreakPoints[I]] := True;
     309    FProgramBreakpoints[TBreakPoint(BreakPoints[I]).TargetAddress] := True;
    308310end;
    309311
     
    324326procedure TTargetInterpretter.Run;
    325327begin
    326   SetState(rsRunning);
    327   Reset;
    328   PrepareBreakPoints;
     328  if FState = rsStopped then begin
     329    Reset;
     330    SetThread(True);
     331    State := rsRunning;
     332  end else State := rsRunning;
     333end;
     334
     335procedure TTargetInterpretter.Pause;
     336begin
     337  if State = rsRunning then State := rsPaused;
     338end;
     339
     340procedure TTargetInterpretter.Stop;
     341begin
     342  State := rsStopped;
    329343  SetThread(False);
    330   SetThread(True);
    331 end;
    332 
    333 procedure TTargetInterpretter.Pause;
    334 begin
    335   if State = rsRunning then SetState(rsPaused);
    336 end;
    337 
    338 procedure TTargetInterpretter.Stop;
    339 begin
    340   SetState(rsStopped);
    341344end;
    342345
     
    345348  Step: TDebugStep;
    346349begin
    347   Step := DebugSteps.SearchByTargetPos(SourcePosition);
    348   FProgramBreakpoints[Step.TargetPosition + 1] := True;
     350  if State = rsPaused then begin
     351    Step := DebugSteps.SearchByTargetPos(SourcePosition);
     352    BreakPoints.SetSystem(Step.TargetPosition + 1);
     353    Run;
     354  end else raise Exception.Create(SProgramNotRunning);
    349355end;
    350356
     
    352358var
    353359  Step: TDebugStep;
    354 begin
     360  StepIndex: Integer;
     361  Nesting: Integer;
     362begin
     363  if State = rsPaused then begin
     364    Step := DebugSteps.SearchByTargetPos(SourcePosition);
     365    if Step.Operation = soStepIn then begin
     366      StepIndex := DebugSteps.IndexOf(Step);
     367      Inc(StepIndex);
     368      Nesting := 1;
     369      while (StepIndex < DebugSteps.Count) and (Nesting > 0) do begin
     370        if TDebugStep(DebugSteps[StepIndex]).Operation <> soStepOut then Dec(Nesting);
     371        if TDebugStep(DebugSteps[StepIndex]).Operation <> soStepIn then Inc(Nesting);
     372        Inc(StepIndex);
     373      end;
     374      BreakPoints.SetSystem(TDebugStep(DebugSteps[StepIndex]).TargetPosition);
     375    end else BreakPoints.SetSystem(Step.TargetPosition + 1);
     376    Run;
     377  end else raise Exception.Create(SProgramNotRunning);
    355378end;
    356379
    357380procedure TTargetInterpretter.StepOut;
    358 begin
    359   inherited StepOut;
     381var
     382  Step: TDebugStep;
     383  StepIndex: Integer;
     384begin
     385  if State = rsPaused then begin
     386    Step := DebugSteps.SearchByTargetPos(SourcePosition);
     387    StepIndex := DebugSteps.IndexOf(Step);
     388    while (StepIndex < DebugSteps.Count) and (TDebugStep(DebugSteps[StepIndex]).Operation <> soStepOut) do Inc(StepIndex);
     389    if StepIndex < DebugSteps.Count then begin
     390      Breakpoints.SetSystem(TDebugStep(DebugSteps[StepIndex]).TargetPosition);
     391      Run;
     392    end;
     393  end else raise Exception.Create(SProgramNotRunning);
    360394end;
    361395
    362396procedure TTargetInterpretter.RunToCursor(Pos: Integer);
    363397begin
    364   FProgramBreakpoints[Pos] := True;
     398  Breakpoints.SetSystem(Pos);
     399  Run;
    365400end;
    366401
Note: See TracChangeset for help on using the changeset viewer.