https://github.com/sga-sc created https://github.com/llvm/llvm-project/pull/127100
During LLDB testing on slow machines with the remote-linux platform all tests from llgs category fail with python exception `BrokenPipeError`. The main reason of these failures is slow start of lldb-server in gdbserver mode. Due to this desired gdbserver socket does not have time to open by the time the Python script tries to establish a connection. List of failed tests: ``` TestAppleSimulatorOSType.py TestGdbRemoteAttach.py TestGdbRemoteAuxvSupport.py TestGdbRemoteCompletion.py TestGdbRemoteExitCode.py TestGdbRemoteExpeditedRegisters.py TestGdbRemoteHostInfo.py TestGdbRemoteKill.py TestGdbRemoteLaunch.py TestGdbRemoteModuleInfo.py TestGdbRemotePlatformFile.py TestGdbRemoteProcessInfo.py TestGdbRemoteRegisterState.py TestGdbRemoteSaveCore.py TestGdbRemoteSingleStep.py TestGdbRemoteThreadsInStopReply.py TestGdbRemote_qThreadStopInfo.py TestGdbRemote_vCont.py TestLldbGdbServer.py TestNonStop.py TestPtyServer.py TestGdbRemoteAttachWait.py TestGdbRemoteConnection.py TestStubSetSID.py TestGdbRemoteAbort.py TestGdbRemoteSegFault.py TestGdbRemoteLibrariesSvr4Support.py TestGdbRemoteMemoryAllocation.py TestGdbRemoteMemoryTagging.py TestGdbRemoteGPacket.py TestGdbRemoteTargetXmlPacket.py TestGdbRemote_QPassSignals.py TestGdbRemoteThreadName.py TestPartialResume.py TestSignal.py ``` This patch implements an additional check for the opened socket on lldb-server side and fixes this error. >From 1fdc2f811c239bc8992fba9aa8e3d4eb9c76e96a Mon Sep 17 00:00:00 2001 From: Georgiy Samoylov <g.samoy...@syntacore.com> Date: Thu, 6 Feb 2025 13:23:13 +0300 Subject: [PATCH 1/2] [lldb] Fixed a typo --- .../test/tools/lldb-server/gdbremote_testcase.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py index cbe430c92fa7f..cf94bf08a5bce 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py @@ -397,13 +397,13 @@ def connect_to_debug_monitor(self, attach_pid=None): # Schedule debug monitor to be shut down during teardown. logger = self.logger - connect_attemps = 0 + connect_attempts = 0 MAX_CONNECT_ATTEMPTS = 10 - while connect_attemps < MAX_CONNECT_ATTEMPTS: + while connect_attempts < MAX_CONNECT_ATTEMPTS: # Create a socket to talk to the server try: - logger.info("Connect attempt %d", connect_attemps + 1) + logger.info("Connect attempt %d", connect_attempts + 1) self.sock = self.create_socket() self._server = Server(self.sock, server) return server @@ -411,7 +411,7 @@ def connect_to_debug_monitor(self, attach_pid=None): # Ignore, and try again. pass time.sleep(0.5) - connect_attemps += 1 + connect_attempts += 1 # We should close the server here to be safe. server.terminate() >From 8844cd67967e7a55682f2b0fd06e8bebe63dd604 Mon Sep 17 00:00:00 2001 From: Georgiy Samoylov <g.samoy...@syntacore.com> Date: Thu, 6 Feb 2025 13:21:42 +0300 Subject: [PATCH 2/2] [lldb] Added function for socket checking --- .../tools/lldb-server/gdbremote_testcase.py | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py index cf94bf08a5bce..8ee41563da59d 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py @@ -343,6 +343,22 @@ def get_target_byte_order(self): target = self.dbg.CreateTarget(inferior_exe_path) return target.GetByteOrder() + def is_port_opened(self): + connect_port = self.port + + err, retcode, cmd_output = self.run_platform_command(f"netstat -ltn | grep {connect_port} | grep LISTEN") + + self.assertTrue( + err.Success(), + "Failed to get opened tcp sockets: %s, retcode: %d" + % (err.GetCString(), retcode), + ) + + if retcode == 0: + return True + else: + return False + def launch_debug_monitor(self, attach_pid=None, logfile=None): if self.reverse_connect: family, type, proto, _, addr = socket.getaddrinfo( @@ -401,15 +417,17 @@ def connect_to_debug_monitor(self, attach_pid=None): MAX_CONNECT_ATTEMPTS = 10 while connect_attempts < MAX_CONNECT_ATTEMPTS: - # Create a socket to talk to the server - try: - logger.info("Connect attempt %d", connect_attempts + 1) - self.sock = self.create_socket() - self._server = Server(self.sock, server) - return server - except _ConnectionRefused as serr: - # Ignore, and try again. - pass + if self.is_port_opened(): + # Create a socket to talk to the server + try: + logger.info("Connect attempt %d", connect_attempts + 1) + self.sock = self.create_socket() + self._server = Server(self.sock, server) + return server + except _ConnectionRefused as serr: + # Ignore, and try again. + pass + time.sleep(0.5) connect_attempts += 1 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits