Changeset 36 for trunk/Target
- Timestamp:
- Feb 19, 2012, 9:44:58 AM (13 years ago)
- Location:
- trunk/Target
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Target/UTarget.pas
r35 r36 32 32 function SearchByTargetPos(Pos: Integer): TDebugStep; 33 33 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; 34 48 end; 35 49 … … 50 64 function LongFileName(FileName: string): string; 51 65 function GetExecutionPosition: Integer; virtual; 66 procedure SetState(AValue: TRunState); virtual; 52 67 public 53 68 Name: string; … … 59 74 ProjectFileName: string; 60 75 Capabilities: TTargetCapabilities; 61 BreakPoints: T ListInteger;76 BreakPoints: TBreakPointList; 62 77 DebugSteps: TDebugStepList; 63 78 constructor Create; virtual; … … 75 90 procedure LoadFromRegistry(Root: HKEY; Key: string); virtual; 76 91 procedure SaveToRegistry(Root: HKEY; Key: string); virtual; 77 property State: TRunState read FState ;92 property State: TRunState read FState write SetState; 78 93 property OnChangeState: TNotifyEvent read FOnChangeState write FOnChangeState; 79 94 property SourceCode: string write SetSourceCode; … … 98 113 99 114 implementation 115 116 { TBreakPointList } 117 118 procedure TBreakPointList.AddItem(TargetAddress: Integer); 119 var 120 NewItem: TBreakPoint; 121 begin 122 NewItem := TBreakPoint.Create; 123 NewItem.TargetAddress := TargetAddress; 124 Add(NewItem); 125 end; 126 127 procedure TBreakPointList.SetSystem(TargetAddress: Integer); 128 var 129 NewItem: TBreakPoint; 130 begin 131 ClearSystem; 132 NewItem := TBreakPoint.Create; 133 NewItem.TargetAddress := TargetAddress; 134 NewItem.System := True; 135 Add(NewItem); 136 end; 137 138 procedure TBreakPointList.ClearSystem; 139 var 140 I: Integer; 141 begin 142 for I := Count - 1 downto 0 do 143 if TBreakPoint(Items[I]).System then Delete(I); 144 end; 145 146 function TBreakPointList.SearchByTargetPos(Pos: Integer): TBreakPoint; 147 var 148 I: Integer; 149 begin 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; 154 end; 100 155 101 156 { TDebugStepList } … … 191 246 begin 192 247 248 end; 249 250 procedure TTarget.SetState(AValue: TRunState); 251 begin 252 if FState = AValue then Exit; 253 FState := AValue; 193 254 end; 194 255 … … 218 279 inherited; 219 280 Optimization := coNormal; 220 BreakPoints := T ListInteger.Create;281 BreakPoints := TBreakPointList.Create; 221 282 DebugSteps := TDebugStepList.Create; 222 283 end; -
trunk/Target/UTargetInterpretter.pas
r35 r36 34 34 function GetMemorySize: Integer; 35 35 procedure SetMemorySize(AValue: Integer); 36 procedure SetState(AValue: TRunState);37 36 procedure SetThread(State: Boolean); 38 37 procedure PrepareJumpTable; … … 48 47 procedure PrepareBreakPoints; 49 48 protected 49 procedure SetState(AValue: TRunState); override; 50 50 function GetTargetCode: string; override; 51 51 function GetExecutionPosition: Integer; override; … … 93 93 SJumpTableColision = 'Jump table colision'; 94 94 SMemoryCellOutOfRange = 'Memory cell %s value out of range'; 95 SProgramNotRunning = 'Program not running'; 95 96 96 97 { TTargetInterpretterThread } … … 104 105 if FProgramBreakpoints[SourcePosition] then begin 105 106 FProgramBreakpoints[SourcePosition] := False; 106 S etState(rsPaused);107 State := rsPaused; 107 108 end else begin 108 109 FCommandTable[FProgram[SourcePosition]]; … … 113 114 if State = rsPaused then Sleep(1); 114 115 end; 115 S etState(rsStopped);116 State := rsStopped; 116 117 until Terminated or (State = rsStopped); 117 118 end; … … 295 296 Memory[I] := 0; 296 297 FStepCount := 0; 298 PrepareBreakPoints; 297 299 end; 298 300 … … 305 307 FProgramBreakpoints[I] := False; 306 308 for I := 0 to BreakPoints.Count - 1 do 307 FProgramBreakpoints[ BreakPoints[I]] := True;309 FProgramBreakpoints[TBreakPoint(BreakPoints[I]).TargetAddress] := True; 308 310 end; 309 311 … … 324 326 procedure TTargetInterpretter.Run; 325 327 begin 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; 333 end; 334 335 procedure TTargetInterpretter.Pause; 336 begin 337 if State = rsRunning then State := rsPaused; 338 end; 339 340 procedure TTargetInterpretter.Stop; 341 begin 342 State := rsStopped; 329 343 SetThread(False); 330 SetThread(True);331 end;332 333 procedure TTargetInterpretter.Pause;334 begin335 if State = rsRunning then SetState(rsPaused);336 end;337 338 procedure TTargetInterpretter.Stop;339 begin340 SetState(rsStopped);341 344 end; 342 345 … … 345 348 Step: TDebugStep; 346 349 begin 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); 349 355 end; 350 356 … … 352 358 var 353 359 Step: TDebugStep; 354 begin 360 StepIndex: Integer; 361 Nesting: Integer; 362 begin 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); 355 378 end; 356 379 357 380 procedure TTargetInterpretter.StepOut; 358 begin 359 inherited StepOut; 381 var 382 Step: TDebugStep; 383 StepIndex: Integer; 384 begin 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); 360 394 end; 361 395 362 396 procedure TTargetInterpretter.RunToCursor(Pos: Integer); 363 397 begin 364 FProgramBreakpoints[Pos] := True; 398 Breakpoints.SetSystem(Pos); 399 Run; 365 400 end; 366 401
Note:
See TracChangeset
for help on using the changeset viewer.