Author: Pavel Labath Date: 2021-12-17T13:59:21+01:00 New Revision: 586765c0ee518310612d286f3a731786b4ea4148
URL: https://github.com/llvm/llvm-project/commit/586765c0ee518310612d286f3a731786b4ea4148 DIFF: https://github.com/llvm/llvm-project/commit/586765c0ee518310612d286f3a731786b4ea4148.diff LOG: [lldb/qemu] Add emulator-env-vars setting This setting is for variables we want to pass to the emulator only -- then will be automatically removed from the target environment by our environment diffing code. This variable can be used to pass various QEMU_*** variables (although most of these can be passed through emulator-args as well), as well as any other variables that can affect the operation of the emulator (e.g. LD_LIBRARY_PATH). Added: Modified: lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp lldb/source/Plugins/Platform/QemuUser/PlatformQemuUserProperties.td 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 2542464301dee..67c9484680a42 100644 --- a/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp +++ b/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp @@ -55,6 +55,13 @@ class PluginProperties : public Properties { return result; } + Environment GetEmulatorEnvVars() { + Args args; + m_collection_sp->GetPropertyAtIndexAsArgs(nullptr, ePropertyEmulatorEnvVars, + args); + return Environment(args); + } + Environment GetTargetEnvVars() { Args args; m_collection_sp->GetPropertyAtIndexAsArgs(nullptr, ePropertyTargetEnvVars, @@ -175,8 +182,13 @@ lldb::ProcessSP PlatformQemuUser::DebugProcess(ProcessLaunchInfo &launch_info, get_arg_range(args)); launch_info.SetArguments(args, true); + + Environment emulator_env = Host::GetEnvironment(); + for (const auto &KV : GetGlobalProperties().GetEmulatorEnvVars()) + emulator_env[KV.first()] = KV.second; launch_info.GetEnvironment() = ComputeLaunchEnvironment( - std::move(launch_info.GetEnvironment()), Host::GetEnvironment()); + std::move(launch_info.GetEnvironment()), std::move(emulator_env)); + launch_info.SetLaunchInSeparateProcessGroup(true); launch_info.GetFlags().Clear(eLaunchFlagDebug); launch_info.SetMonitorProcessCallback(ProcessLaunchInfo::NoOpMonitorCallback, diff --git a/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUserProperties.td b/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUserProperties.td index 2792e2cef0349..4e8fbcfd67609 100644 --- a/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUserProperties.td +++ b/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUserProperties.td @@ -13,7 +13,12 @@ let Definition = "platformqemuuser" in { Global, DefaultStringValue<"">, Desc<"Extra arguments to pass to the emulator.">; + def EmulatorEnvVars: Property<"emulator-env-vars", "Dictionary">, + Global, + ElementType<"String">, + Desc<"Extra variables to add to the emulator environment.">; def TargetEnvVars: Property<"target-env-vars", "Dictionary">, + Global, ElementType<"String">, Desc<"Extra variables to add to emulated target environment.">; } diff --git a/lldb/test/API/qemu/TestQemuLaunch.py b/lldb/test/API/qemu/TestQemuLaunch.py index 07d7cb6a82f9d..2e817ede4154d 100644 --- a/lldb/test/API/qemu/TestQemuLaunch.py +++ b/lldb/test/API/qemu/TestQemuLaunch.py @@ -171,7 +171,7 @@ def test_extra_args(self): self.assertEqual(state["fake-arg"], "fake-value") - def test_target_env_vars(self): + def test_env_vars(self): # First clear any global environment to have a clean slate for this test self.runCmd("settings clear target.env-vars") self.runCmd("settings clear target.unset-env-vars") @@ -187,6 +187,10 @@ def cleanup(): del os.environ[var(i)] self.addTearDownHook(cleanup) + # Set some emulator-only variables. + self.set_emulator_setting("emulator-env-vars", + "%s='emulator only'"%var(4)) + # And through the platform setting. self.set_emulator_setting("target-env-vars", "%s='from platform' %s='from platform'" % (var(1), var(2))) @@ -195,11 +199,13 @@ def cleanup(): info = target.GetLaunchInfo() env = info.GetEnvironment() - # Platform settings should trump host values. + # Platform settings should trump host values. Emulator-only variables + # should not be visible. self.assertEqual(env.Get(var(0)), "from host") self.assertEqual(env.Get(var(1)), "from platform") self.assertEqual(env.Get(var(2)), "from platform") self.assertEqual(env.Get(var(3)), "from host") + self.assertIsNone(env.Get(var(4))) # Finally, make some launch_info specific changes. env.Set(var(2), "from target", True) @@ -212,7 +218,8 @@ def cleanup(): state = self._run_and_get_state(target, info) for i in range(4): self.assertEqual(state["environ"][var(i)], "from host") + self.assertEqual(state["environ"][var(4)], "emulator only") self.assertEqual(state["environ"]["QEMU_SET_ENV"], "%s=from platform,%s=from target" % (var(1), var(2))) self.assertEqual(state["environ"]["QEMU_UNSET_ENV"], - "%s,QEMU_SET_ENV,QEMU_UNSET_ENV" % var(3)) + "%s,%s,QEMU_SET_ENV,QEMU_UNSET_ENV" % (var(3), var(4))) _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits