forked from qt-creator/qt-creator
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: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
@@ -1073,6 +1073,42 @@ static QString msgParameterMissing(const QString &a)
|
|||||||
return DebuggerPlugin::tr("Option \"%1\" is missing the parameter.").arg(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,
|
bool DebuggerPluginPrivate::parseArgument(QStringList::const_iterator &it,
|
||||||
const QStringList::const_iterator &cend, QString *errorMessage)
|
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.inferior.environment = Utils::Environment::systemEnvironment();
|
||||||
rp.stubEnvironment = Utils::Environment::systemEnvironment();
|
rp.stubEnvironment = Utils::Environment::systemEnvironment();
|
||||||
rp.debuggerEnvironment = Utils::Environment::systemEnvironment();
|
rp.debuggerEnvironment = Utils::Environment::systemEnvironment();
|
||||||
|
|
||||||
|
if (!kit)
|
||||||
|
kit = guessKitFromParameters(rp);
|
||||||
m_scheduledStarts.append(QPair<DebuggerRunParameters, Kit *>(rp, kit));
|
m_scheduledStarts.append(QPair<DebuggerRunParameters, Kit *>(rp, kit));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -2074,6 +2113,8 @@ void DebuggerPlugin::attachExternalApplication(RunControl *rc)
|
|||||||
if (const RunConfiguration *runConfiguration = rc->runConfiguration())
|
if (const RunConfiguration *runConfiguration = rc->runConfiguration())
|
||||||
if (const Target *target = runConfiguration->target())
|
if (const Target *target = runConfiguration->target())
|
||||||
kit = target->kit();
|
kit = target->kit();
|
||||||
|
if (!kit)
|
||||||
|
kit = guessKitFromParameters(rp);
|
||||||
createAndScheduleRun(rp, kit);
|
createAndScheduleRun(rp, kit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -321,6 +321,7 @@ void DebuggerRunControlCreator::initialize(const DebuggerStartParameters &sp)
|
|||||||
void DebuggerRunControlCreator::enrich(const RunConfiguration *runConfig, const Kit *kit)
|
void DebuggerRunControlCreator::enrich(const RunConfiguration *runConfig, const Kit *kit)
|
||||||
{
|
{
|
||||||
m_runConfig = runConfig;
|
m_runConfig = runConfig;
|
||||||
|
QTC_ASSERT(kit, return);
|
||||||
|
|
||||||
Target *target = 0;
|
Target *target = 0;
|
||||||
Project *project = 0;
|
Project *project = 0;
|
||||||
@@ -329,9 +330,6 @@ void DebuggerRunControlCreator::enrich(const RunConfiguration *runConfig, const
|
|||||||
if (m_runConfig)
|
if (m_runConfig)
|
||||||
target = m_runConfig->target();
|
target = m_runConfig->target();
|
||||||
|
|
||||||
if (!kit && target)
|
|
||||||
kit = target->kit();
|
|
||||||
|
|
||||||
// Extract as much as possible from available RunConfiguration.
|
// Extract as much as possible from available RunConfiguration.
|
||||||
if (m_runConfig && m_runConfig->runnable().is<StandardRunnable>()) {
|
if (m_runConfig && m_runConfig->runnable().is<StandardRunnable>()) {
|
||||||
m_rp.inferior = m_runConfig->runnable().as<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;
|
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 (m_runConfig) {
|
||||||
if (auto envAspect = m_runConfig->extraAspect<EnvironmentAspect>()) {
|
if (auto envAspect = m_runConfig->extraAspect<EnvironmentAspect>()) {
|
||||||
m_rp.inferior.environment = envAspect->environment(); // Correct.
|
m_rp.inferior.environment = envAspect->environment(); // Correct.
|
||||||
@@ -410,7 +368,7 @@ void DebuggerRunControlCreator::enrich(const RunConfiguration *runConfig, const
|
|||||||
if (project && m_rp.projectSourceFiles.isEmpty())
|
if (project && m_rp.projectSourceFiles.isEmpty())
|
||||||
m_rp.projectSourceFiles = project->files(Project::SourceFiles);
|
m_rp.projectSourceFiles = project->files(Project::SourceFiles);
|
||||||
|
|
||||||
if (false && project && kit) {
|
if (false && project) {
|
||||||
const QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(kit);
|
const QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(kit);
|
||||||
m_rp.nativeMixedEnabled = version && version->qtVersion() >= QtSupport::QtVersionNumber(5, 7, 0);
|
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
|
// We cover only local setup here. Remote setups are handled by the
|
||||||
// RunControl factories in the target specific plugins.
|
// RunControl factories in the target specific plugins.
|
||||||
DebuggerRunControlCreator creator;
|
DebuggerRunControlCreator creator;
|
||||||
creator.enrich(runConfig, 0);
|
creator.enrich(runConfig, runConfig->target()->kit());
|
||||||
creator.createRunControl(mode);
|
creator.createRunControl(mode);
|
||||||
if (errorMessage)
|
if (errorMessage)
|
||||||
*errorMessage = creator.fullError();
|
*errorMessage = creator.fullError();
|
||||||
@@ -654,6 +612,7 @@ QObject *createDebuggerRunControlFactory(QObject *parent)
|
|||||||
*/
|
*/
|
||||||
DebuggerRunControl *createAndScheduleRun(const DebuggerRunParameters &rp, const Kit *kit)
|
DebuggerRunControl *createAndScheduleRun(const DebuggerRunParameters &rp, const Kit *kit)
|
||||||
{
|
{
|
||||||
|
QTC_ASSERT(kit, return 0); // Caller needs to look for a suitable kit.
|
||||||
DebuggerRunControlCreator creator;
|
DebuggerRunControlCreator creator;
|
||||||
creator.m_rp = rp;
|
creator.m_rp = rp;
|
||||||
creator.enrich(0, kit);
|
creator.enrich(0, kit);
|
||||||
@@ -677,9 +636,10 @@ DebuggerRunControl *createDebuggerRunControl(const DebuggerStartParameters &sp,
|
|||||||
QString *errorMessage,
|
QString *errorMessage,
|
||||||
Core::Id runMode)
|
Core::Id runMode)
|
||||||
{
|
{
|
||||||
|
QTC_ASSERT(runConfig, return 0);
|
||||||
DebuggerRunControlCreator creator;
|
DebuggerRunControlCreator creator;
|
||||||
creator.initialize(sp);
|
creator.initialize(sp);
|
||||||
creator.enrich(runConfig, 0);
|
creator.enrich(runConfig, runConfig->target()->kit());
|
||||||
creator.createRunControl(runMode);
|
creator.createRunControl(runMode);
|
||||||
if (errorMessage)
|
if (errorMessage)
|
||||||
*errorMessage = creator.fullError();
|
*errorMessage = creator.fullError();
|
||||||
|
|||||||
Reference in New Issue
Block a user