mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-15 04:59:16 +02:00
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:
parent
9dde3160c2
commit
c9ba4326e2
@ -329,26 +329,36 @@ end;
|
|||||||
|
|
||||||
function TCmdLineDebugger.CreateDebugProcess(const AOptions: String): Boolean;
|
function TCmdLineDebugger.CreateDebugProcess(const AOptions: String): Boolean;
|
||||||
begin
|
begin
|
||||||
|
Result := False;
|
||||||
if FDbgProcess = nil
|
if FDbgProcess = nil
|
||||||
then begin
|
then begin
|
||||||
FDbgProcess := TProcessUTF8.Create(nil);
|
FDbgProcess := TProcessUTF8.Create(nil);
|
||||||
FDbgProcess.CommandLine := ExternalDebugger + ' ' + AOptions;
|
try
|
||||||
// TODO: under win9x and winMe should be created with console,
|
FDbgProcess.CommandLine := ExternalDebugger + ' ' + AOptions;
|
||||||
// otherwise no break can be sent.
|
// TODO: under win9x and winMe should be created with console,
|
||||||
FDbgProcess.Options:= [poUsePipes, poNoConsole, poStdErrToOutPut, poNewProcessGroup];
|
// otherwise no break can be sent.
|
||||||
FDbgProcess.ShowWindow := swoNone;
|
FDbgProcess.Options:= [poUsePipes, poNoConsole, poStdErrToOutPut, poNewProcessGroup];
|
||||||
FDbgProcess.Environment:=DebuggerEnvironment;
|
FDbgProcess.ShowWindow := swoNone;
|
||||||
|
FDbgProcess.Environment:=DebuggerEnvironment;
|
||||||
|
except
|
||||||
|
FreeAndNil(FDbgProcess);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
if FDbgProcess = nil then exit;
|
||||||
|
|
||||||
if not FDbgProcess.Running
|
if not FDbgProcess.Running
|
||||||
then begin
|
then begin
|
||||||
try
|
try
|
||||||
FDbgProcess.Execute;
|
FDbgProcess.Execute;
|
||||||
DebugLn('[TCmdLineDebugger] Debug PID: ', IntToStr(FDbgProcess.Handle));
|
DebugLn('[TCmdLineDebugger] Debug PID: ', IntToStr(FDbgProcess.Handle));
|
||||||
|
Result := FDbgProcess.Running;
|
||||||
except
|
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;
|
||||||
end;
|
end;
|
||||||
Result := FDbgProcess.Running;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TCmdLineDebugger.Destroy;
|
destructor TCmdLineDebugger.Destroy;
|
||||||
@ -430,6 +440,16 @@ begin
|
|||||||
// TODO: get extra handles to wait for
|
// TODO: get extra handles to wait for
|
||||||
// TODO: Fix multiple peeks
|
// TODO: Fix multiple peeks
|
||||||
Result := '';
|
Result := '';
|
||||||
|
if not DebugProcessRunning then begin
|
||||||
|
if FOutputBuf <> '' then begin
|
||||||
|
Result := FOutputBuf;
|
||||||
|
FOutputBuf := '';
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
DoReadError;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
FReadLineTimedOut := False;
|
FReadLineTimedOut := False;
|
||||||
FReadLineWasAbortedByNested := False;
|
FReadLineWasAbortedByNested := False;
|
||||||
if FReadLineCallStamp = high(FReadLineCallStamp) then
|
if FReadLineCallStamp = high(FReadLineCallStamp) then
|
||||||
@ -469,6 +489,10 @@ begin
|
|||||||
|
|
||||||
if FReadLineTimedOut
|
if FReadLineTimedOut
|
||||||
then break;
|
then break;
|
||||||
|
if FDbgProcess.Output = nil then begin
|
||||||
|
DoReadError;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
|
||||||
WaitSet := WaitForHandles([FDbgProcess.Output.Handle], ATimeOut);
|
WaitSet := WaitForHandles([FDbgProcess.Output.Handle], ATimeOut);
|
||||||
|
|
||||||
@ -490,7 +514,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
if ((WaitSet and 1) <> 0)
|
if ((WaitSet and 1) <> 0)
|
||||||
and (FDbgProcess <> nil)
|
and DebugProcessRunning
|
||||||
and (ReadData(FDbgProcess.Output, FOutputBuf) > 0)
|
and (ReadData(FDbgProcess.Output, FOutputBuf) > 0)
|
||||||
then Continue; // start lineend search
|
then Continue; // start lineend search
|
||||||
|
|
||||||
|
@ -8622,10 +8622,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
if DebugProcess = nil
|
include(FErrorHandlingFlags, ehfDeferReadWriteError);
|
||||||
then MessageDlg('Debugger', 'Failed to create debug process for unknown reason', mtError, [mbOK], 0)
|
SetErrorState(gdbmiFailedToLaunchExternalDbg, ReadLine(50));
|
||||||
else MessageDlg('Debugger', Format('Failed to create debug process: %s', [ReadLine(50)]), mtError, [mbOK], 0);
|
|
||||||
SetState(dsError);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
FGDBPtrSize := CpuNameToPtrSize(FGDBCPU); // will be set in StartDebugging
|
FGDBPtrSize := CpuNameToPtrSize(FGDBCPU); // will be set in StartDebugging
|
||||||
|
@ -60,6 +60,7 @@ resourcestring
|
|||||||
gdbmiEventLogDebugOutput = 'Debug Output: %s';
|
gdbmiEventLogDebugOutput = 'Debug Output: %s';
|
||||||
gdbmiEventLogProcessExitNormally = 'Process Exit: normally';
|
gdbmiEventLogProcessExitNormally = 'Process Exit: normally';
|
||||||
gdbmiEventLogProcessExitCode = 'Process Exit: %s';
|
gdbmiEventLogProcessExitCode = 'Process Exit: %s';
|
||||||
|
gdbmiFailedToLaunchExternalDbg = 'Failed to create process for GDB';
|
||||||
gdbmiFailedToTerminateGDBTitle = 'GDB did not terminate';
|
gdbmiFailedToTerminateGDBTitle = 'GDB did not terminate';
|
||||||
gdbmiFailedToTerminateGDB = 'The IDE was unable to terminate the GDB process. '
|
gdbmiFailedToTerminateGDB = 'The IDE was unable to terminate the GDB process. '
|
||||||
+ 'This process may be left running outside the control of IDE.%0:s'
|
+ 'This process may be left running outside the control of IDE.%0:s'
|
||||||
|
Loading…
Reference in New Issue
Block a user