Debugger: Support linux remote debugging with LLDB

Adds support for Linux remote debugging with lldb-server

Change-Id: I3ee08704a3116030111df75273a46a2e4888f98e
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2023-06-23 09:14:05 +02:00
committed by hjk
parent fd83aa0bf7
commit 77edffe3cf
3 changed files with 56 additions and 12 deletions

View File

@@ -972,30 +972,56 @@ class Dumper(DumperBase):
self.remoteChannel_, None, error)
else:
if self.platform_ == "remote-macosx":
DumperBase.warn("TARGET: %s" % self.target)
self.report("Connecting to remote target: connect://%s" % self.remoteChannel_)
self.process = self.target.ConnectRemote(
self.debugger.GetListener(),
"connect://" + self.remoteChannel_, None, error)
if not error.Success():
self.report("Failed to connect to remote target: %s" % error.GetCString())
self.reportState('enginerunfailed')
return
if self.breakOnMain_:
self.createBreakpointAtMain()
DumperBase.warn("PROCESS: %s" % self.process)
else:
DumperBase.warn("PROCESS: %s (%s)" % (self.process, error.Success() and "Success" or error.GetCString()))
elif self.platform_ == "remote-linux":
self.report("Connecting to remote target: connect://%s" % self.remoteChannel_)
platform = self.target.GetPlatform()
url = "connect://" + self.remoteChannel_
conOptions = lldb.SBPlatformConnectOptions(url)
error = platform.ConnectRemote(conOptions)
if not error.Success():
self.report("Failed to connect to remote target (%s): %s" % (url, error.GetCString()))
self.reportState('enginerunfailed')
return
f = lldb.SBFileSpec()
f.SetFilename(self.executable_)
launchInfo = lldb.SBLaunchInfo(self.processArgs_)
#launchInfo.SetWorkingDirectory(self.workingDirectory_)
launchInfo.SetWorkingDirectory(self.workingDirectory_)
launchInfo.SetWorkingDirectory('/tmp')
if self.platform_ == 'remote-android':
launchInfo.SetWorkingDirectory('/data/local/tmp')
launchInfo.SetEnvironmentEntries(self.environment_, False)
launchInfo.SetExecutableFile(f, True)
DumperBase.warn("TARGET: %s" % self.target)
self.process = self.target.Launch(launchInfo, error)
DumperBase.warn("PROCESS: %s" % self.process)
if not error.Success():
self.report("Failed to launch remote target: %s" % (error.GetCString()))
self.reportState('enginerunfailed')
return
else:
self.report("Process has launched.")
if self.breakOnMain_:
self.createBreakpointAtMain()
else:
self.report("Unsupported platform: %s" % self.platform_)
self.reportState('enginerunfailed')
return
if not error.Success():
self.report(self.describeError(error))

View File

@@ -1068,7 +1068,26 @@ DebugServerRunner::DebugServerRunner(RunControl *runControl, DebugServerPortsGat
cmd.setExecutable(lldbserver);
}
} else {
cmd.setExecutable(runControl->device()->filePath("gdbserver"));
const FilePath gdbServerPath
= runControl->device()->filePath("gdbserver").searchInPath();
FilePath lldbServerPath
= runControl->device()->filePath("lldb-server").searchInPath();
// TODO: Which one should we prefer?
if (gdbServerPath.isExecutableFile())
cmd.setExecutable(gdbServerPath);
else if (lldbServerPath.isExecutableFile()) {
// lldb-server will fail if we start it through a link.
// see: https://github.com/llvm/llvm-project/issues/61955
//
// So we first search for the real executable.
// This is safe because we already checked that the file is executable.
while (lldbServerPath.isSymLink())
lldbServerPath = lldbServerPath.symLinkTarget();
cmd.setExecutable(lldbServerPath);
}
}
}
if (cmd.executable().baseName().contains("lldb-server")) {

View File

@@ -295,7 +295,6 @@ void LldbEngine::handleLldbStarted()
cmd2.arg("remotechannel", ((rp.startMode == AttachToRemoteProcess
|| rp.startMode == AttachToRemoteServer)
? rp.remoteChannel : QString()));
cmd2.arg("platform", rp.platform);
QTC_CHECK(!rp.continueAfterAttach || (rp.startMode == AttachToRemoteProcess
|| rp.startMode == AttachToLocalProcess
|| rp.startMode == AttachToRemoteServer));