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

Jim Ingham via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu May 12 17:11:20 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG2a21700bc5be: In 92eaad2dd7adb5ee92f397cef85ab11f2612294e I made it possible to run (authored by jingham).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124947/new/

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.429106.patch
Type: text/x-patch
Size: 3892 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220513/e89dd29e/attachment.bin>


More information about the lldb-commits mailing list