[Lldb-commits] [lldb] 9b8f9d3 - [lldb/qemu] More flexible emulator specification

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Thu Dec 30 06:14:48 PST 2021


Author: Pavel Labath
Date: 2021-12-30T15:14:41+01:00
New Revision: 9b8f9d33dbbcd6525ab4d582cb9abb6f98e3601c

URL: https://github.com/llvm/llvm-project/commit/9b8f9d33dbbcd6525ab4d582cb9abb6f98e3601c
DIFF: https://github.com/llvm/llvm-project/commit/9b8f9d33dbbcd6525ab4d582cb9abb6f98e3601c.diff

LOG: [lldb/qemu] More flexible emulator specification

This small patch adds two useful improvements:
- allows one to specify the emulator path as a bare filename, and have
  it be looked up in the PATH
- allows one to leave the path empty and have the filename be derived
  from the architecture.

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 67c9484680a42..572a5b39985ec 100644
--- a/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp
+++ b/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUser.cpp
@@ -162,7 +162,10 @@ lldb::ProcessSP PlatformQemuUser::DebugProcess(ProcessLaunchInfo &launch_info,
                                                Target &target, Status &error) {
   Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
 
-  std::string qemu = GetGlobalProperties().GetEmulatorPath().GetPath();
+  FileSpec qemu = GetGlobalProperties().GetEmulatorPath();
+  if (!qemu)
+    qemu.SetPath(("qemu-" + GetGlobalProperties().GetArchitecture()).str());
+  FileSystem::Instance().ResolveExecutableLocation(qemu);
 
   llvm::SmallString<0> socket_model, socket_path;
   HostInfo::GetProcessTempDir().GetPath(socket_model);
@@ -171,7 +174,7 @@ 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});
+  Args args({qemu.GetPath(), "-g", socket_path});
   args.AppendArguments(GetGlobalProperties().GetEmulatorArgs());
   args.AppendArgument("--");
   args.AppendArgument(launch_info.GetExecutableFile().GetPath());

diff  --git a/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUserProperties.td b/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUserProperties.td
index 4e8fbcfd67609..c7ec4bbc6e786 100644
--- a/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUserProperties.td
+++ b/lldb/source/Plugins/Platform/QemuUser/PlatformQemuUserProperties.td
@@ -8,7 +8,7 @@ let Definition = "platformqemuuser" in {
   def EmulatorPath: Property<"emulator-path", "FileSpec">,
     Global,
     DefaultStringValue<"">,
-    Desc<"Path to the emulator binary.">;
+    Desc<"Path to the emulator binary. If the path does not contain a directory separator, the filename is looked up in the PATH environment variable. If empty, the filename is derived from the architecture setting.">;
   def EmulatorArgs: Property<"emulator-args", "Args">,
     Global,
     DefaultStringValue<"">,

diff  --git a/lldb/test/API/qemu/TestQemuLaunch.py b/lldb/test/API/qemu/TestQemuLaunch.py
index 2e817ede4154d..01c4143c9e77e 100644
--- a/lldb/test/API/qemu/TestQemuLaunch.py
+++ b/lldb/test/API/qemu/TestQemuLaunch.py
@@ -154,6 +154,24 @@ def test_stdio_redirect(self):
             state = json.load(s)
         self.assertEqual(state["stdin"], "STDIN CONTENT")
 
+    def test_find_in_PATH(self):
+        emulator = self.getBuildArtifact("qemu-" + self.getArchitecture())
+        os.rename(self.getBuildArtifact("qemu.py"), emulator)
+        self.set_emulator_setting("emulator-path", "''")
+
+        original_path = os.environ["PATH"]
+        os.environ["PATH"] = (self.getBuildDir() +
+            self.platformContext.shlib_path_separator + original_path)
+        def cleanup():
+            os.environ["PATH"] = original_path
+
+        self.addTearDownHook(cleanup)
+        state = self._run_and_get_state()
+
+        self.assertEqual(state["program"], self.getBuildArtifact())
+        self.assertEqual(state["args"],
+                ["dump:" + self.getBuildArtifact("state.log")])
+
     def test_bad_emulator_path(self):
         self.set_emulator_setting("emulator-path",
                 self.getBuildArtifact("nonexistent.file"))


        


More information about the lldb-commits mailing list