From 96277bbbdba86b62e77e764277c4f0e16276098d Mon Sep 17 00:00:00 2001 From: Charalampos Stratakis Date: Wed, 26 Aug 2026 16:52:07 +0200 Subject: [PATCH] gh-98894: Set LD_LIBRARY_PATH in SystemTap trace commands Prefix commands passed to stap -c with LD_LIBRARY_PATH via env, when probes reside in libpython. This allows the interpreter to find libpython when staprun does not preserve the loader path. --- Lib/test/test_dtrace.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Lib/test/test_dtrace.py b/Lib/test/test_dtrace.py index 4967a18053057b..126e47a20cb7c6 100644 --- a/Lib/test/test_dtrace.py +++ b/Lib/test/test_dtrace.py @@ -229,6 +229,17 @@ def render_script(self, filename): return script.replace(self.PROBE_PLACEHOLDER, self.python_probe()) + def generate_trace_command(self, script_file, subcommand=None): + probe_binary = get_probe_binary() + if subcommand and probe_binary != sys.executable: + library_path = os.path.dirname(probe_binary) + if existing_path := os.environ.get("LD_LIBRARY_PATH"): + library_path = os.pathsep.join((library_path, existing_path)) + env = shlex.join(["env", f"LD_LIBRARY_PATH={library_path}"]) + subcommand = f"{env} {subcommand}" + + return super().generate_trace_command(script_file, subcommand) + def trace(self, script_file, subcommand=None, *, timeout=None, check_returncode=False): with tempfile.NamedTemporaryFile(