[Lldb-commits] [PATCH] D124947: Allow `target create` with no local file

Jim Ingham via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed May 4 10:33:32 PDT 2022


jingham created this revision.
jingham added reviewers: JDevlieghere, labath, clayborg, jasonmolenda.
Herald added a project: All.
jingham requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

In 92eaad2dd7adb5ee92f397cef85ab11f2612294e <https://reviews.llvm.org/rG92eaad2dd7adb5ee92f397cef85ab11f2612294e> I made it possible to run a debug session with only a remote path to the file you are debugging using the SB API's.  This patch makes it possible to do this using `target create --remote-file <some_path>` without supplying a local file as well.

Prior to this change we errored out saying that we haven't implemented copying the binary back from the remote.  I didn't implement the copy back (in the case I'm interested in - iOS debugging - we don't actually have a way for lldb to do that).  This patch doesn't impede doing that, I just didn't need it.  I think for some object file formats debugging w/o the binary file is hard because of what doesn't get mapped in.  I didn't try to arbitrate that, I'm assuming anybody who has to do this knows what they are going to get.

If there's a connected platform that can check that the remote file exists, it will do so, otherwise we trust the user's input - if it isn't there the process launch is going to fail with no-such-file so it will be pretty clear what went wrong.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124947

Files:
  lldb/source/Commands/CommandObjectTarget.cpp
  lldb/test/API/functionalities/gdb_remote_client/TestNoLocalFile.py


Index: lldb/test/API/functionalities/gdb_remote_client/TestNoLocalFile.py
===================================================================
--- lldb/test/API/functionalities/gdb_remote_client/TestNoLocalFile.py
+++ lldb/test/API/functionalities/gdb_remote_client/TestNoLocalFile.py
@@ -12,7 +12,13 @@
     mydir = TestBase.compute_mydir(__file__)
     
     @skipIfXmlSupportMissing
-    def test(self):
+    def test_with_python(self):
+        self.do_test(False)
+    @skipIfXmlSupportMissing
+    def test_with_target_ceate(self):
+        self.do_test(True)
+
+    def do_test(self, use_target_create):
         self.absent_file = '/nosuch_dir/nosuch_subdir/nosuch_executable'
         self.a_packet_file = None
         class MyResponder(MockGDBServerResponder):
@@ -67,10 +73,19 @@
             
         error = lldb.SBError()
         self.server.responder = MyResponder(self)
-        target = self.dbg.CreateTarget(None, "x86_64-apple-macosx", "remote-macosx", False, error)
-        self.assertSuccess(error, "Made a valid target")
+        target = lldb.SBTarget()
+        if (use_target_create):
+            create_cmd = "target create --arch x86_64-apple-macosx --platform remote-macosx --remote-file {0}".format(self.absent_file)
+            self.runCmd(create_cmd)
+            target = self.dbg.GetSelectedTarget()
+            self.assertTrue(target.IsValid(), "Made a valid target")
+        else:
+            target = self.dbg.CreateTarget(None, "x86_64-apple-macosx", "remote-macosx", False, error)
+            self.assertSuccess(error, "Made a valid target")
+
         launch_info = target.GetLaunchInfo()
-        launch_info.SetExecutableFile(lldb.SBFileSpec(self.absent_file), True)
+        if (not use_target_create):
+            launch_info.SetExecutableFile(lldb.SBFileSpec(self.absent_file), True)
         flags = launch_info.GetLaunchFlags()
         flags |= lldb.eLaunchFlagStopAtEntry
         launch_info.SetLaunchFlags(flags)
Index: lldb/source/Commands/CommandObjectTarget.cpp
===================================================================
--- lldb/source/Commands/CommandObjectTarget.cpp
+++ lldb/source/Commands/CommandObjectTarget.cpp
@@ -358,10 +358,29 @@
                 return false;
               }
             } else {
-              // make up a local file
-              result.AppendError("remote --> local transfer without local "
+              // If the remote file exists, we can debug reading that out of
+              // memory.  If the platform is already connected to an lldb-server
+              // then we can at least check the file exists remotely.  Otherwise
+              // we'll just have to trust that it will be there when we do
+              // process connect.
+              // I don't do this for the host platform because it seems odd to
+              // support supplying a remote file but no local file for a local
+              // debug session.
+              if (platform_sp->IsHost()) {
+                result.AppendError("Supply a local file, not a remote file, "
+                                   "when debugging on the host.");
+                return false;
+              }
+              if (platform_sp->IsConnected() && !platform_sp->GetFileExists(remote_file)) {
+                result.AppendError("remote --> local transfer without local "
                                  "path is not implemented yet");
-              return false;
+                return false;
+              }
+              // Since there's only a remote file, we need to set the executable
+              // file spec to the remote one.
+              ProcessLaunchInfo launch_info = target_sp->GetProcessLaunchInfo();
+              launch_info.SetExecutableFile(FileSpec(remote_file), true);
+              target_sp->SetProcessLaunchInfo(launch_info);
             }
           }
         } else {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124947.427060.patch
Type: text/x-patch
Size: 3892 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220504/8721cd75/attachment.bin>


More information about the lldb-commits mailing list