diff --git a/components/debuggerintf/dbgintfdebuggerbase.pp b/components/debuggerintf/dbgintfdebuggerbase.pp index 3afa1cf601..f285f15565 100644 --- a/components/debuggerintf/dbgintfdebuggerbase.pp +++ b/components/debuggerintf/dbgintfdebuggerbase.pp @@ -1891,7 +1891,7 @@ type procedure DoState(const OldState: TDBGState); virtual; function ChangeFileName: Boolean; virtual; function GetCommands: TDBGCommands; virtual; - function GetSupportedCommands: TDBGCommands; virtual; + class function GetSupportedCommands: TDBGCommands; virtual; function GetTargetWidth: Byte; virtual; function GetWaiting: Boolean; virtual; function GetIsIdle: Boolean; virtual; @@ -1986,6 +1986,7 @@ type property PseudoTerminal: TPseudoTerminal read GetPseudoTerminal; experimental; // 'may be replaced with a more general API'; property State: TDBGState read FState; // The current state of the debugger property SupportedCommands: TDBGCommands read GetSupportedCommands; // All available commands of the debugger + class function SupportedCommandsFor(AState: TDBGState): TDBGCommands; property TargetWidth: Byte read GetTargetWidth; // Currently only 32 or 64 //property Waiting: Boolean read GetWaiting; // Set when the debugger is wating for a command to complete property Watches: TWatchesSupplier read FWatches; // list of all watches etc @@ -5954,6 +5955,11 @@ begin FDestroyNotificationList[AReason].Remove(TMethod(AnEvent)); end; +class function TDebuggerIntf.SupportedCommandsFor(AState: TDBGState): TDBGCommands; +begin + Result := COMMANDMAP[AState] * GetSupportedCommands; +end; + procedure TDebuggerIntf.Done; begin SetState(dsNone); @@ -6160,7 +6166,7 @@ begin ReqCmd(ACommand, AParams, dummy); end; -function TDebuggerIntf.GetSupportedCommands: TDBGCommands; +class function TDebuggerIntf.GetSupportedCommands: TDBGCommands; begin Result := []; end; diff --git a/components/lazdebuggergdbmi/gdbmidebugger.pp b/components/lazdebuggergdbmi/gdbmidebugger.pp index d2322fe98e..b367d1ad21 100644 --- a/components/lazdebuggergdbmi/gdbmidebugger.pp +++ b/components/lazdebuggergdbmi/gdbmidebugger.pp @@ -1014,7 +1014,7 @@ type function CreateDisassembler: TDBGDisassembler; override; function CreateWatches: TWatchesSupplier; override; function CreateThreads: TThreadsSupplier; override; - function GetSupportedCommands: TDBGCommands; override; + class function GetSupportedCommands: TDBGCommands; override; function GetCommands: TDBGCommands; override; function GetTargetWidth: Byte; override; procedure InterruptTarget; virtual; @@ -9738,7 +9738,7 @@ begin Result := True; end; -function TGDBMIDebuggerBase.GetSupportedCommands: TDBGCommands; +class function TGDBMIDebuggerBase.GetSupportedCommands: TDBGCommands; begin Result := [dcRun, dcPause, dcStop, dcStepOver, dcStepInto, dcStepOut, dcStepOverInstr, dcStepIntoInstr, dcStepTo, dcRunTo, dcAttach, dcDetach, dcJumpto, diff --git a/components/lazdebuggers/lazdebuggerfp/fpdebugdebugger.pas b/components/lazdebuggers/lazdebuggerfp/fpdebugdebugger.pas index 846b86b0e2..7c34908db1 100644 --- a/components/lazdebuggers/lazdebuggerfp/fpdebugdebugger.pas +++ b/components/lazdebuggers/lazdebuggerfp/fpdebugdebugger.pas @@ -319,7 +319,7 @@ type class function NeedsExePath: boolean; override; class function RequiredCompilerOpts({%H-}ATargetCPU, {%H-}ATargetOS: String): TDebugCompilerRequirements; override; class function CreateProperties: TDebuggerProperties; override; - function GetSupportedCommands: TDBGCommands; override; + class function GetSupportedCommands: TDBGCommands; override; end; { TFpLineInfo } @@ -3472,7 +3472,7 @@ begin Result := Result - [dcStepInto, dcStepOver, dcStepOut, dcStepIntoInstr, dcStepOverInstr]; end; -function TFpDebugDebugger.GetSupportedCommands: TDBGCommands; +class function TFpDebugDebugger.GetSupportedCommands: TDBGCommands; begin Result:=[dcRun, dcStop, dcStepIntoInstr, dcStepOverInstr, dcStepOver, dcStepTo, dcRunTo, dcPause, dcStepOut, dcStepInto, dcEvaluate, dcSendConsoleInput diff --git a/components/lazdebuggers/lazdebuggerfpdserver/fpdserverdebugger.pas b/components/lazdebuggers/lazdebuggerfpdserver/fpdserverdebugger.pas index 4aaf4e87ca..b1d48faa5b 100644 --- a/components/lazdebuggers/lazdebuggerfpdserver/fpdserverdebugger.pas +++ b/components/lazdebuggers/lazdebuggerfpdserver/fpdserverdebugger.pas @@ -300,7 +300,7 @@ type procedure DisconnectFromFPDServer; protected // Overrides of TDebuggerIntf methods. - function GetSupportedCommands: TDBGCommands; override; + class function GetSupportedCommands: TDBGCommands; override; // Handle Notifications received from the FPDebug-server procedure HandleNotification(ANotification: TJSONObject); // Handle log-messages received from the FPDebug-server @@ -1244,7 +1244,7 @@ begin end; end; -function TFPDServerDebugger.GetSupportedCommands: TDBGCommands; +class function TFPDServerDebugger.GetSupportedCommands: TDBGCommands; begin Result:=[dcRun, dcStepOver, dcStepInto, dcStepOut, dcStepOverInstr, dcStepIntoInstr, dcStop, dcEvaluate]; end; diff --git a/components/lazdebuggers/lazdebuggerlldb/lldbdebugger.pas b/components/lazdebuggers/lazdebuggerlldb/lldbdebugger.pas index c9093a5abe..2e4b955fd6 100644 --- a/components/lazdebuggers/lazdebuggerlldb/lldbdebugger.pas +++ b/components/lazdebuggers/lazdebuggerlldb/lldbdebugger.pas @@ -362,7 +362,7 @@ type function GetTargetWidth: Byte; override; function GetIsIdle: Boolean; override; - function GetSupportedCommands: TDBGCommands; override; + class function GetSupportedCommands: TDBGCommands; override; //function GetCommands: TDBGCommands; override; function RequestCommand(const ACommand: TDBGCommand; const AParams: array of const; @@ -2985,7 +2985,7 @@ begin Result := FInIdle or ( (CommandQueue.Count = 0) and (CommandQueue.RunningCommand = nil) ); end; -function TLldbDebugger.GetSupportedCommands: TDBGCommands; +class function TLldbDebugger.GetSupportedCommands: TDBGCommands; begin Result := [dcRun, dcStop, dcStepOver, dcStepInto, dcStepOut, dcEvaluate, dcStepOverInstr, dcStepIntoInstr, dcPause, dcEnvironment]; diff --git a/debugger/processdebugger.pp b/debugger/processdebugger.pp index fab34bd3d6..0d3c6549a2 100644 --- a/debugger/processdebugger.pp +++ b/debugger/processdebugger.pp @@ -53,7 +53,7 @@ type function ProcessRun: Boolean; function ProcessStop: Boolean; protected - function GetSupportedCommands: TDBGCommands; override; + class function GetSupportedCommands: TDBGCommands; override; function RequestCommand(const ACommand: TDBGCommand; const AParams: array of const; const {%H-}ACallback: TMethod): Boolean; override; public @@ -156,7 +156,7 @@ begin Result := True; end; -function TProcessDebugger.GetSupportedCommands: TDBGCommands; +class function TProcessDebugger.GetSupportedCommands: TDBGCommands; begin Result := [dcRun, dcStop, dcEnvironment] end; diff --git a/ide/debugmanager.pas b/ide/debugmanager.pas index c6dbee0f56..5f34a32798 100644 --- a/ide/debugmanager.pas +++ b/ide/debugmanager.pas @@ -2072,67 +2072,63 @@ var CanRun: Boolean; SrcEdit: TSourceEditorInterface; AnUnitInfo: TUnitInfo; + AvailCommands: TDBGCommands; + CurState: TDBGState; begin if (MainIDE=nil) or (MainIDE.ToolStatus = itExiting) then exit; - if FDebugger = nil then - InitDebugger(); // make sure we get the supported commands - DebuggerIsValid:=(FDebugger<>nil) and (MainIDE.ToolStatus in [itNone, itDebugger]); + if FDebugger <> nil then begin + AvailCommands := FDebugger.Commands; + CurState := FDebugger.State; + end + else begin + AvailCommands := GetDebuggerClass.SupportedCommandsFor(dsStop); + CurState := dsStop; + end; + DebuggerIsValid:=(MainIDE.ToolStatus in [itNone, itDebugger]); MainIDE.GetCurrentUnitInfo(SrcEdit,AnUnitInfo); with MainIDEBar do begin // For 'run' and 'step' bypass 'idle', so we can set the filename later CanRun:=false; - if Project1<>nil then + if (Project1<>nil) and DebuggerIsValid then CanRun:=( (AnUnitInfo<>nil) and (AnUnitInfo.RunFileIfActive) ) or ( ((Project1.CompilerOptions.ExecutableType=cetProgram) or ((Project1.RunParameterOptions.GetActiveMode<>nil) and (Project1.RunParameterOptions.GetActiveMode.HostApplicationFilename<>''))) and (pfRunnable in Project1.Flags) ); // Run - itmRunMenuRun.Enabled := CanRun and (not DebuggerIsValid - or (dcRun in FDebugger.Commands)); + itmRunMenuRun.Enabled := CanRun and (dcRun in AvailCommands); // Pause - itmRunMenuPause.Enabled := CanRun and DebuggerIsValid - and ((dcPause in FDebugger.Commands) or FAutoContinueTimer.Enabled); + itmRunMenuPause.Enabled := CanRun and ((dcPause in AvailCommands) or FAutoContinueTimer.Enabled); // Show execution point - itmRunMenuShowExecutionPoint.Enabled := CanRun and DebuggerIsValid - and (FDebugger.State = dsPause); + itmRunMenuShowExecutionPoint.Enabled := CanRun and (CurState = dsPause); // Step into - itmRunMenuStepInto.Enabled := CanRun and (not DebuggerIsValid - or (dcStepInto in FDebugger.Commands)); + itmRunMenuStepInto.Enabled := CanRun and (dcStepInto in AvailCommands); // Step over - itmRunMenuStepOver.Enabled := CanRun and (not DebuggerIsValid - or (dcStepOver in FDebugger.Commands)); + itmRunMenuStepOver.Enabled := CanRun and (dcStepOver in AvailCommands); // Step out - itmRunMenuStepOut.Enabled := CanRun and DebuggerIsValid - and (dcStepOut in FDebugger.Commands) and (FDebugger.State = dsPause); + itmRunMenuStepOut.Enabled := CanRun and (dcStepOut in AvailCommands) and (CurState = dsPause); // Step to cursor - itmRunMenuStepToCursor.Enabled := CanRun and DebuggerIsValid - and (dcStepTo in FDebugger.Commands); + itmRunMenuStepToCursor.Enabled := CanRun and (dcStepTo in AvailCommands); // Run to cursor - itmRunMenuRunToCursor.Enabled := CanRun and DebuggerIsValid - and (dcRunTo in FDebugger.Commands); + itmRunMenuRunToCursor.Enabled := CanRun and (dcRunTo in AvailCommands); // Stop - itmRunMenuStop.Enabled := CanRun and DebuggerIsValid and (MainIDE.ToolStatus = itDebugger) and - (FDebugger.State in [dsPause, dsInternalPause, dsInit, dsRun, dsError]); + itmRunMenuStop.Enabled := CanRun and (MainIDE.ToolStatus = itDebugger) and + (CurState in [dsPause, dsInternalPause, dsInit, dsRun, dsError]); //Attach / Detach - itmRunMenuAttach.Enabled := (not DebuggerIsValid) or (dcAttach in FDebugger.Commands); - itmRunMenuDetach.Enabled := (DebuggerIsValid) and (dcDetach in FDebugger.Commands); + itmRunMenuAttach.Enabled := DebuggerIsValid and (dcAttach in AvailCommands); + itmRunMenuDetach.Enabled := DebuggerIsValid and (dcDetach in AvailCommands); // Evaluate - itmRunMenuEvaluate.Enabled := CanRun and DebuggerIsValid - and (dcEvaluate in FDebugger.Commands); + itmRunMenuEvaluate.Enabled := CanRun and (dcEvaluate in AvailCommands); // Evaluate / modify - SrcEditMenuEvaluateModify.Enabled := CanRun and DebuggerIsValid - and (dcEvaluate in FDebugger.Commands); + SrcEditMenuEvaluateModify.Enabled := CanRun and (dcEvaluate in AvailCommands); // Inspect - SrcEditMenuInspect.Enabled := CanRun and DebuggerIsValid - and (dcEvaluate in FDebugger.Commands); - itmRunMenuInspect.Enabled := CanRun and DebuggerIsValid - and (dcEvaluate in FDebugger.Commands); + SrcEditMenuInspect.Enabled := CanRun and (dcEvaluate in AvailCommands); + itmRunMenuInspect.Enabled := CanRun and (dcEvaluate in AvailCommands); // Add watch - itmRunMenuAddWatch.Enabled := True; // always allow to add a watch + itmRunMenuAddWatch.Enabled := True; // always allow to add a watch // Add Breakpoint itmRunMenuAddBpSource.Enabled := True; @@ -3093,12 +3089,6 @@ var ActiveUnitInfo: TUnitInfo; UnitFilename: string; begin - if (FDebugger = nil) or not(dcRunTo in FDebugger.Commands) - then begin - Result := mrAbort; - Exit; - end; - if (MainIDE.DoInitProjectRun <> mrOK) or (MainIDE.ToolStatus <> itDebugger) or (FDebugger = nil) or Destroying @@ -3107,8 +3097,6 @@ begin Exit; end; - Result := mrCancel; - MainIDE.GetCurrentUnitInfo(ActiveSrcEdit,ActiveUnitInfo); if (ActiveSrcEdit=nil) or (ActiveUnitInfo=nil) then begin @@ -3122,6 +3110,7 @@ begin then UnitFilename:=ActiveUnitInfo.Filename else UnitFilename:=BuildBoss.GetTestUnitFilename(ActiveUnitInfo); + FStepping:=True; FDebugger.RunTo(ExtractFilename(UnitFilename), TSourceEditor(ActiveSrcEdit).EditorComponent.CaretY);