Commit e16b02c6 authored by hjk's avatar hjk

Debugger: Move kit guessing out of run control creation

It's only used when starting with a -debug command line and
when attaching to a running run control. No need to clutter
the normal codepaths with it.

Change-Id: Ib374c64a7f63fa79e88967573c37a5da1f415d50
Reviewed-by: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
parent 0301a703
......@@ -1073,6 +1073,42 @@ static QString msgParameterMissing(const QString &a)
return DebuggerPlugin::tr("Option \"%1\" is missing the parameter.").arg(a);
}
static Kit *guessKitFromParameters(const DebuggerRunParameters &rp)
{
Kit *kit = 0;
// Try to find a kit via ABI.
QList<Abi> abis;
if (rp.toolChainAbi.isValid())
abis.push_back(rp.toolChainAbi);
else if (!rp.inferior.executable.isEmpty())
abis = Abi::abisOfBinary(FileName::fromString(rp.inferior.executable));
if (!abis.isEmpty()) {
// Try exact abis.
kit = KitManager::find(KitMatcher([abis](const Kit *k) -> bool {
if (const ToolChain *tc = ToolChainKitInformation::toolChain(k))
return abis.contains(tc->targetAbi()) && DebuggerKitInformation::isValidDebugger(k);
return false;
}));
if (!kit) {
// Or something compatible.
kit = KitManager::find(KitMatcher([abis](const Kit *k) -> bool {
if (const ToolChain *tc = ToolChainKitInformation::toolChain(k))
foreach (const Abi &a, abis)
if (a.isCompatibleWith(tc->targetAbi()) && DebuggerKitInformation::isValidDebugger(k))
return true;
return false;
}));
}
}
if (!kit)
kit = KitManager::defaultKit();
return kit;
}
bool DebuggerPluginPrivate::parseArgument(QStringList::const_iterator &it,
const QStringList::const_iterator &cend, QString *errorMessage)
{
......@@ -1135,6 +1171,9 @@ bool DebuggerPluginPrivate::parseArgument(QStringList::const_iterator &it,
rp.inferior.environment = Utils::Environment::systemEnvironment();
rp.stubEnvironment = Utils::Environment::systemEnvironment();
rp.debuggerEnvironment = Utils::Environment::systemEnvironment();
if (!kit)
kit = guessKitFromParameters(rp);
m_scheduledStarts.append(QPair<DebuggerRunParameters, Kit *>(rp, kit));
return true;
}
......@@ -2074,6 +2113,8 @@ void DebuggerPlugin::attachExternalApplication(RunControl *rc)
if (const RunConfiguration *runConfiguration = rc->runConfiguration())
if (const Target *target = runConfiguration->target())
kit = target->kit();
if (!kit)
kit = guessKitFromParameters(rp);
createAndScheduleRun(rp, kit);
}
......
......@@ -321,6 +321,7 @@ void DebuggerRunControlCreator::initialize(const DebuggerStartParameters &sp)
void DebuggerRunControlCreator::enrich(const RunConfiguration *runConfig, const Kit *kit)
{
m_runConfig = runConfig;
QTC_ASSERT(kit, return);
Target *target = 0;
Project *project = 0;
......@@ -329,9 +330,6 @@ void DebuggerRunControlCreator::enrich(const RunConfiguration *runConfig, const
if (m_runConfig)
target = m_runConfig->target();
if (!kit && target)
kit = target->kit();
// Extract as much as possible from available RunConfiguration.
if (m_runConfig && m_runConfig->runnable().is<StandardRunnable>()) {
m_rp.inferior = m_runConfig->runnable().as<StandardRunnable>();
......@@ -347,46 +345,6 @@ void DebuggerRunControlCreator::enrich(const RunConfiguration *runConfig, const
m_rp.inferior.executable = p.exe;
}
if (!kit) {
// This code can only be reached when starting via the command line
// (-debug pid or executable) or attaching from runconfiguration
// without specifying a kit. Try to find a kit via ABI.
QList<Abi> abis;
if (m_rp.toolChainAbi.isValid()) {
abis.push_back(m_rp.toolChainAbi);
} else if (!m_rp.inferior.executable.isEmpty()) {
abis = Abi::abisOfBinary(FileName::fromString(m_rp.inferior.executable));
}
if (!abis.isEmpty()) {
// Try exact abis.
kit = KitManager::find(KitMatcher([abis](const Kit *k) -> bool {
if (const ToolChain *tc = ToolChainKitInformation::toolChain(k))
return abis.contains(tc->targetAbi()) && DebuggerKitInformation::isValidDebugger(k);
return false;
}));
if (!kit) {
// Or something compatible.
kit = KitManager::find(KitMatcher([abis](const Kit *k) -> bool {
if (const ToolChain *tc = ToolChainKitInformation::toolChain(k))
foreach (const Abi &a, abis)
if (a.isCompatibleWith(tc->targetAbi()) && DebuggerKitInformation::isValidDebugger(k))
return true;
return false;
}));
}
}
}
if (!kit)
kit = KitManager::defaultKit();
// We really should have a kit now.
if (!kit) {
m_errors.append(DebuggerKitInformation::tr("No kit found."));
return;
}
if (m_runConfig) {
if (auto envAspect = m_runConfig->extraAspect<EnvironmentAspect>()) {
m_rp.inferior.environment = envAspect->environment(); // Correct.
......@@ -410,7 +368,7 @@ void DebuggerRunControlCreator::enrich(const RunConfiguration *runConfig, const
if (project && m_rp.projectSourceFiles.isEmpty())
m_rp.projectSourceFiles = project->files(Project::SourceFiles);
if (false && project && kit) {
if (false && project) {
const QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(kit);
m_rp.nativeMixedEnabled = version && version->qtVersion() >= QtSupport::QtVersionNumber(5, 7, 0);
}
......@@ -616,7 +574,7 @@ public:
// We cover only local setup here. Remote setups are handled by the
// RunControl factories in the target specific plugins.
DebuggerRunControlCreator creator;
creator.enrich(runConfig, 0);
creator.enrich(runConfig, runConfig->target()->kit());
creator.createRunControl(mode);
if (errorMessage)
*errorMessage = creator.fullError();
......@@ -654,6 +612,7 @@ QObject *createDebuggerRunControlFactory(QObject *parent)
*/
DebuggerRunControl *createAndScheduleRun(const DebuggerRunParameters &rp, const Kit *kit)
{
QTC_ASSERT(kit, return 0); // Caller needs to look for a suitable kit.
DebuggerRunControlCreator creator;
creator.m_rp = rp;
creator.enrich(0, kit);
......@@ -677,9 +636,10 @@ DebuggerRunControl *createDebuggerRunControl(const DebuggerStartParameters &sp,
QString *errorMessage,
Core::Id runMode)
{
QTC_ASSERT(runConfig, return 0);
DebuggerRunControlCreator creator;
creator.initialize(sp);
creator.enrich(runConfig, 0);
creator.enrich(runConfig, runConfig->target()->kit());
creator.createRunControl(runMode);
if (errorMessage)
*errorMessage = creator.fullError();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment