[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).
This commit is contained in:
Pavel Labath 2021-12-17 13:51:58 +01:00
parent d91b5b0f57
commit 586765c0ee
3 changed files with 28 additions and 4 deletions

View File

@ -55,6 +55,13 @@ public:
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,

View File

@ -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.">;
}

View File

@ -171,7 +171,7 @@ class TestQemuLaunch(TestBase):
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 @@ class TestQemuLaunch(TestBase):
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 @@ class TestQemuLaunch(TestBase):
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 @@ class TestQemuLaunch(TestBase):
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)))