Skip to content

Commit 586765c

Browse files
committed
[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).
1 parent d91b5b0 commit 586765c

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ class PluginProperties : public Properties {
5555
return result;
5656
}
5757

58+
Environment GetEmulatorEnvVars() {
59+
Args args;
60+
m_collection_sp->GetPropertyAtIndexAsArgs(nullptr, ePropertyEmulatorEnvVars,
61+
args);
62+
return Environment(args);
63+
}
64+
5865
Environment GetTargetEnvVars() {
5966
Args args;
6067
m_collection_sp->GetPropertyAtIndexAsArgs(nullptr, ePropertyTargetEnvVars,
@@ -175,8 +182,13 @@ lldb::ProcessSP PlatformQemuUser::DebugProcess(ProcessLaunchInfo &launch_info,
175182
get_arg_range(args));
176183

177184
launch_info.SetArguments(args, true);
185+
186+
Environment emulator_env = Host::GetEnvironment();
187+
for (const auto &KV : GetGlobalProperties().GetEmulatorEnvVars())
188+
emulator_env[KV.first()] = KV.second;
178189
launch_info.GetEnvironment() = ComputeLaunchEnvironment(
179-
std::move(launch_info.GetEnvironment()), Host::GetEnvironment());
190+
std::move(launch_info.GetEnvironment()), std::move(emulator_env));
191+
180192
launch_info.SetLaunchInSeparateProcessGroup(true);
181193
launch_info.GetFlags().Clear(eLaunchFlagDebug);
182194
launch_info.SetMonitorProcessCallback(ProcessLaunchInfo::NoOpMonitorCallback,

lldb/source/Plugins/Platform/QemuUser/PlatformQemuUserProperties.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ let Definition = "platformqemuuser" in {
1313
Global,
1414
DefaultStringValue<"">,
1515
Desc<"Extra arguments to pass to the emulator.">;
16+
def EmulatorEnvVars: Property<"emulator-env-vars", "Dictionary">,
17+
Global,
18+
ElementType<"String">,
19+
Desc<"Extra variables to add to the emulator environment.">;
1620
def TargetEnvVars: Property<"target-env-vars", "Dictionary">,
21+
Global,
1722
ElementType<"String">,
1823
Desc<"Extra variables to add to emulated target environment.">;
1924
}

lldb/test/API/qemu/TestQemuLaunch.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def test_extra_args(self):
171171

172172
self.assertEqual(state["fake-arg"], "fake-value")
173173

174-
def test_target_env_vars(self):
174+
def test_env_vars(self):
175175
# First clear any global environment to have a clean slate for this test
176176
self.runCmd("settings clear target.env-vars")
177177
self.runCmd("settings clear target.unset-env-vars")
@@ -187,6 +187,10 @@ def cleanup():
187187
del os.environ[var(i)]
188188
self.addTearDownHook(cleanup)
189189

190+
# Set some emulator-only variables.
191+
self.set_emulator_setting("emulator-env-vars",
192+
"%s='emulator only'"%var(4))
193+
190194
# And through the platform setting.
191195
self.set_emulator_setting("target-env-vars",
192196
"%s='from platform' %s='from platform'" % (var(1), var(2)))
@@ -195,11 +199,13 @@ def cleanup():
195199
info = target.GetLaunchInfo()
196200
env = info.GetEnvironment()
197201

198-
# Platform settings should trump host values.
202+
# Platform settings should trump host values. Emulator-only variables
203+
# should not be visible.
199204
self.assertEqual(env.Get(var(0)), "from host")
200205
self.assertEqual(env.Get(var(1)), "from platform")
201206
self.assertEqual(env.Get(var(2)), "from platform")
202207
self.assertEqual(env.Get(var(3)), "from host")
208+
self.assertIsNone(env.Get(var(4)))
203209

204210
# Finally, make some launch_info specific changes.
205211
env.Set(var(2), "from target", True)
@@ -212,7 +218,8 @@ def cleanup():
212218
state = self._run_and_get_state(target, info)
213219
for i in range(4):
214220
self.assertEqual(state["environ"][var(i)], "from host")
221+
self.assertEqual(state["environ"][var(4)], "emulator only")
215222
self.assertEqual(state["environ"]["QEMU_SET_ENV"],
216223
"%s=from platform,%s=from target" % (var(1), var(2)))
217224
self.assertEqual(state["environ"]["QEMU_UNSET_ENV"],
218-
"%s,QEMU_SET_ENV,QEMU_UNSET_ENV" % var(3))
225+
"%s,%s,QEMU_SET_ENV,QEMU_UNSET_ENV" % (var(3), var(4)))

0 commit comments

Comments
 (0)