mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-02 08:20:39 +01:00
FpDbg: Disasemble on non-Windows systems
git-svn-id: trunk@44492 -
This commit is contained in:
parent
4613232478
commit
327140d6b8
@ -53,20 +53,31 @@ procedure DebugLoop;
|
||||
var
|
||||
a: TDbgPtr;
|
||||
Code, CodeBytes: String;
|
||||
CodeBin: array[0..20] of Byte;
|
||||
p: pointer;
|
||||
i: integer;
|
||||
begin
|
||||
WriteLN('===');
|
||||
a := GCurrentProcess.GetInstructionPointerRegisterValue;
|
||||
Write(' [', FormatAddress(a), ']');
|
||||
{$ifdef windows}
|
||||
{$ifdef cpui386}
|
||||
Disassemble(GCurrentProcess.Handle, False, a, CodeBytes, Code);
|
||||
{$else}
|
||||
Disassemble(GCurrentProcess.Handle, True, a, CodeBytes, Code);
|
||||
{$endif}
|
||||
{$else}
|
||||
a := 0;
|
||||
{$endif}
|
||||
WriteLN(' ', CodeBytes, ' ', Code);
|
||||
for i := 0 to 5 do
|
||||
begin
|
||||
Write(' [', FormatAddress(a), ']');
|
||||
|
||||
if not GCurrentProcess.ReadData(a,sizeof(CodeBin),CodeBin)
|
||||
then begin
|
||||
Log('Disassemble: Failed to read memory at %s.', [FormatAddress(a)]);
|
||||
Code := '??';
|
||||
CodeBytes := '??';
|
||||
Inc(a);
|
||||
Exit;
|
||||
end;
|
||||
p := @CodeBin;
|
||||
|
||||
Disassemble(p, GMode=dm64, CodeBytes, Code);
|
||||
|
||||
WriteLN(' ', CodeBytes:20, ' ', Code);
|
||||
Inc(a, PtrUInt(p) - PtrUInt(@CodeBin));
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure ShowCode;
|
||||
|
||||
@ -40,9 +40,6 @@ interface
|
||||
|
||||
uses
|
||||
SysUtils,
|
||||
{$ifdef windows}
|
||||
Windows,
|
||||
{$endif}
|
||||
FpDbgUtil, FpDbgInfo, DbgIntfBaseTypes, FpdMemoryTools;
|
||||
|
||||
{
|
||||
@ -58,11 +55,7 @@ uses
|
||||
}
|
||||
|
||||
|
||||
{$ifdef windows}
|
||||
procedure Disassemble(var AAddress: Pointer; const A64Bit: Boolean; out ACodeBytes: String; out ACode: String);
|
||||
procedure Disassemble(const AProcess: Handle; const A64Bit: Boolean; var AAddress: TDbgPtr; out ACodeBytes: String; out ACode: String);
|
||||
function Disassemble(const AProcess: Handle; const A64Bit: Boolean; var AAddress: TDbgPtr): String;
|
||||
{$endif}
|
||||
|
||||
implementation
|
||||
|
||||
@ -88,36 +81,6 @@ type
|
||||
TOperandFlag = (ofMemory);
|
||||
TOperandFlags = set of TOperandFlag;
|
||||
|
||||
{$ifdef windows}
|
||||
function Disassemble(const AProcess: Handle; const A64Bit: Boolean; var AAddress: TDbgPtr): String;
|
||||
var
|
||||
S: String;
|
||||
begin
|
||||
Disassemble(AProcess, A64bit, AAddress, S, Result);
|
||||
end;
|
||||
|
||||
procedure Disassemble(const AProcess: Handle; const A64Bit: Boolean; var AAddress: TDbgPtr; out ACodeBytes: String; out ACode: String);
|
||||
const
|
||||
PTRSIZE: array[Boolean] of Byte = (4, 8);
|
||||
var
|
||||
BytesRead: Cardinal;
|
||||
Code: array[0..20] of Byte;
|
||||
p: Pointer;
|
||||
begin
|
||||
BytesRead := 0;
|
||||
if not ReadProcessMemory(AProcess, Pointer(PtrUInt(AAddress)), @Code, SizeOf(Code), BytesRead) and (BytesRead = SizeOf(Code))
|
||||
then begin
|
||||
Log('Disassemble: Failed to read memory at %s, got %u bytes', [HexValue(AAddress, PTRSIZE[A64Bit], [hvfIncludeHexchar]), BytesRead]);
|
||||
ACode := '??';
|
||||
ACodeBytes := '??';
|
||||
Inc(AAddress);
|
||||
Exit;
|
||||
end;
|
||||
p := @Code;
|
||||
Disassemble(p, A64Bit, ACodeBytes, ACode);
|
||||
Inc(AAddress, PtrUInt(p) - PtrUInt(@Code));
|
||||
end;
|
||||
|
||||
procedure Disassemble(var AAddress: Pointer; const A64Bit: Boolean; out ACodeBytes: String; out ACode: String);
|
||||
var
|
||||
Code: PByte;
|
||||
@ -3131,7 +3094,6 @@ begin
|
||||
ACodeBytes := S;
|
||||
Inc(AAddress, CodeIdx);
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
|
||||
end.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user