Commit 04532fe6 authored by hjk's avatar hjk

Debugger: Add some expandable macros to Debugger options page

New %{Debugger:Name} for global use, %{Debugger:{Type,Version,...}}
for expansion within the name. Also re-initialize from file if the
saved version is empty (e.g. if the debugger was registered before
the version field was present)

Change-Id: I45568d78147597b30074a2ce4ddcf569bce15192
Reviewed-by: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 3ddbba14
......@@ -1183,7 +1183,7 @@ void AndroidConfigurations::updateAutomaticKitList()
Debugger::DebuggerItem debugger;
debugger.setCommand(tc->suggestedDebugger());
debugger.setEngineType(Debugger::GdbEngineType);
debugger.setDisplayName(tr("Android Debugger for %1").arg(tc->displayName()));
debugger.setUnexpandedDisplayName(tr("Android Debugger for %1").arg(tc->displayName()));
debugger.setAutoDetected(true);
debugger.setAbi(tc->targetAbi());
QVariant id = Debugger::DebuggerItemManager::registerDebugger(debugger);
......@@ -1229,7 +1229,7 @@ void AndroidConfigurations::updateAutomaticKitList()
Debugger::DebuggerItem debugger;
debugger.setCommand(tc->suggestedDebugger());
debugger.setEngineType(Debugger::GdbEngineType);
debugger.setDisplayName(tr("Android Debugger for %1").arg(tc->displayName()));
debugger.setUnexpandedDisplayName(tr("Android Debugger for %1").arg(tc->displayName()));
debugger.setAutoDetected(true);
debugger.setAbi(tc->targetAbi());
QVariant id = Debugger::DebuggerItemManager::registerDebugger(debugger);
......
......@@ -35,8 +35,10 @@
#include "debuggerprotocol.h"
#include <projectexplorer/abi.h>
#include <utils/fileutils.h>
#include <utils/hostosinfo.h>
#include <utils/macroexpander.h>
#include <utils/qtcassert.h>
#include <QProcess>
......@@ -83,7 +85,7 @@ DebuggerItem::DebuggerItem(const QVariantMap &data)
{
m_command = FileName::fromUserInput(data.value(QLatin1String(DEBUGGER_INFORMATION_COMMAND)).toString());
m_id = data.value(QLatin1String(DEBUGGER_INFORMATION_ID)).toString();
m_displayName = data.value(QLatin1String(DEBUGGER_INFORMATION_DISPLAYNAME)).toString();
m_unexpandedDisplayName = data.value(QLatin1String(DEBUGGER_INFORMATION_DISPLAYNAME)).toString();
m_isAutoDetected = data.value(QLatin1String(DEBUGGER_INFORMATION_AUTODETECTED), false).toBool();
m_autoDetectionSource = data.value(QLatin1String(DEBUGGER_INFORMATION_AUTODETECTION_SOURCE)).toString();
m_version = data.value(QLatin1String(DEBUGGER_INFORMATION_VERSION)).toString();
......@@ -95,6 +97,9 @@ DebuggerItem::DebuggerItem(const QVariantMap &data)
if (!abi.isNull())
m_abis.append(abi);
}
if (m_version.isEmpty())
reinitializeFromFile();
}
void DebuggerItem::createId()
......@@ -204,7 +209,7 @@ QStringList DebuggerItem::abiNames() const
bool DebuggerItem::operator==(const DebuggerItem &other) const
{
return m_id == other.m_id
&& m_displayName == other.m_displayName
&& m_unexpandedDisplayName == other.m_unexpandedDisplayName
&& m_isAutoDetected == other.m_isAutoDetected
&& m_command == other.m_command;
}
......@@ -212,7 +217,7 @@ bool DebuggerItem::operator==(const DebuggerItem &other) const
QVariantMap DebuggerItem::toMap() const
{
QVariantMap data;
data.insert(QLatin1String(DEBUGGER_INFORMATION_DISPLAYNAME), m_displayName);
data.insert(QLatin1String(DEBUGGER_INFORMATION_DISPLAYNAME), m_unexpandedDisplayName);
data.insert(QLatin1String(DEBUGGER_INFORMATION_ID), m_id);
data.insert(QLatin1String(DEBUGGER_INFORMATION_COMMAND), m_command.toString());
data.insert(QLatin1String(DEBUGGER_INFORMATION_ENGINETYPE), int(m_engineType));
......@@ -223,9 +228,26 @@ QVariantMap DebuggerItem::toMap() const
return data;
}
void DebuggerItem::setDisplayName(const QString &displayName)
QString DebuggerItem::displayName() const
{
if (!m_unexpandedDisplayName.contains(QLatin1Char('%')))
return m_unexpandedDisplayName;
MacroExpander expander;
expander.registerVariable("Debugger:Type", DebuggerKitInformation::tr("Type of Debugger Backend"),
[this] { return engineTypeName(); });
expander.registerVariable("Debugger:Version", DebuggerKitInformation::tr("Debugger"),
[this] { return !m_version.isEmpty() ? m_version :
DebuggerKitInformation::tr("Unknown debugger version"); });
expander.registerVariable("Debugger:Abi", DebuggerKitInformation::tr("Debugger"),
[this] { return !m_abis.isEmpty() ? abiNames().join(QLatin1Char(' ')) :
DebuggerKitInformation::tr("Unknown debugger ABI"); });
return expander.expand(m_unexpandedDisplayName);
}
void DebuggerItem::setUnexpandedDisplayName(const QString &displayName)
{
m_displayName = displayName;
m_unexpandedDisplayName = displayName;
}
void DebuggerItem::setEngineType(const DebuggerEngineType &engineType)
......
......@@ -44,7 +44,9 @@
namespace Debugger {
class DebuggerItemManager;
namespace Internal {
class DebuggerConfigWidget;
class DebuggerItemConfigWidget;
class DebuggerItemModel;
} // namespace Internal
......@@ -68,8 +70,9 @@ public:
QVariant id() const { return m_id; }
QString displayName() const { return m_displayName; }
void setDisplayName(const QString &displayName);
QString displayName() const;
QString unexpandedDisplayName() const { return m_unexpandedDisplayName; }
void setUnexpandedDisplayName(const QString &unexpandedDisplayName);
DebuggerEngineType engineType() const { return m_engineType; }
void setEngineType(const DebuggerEngineType &engineType);
......@@ -101,9 +104,10 @@ public:
private:
DebuggerItem(const QVariant &id);
void reinitializeFromFile();
void initMacroExpander();
QVariant m_id;
QString m_displayName;
QString m_unexpandedDisplayName;
DebuggerEngineType m_engineType;
Utils::FileName m_command;
bool m_isAutoDetected;
......@@ -111,6 +115,7 @@ private:
QString m_version;
QList<ProjectExplorer::Abi> m_abis;
friend class Internal::DebuggerConfigWidget;
friend class Internal::DebuggerItemConfigWidget;
friend class Internal::DebuggerItemModel;
friend class DebuggerItemManager;
......
......@@ -191,7 +191,7 @@ void DebuggerItemManager::autoDetectCdbDebuggers()
item.setAbis(Abi::abisOfBinary(cdb));
item.setCommand(cdb);
item.setEngineType(CdbEngineType);
item.setDisplayName(uniqueDisplayName(tr("Auto-detected CDB at %1").arg(cdb.toUserOutput())));
item.setUnexpandedDisplayName(uniqueDisplayName(tr("Auto-detected CDB at %1").arg(cdb.toUserOutput())));
addDebugger(item);
}
}
......@@ -260,7 +260,7 @@ void DebuggerItemManager::autoDetectGdbOrLldbDebuggers()
item.setCommand(command);
item.reinitializeFromFile();
//: %1: Debugger engine type (GDB, LLDB, CDB...), %2: Path
item.setDisplayName(tr("System %1 at %2")
item.setUnexpandedDisplayName(tr("System %1 at %2")
.arg(item.engineTypeName()).arg(command.toUserOutput()));
item.setAutoDetected(true);
addDebugger(item);
......@@ -299,7 +299,7 @@ void DebuggerItemManager::readLegacyDebuggers(const FileName &file)
item.setCommand(command);
item.setAutoDetected(true);
item.reinitializeFromFile();
item.setDisplayName(tr("Extracted from Kit %1").arg(kitName));
item.setUnexpandedDisplayName(tr("Extracted from Kit %1").arg(kitName));
addDebugger(item);
}
}
......@@ -379,7 +379,7 @@ QVariant DebuggerItemManager::registerDebugger(const DebuggerItem &item)
if (d.command() == item.command()
&& d.isAutoDetected() == item.isAutoDetected()
&& d.engineType() == item.engineType()
&& d.displayName() == item.displayName()
&& d.unexpandedDisplayName() == item.unexpandedDisplayName()
&& d.abis() == item.abis()) {
return d.id();
}
......@@ -407,7 +407,7 @@ void DebuggerItemManager::deregisterDebugger(const QVariant &id)
QString DebuggerItemManager::uniqueDisplayName(const QString &base)
{
foreach (const DebuggerItem &item, m_debuggers)
if (item.displayName() == base)
if (item.unexpandedDisplayName() == base)
return uniqueDisplayName(base + QLatin1String(" (1)"));
return base;
......
......@@ -304,16 +304,16 @@ KitConfigWidget *DebuggerKitInformation::createConfigWidget(Kit *k) const
void DebuggerKitInformation::addToMacroExpander(Kit *kit, MacroExpander *expander) const
{
expander->registerVariable("Debugger:Type", tr("Type of Debugger Backend"),
expander->registerVariable("Debugger:Name", tr("Name of Debugger"),
[this, kit]() -> QString {
const DebuggerItem *item = debugger(kit);
return item ? item->engineTypeName() : tr("Unknown debugger type");
return item ? item->displayName() : tr("Unknown debugger");
});
expander->registerVariable("Debugger:Name", tr("Debugger"),
expander->registerVariable("Debugger:Type", tr("Type of Debugger Backend"),
[this, kit]() -> QString {
const DebuggerItem *item = debugger(kit);
return item ? item->displayName() : tr("Unknown debugger");
return item ? item->engineTypeName() : tr("Unknown debugger type");
});
expander->registerVariable("Debugger:Version", tr("Debugger"),
......
......@@ -259,7 +259,7 @@ DebuggerItemConfigWidget::DebuggerItemConfigWidget(DebuggerItemModel *model)
DebuggerItem DebuggerItemConfigWidget::item() const
{
DebuggerItem item(m_id);
item.setDisplayName(m_displayNameLineEdit->text());
item.setUnexpandedDisplayName(m_displayNameLineEdit->text());
item.setCommand(m_binaryChooser->fileName());
item.setAutoDetected(m_autodetected);
QList<ProjectExplorer::Abi> abiList;
......@@ -295,7 +295,7 @@ void DebuggerItemConfigWidget::load(const DebuggerItem *item)
m_autodetected = item->isAutoDetected();
m_displayNameLineEdit->setEnabled(!item->isAutoDetected());
m_displayNameLineEdit->setText(item->displayName());
m_displayNameLineEdit->setText(item->unexpandedDisplayName());
m_typeLineEdit->setText(item->engineTypeName());
......@@ -435,11 +435,9 @@ void DebuggerConfigWidget::cloneDebugger()
DebuggerItem newItem;
newItem.createId();
newItem.setAutoDetected(false);
newItem.setCommand(item->command());
newItem.setEngineType(item->engineType());
newItem.setAbis(item->abis());
newItem.setDisplayName(DebuggerItemManager::uniqueDisplayName(tr("Clone of %1").arg(item->displayName())));
newItem.setUnexpandedDisplayName(DebuggerItemManager::uniqueDisplayName(tr("Clone of %1").arg(item->displayName())));
newItem.reinitializeFromFile();
newItem.setAutoDetected(false);
m_model.addDebugger(newItem, true);
m_debuggerView->setCurrentIndex(m_model.lastIndex());
......@@ -451,7 +449,7 @@ void DebuggerConfigWidget::addDebugger()
item.createId();
item.setAutoDetected(false);
item.setEngineType(NoEngineType);
item.setDisplayName(DebuggerItemManager::uniqueDisplayName(tr("New Debugger")));
item.setUnexpandedDisplayName(DebuggerItemManager::uniqueDisplayName(tr("New Debugger")));
item.setAutoDetected(false);
m_model.addDebugger(item, true);
m_debuggerView->setCurrentIndex(m_model.lastIndex());
......
......@@ -183,7 +183,7 @@ QVariant QnxBaseConfiguration::createDebuggerItem(QnxArchitecture arch,
debugger.setAbi(Abi(arch == Qnx::ArmLeV7 ? Abi::ArmArchitecture : Abi::X86Architecture,
Abi::LinuxOS, Abi::GenericLinuxFlavor, Abi::ElfFormat, 32));
debugger.setAutoDetected(true);
debugger.setDisplayName(displayName);
debugger.setUnexpandedDisplayName(displayName);
return Debugger::DebuggerItemManager::registerDebugger(debugger);
}
......
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