mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-11 13:56:05 +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/windebugger.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/abstracteditor.pp svneol=native#text/pascal
|
||||
designer/abstractfilesystem.pp svneol=native#text/pascal
|
||||
|
@ -305,7 +305,7 @@ begin
|
||||
BytesRead := Count * Size;
|
||||
if not GMainProcess.ReadData(Adress, BytesRead, buf)
|
||||
then begin
|
||||
WriteLN('Could not read memory at: ', FormatAdress(Adress));
|
||||
WriteLN('Could not read memory at: ', FormatAddress(Adress));
|
||||
Exit;
|
||||
end;
|
||||
|
||||
@ -313,7 +313,7 @@ begin
|
||||
while BytesRead >= size do
|
||||
begin
|
||||
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));
|
||||
|
||||
@ -406,7 +406,7 @@ end;
|
||||
|
||||
procedure HandleShowCallStack(AParams: String);
|
||||
var
|
||||
Adress, Frame, LastFrame: QWord;
|
||||
Address, Frame, LastFrame: QWord;
|
||||
Size, Count: integer;
|
||||
begin
|
||||
if (GMainProcess = nil) or (GCurrentProcess = nil)
|
||||
@ -421,23 +421,23 @@ begin
|
||||
end;
|
||||
|
||||
{$ifdef cpui386}
|
||||
Adress := GCurrentContext^.Eip;
|
||||
Address := GCurrentContext^.Eip;
|
||||
Frame := GCurrentContext^.Ebp;
|
||||
Size := 4;
|
||||
{$else}
|
||||
Adress := GCurrentContext^.Rip;
|
||||
Address := GCurrentContext^.Rip;
|
||||
Frame := GCurrentContext^.Rdi;
|
||||
Size := 8;
|
||||
{$endif}
|
||||
|
||||
WriteLN('Callstack:');
|
||||
WriteLn(' ', FormatAdress(Adress));
|
||||
WriteLn(' ', FormatAddress(Address));
|
||||
LastFrame := 0;
|
||||
Count := 25;
|
||||
while (Frame <> 0) and (Frame > LastFrame) do
|
||||
begin
|
||||
if not GCurrentProcess.ReadData(Frame + Size, Size, Adress) or (Adress = 0) then Break;
|
||||
WriteLn(' ', FormatAdress(Adress));
|
||||
if not GCurrentProcess.ReadData(Frame + Size, Size, Address) or (Address = 0) then Break;
|
||||
WriteLn(' ', FormatAddress(Address));
|
||||
Dec(count);
|
||||
if Count <= 0 then Exit;
|
||||
if not GCurrentProcess.ReadData(Frame, Size, Frame) then Break;
|
||||
|
@ -37,7 +37,7 @@ unit FPWDLoop;
|
||||
interface
|
||||
|
||||
uses
|
||||
Windows, SysUtils, WinDebugger, WinDExtra;
|
||||
Windows, SysUtils, WinDebugger, WinDExtra, WinDisas;
|
||||
|
||||
procedure DebugLoop;
|
||||
|
||||
@ -58,7 +58,7 @@ begin
|
||||
WriteLN(Format('hFile: 0x%x', [AEvent.CreateProcessInfo.hFile]));
|
||||
WriteLN(Format('hProcess: 0x%x', [AEvent.CreateProcessInfo.hProcess]));
|
||||
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('Debugoffset: %d', [AEvent.CreateProcessInfo.dwDebugInfoFileOffset]));
|
||||
|
||||
@ -117,7 +117,7 @@ begin
|
||||
Write(' Unknown code: ', AEvent.Exception.ExceptionRecord.ExceptionCode);
|
||||
end;
|
||||
Info0 := PtrUInt(AEvent.Exception.ExceptionRecord.ExceptionAddress);
|
||||
Write(' at: ', FormatAdress(Info0));
|
||||
Write(' at: ', FormatAddress(Info0));
|
||||
Write(' Flags:', Format('%x', [AEvent.Exception.ExceptionRecord.ExceptionFlags]), ' [');
|
||||
if AEvent.Exception.ExceptionRecord.ExceptionFlags = 0
|
||||
then Write('Continuable')
|
||||
@ -128,7 +128,7 @@ begin
|
||||
case AEvent.Exception.ExceptionRecord.ExceptionCode of
|
||||
EXCEPTION_ACCESS_VIOLATION: begin
|
||||
Info0 := AEvent.Exception.ExceptionRecord.ExceptionInformation[0];
|
||||
Info1Str := FormatAdress(AEvent.Exception.ExceptionRecord.ExceptionInformation[1]);
|
||||
Info1Str := FormatAddress(AEvent.Exception.ExceptionRecord.ExceptionInformation[1]);
|
||||
|
||||
case Info0 of
|
||||
0: begin
|
||||
@ -180,7 +180,7 @@ procedure HandleLoadDll(const AEvent: TDebugEvent);
|
||||
// Proc: TDbgProcess;
|
||||
// Lib: TDbgLibrary;
|
||||
begin
|
||||
WriteLN('Base adress: ', FormatAdress(AEvent.LoadDll.lpBaseOfDll));
|
||||
WriteLN('Base adress: ', FormatAddress(AEvent.LoadDll.lpBaseOfDll));
|
||||
|
||||
|
||||
// if GetProcess(AEvent.dwProcessId, Proc)
|
||||
@ -220,7 +220,7 @@ end;
|
||||
|
||||
procedure HandleUnloadDll(const AEvent: TDebugEvent);
|
||||
begin
|
||||
WriteLN('Base adress: ', FormatAdress(AEvent.UnloadDll.lpBaseOfDll));
|
||||
WriteLN('Base adress: ', FormatAddress(AEvent.UnloadDll.lpBaseOfDll));
|
||||
end;
|
||||
|
||||
procedure DebugLoop;
|
||||
@ -307,6 +307,24 @@ procedure DebugLoop;
|
||||
end;
|
||||
WriteLN('---');
|
||||
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
|
||||
repeat
|
||||
@ -390,6 +408,9 @@ begin
|
||||
end;
|
||||
end;
|
||||
until (GState in [dsStop, dsPause, dsQuit]);
|
||||
|
||||
if GState = dsPause
|
||||
then ShowDisas
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -41,7 +41,7 @@ interface
|
||||
{$ENDIF}
|
||||
|
||||
uses
|
||||
Windows, SysUtils, FPWDGLobal, WinDebugger;
|
||||
Windows, SysUtils, FPWDGLobal, WinDExtra;
|
||||
|
||||
const
|
||||
IMAGE_FILE_MACHINE_IA64 = $0200; { Intel IPF }
|
||||
|
@ -39,7 +39,6 @@ uses
|
||||
Windows, Classes, Maps, WindExtra;
|
||||
|
||||
type
|
||||
TDbgPtr = PtrUInt;
|
||||
TDbgProcess = class;
|
||||
|
||||
TDbgThread = class(TObject)
|
||||
@ -169,17 +168,6 @@ implementation
|
||||
uses
|
||||
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;
|
||||
begin
|
||||
WriteLN('ERROR: ', GetLastErrorText);
|
||||
@ -275,7 +263,7 @@ end;
|
||||
|
||||
function TDbgProcess.AddLib(const AInfo: TLoadDLLDebugInfo): TDbgLibrary;
|
||||
begin
|
||||
Result := TDbgLibrary.Create(Self, FormatAdress(AInfo.lpBaseOfDll), AInfo);
|
||||
Result := TDbgLibrary.Create(Self, FormatAddress(AInfo.lpBaseOfDll), AInfo);
|
||||
FLibMap.Add(TDbgPtr(AInfo.lpBaseOfDll), Result);
|
||||
end;
|
||||
|
||||
@ -672,7 +660,7 @@ begin
|
||||
Context^.ContextFlags := CONTEXT_CONTROL;
|
||||
if not GetThreadContext(Thread.Handle, Context^)
|
||||
then begin
|
||||
Log('Break $s: Unable to get context', [FormatAdress(FLocation)]);
|
||||
Log('Break $s: Unable to get context', [FormatAddress(FLocation)]);
|
||||
Exit;
|
||||
end;
|
||||
|
||||
@ -685,7 +673,7 @@ begin
|
||||
|
||||
if not SetThreadContext(Thread.Handle, Context^)
|
||||
then begin
|
||||
Log('Break %s: Unable to set context', [FormatAdress(FLocation)]);
|
||||
Log('Break %s: Unable to set context', [FormatAddress(FLocation)]);
|
||||
Exit;
|
||||
end;
|
||||
Result := True;
|
||||
|
@ -39,11 +39,17 @@ interface
|
||||
|
||||
uses
|
||||
Windows;
|
||||
|
||||
type
|
||||
TDbgPtr = PtrUInt;
|
||||
|
||||
function FormatAdress(const P): String;
|
||||
function GetLastErrorText(AErrorCode: Cardinal): String; {$IFNDEF FPC} overload; {$ENDIF}
|
||||
function GetLastErrorText: String; {$IFNDEF FPC} overload; {$ENDIF}
|
||||
|
||||
function FormatAddress(const P): String;
|
||||
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;
|
||||
@ -59,7 +65,7 @@ uses
|
||||
//function Wow64GetThreadContext(hThread: THandle; var lpContext: TContext): BOOL; stdcall; external 'kernel32';
|
||||
|
||||
|
||||
function FormatAdress(const P): String;
|
||||
function FormatAddress(const P): String;
|
||||
begin
|
||||
case GMode of
|
||||
dm32: Result := '$' + IntToHex(DWord(p), 8);
|
||||
@ -106,5 +112,16 @@ begin
|
||||
Result := Pointer(((PtrUInt(Src) + Alignment - 1) and not PtrUInt(Alignment - 1)));
|
||||
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.
|
||||
|
||||
|
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