[Lldb-commits] [lldb] f51c47d - Revert "[lldb/test] Don't use preexec_fn for launching inferiors"

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Tue Jul 5 10:14:31 PDT 2022


Author: Jonas Devlieghere
Date: 2022-07-05T10:12:57-07:00
New Revision: f51c47d987917d18108f0415334f47c75db9e908

URL: https://github.com/llvm/llvm-project/commit/f51c47d987917d18108f0415334f47c75db9e908
DIFF: https://github.com/llvm/llvm-project/commit/f51c47d987917d18108f0415334f47c75db9e908.diff

LOG: Revert "[lldb/test] Don't use preexec_fn for launching inferiors"

This reverts commit b15b1421bc9a11b318b65b489e5fd58dd917db1f because it
breaks GreenDragon [1]. The bot has been red for several days, so
reverting to green while I take a look.

[1] https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/45012/

Added: 
    lldb/test/API/tools/lldb-server/TestGdbRemoteAttachWait.py

Modified: 
    lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
    lldb/packages/Python/lldbsuite/test/lldbtest.py

Removed: 
    lldb/test/API/tools/lldb-server/attach-wait/Makefile
    lldb/test/API/tools/lldb-server/attach-wait/TestGdbRemoteAttachWait.py
    lldb/test/API/tools/lldb-server/attach-wait/main.cpp
    lldb/test/API/tools/lldb-server/attach-wait/shim.cpp


################################################################################
diff  --git a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
index 719131c9248e8..e14c4f8c0d383 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
@@ -4,11 +4,12 @@
 from __future__ import absolute_import
 
 # System modules
+import ctypes
 import itertools
+import os
 import re
 import subprocess
 import sys
-import os
 
 # Third-party modules
 import six
@@ -191,3 +192,14 @@ def hasChattyStderr(test_case):
     if match_android_device(test_case.getArchitecture(), ['aarch64'], range(22, 25+1)):
         return True  # The dynamic linker on the device will complain about unknown DT entries
     return False
+
+if getHostPlatform() == "linux":
+    def enable_attach():
+        """Enable attaching to _this_ process, if host requires such an action.
+        Suitable for use as a preexec_fn in subprocess.Popen and similar."""
+        c = ctypes.CDLL(None)
+        PR_SET_PTRACER = ctypes.c_int(0x59616d61)
+        PR_SET_PTRACER_ANY = ctypes.c_ulong(-1)
+        c.prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY)
+else:
+    enable_attach = None

diff  --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index d46e54f30bd55..22851730153e0 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -393,6 +393,7 @@ def launch(self, executable, args, extra_env):
             stdout=open(
                 os.devnull) if not self._trace_on else None,
             stdin=PIPE,
+            preexec_fn=lldbplatformutil.enable_attach,
             env=env)
 
     def terminate(self):

diff  --git a/lldb/test/API/tools/lldb-server/attach-wait/TestGdbRemoteAttachWait.py b/lldb/test/API/tools/lldb-server/TestGdbRemoteAttachWait.py
similarity index 80%
rename from lldb/test/API/tools/lldb-server/attach-wait/TestGdbRemoteAttachWait.py
rename to lldb/test/API/tools/lldb-server/TestGdbRemoteAttachWait.py
index abcc98d22090c..ed31b5645c336 100644
--- a/lldb/test/API/tools/lldb-server/attach-wait/TestGdbRemoteAttachWait.py
+++ b/lldb/test/API/tools/lldb-server/TestGdbRemoteAttachWait.py
@@ -14,12 +14,10 @@ class TestGdbRemoteAttachWait(gdbremote_testcase.GdbRemoteTestCaseBase):
     @skipIfWindows # This test is flaky on Windows
     def test_attach_with_vAttachWait(self):
         exe = '%s_%d' % (self.testMethodName, os.getpid())
-        exe_to_attach = exe
-        args = []
 
         def launch_inferior():
             inferior = self.launch_process_for_attach(
-                inferior_args=args,
+                inferior_args=["sleep:60"],
                 exe_path=self.getBuildArtifact(exe))
             self.assertIsNotNone(inferior)
             self.assertTrue(inferior.pid > 0)
@@ -28,14 +26,7 @@ def launch_inferior():
                     inferior.pid, True))
             return inferior
 
-        self.build(dictionary={'EXE': exe, 'CXX_SOURCES': 'main.cpp'})
-        if self.getPlatform() != "windows":
-            # Use a shim to ensure that the process is ready to be attached from
-            # the get-go.
-            args = [self.getBuildArtifact(exe)]
-            exe = "shim"
-            self.build(dictionary={'EXE': exe, 'CXX_SOURCES': 'shim.cpp'})
-
+        self.build(dictionary={'EXE': exe})
         self.set_inferior_startup_attach_manually()
 
         server = self.connect_to_debug_monitor()
@@ -47,8 +38,7 @@ def launch_inferior():
         self.do_handshake()
         self.test_sequence.add_log_lines([
             # Do the attach.
-            "read packet: $vAttachWait;{}#00".format(
-                lldbgdbserverutils.gdbremote_hex_encode_string(exe_to_attach)),
+            "read packet: $vAttachWait;{}#00".format(lldbgdbserverutils.gdbremote_hex_encode_string(exe)),
         ], True)
         # Run the stream until attachWait.
         context = self.expect_gdbremote_sequence()

diff  --git a/lldb/test/API/tools/lldb-server/attach-wait/Makefile b/lldb/test/API/tools/lldb-server/attach-wait/Makefile
deleted file mode 100644
index 22f1051530f87..0000000000000
--- a/lldb/test/API/tools/lldb-server/attach-wait/Makefile
+++ /dev/null
@@ -1 +0,0 @@
-include Makefile.rules

diff  --git a/lldb/test/API/tools/lldb-server/attach-wait/main.cpp b/lldb/test/API/tools/lldb-server/attach-wait/main.cpp
deleted file mode 100644
index 891dc9f5e7d15..0000000000000
--- a/lldb/test/API/tools/lldb-server/attach-wait/main.cpp
+++ /dev/null
@@ -1,8 +0,0 @@
-#include <thread>
-
-int main()
-{
-  // Wait to be attached.
-  std::this_thread::sleep_for(std::chrono::minutes(1));
-  return 0;
-}

diff  --git a/lldb/test/API/tools/lldb-server/attach-wait/shim.cpp b/lldb/test/API/tools/lldb-server/attach-wait/shim.cpp
deleted file mode 100644
index 33d75b1957629..0000000000000
--- a/lldb/test/API/tools/lldb-server/attach-wait/shim.cpp
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <unistd.h>
-#include <cstdio>
-
-int main(int argc, char *argv[]) {
-  lldb_enable_attach();
-  execlp(argv[1], argv[1], nullptr);
-  perror("execlp");
-  return 1;
-}


        


More information about the lldb-commits mailing list