DBG: Refactor state handling

git-svn-id: trunk@32792 -
This commit is contained in:
martin 2011-10-09 20:20:28 +00:00
parent 93b79f2889
commit 876299b8d0
2 changed files with 43 additions and 5 deletions

View File

@ -2725,6 +2725,7 @@ type
procedure SetEnvironment(const AValue: TStrings);
procedure SetFileName(const AValue: String);
protected
procedure ResetStateToIdle; virtual;
function CreateBreakPoints: TDBGBreakPoints; virtual;
function CreateLocals: TLocalsSupplier; virtual;
function CreateLineInfo: TDBGLineInfo; virtual;
@ -2748,7 +2749,7 @@ type
procedure DoBeforeState(const OldState: TDBGState); virtual;
procedure DoState(const OldState: TDBGState); virtual;
function ChangeFileName: Boolean; virtual;
function GetCommands: TDBGCommands;
function GetCommands: TDBGCommands; virtual;
function GetSupportedCommands: TDBGCommands; virtual;
function GetTargetWidth: Byte; virtual;
function GetWaiting: Boolean; virtual;
@ -5210,11 +5211,10 @@ begin
else
if (AOldState in [dsPause, dsInternalPause, dsNone] )
then begin
if (FNotifiedState in [dsRun, dsStop]) or (AOldState = dsNone)
// dsIdle happens after dsStop
if (FNotifiedState in [dsRun, dsInit, dsIdle]) or (AOldState = dsNone)
then begin
// typical: finalize snapshot and clear data.
// TODO: Need stop notification, only if run has exited, maybe dsIdle again ?
// dsStop can be nested
DoStateLeavePauseClean;
end
else begin
@ -5222,6 +5222,12 @@ begin
// Do *not* clear data. Objects may be in use (e.g. dsError)
DoStateLeavePause;
end;
end
else
if (AOldState in [dsStop]) and (FNotifiedState = dsIdle)
then begin
// stopped // typical: finalize snapshot and clear data.
DoStateLeavePauseClean;
end;
{$IFDEF DBG_DATA_MONITORS} DebugLnExit(['DebugDataMonitor: <<EXIT: ', ClassName, '.DoStateChange']); {$ENDIF}
end;
@ -6180,7 +6186,7 @@ begin
then begin
// Reset state
FFileName := '';
SetState(dsIdle);
ResetStateToIdle;
ChangeFileName;
end;
@ -6190,6 +6196,11 @@ begin
end;
end;
procedure TDebugger.ResetStateToIdle;
begin
SetState(dsIdle);
end;
class procedure TDebugger.SetProperties(const AProperties: TDebuggerProperties);
var
Props: TDebuggerProperties;

View File

@ -386,6 +386,7 @@ type
protected
FErrorHandlingFlags: set of (ehfDeferReadWriteError, ehfGotReadError, ehfGotWriteError);
FNeedStateToIdle: Boolean;
{$IFDEF MSWindows}
FPauseRequestInThreadID: Cardinal;
{$ENDIF}
@ -407,12 +408,14 @@ type
function CreateWatches: TWatchesSupplier; override;
function CreateThreads: TThreadsSupplier; override;
function GetSupportedCommands: TDBGCommands; override;
function GetCommands: TDBGCommands; override;
function GetTargetWidth: Byte; override;
procedure InterruptTarget; virtual;
function ParseInitialization: Boolean; virtual;
function RequestCommand(const ACommand: TDBGCommand; const AParams: array of const): Boolean; override;
procedure ClearCommandQueue;
function GetIsIdle: Boolean; override;
procedure ResetStateToIdle; override;
procedure DoState(const OldState: TDBGState); override;
procedure DoBeforeState(const OldState: TDBGState); override;
procedure DoReadError; override;
@ -5839,6 +5842,7 @@ begin
FTypeRequestCache := TGDBPTypeRequestCache.Create;
FMaxLineForUnitCache := TStringList.Create;
FInProcessStopped := False;
FNeedStateToIdle := False;
{$IFdef MSWindows}
@ -6284,6 +6288,8 @@ begin
if (FCommandQueue.Count = 0) and assigned(OnIdle)
then OnIdle(Self);
if FNeedStateToIdle and (FInExecuteCount = 0)
then ResetStateToIdle;
end;
procedure TGDBMIDebugger.QueueCommand(const ACommand: TGDBMIDebuggerCommand; ForceQueue: Boolean = False);
@ -6853,6 +6859,13 @@ begin
];
end;
function TGDBMIDebugger.GetCommands: TDBGCommands;
begin
if FNeedStateToIdle
then Result := []
else Result := inherited GetCommands;
end;
function TGDBMIDebugger.GetTargetWidth: Byte;
begin
Result := FTargetInfo.TargetPtrSize*8;
@ -6882,6 +6895,7 @@ begin
FPauseWaitState := pwsNone;
FErrorHandlingFlags := [];
FInExecuteCount := 0;
FNeedStateToIdle := False;
Options := '-silent -i mi -nx';
if Length(TGDBMIDebuggerProperties(GetProperties).Debugger_Startup_Options) > 0
@ -7072,6 +7086,19 @@ begin
Result := (FCommandQueue.Count = 0) and (State in [dsPause, dsInternalPause]);
end;
procedure TGDBMIDebugger.ResetStateToIdle;
begin
{$IFDEF DBGMI_QUEUE_DEBUG}
debugln(['Defer dsIdle: Recurse-Count=', FInExecuteCount]);
{$ENDIF}
if FInExecuteCount > 0 then begin
FNeedStateToIdle := True;
exit;
end;
FNeedStateToIdle := False;
inherited ResetStateToIdle;
end;
procedure TGDBMIDebugger.ClearSourceInfo;
var
n: Integer;