* aligned context

* fixed svn properties

git-svn-id: trunk@9154 -
This commit is contained in:
marc 2006-04-21 17:35:41 +00:00
parent 8b2b8e4176
commit f5574b19f9
8 changed files with 61 additions and 52 deletions

View File

@ -1,4 +1,4 @@
{ $Id: $ } { $Id$ }
{ {
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
fpwd - FP standalone windows debugger fpwd - FP standalone windows debugger
@ -11,7 +11,7 @@
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
@created(Mon Apr 10th WET 2006) @created(Mon Apr 10th WET 2006)
@lastmod($Date: $) @lastmod($Date$)
@author(Marc Weustink <marc@@dommelstein.nl>) @author(Marc Weustink <marc@@dommelstein.nl>)
*************************************************************************** ***************************************************************************
@ -44,7 +44,7 @@ uses
FPWDLoop, FPWDLoop,
FPWDPEImage, FPWDPEImage,
FPWDType, FPWDType,
WinDebugger, WindExtra; WinDebugger, WinDExtra;
function CtrlCHandler(CtrlType: Cardinal): BOOL; stdcall; function CtrlCHandler(CtrlType: Cardinal): BOOL; stdcall;
begin begin
@ -69,11 +69,11 @@ end;
var var
S, Last: String; S, Last: String;
begin begin
WriteLN('MWDebugger starting...'); WriteLN('FPWDebugger starting...');
SetConsoleCtrlHandler(@CtrlCHandler, True); SetConsoleCtrlHandler(@CtrlCHandler, True);
repeat repeat
Write('MWD>'); Write('FPWD>');
ReadLn(S); ReadLn(S);
if S <> '' if S <> ''
then Last := S; then Last := S;

View File

@ -1,4 +1,4 @@
{ $Id: $ } { $Id$ }
{ {
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
fpwdcommand.pas - FP standalone windows debugger - Command interpreter fpwdcommand.pas - FP standalone windows debugger - Command interpreter
@ -9,7 +9,7 @@
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
@created(Mon Apr 10th WET 2006) @created(Mon Apr 10th WET 2006)
@lastmod($Date: $) @lastmod($Date$)
@author(Marc Weustink <marc@@dommelstein.nl>) @author(Marc Weustink <marc@@dommelstein.nl>)
*************************************************************************** ***************************************************************************
@ -255,9 +255,9 @@ begin
Size := 4; Size := 4;
{$ifdef cpui386} {$ifdef cpui386}
Adress := GCurrentContext.Eip; Adress := GCurrentContext^.Eip;
{$else} {$else}
Adress := GCurrentContext.Rip; Adress := GCurrentContext^.Rip;
{$endif} {$endif}
if P[idx] <> '' if P[idx] <> ''
@ -421,12 +421,12 @@ begin
end; end;
{$ifdef cpui386} {$ifdef cpui386}
Adress := GCurrentContext.Eip; Adress := GCurrentContext^.Eip;
Frame := GCurrentContext.Ebp; Frame := GCurrentContext^.Ebp;
Size := 4; Size := 4;
{$else} {$else}
Adress := GCurrentContext.Rip; Adress := GCurrentContext^.Rip;
Frame := GCurrentContext.Rdi; Frame := GCurrentContext^.Rdi;
Size := 8; Size := 8;
{$endif} {$endif}

View File

@ -1,4 +1,4 @@
{ $Id: $ } { $Id$ }
{ {
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
fpwdglobal.pas - FP standalone windows debugger - Globals fpwdglobal.pas - FP standalone windows debugger - Globals
@ -9,7 +9,7 @@
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
@created(Mon Apr 10th WET 2006) @created(Mon Apr 10th WET 2006)
@lastmod($Date: $) @lastmod($Date$)
@author(Marc Weustink <marc@@dommelstein.nl>) @author(Marc Weustink <marc@@dommelstein.nl>)
*************************************************************************** ***************************************************************************
@ -50,7 +50,8 @@ var
{$else} {$else}
GMode: TMWDMode = dm64; GMode: TMWDMode = dm64;
{$endif} {$endif}
GCurrentContext: TContext;
GCurrentContext: PContext;
GMainProcess: TDbgProcess = nil; GMainProcess: TDbgProcess = nil;
GCurrentProcess: TDbgProcess = nil; GCurrentProcess: TDbgProcess = nil;
@ -68,11 +69,19 @@ begin
// then Log('Unknown Process ID %u', [AID]); // then Log('Unknown Process ID %u', [AID]);
end; end;
var
_UnAligendContext: record
C: TContext;
dummy: array[1..16] of byte;
end;
initialization initialization
GState := dsStop; GState := dsStop;
GProcessMap := TMap.Create(itu4, SizeOf(TDbgProcess));; GProcessMap := TMap.Create(itu4, SizeOf(TDbgProcess));
PtrUInt(GCurrentContext) := (PtrUInt(@_UnAligendContext) + 15) and not PtrUInt($F);
finalization finalization
FreeAndNil(GProcessMap) FreeAndNil(GProcessMap)

View File

@ -10,7 +10,7 @@
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
@created(Mon Apr 10th WET 2006) @created(Mon Apr 10th WET 2006)
@lastmod($Date: $) @lastmod($Date$)
@author(Marc Weustink <marc@@dommelstein.nl>) @author(Marc Weustink <marc@@dommelstein.nl>)
*************************************************************************** ***************************************************************************
@ -48,10 +48,9 @@ uses
FPWDGlobal, FPWDPEImage, FPWDType; FPWDGlobal, FPWDPEImage, FPWDType;
var var
MDebugEvent: TDebugEvent64; MDebugEvent: TDebugEvent;
MDebugEvent32: TDebugEvent absolute MDebugEvent;
procedure HandleCreateProcess(const AEvent: TDebugEvent64); procedure HandleCreateProcess(const AEvent: TDebugEvent);
var var
Proc: TDbgProcess; Proc: TDbgProcess;
S: String; S: String;
@ -60,7 +59,7 @@ begin
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: ', FormatAdress(AEvent.CreateProcessInfo.lpBaseOfImage));
WriteLN('Base adress64: $', IntToHex(PInt64(@AEvent.CreateProcessInfo.lpBaseOfImage)^, 16)); // WriteLN('Base adress64: $', IntToHex(PInt64(@AEvent.CreateProcessInfo.lpBaseOfImage)^, 16));
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]));
@ -76,12 +75,12 @@ begin
GProcessMap.Add(AEvent.dwProcessId, Proc); GProcessMap.Add(AEvent.dwProcessId, Proc);
end; end;
procedure HandleCreateThread(const AEvent: TDebugEvent64); procedure HandleCreateThread(const AEvent: TDebugEvent);
begin begin
WriteLN(Format('Start adress: 0x%p', [AEvent.CreateThread.lpStartAddress])); WriteLN(Format('Start adress: 0x%p', [AEvent.CreateThread.lpStartAddress]));
end; end;
procedure HandleException(const AEvent: TDebugEvent64); procedure HandleException(const AEvent: TDebugEvent);
var var
N: Integer; N: Integer;
Info0: QWORD; Info0: QWORD;
@ -184,7 +183,7 @@ begin
GState := dsPause; GState := dsPause;
end; end;
procedure HandleExitProcess(const AEvent: TDebugEvent64); procedure HandleExitProcess(const AEvent: TDebugEvent);
var var
Proc: TDbgProcess; Proc: TDbgProcess;
begin begin
@ -197,12 +196,12 @@ begin
WriteLN('Process stopped with exitcode: ', AEvent.ExitProcess.dwExitCode); WriteLN('Process stopped with exitcode: ', AEvent.ExitProcess.dwExitCode);
end; end;
procedure HandleExitThread(const AEvent: TDebugEvent64); procedure HandleExitThread(const AEvent: TDebugEvent);
begin begin
WriteLN('Exitcode: ', AEvent.ExitThread.dwExitCode); WriteLN('Exitcode: ', AEvent.ExitThread.dwExitCode);
end; end;
procedure HandleLoadDll(const AEvent: TDebugEvent64); procedure HandleLoadDll(const AEvent: TDebugEvent);
//var //var
// Proc: TDbgProcess; // Proc: TDbgProcess;
// Lib: TDbgLibrary; // Lib: TDbgLibrary;
@ -218,7 +217,7 @@ begin
// end; // end;
end; end;
procedure HandleOutputDebug(const AEvent: TDebugEvent64); procedure HandleOutputDebug(const AEvent: TDebugEvent);
var var
Proc: TDbgProcess; Proc: TDbgProcess;
S: String; S: String;
@ -239,13 +238,13 @@ begin
WriteLN('[', AEvent.dwProcessId, ':', AEvent.dwThreadId, '] ', S); WriteLN('[', AEvent.dwProcessId, ':', AEvent.dwThreadId, '] ', S);
end; end;
procedure HandleRipEvent(const AEvent: TDebugEvent64); procedure HandleRipEvent(const AEvent: TDebugEvent);
begin begin
WriteLN('Error: ', AEvent.RipInfo.dwError); WriteLN('Error: ', AEvent.RipInfo.dwError);
WriteLN('Type: ', AEvent.RipInfo.dwType); WriteLN('Type: ', AEvent.RipInfo.dwType);
end; end;
procedure HandleUnloadDll(const AEvent: TDebugEvent64); procedure HandleUnloadDll(const AEvent: TDebugEvent);
begin begin
WriteLN('Base adress: ', FormatAdress(AEvent.UnloadDll.lpBaseOfDll)); WriteLN('Base adress: ', FormatAdress(AEvent.UnloadDll.lpBaseOfDll));
end; end;
@ -265,10 +264,10 @@ procedure DebugLoop;
if GCurrentThread = nil then Exit; if GCurrentThread = nil then Exit;
{$ifdef cpui386} {$ifdef cpui386}
with GCurrentContext do WriteLN(Format('DS: 0x%x, ES: 0x%x, FS: 0x%x, GS: 0x%x', [SegDs, SegEs, SegFs, SegGs])); with GCurrentContext^ do WriteLN(Format('DS: 0x%x, ES: 0x%x, FS: 0x%x, GS: 0x%x', [SegDs, SegEs, SegFs, SegGs]));
with GCurrentContext do WriteLN(Format('EAX: 0x%x, EBX: 0x%x, ECX: 0x%x, EDX: 0x%x, EDI: 0x%x, ESI: 0x%x', [Eax, Ebx, Ecx, Edx, Edi, Esi])); with GCurrentContext^ do WriteLN(Format('EAX: 0x%x, EBX: 0x%x, ECX: 0x%x, EDX: 0x%x, EDI: 0x%x, ESI: 0x%x', [Eax, Ebx, Ecx, Edx, Edi, Esi]));
with GCurrentContext do WriteLN(Format('CS: 0x%x, SS: 0x%x, EBP: 0x%x, EIP: 0x%x, ESP: 0x%x, EFlags: 0x%x', [SegCs, SegSs, Ebp, Eip, Esp, EFlags])); with GCurrentContext^ do WriteLN(Format('CS: 0x%x, SS: 0x%x, EBP: 0x%x, EIP: 0x%x, ESP: 0x%x, EFlags: 0x%x', [SegCs, SegSs, Ebp, Eip, Esp, EFlags]));
with GCurrentContext do with GCurrentContext^ do
begin begin
Write(Format('DR0: 0x%x, DR1: 0x%x, DR2: 0x%x, DR3: 0x%x', [Dr0, Dr1, Dr2, Dr3])); Write(Format('DR0: 0x%x, DR1: 0x%x, DR2: 0x%x, DR3: 0x%x', [Dr0, Dr1, Dr2, Dr3]));
Write(' DR6: 0x', IntToHex(Dr6, 8), ' ['); Write(' DR6: 0x', IntToHex(Dr6, 8), ' [');
@ -308,9 +307,9 @@ procedure DebugLoop;
WriteLN(']'); WriteLN(']');
end; end;
{$else} {$else}
with GCurrentContext do WriteLN(Format('SegDS: 0x%4.4x, SegES: 0x%4.4x, SegFS: 0x%4.4x, SegGS: 0x%4.4x', [SegDs, SegEs, SegFs, SegGs])); with GCurrentContext^ do WriteLN(Format('SegDS: 0x%4.4x, SegES: 0x%4.4x, SegFS: 0x%4.4x, SegGS: 0x%4.4x', [SegDs, SegEs, SegFs, SegGs]));
with GCurrentContext do WriteLN(Format('RAX: 0x%16.16x, RBX: 0x%16.16x, RCX: 0x%16.16x, RDX: 0x%16.16x, RDI: 0x%16.16x, RSI: 0x%16.16x, R9: 0x%16.16x, R10: 0x%16.16x, R11: 0x%16.16x, R12: 0x%16.16x, R13: 0x%16.16x, R14: 0x%16.16x, R15: 0x%16.16x', [Rax, Rbx, Rcx, Rdx, Rdi, Rsi, R9, R10, R11, R12, R13, R14, R15])); with GCurrentContext^ do WriteLN(Format('RAX: 0x%16.16x, RBX: 0x%16.16x, RCX: 0x%16.16x, RDX: 0x%16.16x, RDI: 0x%16.16x, RSI: 0x%16.16x, R9: 0x%16.16x, R10: 0x%16.16x, R11: 0x%16.16x, R12: 0x%16.16x, R13: 0x%16.16x, R14: 0x%16.16x, R15: 0x%16.16x', [Rax, Rbx, Rcx, Rdx, Rdi, Rsi, R9, R10, R11, R12, R13, R14, R15]));
with GCurrentContext do WriteLN(Format('SegCS: 0x%4.4x, SegSS: 0x%4.4x, RBP: 0x%16.16x, RIP: 0x%16.16x, RSP: 0x%16.16x, EFlags: 0x%8.8x', [SegCs, SegSs, Rbp, Rip, Rsp, EFlags])); with GCurrentContext^ do WriteLN(Format('SegCS: 0x%4.4x, SegSS: 0x%4.4x, RBP: 0x%16.16x, RIP: 0x%16.16x, RSP: 0x%16.16x, EFlags: 0x%8.8x', [SegCs, SegSs, Rbp, Rip, Rsp, EFlags]));
{$endif} {$endif}
WriteLN('---'); WriteLN('---');
end; end;
@ -319,7 +318,7 @@ begin
repeat repeat
if (GCurrentProcess <> nil) and (GState = dsPause) if (GCurrentProcess <> nil) and (GState = dsPause)
then begin then begin
GCurrentProcess.ContinueDebugEvent(GCurrentThread, MDebugEvent32); GCurrentProcess.ContinueDebugEvent(GCurrentThread, MDebugEvent);
end; end;
if GState in [dsStop, dsPause, dsEvent] if GState in [dsStop, dsPause, dsEvent]
@ -333,7 +332,7 @@ begin
GState := dsRun; GState := dsRun;
end; end;
if not WaitForDebugEvent(MDebugEvent32, 10) then Continue; if not WaitForDebugEvent(MDebugEvent, 10) then Continue;
GCurrentProcess := nil; GCurrentProcess := nil;
GCurrentThread := nil; GCurrentThread := nil;
@ -342,7 +341,7 @@ begin
GState := dsEvent; GState := dsEvent;
if GCurrentProcess <> nil if GCurrentProcess <> nil
then begin then begin
if GCurrentProcess.HandleDebugEvent(MDebugEvent32) then Continue; if GCurrentProcess.HandleDebugEvent(MDebugEvent) then Continue;
if not GCurrentProcess.GetThread(MDebugEvent.dwTHreadID, GCurrentThread) if not GCurrentProcess.GetThread(MDebugEvent.dwTHreadID, GCurrentThread)
then WriteLN('LOOP: Unable to retrieve current thread') then WriteLN('LOOP: Unable to retrieve current thread')
else WriteLN('LOOP: ID:', MDebugEvent.dwTHreadID, ' -> H:', GCurrentThread.Handle); else WriteLN('LOOP: ID:', MDebugEvent.dwTHreadID, ' -> H:', GCurrentThread.Handle);
@ -354,15 +353,15 @@ begin
then begin then begin
// TODO: move to TDbgThread // TODO: move to TDbgThread
{$ifdef cpui386} {$ifdef cpui386}
GCurrentContext.ContextFlags := CONTEXT_SEGMENTS or CONTEXT_INTEGER or CONTEXT_CONTROL {or CONTEXT_DEBUG_REGISTERS}; GCurrentContext^.ContextFlags := CONTEXT_SEGMENTS or CONTEXT_INTEGER or CONTEXT_CONTROL {or CONTEXT_DEBUG_REGISTERS};
{$else} {$else}
GCurrentContext.ContextFlags := CONTEXT_SEGMENTS_AMD64 or CONTEXT_INTEGER_AMD64 or CONTEXT_CONTROL_AMD64; GCurrentContext^.ContextFlags := CONTEXT_SEGMENTS_AMD64 or CONTEXT_INTEGER_AMD64 or CONTEXT_CONTROL_AMD64;
{$endif} {$endif}
SetLastError(0); SetLastError(0);
// SuspendTHread(GCurrentThread.Handle); // SuspendTHread(GCurrentThread.Handle);
if not GetThreadContext(GCurrentThread.Handle, GCurrentContext) if not GetThreadContext(GCurrentThread.Handle, GCurrentContext^)
then WriteLN('LOOP: Unable to retrieve thread context') then WriteLN('LOOP: Unable to retrieve thread context')
else WriteLN('LOOP context: ', IntToHex(GCurrentContext.ContextFlags, 8), ' error: ', GetLastErrorText); else WriteLN('LOOP context: ', IntToHex(GCurrentContext^.ContextFlags, SizeOf(Pointer) * 2), ' error: ', GetLastErrorText);
// ResumeThread(GCurrentThread.Handle); // ResumeThread(GCurrentThread.Handle);
end; end;

View File

@ -1,4 +1,4 @@
{ $Id: $ } { $Id$ }
{ {
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
fpwdpeimage.pas - FP standalone windows debugger - PE Image fpwdpeimage.pas - FP standalone windows debugger - PE Image
@ -10,7 +10,7 @@
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
@created(Mon Apr 10th WET 2006) @created(Mon Apr 10th WET 2006)
@lastmod($Date: $) @lastmod($Date$)
@author(Marc Weustink <marc@@dommelstein.nl>) @author(Marc Weustink <marc@@dommelstein.nl>)
*************************************************************************** ***************************************************************************

View File

@ -10,7 +10,7 @@
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
@created(Mon Apr 10th WET 2006) @created(Mon Apr 10th WET 2006)
@lastmod($Date: $) @lastmod($Date$)
@author(Marc Weustink <marc@@dommelstein.nl>) @author(Marc Weustink <marc@@dommelstein.nl>)
*************************************************************************** ***************************************************************************
@ -163,6 +163,7 @@ type
PRIPInfo64 = QWORD; PRIPInfo64 = QWORD;
*) *)
(*
PDebugEvent64 = ^TDebugEvent64; PDebugEvent64 = ^TDebugEvent64;
_DEBUG_EVENT64 = record _DEBUG_EVENT64 = record
dwDebugEventCode: DWORD; dwDebugEventCode: DWORD;
@ -182,7 +183,7 @@ type
end; end;
TDebugEvent64 = _DEBUG_EVENT64; TDebugEvent64 = _DEBUG_EVENT64;
DEBUG_EVENT64 = _DEBUG_EVENT64; DEBUG_EVENT64 = _DEBUG_EVENT64;
*)
const const
CONTEXT_AMD64 = $100000; CONTEXT_AMD64 = $100000;

View File

@ -1,4 +1,4 @@
{ $Id: $ } { $Id$ }
{ {
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
windebugger.pp - Native windows debugger windebugger.pp - Native windows debugger
@ -9,7 +9,7 @@
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
@created(Mon Apr 10th WET 2006) @created(Mon Apr 10th WET 2006)
@lastmod($Date: $) @lastmod($Date$)
@author(Marc Weustink <marc@@dommelstein.nl>) @author(Marc Weustink <marc@@dommelstein.nl>)
*************************************************************************** ***************************************************************************

View File

@ -1,4 +1,4 @@
{ $Id: $ } { $Id$ }
{ {
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
windextra.pp - Native windows debugger - Extra utilities windextra.pp - Native windows debugger - Extra utilities
@ -9,7 +9,7 @@
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
@created(Mon Apr 10th WET 2006) @created(Mon Apr 10th WET 2006)
@lastmod($Date: $) @lastmod($Date$)
@author(Marc Weustink <marc@@dommelstein.nl>) @author(Marc Weustink <marc@@dommelstein.nl>)
*************************************************************************** ***************************************************************************