diff --git a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py index 3d6402c13b47b6..94b133589dcc5a 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 @@ -198,3 +199,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 c377b64e9b9ea3..958cadd3a7c812 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbtest.py +++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py @@ -384,7 +384,8 @@ def launch(self, executable, args): [executable] + args, stdout=open( os.devnull) if not self._trace_on else None, - stdin=PIPE) + stdin=PIPE, + preexec_fn=lldbplatformutil.enable_attach) def terminate(self): if self._proc.poll() is None: