FpDebug, fpd-app: fix some compile errors

git-svn-id: trunk@61335 -
This commit is contained in:
martin 2019-06-07 12:24:00 +00:00
parent 0ed78196c7
commit c13bcb61c2
2 changed files with 68 additions and 33 deletions

View File

@ -38,7 +38,7 @@ interface
uses uses
SysUtils, Classes, SysUtils, Classes,
{$ifdef windows} {$ifdef windows}
Windows, Windows, fgl,
{$endif} {$endif}
LCLProc, FpDbgInfo, FpDbgClasses, DbgIntfBaseTypes, FpDbgUtil, CustApp, LCLProc, FpDbgInfo, FpDbgClasses, DbgIntfBaseTypes, FpDbgUtil, CustApp,
FpPascalParser, FpPascalParser,
@ -59,6 +59,10 @@ uses
type type
TFPDCommandHandler = procedure(AParams: String; out CallProcessLoop: boolean); TFPDCommandHandler = procedure(AParams: String; out CallProcessLoop: boolean);
TBreakPointIdMap = class(specialize TFPGMap<Integer, TFpInternalBreakpoint>)
public
function DoBreakPointCompare(Key1, Key2: Pointer): Integer;
end;
TFPDCommand = class TFPDCommand = class
private private
@ -93,12 +97,19 @@ var
MCommands: TFPDCommandList; MCommands: TFPDCommandList;
MShowCommands: TFPDCommandList; MShowCommands: TFPDCommandList;
MSetCommands: TFPDCommandList; MSetCommands: TFPDCommandList;
BreakPointIdMap: TBreakPointIdMap;
CurBreakId: Integer;
resourcestring resourcestring
sAddBreakpoint = 'Breakpoint added at address %s.'; sAddBreakpoint = 'Breakpoint %d added at address %s.';
sAddBreakpointFailed = 'Adding breakpoint at %s failed.'; sAddBreakpointFailed = 'Adding breakpoint at %s failed.';
sRemoveBreakpoint = 'Breakpoint removed from address %s.'; sRemoveBreakpoint = 'Breakpoint removed from address %s.';
sRemoveBreakpointFailed = 'Removing breakpoint at %s failed.'; sRemoveBreakpointFailed = 'Removing breakpoint %s failed.';
function TBreakPointIdMap.DoBreakPointCompare(Key1, Key2: Pointer): Integer;
begin
Result := PPointer(Key1)^ - PPointer(Key1)^;
end;
procedure HandleCommand(ACommand: String; out CallProcessLoop: boolean); procedure HandleCommand(ACommand: String; out CallProcessLoop: boolean);
begin begin
@ -200,7 +211,7 @@ var
S, P: String; S, P: String;
Remove: Boolean; Remove: Boolean;
Address: TDbgPtr; Address: TDbgPtr;
e: Integer; e, Id: Integer;
Line: Cardinal; Line: Cardinal;
bp: TFpInternalBreakpoint; bp: TFpInternalBreakpoint;
@ -221,6 +232,19 @@ begin
if not Remove if not Remove
then S := P; then S := P;
If Remove then begin
Val(S, Id, e);
if (e = 0) and BreakPointIdMap.TryGetData(Id, bp) then begin
GController.CurrentProcess.RemoveBreak(bp);
BreakPointIdMap.Remove(Id);
bp.Destroy;
WriteLn(format(sRemoveBreakpoint,[S]))
end
else
WriteLn(Format(sRemoveBreakpointFailed, [S]));
exit;
end;
if S = '' if S = ''
then begin then begin
// current addr // current addr
@ -252,17 +276,22 @@ begin
Address:=AValue.Address.Address; Address:=AValue.Address.Address;
end; end;
end; end;
if Remove //if Remove
then begin //then begin
if GController.CurrentProcess.RemoveBreak(Address) // if GController.CurrentProcess.RemoveBreak(Address)
then WriteLn(format(sRemoveBreakpoint,[FormatAddress(Address)])) // then WriteLn(format(sRemoveBreakpoint,[FormatAddress(Address)]))
else WriteLn(Format(sRemoveBreakpointFailed, [FormatAddress(Address)])); // else WriteLn(Format(sRemoveBreakpointFailed, [FormatAddress(Address)]));
end //end
else begin //else begin
if GController.CurrentProcess.AddBreak(Address) <> nil bp := GController.CurrentProcess.AddBreak(Address);
then WriteLn(format(sAddBreakpoint, [FormatAddress(Address)])) if bp <> nil then begin
else WriteLn(Format(sAddBreakpointFailed, [FormatAddress(Address)])); inc(CurBreakId);
end; BreakPointIdMap.Add(CurBreakId, bp);
WriteLn(format(sAddBreakpoint, [CurBreakId, FormatAddress(Address)]));
end
else
WriteLn(Format(sAddBreakpointFailed, [FormatAddress(Address)]));
//end;
end end
else begin else begin
S := GetPart([':'], [], S); S := GetPart([':'], [], S);
@ -272,13 +301,13 @@ begin
WriteLN('Illegal line: ', S); WriteLN('Illegal line: ', S);
Exit; Exit;
end; end;
if Remove //if Remove
then begin //then begin
if TDbgInstance(GController.CurrentProcess).RemoveBreak(P, Line) // if TDbgInstance(GController.CurrentProcess).RemoveBreak(P, Line)
then WriteLn('breakpoint removed') // then WriteLn('breakpoint removed')
else WriteLn('remove breakpoint failed'); // else WriteLn('remove breakpoint failed');
Exit; // Exit;
end; //end;
bp := TDbgInstance(GController.CurrentProcess).AddBreak(P, Line); bp := TDbgInstance(GController.CurrentProcess).AddBreak(P, Line);
if bp = nil if bp = nil
@ -287,7 +316,9 @@ begin
Exit; Exit;
end; end;
WriteLn(format(sAddBreakpoint, [FormatAddress(bp.Location)])) inc(CurBreakId);
BreakPointIdMap.Add(CurBreakId, bp);
WriteLn(format(sAddBreakpoint, [CurBreakId, ''])); // FormatAddress(bp.Location)]))
end; end;
end; end;
@ -876,7 +907,8 @@ begin
MCommands.AddCommand(['show', 's'], @HandleShow, 'show <info>: Enter show help for more info'); MCommands.AddCommand(['show', 's'], @HandleShow, 'show <info>: Enter show help for more info');
MCommands.AddCommand(['set'], @HandleSet, 'set param: Enter set help for more info'); MCommands.AddCommand(['set'], @HandleSet, 'set param: Enter set help for more info');
MCommands.AddCommand(['run', 'r'], @HandleRun, 'run [params]: Starts the loaded debuggee'); MCommands.AddCommand(['run', 'r'], @HandleRun, 'run [params]: Starts the loaded debuggee');
MCommands.AddCommand(['break', 'b'], @HandleBreak, 'break [-d] <adress>|<filename:line>: Set a breakpoint at <adress> or <filename:line>. -d removes'); MCommands.AddCommand(['break', 'b'], @HandleBreak, 'break <adress>|<filename:line>: Set a breakpoint at <adress> or <filename:line>.' +LineEnding+
'break -d <id>: Remove break');
MCommands.AddCommand(['continue', 'cont', 'c'], @HandleContinue, 'continue: Continues execution'); MCommands.AddCommand(['continue', 'cont', 'c'], @HandleContinue, 'continue: Continues execution');
MCommands.AddCommand(['kill', 'k'], @HandleKill, 'kill: Stops execution of the debuggee'); MCommands.AddCommand(['kill', 'k'], @HandleKill, 'kill: Stops execution of the debuggee');
MCommands.AddCommand(['step-inst', 'si'], @HandleStepInst, 'step-inst: Steps-into one instruction'); MCommands.AddCommand(['step-inst', 'si'], @HandleStepInst, 'step-inst: Steps-into one instruction');
@ -904,6 +936,10 @@ begin
MSetCommands.AddCommand(['mode', 'm'], @HandleSetMode, 'set mode 32|64: Set the mode for retrieving process info'); MSetCommands.AddCommand(['mode', 'm'], @HandleSetMode, 'set mode 32|64: Set the mode for retrieving process info');
MSetCommands.AddCommand(['break_on_library_load', 'boll'], @HandleSetBOLL, 'set break_on_library_load on|off: Pause running when a library is loaded (default off)'); MSetCommands.AddCommand(['break_on_library_load', 'boll'], @HandleSetBOLL, 'set break_on_library_load on|off: Pause running when a library is loaded (default off)');
MSetCommands.AddCommand(['imageinfo', 'ii'], @HandleSetImageInfo, 'set imageinfo none|name|detail: When a library is loaded, show nothing, only its name or all details (default none)'); MSetCommands.AddCommand(['imageinfo', 'ii'], @HandleSetImageInfo, 'set imageinfo none|name|detail: When a library is loaded, show nothing, only its name or all details (default none)');
BreakPointIdMap := TBreakPointIdMap.Create;
BreakPointIdMap.OnDataPtrCompare := @BreakPointIdMap.DoBreakPointCompare;
CurBreakId := 0;
end; end;
procedure Finalize; procedure Finalize;
@ -911,6 +947,7 @@ begin
FreeAndNil(MCommands); FreeAndNil(MCommands);
FreeAndNil(MSetCommands); FreeAndNil(MSetCommands);
FreeAndNil(MShowCommands); FreeAndNil(MShowCommands);
FreeAndNil(BreakPointIdMap);
end; end;
initialization initialization

View File

@ -37,10 +37,8 @@ unit FPDLoop;
interface interface
uses uses
Classes, SysUtils, FileUtil, FpDbgInfo, FpDbgClasses, FpDbgDisasX86, DbgIntfBaseTypes, Classes, SysUtils, FileUtil, LazFileUtils, LazUTF8, FpDbgInfo, FpDbgClasses,
FpDbgDwarf, FpDbgDisasX86, DbgIntfBaseTypes, FpDbgDwarf, FpdMemoryTools, CustApp;
FpdMemoryTools,
CustApp;
type type
@ -55,7 +53,7 @@ type
procedure ShowCode; procedure ShowCode;
procedure GControllerExceptionEvent(var continue: boolean; const ExceptionClass, ExceptionMessage: string); procedure GControllerExceptionEvent(var continue: boolean; const ExceptionClass, ExceptionMessage: string);
procedure GControllerCreateProcessEvent(var continue: boolean); procedure GControllerCreateProcessEvent(var continue: boolean);
procedure GControllerHitBreakpointEvent(var continue: boolean; const Breakpoint: TDbgBreakpoint); procedure GControllerHitBreakpointEvent(var continue: boolean; const Breakpoint: TFpInternalBreakpoint);
procedure GControllerProcessExitEvent(ExitCode: DWord); procedure GControllerProcessExitEvent(ExitCode: DWord);
procedure GControllerDebugInfoLoaded(Sender: TObject); procedure GControllerDebugInfoLoaded(Sender: TObject);
procedure OnLog(const AString: string; const ALogLevel: TFPDLogLevel); procedure OnLog(const AString: string; const ALogLevel: TFPDLogLevel);
@ -132,7 +130,7 @@ var
i: integer; i: integer;
begin begin
WriteLN('==='); WriteLN('===');
a := GController.CurrentProcess.GetInstructionPointerRegisterValue; a := GController.CurrentThread.GetInstructionPointerRegisterValue;
for i := 0 to 5 do for i := 0 to 5 do
begin begin
Write(' [', FormatAddress(a), ']'); Write(' [', FormatAddress(a), ']');
@ -162,7 +160,7 @@ var
AName: String; AName: String;
begin begin
WriteLN('==='); WriteLN('===');
a := GController.CurrentProcess.GetInstructionPointerRegisterValue; a := GController.CurrentThread.GetInstructionPointerRegisterValue;
sym := GController.CurrentProcess.FindSymbol(a); sym := GController.CurrentProcess.FindSymbol(a);
if sym = nil if sym = nil
then begin then begin
@ -224,10 +222,10 @@ begin
continue:=false; continue:=false;
end; end;
procedure TFPDLoop.GControllerHitBreakpointEvent(var continue: boolean; const Breakpoint: TDbgBreakpoint); procedure TFPDLoop.GControllerHitBreakpointEvent(var continue: boolean; const Breakpoint: TFpInternalBreakpoint);
begin begin
if assigned(Breakpoint) then if assigned(Breakpoint) then
writeln(Format(sBreakpointReached, [FormatAddress(Breakpoint.Location)])) writeln(Format(sBreakpointReached, ['' {FormatAddress(Breakpoint.Location)}]))
else else
writeln(sProcessPaused); writeln(sProcessPaused);
if not continue then if not continue then