mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 07:29:21 +02:00
+ Added disassembler (1byte opcodes)
git-svn-id: trunk@9188 -
This commit is contained in:
parent
932a652c95
commit
6f9e11bc79
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -575,6 +575,7 @@ debugger/windebug/fpwd/fpwdpeimage.pas svneol=native#text/pascal
|
|||||||
debugger/windebug/fpwd/fpwdtype.pas svneol=native#text/pascal
|
debugger/windebug/fpwd/fpwdtype.pas svneol=native#text/pascal
|
||||||
debugger/windebug/windebugger.pp svneol=native#text/pascal
|
debugger/windebug/windebugger.pp svneol=native#text/pascal
|
||||||
debugger/windebug/windextra.pp svneol=native#text/pascal
|
debugger/windebug/windextra.pp svneol=native#text/pascal
|
||||||
|
debugger/windebug/windisas.pp svneol=native#text/plain
|
||||||
designer/abstractcompiler.pp svneol=native#text/pascal
|
designer/abstractcompiler.pp svneol=native#text/pascal
|
||||||
designer/abstracteditor.pp svneol=native#text/pascal
|
designer/abstracteditor.pp svneol=native#text/pascal
|
||||||
designer/abstractfilesystem.pp svneol=native#text/pascal
|
designer/abstractfilesystem.pp svneol=native#text/pascal
|
||||||
|
@ -305,7 +305,7 @@ begin
|
|||||||
BytesRead := Count * Size;
|
BytesRead := Count * Size;
|
||||||
if not GMainProcess.ReadData(Adress, BytesRead, buf)
|
if not GMainProcess.ReadData(Adress, BytesRead, buf)
|
||||||
then begin
|
then begin
|
||||||
WriteLN('Could not read memory at: ', FormatAdress(Adress));
|
WriteLN('Could not read memory at: ', FormatAddress(Adress));
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -313,7 +313,7 @@ begin
|
|||||||
while BytesRead >= size do
|
while BytesRead >= size do
|
||||||
begin
|
begin
|
||||||
if e and ((32 div Size) - 1) = 0
|
if e and ((32 div Size) - 1) = 0
|
||||||
then Write('[', FormatAdress(Adress), '] ');
|
then Write('[', FormatAddress(Adress), '] ');
|
||||||
|
|
||||||
for idx := Size - 1 downto 0 do Write(IntToHex(buf[e * size + idx], 2));
|
for idx := Size - 1 downto 0 do Write(IntToHex(buf[e * size + idx], 2));
|
||||||
|
|
||||||
@ -406,7 +406,7 @@ end;
|
|||||||
|
|
||||||
procedure HandleShowCallStack(AParams: String);
|
procedure HandleShowCallStack(AParams: String);
|
||||||
var
|
var
|
||||||
Adress, Frame, LastFrame: QWord;
|
Address, Frame, LastFrame: QWord;
|
||||||
Size, Count: integer;
|
Size, Count: integer;
|
||||||
begin
|
begin
|
||||||
if (GMainProcess = nil) or (GCurrentProcess = nil)
|
if (GMainProcess = nil) or (GCurrentProcess = nil)
|
||||||
@ -421,23 +421,23 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
{$ifdef cpui386}
|
{$ifdef cpui386}
|
||||||
Adress := GCurrentContext^.Eip;
|
Address := GCurrentContext^.Eip;
|
||||||
Frame := GCurrentContext^.Ebp;
|
Frame := GCurrentContext^.Ebp;
|
||||||
Size := 4;
|
Size := 4;
|
||||||
{$else}
|
{$else}
|
||||||
Adress := GCurrentContext^.Rip;
|
Address := GCurrentContext^.Rip;
|
||||||
Frame := GCurrentContext^.Rdi;
|
Frame := GCurrentContext^.Rdi;
|
||||||
Size := 8;
|
Size := 8;
|
||||||
{$endif}
|
{$endif}
|
||||||
|
|
||||||
WriteLN('Callstack:');
|
WriteLN('Callstack:');
|
||||||
WriteLn(' ', FormatAdress(Adress));
|
WriteLn(' ', FormatAddress(Address));
|
||||||
LastFrame := 0;
|
LastFrame := 0;
|
||||||
Count := 25;
|
Count := 25;
|
||||||
while (Frame <> 0) and (Frame > LastFrame) do
|
while (Frame <> 0) and (Frame > LastFrame) do
|
||||||
begin
|
begin
|
||||||
if not GCurrentProcess.ReadData(Frame + Size, Size, Adress) or (Adress = 0) then Break;
|
if not GCurrentProcess.ReadData(Frame + Size, Size, Address) or (Address = 0) then Break;
|
||||||
WriteLn(' ', FormatAdress(Adress));
|
WriteLn(' ', FormatAddress(Address));
|
||||||
Dec(count);
|
Dec(count);
|
||||||
if Count <= 0 then Exit;
|
if Count <= 0 then Exit;
|
||||||
if not GCurrentProcess.ReadData(Frame, Size, Frame) then Break;
|
if not GCurrentProcess.ReadData(Frame, Size, Frame) then Break;
|
||||||
|
@ -37,7 +37,7 @@ unit FPWDLoop;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Windows, SysUtils, WinDebugger, WinDExtra;
|
Windows, SysUtils, WinDebugger, WinDExtra, WinDisas;
|
||||||
|
|
||||||
procedure DebugLoop;
|
procedure DebugLoop;
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ begin
|
|||||||
WriteLN(Format('hFile: 0x%x', [AEvent.CreateProcessInfo.hFile]));
|
WriteLN(Format('hFile: 0x%x', [AEvent.CreateProcessInfo.hFile]));
|
||||||
WriteLN(Format('hProcess: 0x%x', [AEvent.CreateProcessInfo.hProcess]));
|
WriteLN(Format('hProcess: 0x%x', [AEvent.CreateProcessInfo.hProcess]));
|
||||||
WriteLN(Format('hThread: 0x%x', [AEvent.CreateProcessInfo.hThread]));
|
WriteLN(Format('hThread: 0x%x', [AEvent.CreateProcessInfo.hThread]));
|
||||||
WriteLN('Base adress: ', FormatAdress(AEvent.CreateProcessInfo.lpBaseOfImage));
|
WriteLN('Base adress: ', FormatAddress(AEvent.CreateProcessInfo.lpBaseOfImage));
|
||||||
WriteLN(Format('Debugsize: %d', [AEvent.CreateProcessInfo.nDebugInfoSize]));
|
WriteLN(Format('Debugsize: %d', [AEvent.CreateProcessInfo.nDebugInfoSize]));
|
||||||
WriteLN(Format('Debugoffset: %d', [AEvent.CreateProcessInfo.dwDebugInfoFileOffset]));
|
WriteLN(Format('Debugoffset: %d', [AEvent.CreateProcessInfo.dwDebugInfoFileOffset]));
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ begin
|
|||||||
Write(' Unknown code: ', AEvent.Exception.ExceptionRecord.ExceptionCode);
|
Write(' Unknown code: ', AEvent.Exception.ExceptionRecord.ExceptionCode);
|
||||||
end;
|
end;
|
||||||
Info0 := PtrUInt(AEvent.Exception.ExceptionRecord.ExceptionAddress);
|
Info0 := PtrUInt(AEvent.Exception.ExceptionRecord.ExceptionAddress);
|
||||||
Write(' at: ', FormatAdress(Info0));
|
Write(' at: ', FormatAddress(Info0));
|
||||||
Write(' Flags:', Format('%x', [AEvent.Exception.ExceptionRecord.ExceptionFlags]), ' [');
|
Write(' Flags:', Format('%x', [AEvent.Exception.ExceptionRecord.ExceptionFlags]), ' [');
|
||||||
if AEvent.Exception.ExceptionRecord.ExceptionFlags = 0
|
if AEvent.Exception.ExceptionRecord.ExceptionFlags = 0
|
||||||
then Write('Continuable')
|
then Write('Continuable')
|
||||||
@ -128,7 +128,7 @@ begin
|
|||||||
case AEvent.Exception.ExceptionRecord.ExceptionCode of
|
case AEvent.Exception.ExceptionRecord.ExceptionCode of
|
||||||
EXCEPTION_ACCESS_VIOLATION: begin
|
EXCEPTION_ACCESS_VIOLATION: begin
|
||||||
Info0 := AEvent.Exception.ExceptionRecord.ExceptionInformation[0];
|
Info0 := AEvent.Exception.ExceptionRecord.ExceptionInformation[0];
|
||||||
Info1Str := FormatAdress(AEvent.Exception.ExceptionRecord.ExceptionInformation[1]);
|
Info1Str := FormatAddress(AEvent.Exception.ExceptionRecord.ExceptionInformation[1]);
|
||||||
|
|
||||||
case Info0 of
|
case Info0 of
|
||||||
0: begin
|
0: begin
|
||||||
@ -180,7 +180,7 @@ procedure HandleLoadDll(const AEvent: TDebugEvent);
|
|||||||
// Proc: TDbgProcess;
|
// Proc: TDbgProcess;
|
||||||
// Lib: TDbgLibrary;
|
// Lib: TDbgLibrary;
|
||||||
begin
|
begin
|
||||||
WriteLN('Base adress: ', FormatAdress(AEvent.LoadDll.lpBaseOfDll));
|
WriteLN('Base adress: ', FormatAddress(AEvent.LoadDll.lpBaseOfDll));
|
||||||
|
|
||||||
|
|
||||||
// if GetProcess(AEvent.dwProcessId, Proc)
|
// if GetProcess(AEvent.dwProcessId, Proc)
|
||||||
@ -220,7 +220,7 @@ end;
|
|||||||
|
|
||||||
procedure HandleUnloadDll(const AEvent: TDebugEvent);
|
procedure HandleUnloadDll(const AEvent: TDebugEvent);
|
||||||
begin
|
begin
|
||||||
WriteLN('Base adress: ', FormatAdress(AEvent.UnloadDll.lpBaseOfDll));
|
WriteLN('Base adress: ', FormatAddress(AEvent.UnloadDll.lpBaseOfDll));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure DebugLoop;
|
procedure DebugLoop;
|
||||||
@ -308,6 +308,24 @@ procedure DebugLoop;
|
|||||||
WriteLN('---');
|
WriteLN('---');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure ShowDisas;
|
||||||
|
var
|
||||||
|
a: PtrUInt;
|
||||||
|
Code, CodeBytes: String;
|
||||||
|
begin
|
||||||
|
WriteLN('===');
|
||||||
|
{$ifdef cpui386}
|
||||||
|
a := GCurrentContext^.EIP;
|
||||||
|
Write(' [', FormatAddress(a), ']');
|
||||||
|
Disassemble(GCurrentProcess.Handle, False, a, CodeBytes, Code);
|
||||||
|
{$else}
|
||||||
|
a := GCurrentContext^.RIP;
|
||||||
|
Write(' [', FormatAddress(a), ']');
|
||||||
|
Disassemble(GCurrentProcess.Handle, True, a, CodeBytes, Code);
|
||||||
|
{$endif}
|
||||||
|
WriteLN(' ', CodeBytes, ' ', Code);
|
||||||
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
repeat
|
repeat
|
||||||
if (GCurrentProcess <> nil) and (GState = dsPause)
|
if (GCurrentProcess <> nil) and (GState = dsPause)
|
||||||
@ -390,6 +408,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
until (GState in [dsStop, dsPause, dsQuit]);
|
until (GState in [dsStop, dsPause, dsQuit]);
|
||||||
|
|
||||||
|
if GState = dsPause
|
||||||
|
then ShowDisas
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -41,7 +41,7 @@ interface
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Windows, SysUtils, FPWDGLobal, WinDebugger;
|
Windows, SysUtils, FPWDGLobal, WinDExtra;
|
||||||
|
|
||||||
const
|
const
|
||||||
IMAGE_FILE_MACHINE_IA64 = $0200; { Intel IPF }
|
IMAGE_FILE_MACHINE_IA64 = $0200; { Intel IPF }
|
||||||
|
@ -39,7 +39,6 @@ uses
|
|||||||
Windows, Classes, Maps, WindExtra;
|
Windows, Classes, Maps, WindExtra;
|
||||||
|
|
||||||
type
|
type
|
||||||
TDbgPtr = PtrUInt;
|
|
||||||
TDbgProcess = class;
|
TDbgProcess = class;
|
||||||
|
|
||||||
TDbgThread = class(TObject)
|
TDbgThread = class(TObject)
|
||||||
@ -169,17 +168,6 @@ implementation
|
|||||||
uses
|
uses
|
||||||
SysUtils;
|
SysUtils;
|
||||||
|
|
||||||
|
|
||||||
procedure Log(const AText: String; const AParams: array of const); overload;
|
|
||||||
begin
|
|
||||||
WriteLN(Format(AText, AParams));
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure Log(const AText: String); overload;
|
|
||||||
begin
|
|
||||||
WriteLN(AText);
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure LogLastError;
|
procedure LogLastError;
|
||||||
begin
|
begin
|
||||||
WriteLN('ERROR: ', GetLastErrorText);
|
WriteLN('ERROR: ', GetLastErrorText);
|
||||||
@ -275,7 +263,7 @@ end;
|
|||||||
|
|
||||||
function TDbgProcess.AddLib(const AInfo: TLoadDLLDebugInfo): TDbgLibrary;
|
function TDbgProcess.AddLib(const AInfo: TLoadDLLDebugInfo): TDbgLibrary;
|
||||||
begin
|
begin
|
||||||
Result := TDbgLibrary.Create(Self, FormatAdress(AInfo.lpBaseOfDll), AInfo);
|
Result := TDbgLibrary.Create(Self, FormatAddress(AInfo.lpBaseOfDll), AInfo);
|
||||||
FLibMap.Add(TDbgPtr(AInfo.lpBaseOfDll), Result);
|
FLibMap.Add(TDbgPtr(AInfo.lpBaseOfDll), Result);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -672,7 +660,7 @@ begin
|
|||||||
Context^.ContextFlags := CONTEXT_CONTROL;
|
Context^.ContextFlags := CONTEXT_CONTROL;
|
||||||
if not GetThreadContext(Thread.Handle, Context^)
|
if not GetThreadContext(Thread.Handle, Context^)
|
||||||
then begin
|
then begin
|
||||||
Log('Break $s: Unable to get context', [FormatAdress(FLocation)]);
|
Log('Break $s: Unable to get context', [FormatAddress(FLocation)]);
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -685,7 +673,7 @@ begin
|
|||||||
|
|
||||||
if not SetThreadContext(Thread.Handle, Context^)
|
if not SetThreadContext(Thread.Handle, Context^)
|
||||||
then begin
|
then begin
|
||||||
Log('Break %s: Unable to set context', [FormatAdress(FLocation)]);
|
Log('Break %s: Unable to set context', [FormatAddress(FLocation)]);
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
Result := True;
|
Result := True;
|
||||||
|
@ -40,10 +40,16 @@ interface
|
|||||||
uses
|
uses
|
||||||
Windows;
|
Windows;
|
||||||
|
|
||||||
function FormatAdress(const P): String;
|
type
|
||||||
|
TDbgPtr = PtrUInt;
|
||||||
|
|
||||||
function GetLastErrorText(AErrorCode: Cardinal): String; {$IFNDEF FPC} overload; {$ENDIF}
|
function GetLastErrorText(AErrorCode: Cardinal): String; {$IFNDEF FPC} overload; {$ENDIF}
|
||||||
function GetLastErrorText: String; {$IFNDEF FPC} overload; {$ENDIF}
|
function GetLastErrorText: String; {$IFNDEF FPC} overload; {$ENDIF}
|
||||||
|
|
||||||
|
function FormatAddress(const P): String;
|
||||||
function AlignPtr(Src: Pointer; Alignment: Byte): Pointer;
|
function AlignPtr(Src: Pointer; Alignment: Byte): Pointer;
|
||||||
|
procedure Log(const AText: String; const AParams: array of const); overload;
|
||||||
|
procedure Log(const AText: String); overload;
|
||||||
|
|
||||||
|
|
||||||
//function OpenThread(dwDesiredAccess: DWORD; bInheritHandle: BOOL; dwThreadId: DWORD): THandle; stdcall;
|
//function OpenThread(dwDesiredAccess: DWORD; bInheritHandle: BOOL; dwThreadId: DWORD): THandle; stdcall;
|
||||||
@ -59,7 +65,7 @@ uses
|
|||||||
//function Wow64GetThreadContext(hThread: THandle; var lpContext: TContext): BOOL; stdcall; external 'kernel32';
|
//function Wow64GetThreadContext(hThread: THandle; var lpContext: TContext): BOOL; stdcall; external 'kernel32';
|
||||||
|
|
||||||
|
|
||||||
function FormatAdress(const P): String;
|
function FormatAddress(const P): String;
|
||||||
begin
|
begin
|
||||||
case GMode of
|
case GMode of
|
||||||
dm32: Result := '$' + IntToHex(DWord(p), 8);
|
dm32: Result := '$' + IntToHex(DWord(p), 8);
|
||||||
@ -106,5 +112,16 @@ begin
|
|||||||
Result := Pointer(((PtrUInt(Src) + Alignment - 1) and not PtrUInt(Alignment - 1)));
|
Result := Pointer(((PtrUInt(Src) + Alignment - 1) and not PtrUInt(Alignment - 1)));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure Log(const AText: String; const AParams: array of const); overload;
|
||||||
|
begin
|
||||||
|
WriteLN(Format(AText, AParams));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure Log(const AText: String); overload;
|
||||||
|
begin
|
||||||
|
WriteLN(AText);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
1462
debugger/windebug/windisas.pp
Normal file
1462
debugger/windebug/windisas.pp
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user