Ignore:
Timestamp:
Feb 19, 2012, 12:41:25 PM (13 years ago)
Author:
chronos
Message:
  • Fixed: Step into, step over, step out, run to cursor debbuging actions.
  • Fixed: Updating interface from interpretter thread using synchronization.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Target/UTargetInterpretter.pas

    r36 r39  
    1414
    1515  TTargetInterpretterThread = class(TThread)
     16  private
     17    FNewState: TRunState;
     18    procedure DoSetState;
     19    procedure SetStateSafe(State: TRunState);
     20  public
    1621    Parent: TTargetInterpretter;
    1722    procedure Execute; override;
     
    98103
    99104procedure TTargetInterpretterThread.Execute;
     105var
     106  BreakPoint: TBreakPoint;
    100107begin
    101108  with Parent do
     
    104111      if State = rsRunning then begin
    105112        if FProgramBreakpoints[SourcePosition] then begin
    106           FProgramBreakpoints[SourcePosition] := False;
    107           State := rsPaused;
     113          BreakPoint := BreakPoints.SearchByTargetPos(SourcePosition);
     114          if BreakPoint.System then BreakPoints.Delete(BreakPoints.IndexOf(BreakPoint));
     115          SetStateSafe(rsPaused);
    108116        end else begin
    109117          FCommandTable[FProgram[SourcePosition]];
     
    114122      if State = rsPaused then Sleep(1);
    115123    end;
    116     State := rsStopped;
     124    if State <> rsStopped then SetStateSafe(rsStopped);
    117125  until Terminated or (State = rsStopped);
     126end;
     127
     128procedure TTargetInterpretterThread.DoSetState;
     129begin
     130  Parent.State := FNewState;
     131end;
     132
     133procedure TTargetInterpretterThread.SetStateSafe(State: TRunState);
     134begin
     135  FNewState := State;
     136  Synchronize(DoSetState);
    118137end;
    119138
     
    307326    FProgramBreakpoints[I] := False;
    308327  for I := 0 to BreakPoints.Count - 1 do
    309     FProgramBreakpoints[TBreakPoint(BreakPoints[I]).TargetAddress] := True;
     328    if TBreakPoint(BreakPoints[I]).TargetAddress < Length(FProgramBreakpoints) then
     329      FProgramBreakpoints[TBreakPoint(BreakPoints[I]).TargetAddress] := True;
    310330end;
    311331
     
    326346procedure TTargetInterpretter.Run;
    327347begin
     348  PrepareBreakPoints;
    328349  if FState = rsStopped then begin
    329350    Reset;
     
    347368var
    348369  Step: TDebugStep;
     370  StepIndex: Integer;
     371  Nesting: Integer;
    349372begin
    350373  if State = rsPaused then begin
    351374    Step := DebugSteps.SearchByTargetPos(SourcePosition);
    352     BreakPoints.SetSystem(Step.TargetPosition + 1);
     375    if Step.Operation = soStepOut then begin
     376      BreakPoints.SetSystem(Step.TargetPosition + 1);
     377      Step := DebugSteps.SearchByTargetPos(SourceJump[Step.TargetPosition]);
     378      BreakPoints.AddSystem(Step.TargetPosition);
     379    end else
     380    if Step.Operation = soStepIn then begin
     381      BreakPoints.SetSystem(Step.TargetPosition + 1);
     382      Step := DebugSteps.SearchByTargetPos(SourceJump[Step.TargetPosition]);
     383      BreakPoints.AddSystem(Step.TargetPosition);
     384    end else BreakPoints.SetSystem(Step.TargetPosition + 1);
    353385    Run;
    354386  end else raise Exception.Create(SProgramNotRunning);
     
    363395  if State = rsPaused then begin
    364396    Step := DebugSteps.SearchByTargetPos(SourcePosition);
     397    if Step.Operation = soStepOut then begin
     398      BreakPoints.SetSystem(Step.TargetPosition + 1);
     399      Step := DebugSteps.SearchByTargetPos(SourceJump[Step.TargetPosition]);
     400      BreakPoints.AddSystem(Step.TargetPosition);
     401    end else
    365402    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);
     403      Step := DebugSteps.SearchByTargetPos(SourceJump[Step.TargetPosition]);
     404      BreakPoints.SetSystem(Step.TargetPosition + 1);
    375405    end else BreakPoints.SetSystem(Step.TargetPosition + 1);
    376406    Run;
     
    382412  Step: TDebugStep;
    383413  StepIndex: Integer;
     414  Nesting: Integer;
    384415begin
    385416  if State = rsPaused then begin
    386417    Step := DebugSteps.SearchByTargetPos(SourcePosition);
    387418    StepIndex := DebugSteps.IndexOf(Step);
    388     while (StepIndex < DebugSteps.Count) and (TDebugStep(DebugSteps[StepIndex]).Operation <> soStepOut) do Inc(StepIndex);
     419    Nesting := 1;
     420    while (StepIndex < DebugSteps.Count) and (Nesting > 0) do begin
     421      if TDebugStep(DebugSteps[StepIndex]).Operation = soStepIn then Inc(Nesting);
     422      if TDebugStep(DebugSteps[StepIndex]).Operation = soStepOut then Dec(Nesting);
     423      Inc(StepIndex);
     424    end;
    389425    if StepIndex < DebugSteps.Count then begin
    390426      Breakpoints.SetSystem(TDebugStep(DebugSteps[StepIndex]).TargetPosition);
    391       Run;
    392427    end;
     428    Run;
    393429  end else raise Exception.Create(SProgramNotRunning);
    394430end;
Note: See TracChangeset for help on using the changeset viewer.