Author: Pavel Labath Date: 2021-12-07T14:19:43+01:00 New Revision: 611fdde4c765d1ed213744263cb2bbc04bd5060c
URL: https://github.com/llvm/llvm-project/commit/611fdde4c765d1ed213744263cb2bbc04bd5060c DIFF: https://github.com/llvm/llvm-project/commit/611fdde4c765d1ed213744263cb2bbc04bd5060c.diff LOG: [lldb/qemu] Add emulator-args setting This setting allows the user to pass additional arguments to the qemu instance. While we may want to introduce dedicated settings for the most common qemu arguments (-cpu, for one), having this setting allows us to avoid creating a setting for every possible argument. Differential Revision: https://reviews.llvm.org/D115151 Added: Modified: lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp lldb/source/Plugins/Platform/QemuUser/PlatformQemuUserProperties.td lldb/test/API/qemu/TestQemuLaunch.py lldb/test/API/qemu/qemu.py Removed: ################################################################################ diff --git a/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp b/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp index 36cf0f010b4cc..82b9bc078ce6c 100644 --- a/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp +++ b/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp @@ -47,6 +47,13 @@ class PluginProperties : public Properties { 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 @@ lldb::ProcessSP PlatformQemuUser::DebugProcess(ProcessLaunchInfo &launch_info, 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 index abfab7f59de40..19de9c810841e 100644 --- a/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUserProperties.td +++ b/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUserProperties.td @@ -9,4 +9,8 @@ let Definition = "platformqemuuser" in { 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 index 36a032190a608..259b381d26721 100644 --- a/lldb/test/API/qemu/TestQemuLaunch.py +++ b/lldb/test/API/qemu/TestQemuLaunch.py @@ -20,7 +20,7 @@ class TestQemuLaunch(TestBase): 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 @@ def setUp(self): 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 @@ def test_basic_launch(self): # 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 @@ def test_bad_emulator_path(self): 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 index 97a9efba81a9b..eca85f8ac99b9 100755 --- a/lldb/test/API/qemu/qemu.py +++ b/lldb/test/API/qemu/qemu.py @@ -53,6 +53,7 @@ def main(): 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() _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits