mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-08 14:07:11 +01:00
Detect socket closed or other error and set status to SIGHUP. Do not access FConnection methods that read or write to socket when status = SIGHUP.
Patch/Contributed by ccrause git-svn-id: trunk@62758 -
This commit is contained in:
parent
62facbb44d
commit
93ee5eb352
@ -228,7 +228,7 @@ end;
|
|||||||
|
|
||||||
function TDbgAvrThread.ReadDebugReg(ind: byte; out AVal: PtrUInt): boolean;
|
function TDbgAvrThread.ReadDebugReg(ind: byte; out AVal: PtrUInt): boolean;
|
||||||
begin
|
begin
|
||||||
if TDbgAvrProcess(Process).FIsTerminating then
|
if TDbgAvrProcess(Process).FIsTerminating or (TDbgAvrProcess(Process).FStatus = SIGHUP) then
|
||||||
begin
|
begin
|
||||||
DebugLn(DBG_WARNINGS, 'TDbgRspThread.GetDebugReg called while FIsTerminating is set.');
|
DebugLn(DBG_WARNINGS, 'TDbgRspThread.GetDebugReg called while FIsTerminating is set.');
|
||||||
Result := false;
|
Result := false;
|
||||||
@ -252,7 +252,7 @@ end;
|
|||||||
|
|
||||||
function TDbgAvrThread.WriteDebugReg(ind: byte; AVal: PtrUInt): boolean;
|
function TDbgAvrThread.WriteDebugReg(ind: byte; AVal: PtrUInt): boolean;
|
||||||
begin
|
begin
|
||||||
if TDbgAvrProcess(Process).FIsTerminating then
|
if TDbgAvrProcess(Process).FIsTerminating or (TDbgAvrProcess(Process).FStatus = SIGHUP) then
|
||||||
begin
|
begin
|
||||||
DebugLn(DBG_WARNINGS, 'TDbgRspThread.WriteDebugReg called while FIsTerminating is set.');
|
DebugLn(DBG_WARNINGS, 'TDbgRspThread.WriteDebugReg called while FIsTerminating is set.');
|
||||||
Result := false;
|
Result := false;
|
||||||
@ -296,7 +296,7 @@ begin
|
|||||||
DebugLn(DBG_WARNINGS, 'TDbgRspThread.RequestInternalPause called while FIsTerminating is set.');
|
DebugLn(DBG_WARNINGS, 'TDbgRspThread.RequestInternalPause called while FIsTerminating is set.');
|
||||||
|
|
||||||
Result := False;
|
Result := False;
|
||||||
if FInternalPauseRequested or FIsPaused then
|
if FInternalPauseRequested or FIsPaused or (TDbgAvrProcess(Process).FStatus = SIGHUP) then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
DebugLn(DBG_VERBOSE, 'TDbgRspThread.RequestInternalPause requesting Ctrl-C.');
|
DebugLn(DBG_VERBOSE, 'TDbgRspThread.RequestInternalPause requesting Ctrl-C.');
|
||||||
@ -404,7 +404,7 @@ var
|
|||||||
i: integer;
|
i: integer;
|
||||||
regs: TBytes;
|
regs: TBytes;
|
||||||
begin
|
begin
|
||||||
if TDbgAvrProcess(Process).FIsTerminating then
|
if TDbgAvrProcess(Process).FIsTerminating or (TDbgAvrProcess(Process).FStatus = SIGHUP) then
|
||||||
begin
|
begin
|
||||||
DebugLn(DBG_WARNINGS, 'TDbgRspThread.LoadRegisterValues called while FIsTerminating is set.');
|
DebugLn(DBG_WARNINGS, 'TDbgRspThread.LoadRegisterValues called while FIsTerminating is set.');
|
||||||
exit;
|
exit;
|
||||||
@ -583,7 +583,7 @@ end;
|
|||||||
function TDbgAvrProcess.ReadData(const AAdress: TDbgPtr;
|
function TDbgAvrProcess.ReadData(const AAdress: TDbgPtr;
|
||||||
const ASize: Cardinal; out AData): Boolean;
|
const ASize: Cardinal; out AData): Boolean;
|
||||||
begin
|
begin
|
||||||
if FIsTerminating then
|
if FIsTerminating or (TDbgAvrProcess(Process).FStatus = SIGHUP) then
|
||||||
begin
|
begin
|
||||||
DebugLn(DBG_WARNINGS, 'TDbgRspProcess.ReadData called while FIsTerminating is set.');
|
DebugLn(DBG_WARNINGS, 'TDbgRspProcess.ReadData called while FIsTerminating is set.');
|
||||||
Result := false;
|
Result := false;
|
||||||
@ -597,7 +597,7 @@ end;
|
|||||||
function TDbgAvrProcess.WriteData(const AAdress: TDbgPtr;
|
function TDbgAvrProcess.WriteData(const AAdress: TDbgPtr;
|
||||||
const ASize: Cardinal; const AData): Boolean;
|
const ASize: Cardinal; const AData): Boolean;
|
||||||
begin
|
begin
|
||||||
if FIsTerminating then
|
if FIsTerminating or (TDbgAvrProcess(Process).FStatus = SIGHUP) then
|
||||||
begin
|
begin
|
||||||
DebugLn(DBG_WARNINGS, 'TDbgRspProcess.WriteData called while FIsTerminating is set.');
|
DebugLn(DBG_WARNINGS, 'TDbgRspProcess.WriteData called while FIsTerminating is set.');
|
||||||
Result := false;
|
Result := false;
|
||||||
@ -610,7 +610,7 @@ end;
|
|||||||
procedure TDbgAvrProcess.TerminateProcess;
|
procedure TDbgAvrProcess.TerminateProcess;
|
||||||
begin
|
begin
|
||||||
// Try to prevent access to the RSP socket after it has been closed
|
// Try to prevent access to the RSP socket after it has been closed
|
||||||
if not FIsTerminating then
|
if not (FIsTerminating or (TDbgAvrProcess(Process).FStatus = SIGHUP)) then
|
||||||
begin
|
begin
|
||||||
DebugLn(DBG_VERBOSE, 'Removing all break points');
|
DebugLn(DBG_VERBOSE, 'Removing all break points');
|
||||||
RemoveAllBreakPoints;
|
RemoveAllBreakPoints;
|
||||||
@ -622,7 +622,7 @@ end;
|
|||||||
|
|
||||||
function TDbgAvrProcess.Pause: boolean;
|
function TDbgAvrProcess.Pause: boolean;
|
||||||
begin
|
begin
|
||||||
if FIsTerminating then
|
if FIsTerminating or (TDbgAvrProcess(Process).FStatus = SIGHUP) then
|
||||||
begin
|
begin
|
||||||
DebugLn(DBG_WARNINGS, 'TDbgRspProcess.Pause called while FIsTerminating is set.');
|
DebugLn(DBG_WARNINGS, 'TDbgRspProcess.Pause called while FIsTerminating is set.');
|
||||||
Result := false;
|
Result := false;
|
||||||
@ -660,7 +660,7 @@ var
|
|||||||
initRegs: TInitializedRegisters;
|
initRegs: TInitializedRegisters;
|
||||||
begin
|
begin
|
||||||
// Terminating process and all threads
|
// Terminating process and all threads
|
||||||
if FIsTerminating then
|
if FIsTerminating or (FStatus = SIGHUP) then
|
||||||
begin
|
begin
|
||||||
AThread.BeforeContinue;
|
AThread.BeforeContinue;
|
||||||
TDbgAvrThread(AThread).InvalidateRegisters;
|
TDbgAvrThread(AThread).InvalidateRegisters;
|
||||||
@ -791,7 +791,7 @@ end;
|
|||||||
function TDbgAvrProcess.InsertBreakInstructionCode(const ALocation: TDBGPtr;
|
function TDbgAvrProcess.InsertBreakInstructionCode(const ALocation: TDBGPtr;
|
||||||
out OrigValue: Byte): Boolean;
|
out OrigValue: Byte): Boolean;
|
||||||
begin
|
begin
|
||||||
if FIsTerminating then
|
if FIsTerminating or (FStatus = SIGHUP) then
|
||||||
DebugLn(DBG_WARNINGS, 'TDbgRspProcess.InsertBreakInstruction called while FIsTerminating is set.');
|
DebugLn(DBG_WARNINGS, 'TDbgRspProcess.InsertBreakInstruction called while FIsTerminating is set.');
|
||||||
|
|
||||||
result := ReadData(ALocation, SizeOf(OrigValue), OrigValue);
|
result := ReadData(ALocation, SizeOf(OrigValue), OrigValue);
|
||||||
@ -809,7 +809,7 @@ end;
|
|||||||
function TDbgAvrProcess.RemoveBreakInstructionCode(const ALocation: TDBGPtr;
|
function TDbgAvrProcess.RemoveBreakInstructionCode(const ALocation: TDBGPtr;
|
||||||
const OrigValue: Byte): Boolean;
|
const OrigValue: Byte): Boolean;
|
||||||
begin
|
begin
|
||||||
if FIsTerminating then
|
if FIsTerminating or (FStatus = SIGHUP) then
|
||||||
begin
|
begin
|
||||||
DebugLn(DBG_WARNINGS, 'TDbgRspProcess.RemoveBreakInstructionCode called while FIsTerminating is set');
|
DebugLn(DBG_WARNINGS, 'TDbgRspProcess.RemoveBreakInstructionCode called while FIsTerminating is set');
|
||||||
result := false;
|
result := false;
|
||||||
|
|||||||
@ -122,7 +122,7 @@ implementation
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
LazLoggerBase, StrUtils,
|
LazLoggerBase, StrUtils,
|
||||||
{$IFNDEF WINDOWS}BaseUnix;
|
{$IFNDEF WINDOWS}BaseUnix, termio;
|
||||||
{$ELSE}winsock2, windows;
|
{$ELSE}winsock2, windows;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
@ -157,26 +157,25 @@ function TRspConnection.FWaitForData({timeout: integer}): boolean;
|
|||||||
{$if defined(unix) or defined(windows)}
|
{$if defined(unix) or defined(windows)}
|
||||||
var
|
var
|
||||||
FDS: TFDSet;
|
FDS: TFDSet;
|
||||||
//TimeV: TTimeVal;
|
r: integer;
|
||||||
{$endif}
|
{$endif}
|
||||||
begin
|
begin
|
||||||
Result:=False;
|
Result:=False;
|
||||||
//{$if defined(unix) or defined(windows)}
|
{$if defined(unix)}
|
||||||
// TimeV.tv_usec := timeout * 1000; // 1 msec
|
|
||||||
// TimeV.tv_sec := 0;
|
|
||||||
//{$endif}
|
|
||||||
{$ifdef unix}
|
|
||||||
FDS := Default(TFDSet);
|
FDS := Default(TFDSet);
|
||||||
fpFD_Zero(FDS);
|
fpFD_Zero(FDS);
|
||||||
fpFD_Set(self.Handle, FDS);
|
fpFD_Set(self.Handle, FDS);
|
||||||
Result := fpSelect(self.Handle + 1, @FDS, nil, nil, nil{@TimeV}) > 0;
|
fpSelect(self.Handle + 1, @FDS, nil, nil, nil);
|
||||||
{$else}
|
// FDS is set even if the socket has been closed.
|
||||||
{$ifdef windows}
|
// Read available data and if 0 data is available then socket must be closed/ or error
|
||||||
|
r := 0;
|
||||||
|
FpIOCtl(self.Handle, FIONREAD, @r);
|
||||||
|
Result := r > 0;
|
||||||
|
{$elseif defined(windows)}
|
||||||
FDS := Default(TFDSet);
|
FDS := Default(TFDSet);
|
||||||
FD_Zero(FDS);
|
FD_Zero(FDS);
|
||||||
FD_Set(self.Handle, FDS);
|
FD_Set(self.Handle, FDS);
|
||||||
Result := Select(self.Handle + 1, @FDS, nil, nil, nil{@TimeV}) > 0;
|
Result := Select(self.Handle + 1, @FDS, nil, nil, nil) > SOCKET_ERROR;
|
||||||
{$endif}
|
|
||||||
{$endif}
|
{$endif}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -439,6 +438,7 @@ begin
|
|||||||
if not FWaitForData() then
|
if not FWaitForData() then
|
||||||
begin
|
begin
|
||||||
msg := '';
|
msg := '';
|
||||||
|
result := SIGHUP;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user