Difference between revisions of "TDebuggerIntf"

From Free Pascal wiki
Jump to navigationJump to search
Line 64: Line 64:
 
{| class="wikitable"  style="width:100%"
 
{| class="wikitable"  style="width:100%"
 
!Command
 
!Command
 +
!Explanation
 
!Parameters
 
!Parameters
 
|-
 
|-
 
|dcRun
 
|dcRun
 +
|
 
|no parameters
 
|no parameters
 
|-
 
|-
 
|dcPause
 
|dcPause
 +
|
 
|no parameters
 
|no parameters
 
|-
 
|-
 
|dcStop
 
|dcStop
 +
|
 
|no parameters
 
|no parameters
 
|-
 
|-
 
|dcStepOver
 
|dcStepOver
 +
|
 
|no parameters
 
|no parameters
 
|-
 
|-
 
|dcStepInto
 
|dcStepInto
 +
|
 
|no parameters
 
|no parameters
 
|-
 
|-
 
|dcStepOut
 
|dcStepOut
 +
|
 
|no parameters
 
|no parameters
 
|-
 
|-
 
|dcRunTo
 
|dcRunTo
 +
|
 
|0 - AnsiString - file name of the source code to run to
 
|0 - AnsiString - file name of the source code to run to
  
1 - INteger - Line number to run to
+
1 - Integer - Line number to run to
 
|-
 
|-
 
|dcJumpto
 
|dcJumpto
 
|
 
|
 +
|0 - AnsiString - file name of the source code to jump to
 +
 +
1 - Integer - Line number to run to
 
|-
 
|-
 
|dcAttach
 
|dcAttach
 
|
 
|
 +
|0 - AnsiString - process ID to attach-to.
 
|-
 
|-
 
|dcDetach
 
|dcDetach
 
|
 
|
 +
|no parameters
 
|-
 
|-
 
|dcBreak
 
|dcBreak
 +
|
 
|
 
|
 
|-
 
|-
 
|dcWatch
 
|dcWatch
 +
|
 
|
 
|
 
|-
 
|-
 
|dcLocal
 
|dcLocal
 +
|
 
|
 
|
 
|-
 
|-
 
|dcEvaluate
 
|dcEvaluate
 
|
 
|
 +
|0 - AnsiString - expression to be evaluated
 +
 +
1 - pointer to AnsiString - the string where the result should be saved into
 +
 +
2 - pointer to TDBGType - the reference where the information about the result type should be saved to
 +
 +
3 - Integer - TDBGEvaluateFlags casted into Integer
 
|-
 
|-
 
|dcModify
 
|dcModify
 
|
 
|
 +
|0 - AnsiString - expression (of what?)
 +
 +
1 - AnsiString - value (of what?)
 
|-
 
|-
 
|dcEnvironment
 
|dcEnvironment
 +
|
 
|
 
|
 
|-
 
|-
 
|dcSetStackFrame
 
|dcSetStackFrame
 +
|
 
|
 
|
 
|-
 
|-
 
|dcDisassemble
 
|dcDisassemble
 +
|
 
|
 
|
 
|-
 
|-
 
|dcStepOverInstr
 
|dcStepOverInstr
 +
|
 
|
 
|
 
|-
 
|-
 
|dcStepIntoInstr
 
|dcStepIntoInstr
 +
|
 
|
 
|
 
|-
 
|-
 
|dcSendConsoleInput
 
|dcSendConsoleInput
 +
|
 
|
 
|
 
|}
 
|}

Revision as of 21:48, 23 October 2017

TDebuggerIntf is the base class of implementing a debugger as Lazarus-IDE plugin package. The package must have DebuggerIntf package as it's requirements. Any debugger plug-in must implement the class and register via RegisterDebugger (called at Register of registering unit).

The class is designed to act as asynchronous object. Thus requested changes are not expected to take effect right after the end of the process (even though this is not forbidden). Any actual change taking place should be reported with an additional method call.

Minimal Implementation

The following methods must be implemented for TDebbugerIntf

  • GetSupportedCommands (or GetCommands) - returns the set of formats that a debugger can perform
  • RequestCommand - the method actually performing commands. Only commands returned by GetSupportedCommands would be passed to this method
  • Caption - the method return user-friendly name of the debugger
type
  TMiniDebugger = class(TDebuggerIntf)
  protected
    function RequestCommand(const ACommand: TDBGCommand; const AParams: array of const): Boolean; override;
    function GetSupportedCommands: TDBGCommands; override;
  public
    class function Caption: String; override;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterDebugger(TMiniDebugger);
end;

class function TMiniDebugger.Caption: String;
begin
  Result:='Initial Debugger Plug-in';
end;

function TMiniDebugger.GetSupportedCommands: TDBGCommands;
begin
  Result := [dcRun, dcStop];
end;
      
function TMiniDebugger.RequestCommand(const ACommand: TDBGCommand;
  const AParams: array of const): Boolean;
begin
  case ACommand of
    dcRun: begin       // the debugger was requested to run
      Result:=true;    // typically it should set the state into dsIdle (to get more data from IDE)
      SetState(dsRun); // the debugger replies as if it started immediately 
    end;
    dcStop: begin      // the debugger was requested to stop
      Result:=true;
      SetState(dsStop); // the debugger replied as if it stopped immediately
    end;
  else
    Result:=false;
  end;
end;

Methods

RequestCommand

The method should return false, if the command cannot be executed.

Debugger Commands

Command Explanation Parameters
dcRun no parameters
dcPause no parameters
dcStop no parameters
dcStepOver no parameters
dcStepInto no parameters
dcStepOut no parameters
dcRunTo 0 - AnsiString - file name of the source code to run to

1 - Integer - Line number to run to

dcJumpto 0 - AnsiString - file name of the source code to jump to

1 - Integer - Line number to run to

dcAttach 0 - AnsiString - process ID to attach-to.
dcDetach no parameters
dcBreak
dcWatch
dcLocal
dcEvaluate 0 - AnsiString - expression to be evaluated

1 - pointer to AnsiString - the string where the result should be saved into

2 - pointer to TDBGType - the reference where the information about the result type should be saved to

3 - Integer - TDBGEvaluateFlags casted into Integer

dcModify 0 - AnsiString - expression (of what?)

1 - AnsiString - value (of what?)

dcEnvironment
dcSetStackFrame
dcDisassemble
dcStepOverInstr
dcStepIntoInstr
dcSendConsoleInput

Development Hints

  • it might be helpful to recompile DebuggerIntf package, adding the following Custom Options to the compiler options of the package
-dDBG_STATE
-dDBG_EVENTS
-dDBG_VERBOSE
-dDBG_WARNINGS
-dDBG_DATA_MONITORS
-dDBG_DISASSEMBLER
these defines provide more logging output of TDebuggerIntf
  • it might be helpful to rebuild IDE adding the following defines into build Options:
-dVerboseDebugger
VerboseDebugger logs messages debugging calls from IDE itself