diff --git a/debugger/windebug/fpwd/fpwd.lpr b/debugger/windebug/fpwd/fpwd.lpr index 1062139822..615a892dc6 100644 --- a/debugger/windebug/fpwd/fpwd.lpr +++ b/debugger/windebug/fpwd/fpwd.lpr @@ -1,4 +1,4 @@ -{ $Id: $ } +{ $Id$ } { --------------------------------------------------------------------------- fpwd - FP standalone windows debugger @@ -11,7 +11,7 @@ --------------------------------------------------------------------------- @created(Mon Apr 10th WET 2006) - @lastmod($Date: $) + @lastmod($Date$) @author(Marc Weustink ) *************************************************************************** @@ -44,7 +44,7 @@ uses FPWDLoop, FPWDPEImage, FPWDType, - WinDebugger, WindExtra; + WinDebugger, WinDExtra; function CtrlCHandler(CtrlType: Cardinal): BOOL; stdcall; begin @@ -69,11 +69,11 @@ end; var S, Last: String; begin - WriteLN('MWDebugger starting...'); + WriteLN('FPWDebugger starting...'); SetConsoleCtrlHandler(@CtrlCHandler, True); repeat - Write('MWD>'); + Write('FPWD>'); ReadLn(S); if S <> '' then Last := S; diff --git a/debugger/windebug/fpwd/fpwdcommand.pas b/debugger/windebug/fpwd/fpwdcommand.pas index f0ebf7eee1..f20852c47f 100644 --- a/debugger/windebug/fpwd/fpwdcommand.pas +++ b/debugger/windebug/fpwd/fpwdcommand.pas @@ -1,4 +1,4 @@ -{ $Id: $ } +{ $Id$ } { --------------------------------------------------------------------------- fpwdcommand.pas - FP standalone windows debugger - Command interpreter @@ -9,7 +9,7 @@ --------------------------------------------------------------------------- @created(Mon Apr 10th WET 2006) - @lastmod($Date: $) + @lastmod($Date$) @author(Marc Weustink ) *************************************************************************** @@ -255,9 +255,9 @@ begin Size := 4; {$ifdef cpui386} - Adress := GCurrentContext.Eip; + Adress := GCurrentContext^.Eip; {$else} - Adress := GCurrentContext.Rip; + Adress := GCurrentContext^.Rip; {$endif} if P[idx] <> '' @@ -421,12 +421,12 @@ begin end; {$ifdef cpui386} - Adress := GCurrentContext.Eip; - Frame := GCurrentContext.Ebp; + Adress := GCurrentContext^.Eip; + Frame := GCurrentContext^.Ebp; Size := 4; {$else} - Adress := GCurrentContext.Rip; - Frame := GCurrentContext.Rdi; + Adress := GCurrentContext^.Rip; + Frame := GCurrentContext^.Rdi; Size := 8; {$endif} diff --git a/debugger/windebug/fpwd/fpwdglobal.pas b/debugger/windebug/fpwd/fpwdglobal.pas index 4a1e471e49..e5cf0a001f 100644 --- a/debugger/windebug/fpwd/fpwdglobal.pas +++ b/debugger/windebug/fpwd/fpwdglobal.pas @@ -1,4 +1,4 @@ -{ $Id: $ } +{ $Id$ } { --------------------------------------------------------------------------- fpwdglobal.pas - FP standalone windows debugger - Globals @@ -9,7 +9,7 @@ --------------------------------------------------------------------------- @created(Mon Apr 10th WET 2006) - @lastmod($Date: $) + @lastmod($Date$) @author(Marc Weustink ) *************************************************************************** @@ -50,7 +50,8 @@ var {$else} GMode: TMWDMode = dm64; {$endif} - GCurrentContext: TContext; + + GCurrentContext: PContext; GMainProcess: TDbgProcess = nil; GCurrentProcess: TDbgProcess = nil; @@ -68,11 +69,19 @@ begin // then Log('Unknown Process ID %u', [AID]); end; +var + _UnAligendContext: record + C: TContext; + dummy: array[1..16] of byte; + end; + initialization GState := dsStop; - GProcessMap := TMap.Create(itu4, SizeOf(TDbgProcess));; + GProcessMap := TMap.Create(itu4, SizeOf(TDbgProcess)); + + PtrUInt(GCurrentContext) := (PtrUInt(@_UnAligendContext) + 15) and not PtrUInt($F); finalization FreeAndNil(GProcessMap) diff --git a/debugger/windebug/fpwd/fpwdloop.pas b/debugger/windebug/fpwd/fpwdloop.pas index 316fb8c806..23b928b83f 100644 --- a/debugger/windebug/fpwd/fpwdloop.pas +++ b/debugger/windebug/fpwd/fpwdloop.pas @@ -10,7 +10,7 @@ --------------------------------------------------------------------------- @created(Mon Apr 10th WET 2006) - @lastmod($Date: $) + @lastmod($Date$) @author(Marc Weustink ) *************************************************************************** @@ -48,10 +48,9 @@ uses FPWDGlobal, FPWDPEImage, FPWDType; var - MDebugEvent: TDebugEvent64; - MDebugEvent32: TDebugEvent absolute MDebugEvent; + MDebugEvent: TDebugEvent; -procedure HandleCreateProcess(const AEvent: TDebugEvent64); +procedure HandleCreateProcess(const AEvent: TDebugEvent); var Proc: TDbgProcess; S: String; @@ -60,7 +59,7 @@ begin 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 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('Debugoffset: %d', [AEvent.CreateProcessInfo.dwDebugInfoFileOffset])); @@ -76,12 +75,12 @@ begin GProcessMap.Add(AEvent.dwProcessId, Proc); end; -procedure HandleCreateThread(const AEvent: TDebugEvent64); +procedure HandleCreateThread(const AEvent: TDebugEvent); begin WriteLN(Format('Start adress: 0x%p', [AEvent.CreateThread.lpStartAddress])); end; -procedure HandleException(const AEvent: TDebugEvent64); +procedure HandleException(const AEvent: TDebugEvent); var N: Integer; Info0: QWORD; @@ -184,7 +183,7 @@ begin GState := dsPause; end; -procedure HandleExitProcess(const AEvent: TDebugEvent64); +procedure HandleExitProcess(const AEvent: TDebugEvent); var Proc: TDbgProcess; begin @@ -197,12 +196,12 @@ begin WriteLN('Process stopped with exitcode: ', AEvent.ExitProcess.dwExitCode); end; -procedure HandleExitThread(const AEvent: TDebugEvent64); +procedure HandleExitThread(const AEvent: TDebugEvent); begin WriteLN('Exitcode: ', AEvent.ExitThread.dwExitCode); end; -procedure HandleLoadDll(const AEvent: TDebugEvent64); +procedure HandleLoadDll(const AEvent: TDebugEvent); //var // Proc: TDbgProcess; // Lib: TDbgLibrary; @@ -218,7 +217,7 @@ begin // end; end; -procedure HandleOutputDebug(const AEvent: TDebugEvent64); +procedure HandleOutputDebug(const AEvent: TDebugEvent); var Proc: TDbgProcess; S: String; @@ -239,13 +238,13 @@ begin WriteLN('[', AEvent.dwProcessId, ':', AEvent.dwThreadId, '] ', S); end; -procedure HandleRipEvent(const AEvent: TDebugEvent64); +procedure HandleRipEvent(const AEvent: TDebugEvent); begin WriteLN('Error: ', AEvent.RipInfo.dwError); WriteLN('Type: ', AEvent.RipInfo.dwType); end; -procedure HandleUnloadDll(const AEvent: TDebugEvent64); +procedure HandleUnloadDll(const AEvent: TDebugEvent); begin WriteLN('Base adress: ', FormatAdress(AEvent.UnloadDll.lpBaseOfDll)); end; @@ -265,10 +264,10 @@ procedure DebugLoop; if GCurrentThread = nil then Exit; {$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('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 + 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('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 begin Write(Format('DR0: 0x%x, DR1: 0x%x, DR2: 0x%x, DR3: 0x%x', [Dr0, Dr1, Dr2, Dr3])); Write(' DR6: 0x', IntToHex(Dr6, 8), ' ['); @@ -308,9 +307,9 @@ procedure DebugLoop; WriteLN(']'); end; {$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('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('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('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} WriteLN('---'); end; @@ -319,7 +318,7 @@ begin repeat if (GCurrentProcess <> nil) and (GState = dsPause) then begin - GCurrentProcess.ContinueDebugEvent(GCurrentThread, MDebugEvent32); + GCurrentProcess.ContinueDebugEvent(GCurrentThread, MDebugEvent); end; if GState in [dsStop, dsPause, dsEvent] @@ -333,7 +332,7 @@ begin GState := dsRun; end; - if not WaitForDebugEvent(MDebugEvent32, 10) then Continue; + if not WaitForDebugEvent(MDebugEvent, 10) then Continue; GCurrentProcess := nil; GCurrentThread := nil; @@ -342,7 +341,7 @@ begin GState := dsEvent; if GCurrentProcess <> nil then begin - if GCurrentProcess.HandleDebugEvent(MDebugEvent32) then Continue; + if GCurrentProcess.HandleDebugEvent(MDebugEvent) then Continue; if not GCurrentProcess.GetThread(MDebugEvent.dwTHreadID, GCurrentThread) then WriteLN('LOOP: Unable to retrieve current thread') else WriteLN('LOOP: ID:', MDebugEvent.dwTHreadID, ' -> H:', GCurrentThread.Handle); @@ -354,15 +353,15 @@ begin then begin // TODO: move to TDbgThread {$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} - 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} SetLastError(0); // SuspendTHread(GCurrentThread.Handle); - if not GetThreadContext(GCurrentThread.Handle, GCurrentContext) + if not GetThreadContext(GCurrentThread.Handle, GCurrentContext^) 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); end; diff --git a/debugger/windebug/fpwd/fpwdpeimage.pas b/debugger/windebug/fpwd/fpwdpeimage.pas index 24efdc913a..218a56f9c9 100644 --- a/debugger/windebug/fpwd/fpwdpeimage.pas +++ b/debugger/windebug/fpwd/fpwdpeimage.pas @@ -1,4 +1,4 @@ -{ $Id: $ } +{ $Id$ } { --------------------------------------------------------------------------- fpwdpeimage.pas - FP standalone windows debugger - PE Image @@ -10,7 +10,7 @@ --------------------------------------------------------------------------- @created(Mon Apr 10th WET 2006) - @lastmod($Date: $) + @lastmod($Date$) @author(Marc Weustink ) *************************************************************************** diff --git a/debugger/windebug/fpwd/fpwdtype.pas b/debugger/windebug/fpwd/fpwdtype.pas index fca377e4c0..bfd61b329f 100644 --- a/debugger/windebug/fpwd/fpwdtype.pas +++ b/debugger/windebug/fpwd/fpwdtype.pas @@ -10,7 +10,7 @@ --------------------------------------------------------------------------- @created(Mon Apr 10th WET 2006) - @lastmod($Date: $) + @lastmod($Date$) @author(Marc Weustink ) *************************************************************************** @@ -163,6 +163,7 @@ type PRIPInfo64 = QWORD; *) +(* PDebugEvent64 = ^TDebugEvent64; _DEBUG_EVENT64 = record dwDebugEventCode: DWORD; @@ -182,7 +183,7 @@ type end; TDebugEvent64 = _DEBUG_EVENT64; DEBUG_EVENT64 = _DEBUG_EVENT64; - +*) const CONTEXT_AMD64 = $100000; diff --git a/debugger/windebug/windebugger.pp b/debugger/windebug/windebugger.pp index f8d97eb664..f77ba43549 100644 --- a/debugger/windebug/windebugger.pp +++ b/debugger/windebug/windebugger.pp @@ -1,4 +1,4 @@ -{ $Id: $ } +{ $Id$ } { --------------------------------------------------------------------------- windebugger.pp - Native windows debugger @@ -9,7 +9,7 @@ --------------------------------------------------------------------------- @created(Mon Apr 10th WET 2006) - @lastmod($Date: $) + @lastmod($Date$) @author(Marc Weustink ) *************************************************************************** diff --git a/debugger/windebug/windextra.pp b/debugger/windebug/windextra.pp index 0ac1afec6e..b202db4d55 100644 --- a/debugger/windebug/windextra.pp +++ b/debugger/windebug/windextra.pp @@ -1,4 +1,4 @@ -{ $Id: $ } +{ $Id$ } { --------------------------------------------------------------------------- windextra.pp - Native windows debugger - Extra utilities @@ -9,7 +9,7 @@ --------------------------------------------------------------------------- @created(Mon Apr 10th WET 2006) - @lastmod($Date: $) + @lastmod($Date$) @author(Marc Weustink ) ***************************************************************************