Docker: Auto-detect debugger binaries in docker devices

Change-Id: Iec7c2b16277ea626520372603ae769418e9efd12
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-06-21 10:27:02 +02:00
parent f558323bac
commit aca55dce58
5 changed files with 50 additions and 14 deletions

View File

@@ -32,6 +32,7 @@
#include <extensionsystem/pluginmanager.h>
#include <projectexplorer/devicesupport/devicemanager.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectexplorericons.h>
@@ -91,7 +92,7 @@ public:
QVariant registerDebugger(const DebuggerItem &item);
void readDebuggers(const FilePath &fileName, bool isSystem);
void autoDetectCdbDebuggers();
void autoDetectGdbOrLldbDebuggers();
void autoDetectGdbOrLldbDebuggers(const FilePath &deviceRoot);
void autoDetectUvscDebuggers();
QString uniqueDisplayName(const QString &base);
@@ -714,7 +715,7 @@ static Utils::FilePaths searchGdbPathsFromRegistry()
return searchPaths;
}
void DebuggerItemManagerPrivate::autoDetectGdbOrLldbDebuggers()
void DebuggerItemManagerPrivate::autoDetectGdbOrLldbDebuggers(const FilePath &deviceRoot)
{
const QStringList filters = {"gdb-i686-pc-mingw32", "gdb-i686-pc-mingw32.exe", "gdb",
"gdb.exe", "lldb", "lldb.exe", "lldb-[1-9]*",
@@ -740,13 +741,17 @@ void DebuggerItemManagerPrivate::autoDetectGdbOrLldbDebuggers()
}
*/
IDevice::ConstPtr device = DeviceManager::deviceForPath(deviceRoot);
QTC_ASSERT(device, return);
FilePaths suspects;
if (HostOsInfo::isMacHost()) {
if (device->osType() == OsTypeMac) {
SynchronousProcess proc;
proc.setTimeoutS(2);
proc.setCommand({"xcrun", {"--find", "lldb"}});
proc.runBlocking();
// FIXME:
if (proc.result() == QtcProcess::FinishedWithSuccess) {
QString lPath = proc.allOutput().trimmed();
if (!lPath.isEmpty()) {
@@ -757,17 +762,15 @@ void DebuggerItemManagerPrivate::autoDetectGdbOrLldbDebuggers()
}
}
FilePaths path = Utils::filteredUnique(
Environment::systemEnvironment().path() + searchGdbPathsFromRegistry());
FilePaths paths = device->systemEnvironment().path();
if (!deviceRoot.needsDevice())
paths.append(searchGdbPathsFromRegistry());
QDir dir;
dir.setNameFilters(filters);
dir.setFilter(QDir::Files | QDir::Executable);
for (const FilePath &base : path) {
dir.setPath(base.toFileInfo().absoluteFilePath());
const QStringList entries = dir.entryList();
for (const QString &entry : entries)
suspects.append(FilePath::fromString(dir.absoluteFilePath(entry)));
paths = Utils::filteredUnique(paths);
for (const FilePath &path : paths) {
const FilePath globalPath = path.onDevice(deviceRoot);
suspects.append(device->directoryEntries(globalPath, filters, QDir::Files | QDir::Executable));
}
for (const FilePath &command : qAsConst(suspects)) {
@@ -939,7 +942,7 @@ void DebuggerItemManagerPrivate::restoreDebuggers()
// Auto detect current.
autoDetectCdbDebuggers();
autoDetectGdbOrLldbDebuggers();
autoDetectGdbOrLldbDebuggers({});
autoDetectUvscDebuggers();
}
@@ -1023,4 +1026,9 @@ void DebuggerItemManager::deregisterDebugger(const QVariant &id)
});
}
void DebuggerItemManager::autoDetectDebuggersForDevice(const Utils::FilePath &deviceRoot)
{
d->autoDetectGdbOrLldbDebuggers(deviceRoot);
}
} // namespace Debugger

View File

@@ -52,6 +52,8 @@ public:
static QVariant registerDebugger(const DebuggerItem &item);
static void deregisterDebugger(const QVariant &id);
static void autoDetectDebuggersForDevice(const Utils::FilePath &deviceRoot);
static const DebuggerItem *findByCommand(const Utils::FilePath &command);
static const DebuggerItem *findById(const QVariant &id);
static const DebuggerItem *findByEngineType(DebuggerEngineType engineType);

View File

@@ -1731,6 +1731,11 @@ void DebuggerPlugin::getEnginesState(QByteArray *json) const
*json = QJsonDocument(QJsonObject::fromVariantMap(result)).toJson();
}
void DebuggerPlugin::autoDetectDebuggersForDevice(const FilePath &deviceRoot)
{
dd->m_debuggerItemManager.autoDetectDebuggersForDevice(deviceRoot);
}
void DebuggerPluginPrivate::attachToQmlPort()
{
AttachToQmlPortDialog dlg(ICore::dialogParent());

View File

@@ -29,6 +29,7 @@
#include <extensionsystem/iplugin.h>
namespace ProjectExplorer { class RunControl; }
namespace Utils { class FilePath; }
namespace Debugger {
namespace Internal {
@@ -57,6 +58,9 @@ private:
// Called from GammaRayIntegration
Q_SLOT void getEnginesState(QByteArray *json) const;
// Called from DockerDevice
Q_SLOT void autoDetectDebuggersForDevice(const Utils::FilePath &deviceRoot);
QVector<QObject *> createTestObjects() const override;
};

View File

@@ -260,6 +260,7 @@ public:
QList<BaseQtVersion *> autoDetectQtVersions(QTextBrowser *log) const;
QList<ToolChain *> autoDetectToolChains(QTextBrowser *log);
void autoDetectCMake(QTextBrowser *log);
void autoDetectDebugger(QTextBrowser *log);
void fetchSystemEnviroment();
@@ -496,6 +497,21 @@ void DockerDevicePrivate::autoDetectCMake(QTextBrowser *log)
}
}
void DockerDevicePrivate::autoDetectDebugger(QTextBrowser *log)
{
QObject *debuggerPlugin = ExtensionSystem::PluginManager::getObjectByName("DebuggerPlugin");
if (!debuggerPlugin)
return;
if (log)
log->append('\n' + tr("Searching debuggers..."));
const FilePath deviceRoot = q->mapToGlobalPath({});
const bool res = QMetaObject::invokeMethod(debuggerPlugin,
"autoDetectDebuggersForDevice",
Q_ARG(Utils::FilePath, deviceRoot));
QTC_CHECK(res);
}
void DockerDevicePrivate::autoDetect(QTextBrowser *log)
{
QApplication::setOverrideCursor(Qt::WaitCursor);
@@ -511,6 +527,7 @@ void DockerDevicePrivate::autoDetect(QTextBrowser *log)
QList<BaseQtVersion *> qtVersions = autoDetectQtVersions(log);
autoDetectCMake(log);
autoDetectDebugger(log);
const auto initializeKit = [this, toolChains, qtVersions](Kit *k) {
k->setAutoDetected(false);