From 3f36dd3c5313cce9d8db0c321b632209fe0cccd4 Mon Sep 17 00:00:00 2001 From: joost Date: Sun, 23 Mar 2014 20:54:32 +0000 Subject: [PATCH] FpDbg: Implemented single-stepping on Darwin git-svn-id: trunk@44500 - --- components/fpdebug/app/fpd/fpdloop.pas | 7 ++++--- components/fpdebug/fpdbgclasses.pp | 2 +- components/fpdebug/fpdbgdarwinclasses.pas | 11 +++++++---- components/fpdebug/fpdbgwinclasses.pas | 5 +++-- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/components/fpdebug/app/fpd/fpdloop.pas b/components/fpdebug/app/fpd/fpdloop.pas index e8358894ad..9cb2b4653a 100644 --- a/components/fpdebug/app/fpd/fpdloop.pas +++ b/components/fpdebug/app/fpd/fpdloop.pas @@ -146,6 +146,7 @@ procedure DebugLoop; var AFirstLoop: boolean; AProcessIdentifier: THandle; + AThreadIdentifier: THandle; ALib: TDbgLibrary; begin @@ -156,7 +157,7 @@ begin GState := dsRun; end; - if not GCurrentProcess.WaitForDebugEvent(AProcessIdentifier) then Continue; + if not GCurrentProcess.WaitForDebugEvent(AProcessIdentifier, AThreadIdentifier) then Continue; if assigned(GCurrentProcess) and not assigned(GMainProcess) then begin @@ -172,8 +173,8 @@ begin if AFirstLoop then GCurrentProcess := GMainProcess; - //if not GetThread(MDebugEvent.dwTHreadID, GCurrentThread) - //then WriteLN('LOOP: Unable to retrieve current thread'); + if not GCurrentProcess.GetThread(AThreadIdentifier, GCurrentThread) + then WriteLN('LOOP: Unable to retrieve current thread'); GState := dsEvent; begin diff --git a/components/fpdebug/fpdbgclasses.pp b/components/fpdebug/fpdbgclasses.pp index e500fa0e39..928d615947 100644 --- a/components/fpdebug/fpdbgclasses.pp +++ b/components/fpdebug/fpdbgclasses.pp @@ -169,7 +169,7 @@ type function ReadWString(const AAdress: TDbgPtr; const AMaxSize: Cardinal; out AData: WideString): Boolean; virtual; function Continue(AProcess: TDbgProcess; AThread: TDbgThread; AState: TFPDState): boolean; virtual; - function WaitForDebugEvent(out ProcessIdentifier: THandle): boolean; virtual; abstract; + function WaitForDebugEvent(out ProcessIdentifier, ThreadIdentifier: THandle): boolean; virtual; abstract; function ResolveDebugEvent(AThread: TDbgThread): TFPDEvent; virtual; abstract; function WriteData(const AAdress: TDbgPtr; const ASize: Cardinal; const AData): Boolean; virtual; diff --git a/components/fpdebug/fpdbgdarwinclasses.pas b/components/fpdebug/fpdbgdarwinclasses.pas index 3ac79b2f91..b56743cdf2 100644 --- a/components/fpdebug/fpdbgdarwinclasses.pas +++ b/components/fpdebug/fpdbgdarwinclasses.pas @@ -72,7 +72,7 @@ type function GetStackBasePointerRegisterValue: TDbgPtr; override; function Continue(AProcess: TDbgProcess; AThread: TDbgThread; AState: TFPDState): boolean; override; - function WaitForDebugEvent(out ProcessIdentifier: THandle): boolean; override; + function WaitForDebugEvent(out ProcessIdentifier, ThreadIdentifier: THandle): boolean; override; function ResolveDebugEvent(AThread: TDbgThread): TFPDEvent; override; end; @@ -310,7 +310,10 @@ begin fpPTrace(PTRACE_CONT, ProcessID, nil, nil); {$endif linux} {$ifdef darwin} - fpPTrace(PTRACE_CONT, ProcessID, pointer(1), nil); + if AThread.SingleStepping then + fpPTrace(PTRACE_SINGLESTEP, ProcessID, pointer(1), nil) + else + fpPTrace(PTRACE_CONT, ProcessID, pointer(1), nil); {$endif darwin} e := fpgeterrno; if e <> 0 then @@ -322,7 +325,7 @@ begin result := true; end; -function TDbgDarwinProcess.WaitForDebugEvent(out ProcessIdentifier: THandle): boolean; +function TDbgDarwinProcess.WaitForDebugEvent(out ProcessIdentifier, ThreadIdentifier: THandle): boolean; var aKernResult: kern_return_t; act_list: thread_act_array_t; @@ -354,7 +357,7 @@ begin FMainThread := AThread; end; end; - + ThreadIdentifier:=act_list^[0]; TDbgDarwinThread(FMainThread).ReadThreadState; end end; diff --git a/components/fpdebug/fpdbgwinclasses.pas b/components/fpdebug/fpdbgwinclasses.pas index 69fb372ad3..0612d08bae 100644 --- a/components/fpdebug/fpdbgwinclasses.pas +++ b/components/fpdebug/fpdbgwinclasses.pas @@ -92,7 +92,7 @@ type class function StartInstance(AFileName: string; AParams: string): TDbgProcess; override; function Continue(AProcess: TDbgProcess; AThread: TDbgThread; AState: TFPDState): boolean; override; - function WaitForDebugEvent(out ProcessIdentifier: THandle): boolean; override; + function WaitForDebugEvent(out ProcessIdentifier, ThreadIdentifier: THandle): boolean; override; function ResolveDebugEvent(AThread: TDbgThread): TFPDEvent; override; procedure StartProcess(const AInfo: TCreateProcessDebugInfo); @@ -449,10 +449,11 @@ begin result := true; end; -function TDbgWinProcess.WaitForDebugEvent(out ProcessIdentifier: THandle): boolean; +function TDbgWinProcess.WaitForDebugEvent(out ProcessIdentifier, ThreadIdentifier: THandle): boolean; begin result := Windows.WaitForDebugEvent(MDebugEvent, 10); ProcessIdentifier:=MDebugEvent.dwProcessId; + ThreadIdentifier:=MDebugEvent.dwThreadId; end; function TDbgWinProcess.ResolveDebugEvent(AThread: TDbgThread): TFPDEvent;