Skip to content

Commit

Permalink
In 92eaad2 I made it possible to run
Browse files Browse the repository at this point in the history
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.

Differential Revision: https://reviews.llvm.org/D124947
  • Loading branch information
jimingham committed May 13, 2022
1 parent 753fe33 commit 2a21700
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
25 changes: 22 additions & 3 deletions lldb/source/Commands/CommandObjectTarget.cpp
Expand Up @@ -358,10 +358,29 @@ class CommandObjectTargetCreate : public CommandObjectParsed {
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 {
Expand Down
23 changes: 19 additions & 4 deletions lldb/test/API/functionalities/gdb_remote_client/TestNoLocalFile.py
Expand Up @@ -12,7 +12,13 @@ class TestNoLocalFile(GDBRemoteTestBase):
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):
Expand Down Expand Up @@ -67,10 +73,19 @@ def qProcessInfo(self):

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)
Expand Down

0 comments on commit 2a21700

Please sign in to comment.