[Lldb-commits] [lldb] 862fffd - [lldb/qemu] Set qemu's "ld prefix" based on the platform sysroot

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Mon Jan 3 05:53:38 PST 2022


Author: Pavel Labath
Date: 2022-01-03T14:48:13+01:00
New Revision: 862fffd8231c8c44a8ea8071041eac8919aed346

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

LOG: [lldb/qemu] Set qemu's "ld prefix" based on the platform sysroot

Both serve the same purpose (finding shared libraries) and allow one to
launch a dynamically linked executable by just specifying the platform
sysroot.

Added: 
    

Modified: 
    lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp
    lldb/test/API/qemu/TestQemuLaunch.py

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp b/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp
index 84e10042a97c..dd7546d8fa15 100644
--- a/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp
+++ b/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp
@@ -191,6 +191,8 @@ lldb::ProcessSP PlatformQemuUser::DebugProcess(ProcessLaunchInfo &launch_info,
   launch_info.SetArguments(args, true);
 
   Environment emulator_env = Host::GetEnvironment();
+  if (ConstString sysroot = GetSDKRootDirectory())
+    emulator_env["QEMU_LD_PREFIX"] = sysroot.GetStringRef().str();
   for (const auto &KV : GetGlobalProperties().GetEmulatorEnvVars())
     emulator_env[KV.first()] = KV.second;
   launch_info.GetEnvironment() = ComputeLaunchEnvironment(

diff  --git a/lldb/test/API/qemu/TestQemuLaunch.py b/lldb/test/API/qemu/TestQemuLaunch.py
index e27d7a70fa0b..afa158339b6e 100644
--- a/lldb/test/API/qemu/TestQemuLaunch.py
+++ b/lldb/test/API/qemu/TestQemuLaunch.py
@@ -249,3 +249,11 @@ def test_arg0(self):
 
         self.assertEqual(state["program"], self.getBuildArtifact())
         self.assertEqual(state["0"], "ARG0")
+
+    def test_sysroot(self):
+        sysroot = self.getBuildArtifact("sysroot")
+        self.runCmd("platform select qemu-user --sysroot %s" % sysroot)
+        state = self._run_and_get_state()
+        self.assertEqual(state["environ"]["QEMU_LD_PREFIX"], sysroot)
+        self.assertIn("QEMU_LD_PREFIX",
+                state["environ"]["QEMU_UNSET_ENV"].split(","))


        


More information about the lldb-commits mailing list