diff --git a/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp b/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp --- a/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp +++ b/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp @@ -47,6 +47,13 @@ return m_collection_sp->GetPropertyAtIndexAsFileSpec(nullptr, ePropertyEmulatorPath); } + + Args GetEmulatorArgs() { + Args result; + m_collection_sp->GetPropertyAtIndexAsArgs(nullptr, ePropertyEmulatorArgs, + result); + return result; + } }; static PluginProperties &GetGlobalProperties() { @@ -112,8 +119,10 @@ llvm::sys::fs::createUniquePath(socket_model, socket_path, false); } while (FileSystem::Instance().Exists(socket_path)); - Args args( - {qemu, "-g", socket_path, launch_info.GetExecutableFile().GetPath()}); + Args args({qemu, "-g", socket_path}); + args.AppendArguments(GetGlobalProperties().GetEmulatorArgs()); + args.AppendArgument("--"); + args.AppendArgument(launch_info.GetExecutableFile().GetPath()); for (size_t i = 1; i < launch_info.GetArguments().size(); ++i) args.AppendArgument(launch_info.GetArguments()[i].ref()); diff --git a/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUserProperties.td b/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUserProperties.td --- a/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUserProperties.td +++ b/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUserProperties.td @@ -9,4 +9,8 @@ Global, DefaultStringValue<"">, Desc<"Path to the emulator binary.">; + def EmulatorArgs: Property<"emulator-args", "Args">, + Global, + DefaultStringValue<"">, + Desc<"Extra arguments to pass to the emulator.">; } diff --git a/lldb/test/API/qemu/TestQemuLaunch.py b/lldb/test/API/qemu/TestQemuLaunch.py --- a/lldb/test/API/qemu/TestQemuLaunch.py +++ b/lldb/test/API/qemu/TestQemuLaunch.py @@ -20,7 +20,7 @@ NO_DEBUG_INFO_TESTCASE = True def set_emulator_setting(self, name, value): - self.runCmd("settings set platform.plugin.qemu-user.%s %s" % + self.runCmd("settings set -- platform.plugin.qemu-user.%s %s" % (name, value)) def setUp(self): @@ -43,7 +43,7 @@ self.set_emulator_setting("architecture", self.getArchitecture()) self.set_emulator_setting("emulator-path", emulator) - def test_basic_launch(self): + def _run_and_get_state(self): self.build() exe = self.getBuildArtifact() @@ -63,7 +63,11 @@ # Verify the qemu invocation parameters. with open(self.getBuildArtifact("state.log")) as s: - state = json.load(s) + return json.load(s) + + def test_basic_launch(self): + state = self._run_and_get_state() + self.assertEqual(state["program"], self.getBuildArtifact()) self.assertEqual(state["args"], ["dump:" + self.getBuildArtifact("state.log")]) @@ -159,3 +163,9 @@ target.Launch(info, error) self.assertTrue(error.Fail()) self.assertIn("doesn't exist", error.GetCString()) + + def test_extra_args(self): + self.set_emulator_setting("emulator-args", "-fake-arg fake-value") + state = self._run_and_get_state() + + self.assertEqual(state["fake-arg"], "fake-value") diff --git a/lldb/test/API/qemu/qemu.py b/lldb/test/API/qemu/qemu.py --- a/lldb/test/API/qemu/qemu.py +++ b/lldb/test/API/qemu/qemu.py @@ -53,6 +53,7 @@ parser = argparse.ArgumentParser(description=_description, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('-g', metavar="unix-socket", required=True) + parser.add_argument('-fake-arg', dest="fake-arg") parser.add_argument('program', help="The program to 'emulate'.") parser.add_argument("args", nargs=argparse.REMAINDER) args = parser.parse_args()