From 34f1c7d3894cb093558a356308f219abaff7e6a0 Mon Sep 17 00:00:00 2001 From: martin Date: Wed, 20 Jun 2018 21:34:30 +0000 Subject: [PATCH] LLDB Debugger: fix debugger done and thread terminate git-svn-id: trunk@58362 - --- .../cmdlinedebuggerbase/debugprocess.pas | 20 +++++++++++-------- .../lazdebuggerlldb/lldbdebugger.pas | 8 +++++++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/components/lazdebuggers/cmdlinedebuggerbase/debugprocess.pas b/components/lazdebuggers/cmdlinedebuggerbase/debugprocess.pas index db8e80c596..b3873f09e4 100644 --- a/components/lazdebuggers/cmdlinedebuggerbase/debugprocess.pas +++ b/components/lazdebuggers/cmdlinedebuggerbase/debugprocess.pas @@ -318,6 +318,9 @@ begin if FReadThread <> nil then begin FReadThread.Terminate; FinishedReadingOutput; +debugln(['DESTROY thread destroying']); + FreeAndNil(FReadThread); +debugln(['DESTROY thread destroyed']); end; {$ENDIF} Result := inherited Terminate(AExitCode); @@ -479,6 +482,12 @@ destructor TDebugProcess.Destroy; begin if DebugProcessRunning then StopDebugProcess; // calls FDbgProcess.Release; + + try + FDbgProcess.Destroy; + except + on E: Exception do DebugLn(DBG_WARNINGS, 'Exception while freeing debugger: ', E.Message); + end; inherited Destroy; end; @@ -486,11 +495,11 @@ function TDebugProcess.CreateDebugProcess(const AOptions: String; AnEnvironment: TStrings): Boolean; begin Result := False; + if FDbgProcess = nil then begin FDbgProcess := TDebugAsyncProcess.Create(nil); try - FDbgProcess.ParseCmdLine(FExternalDebugger + ' ' + AOptions); FDbgProcess.Options:= [poUsePipes, poNoConsole, poStdErrToOutPut, poNewProcessGroup]; {$if defined(windows) and not defined(wince)} // under win9x and winMe should be created with console, @@ -499,13 +508,14 @@ begin FDbgProcess.Options:= [poUsePipes, poNewConsole, poStdErrToOutPut, poNewProcessGroup]; {$endif windows} FDbgProcess.ShowWindow := swoNone; - FDbgProcess.Environment:= AnEnvironment; except FreeAndNil(FDbgProcess); end; end; if FDbgProcess = nil then exit; + FDbgProcess.ParseCmdLine(FExternalDebugger + ' ' + AOptions); + FDbgProcess.Environment:= AnEnvironment; FDbgProcess.OnReadData := @DoReadData; FDbgProcess.OnTerminate := @DoTerminate; @@ -531,12 +541,6 @@ debugln(['TDebugProcess.StopDebugProcess FDbgProcess = nil ',FDbgProcess = nil]) if FDbgProcess = nil then exit; FDbgProcess.Terminate(0); - try - FDbgProcess.Destroy; - except - on E: Exception do DebugLn(DBG_WARNINGS, 'Exception while freeing debugger: ', E.Message); - end; - FDbgProcess := nil; end; procedure TDebugProcess.SendCmdLn(const ACommand: String); diff --git a/components/lazdebuggers/lazdebuggerlldb/lldbdebugger.pas b/components/lazdebuggers/lazdebuggerlldb/lldbdebugger.pas index cbeb80d977..6ffee42256 100644 --- a/components/lazdebuggers/lazdebuggerlldb/lldbdebugger.pas +++ b/components/lazdebuggers/lazdebuggerlldb/lldbdebugger.pas @@ -1268,8 +1268,14 @@ procedure TLldbDebugger.Done; begin DebugLnEnter('!!! TLldbDebugger.Done;'); // TODO: cancel all commands - FDebugInstructionQueue.OnDebuggerTerminated := nil; + if FDebugProcess.DebugProcessRunning then begin + FDebugProcess.SendCmdLn('process kill'); + FDebugProcess.SendCmdLn('quit'); + end; + + FDebugInstructionQueue.OnDebuggerTerminated := nil; // TODO: use a flag to prevent this FDebugProcess.StopDebugProcess; + FDebugInstructionQueue.OnDebuggerTerminated := @DoCmdLineDebuggerTerminated; inherited Done; DebugLnExit('!!! TLldbDebugger.Done;'); end;