DebuggerGDBMI: improve checks if gdb is running. Fix crash when gdb can not be launched. Issue #0027003

git-svn-id: trunk@47377 -
This commit is contained in:
martin 2015-01-14 01:14:23 +00:00
parent 9dde3160c2
commit c9ba4326e2
3 changed files with 37 additions and 14 deletions

View File

@ -329,26 +329,36 @@ end;
function TCmdLineDebugger.CreateDebugProcess(const AOptions: String): Boolean;
begin
Result := False;
if FDbgProcess = nil
then begin
FDbgProcess := TProcessUTF8.Create(nil);
FDbgProcess.CommandLine := ExternalDebugger + ' ' + AOptions;
// TODO: under win9x and winMe should be created with console,
// otherwise no break can be sent.
FDbgProcess.Options:= [poUsePipes, poNoConsole, poStdErrToOutPut, poNewProcessGroup];
FDbgProcess.ShowWindow := swoNone;
FDbgProcess.Environment:=DebuggerEnvironment;
try
FDbgProcess.CommandLine := ExternalDebugger + ' ' + AOptions;
// TODO: under win9x and winMe should be created with console,
// otherwise no break can be sent.
FDbgProcess.Options:= [poUsePipes, poNoConsole, poStdErrToOutPut, poNewProcessGroup];
FDbgProcess.ShowWindow := swoNone;
FDbgProcess.Environment:=DebuggerEnvironment;
except
FreeAndNil(FDbgProcess);
end;
end;
if not FDbgProcess.Running
if FDbgProcess = nil then exit;
if not FDbgProcess.Running
then begin
try
FDbgProcess.Execute;
DebugLn('[TCmdLineDebugger] Debug PID: ', IntToStr(FDbgProcess.Handle));
Result := FDbgProcess.Running;
except
on E: Exception do DebugLn('Exeption while executing debugger: ', E.Message);
on E: Exception do begin
FOutputBuf := E.Message;
DebugLn('Exeption while executing debugger: ', FOutputBuf);
end;
end;
end;
Result := FDbgProcess.Running;
end;
destructor TCmdLineDebugger.Destroy;
@ -430,6 +440,16 @@ begin
// TODO: get extra handles to wait for
// TODO: Fix multiple peeks
Result := '';
if not DebugProcessRunning then begin
if FOutputBuf <> '' then begin
Result := FOutputBuf;
FOutputBuf := '';
exit;
end;
DoReadError;
exit;
end;
FReadLineTimedOut := False;
FReadLineWasAbortedByNested := False;
if FReadLineCallStamp = high(FReadLineCallStamp) then
@ -469,6 +489,10 @@ begin
if FReadLineTimedOut
then break;
if FDbgProcess.Output = nil then begin
DoReadError;
break;
end;
WaitSet := WaitForHandles([FDbgProcess.Output.Handle], ATimeOut);
@ -490,7 +514,7 @@ begin
end;
if ((WaitSet and 1) <> 0)
and (FDbgProcess <> nil)
and DebugProcessRunning
and (ReadData(FDbgProcess.Output, FOutputBuf) > 0)
then Continue; // start lineend search

View File

@ -8622,10 +8622,8 @@ begin
end;
end
else begin
if DebugProcess = nil
then MessageDlg('Debugger', 'Failed to create debug process for unknown reason', mtError, [mbOK], 0)
else MessageDlg('Debugger', Format('Failed to create debug process: %s', [ReadLine(50)]), mtError, [mbOK], 0);
SetState(dsError);
include(FErrorHandlingFlags, ehfDeferReadWriteError);
SetErrorState(gdbmiFailedToLaunchExternalDbg, ReadLine(50));
end;
FGDBPtrSize := CpuNameToPtrSize(FGDBCPU); // will be set in StartDebugging

View File

@ -60,6 +60,7 @@ resourcestring
gdbmiEventLogDebugOutput = 'Debug Output: %s';
gdbmiEventLogProcessExitNormally = 'Process Exit: normally';
gdbmiEventLogProcessExitCode = 'Process Exit: %s';
gdbmiFailedToLaunchExternalDbg = 'Failed to create process for GDB';
gdbmiFailedToTerminateGDBTitle = 'GDB did not terminate';
gdbmiFailedToTerminateGDB = 'The IDE was unable to terminate the GDB process. '
+ 'This process may be left running outside the control of IDE.%0:s'