Commit ab899983 authored by Tobias Hunger's avatar Tobias Hunger Committed by hjk
Browse files

Debugger: Move classes into their own files



Change-Id: I89853ffb4192b0da1f34d471e250d4ec32daa3da
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 3a24b2d3
......@@ -44,6 +44,7 @@
#include <projectexplorer/devicesupport/devicemanager.h>
#include <projectexplorer/toolchainmanager.h>
#include <projectexplorer/session.h>
#include <debugger/debuggeritemmanager.h>
#include <debugger/debuggerkitinformation.h>
#include <qtsupport/baseqtversion.h>
#include <qtsupport/qtkitinformation.h>
......
......@@ -24,9 +24,13 @@ HEADERS += \
debuggercore.h \
debuggerconstants.h \
debuggerinternalconstants.h \
debuggeritem.h \
debuggeritemmanager.h \
debuggeritemmodel.h \
debuggerdialogs.h \
debuggerengine.h \
debuggermainwindow.h \
debuggeroptionspage.h \
debuggerplugin.h \
debuggerprotocol.h \
debuggerrunconfigurationaspect.h \
......@@ -80,12 +84,16 @@ SOURCES += \
debuggeractions.cpp \
debuggerdialogs.cpp \
debuggerengine.cpp \
debuggeritem.cpp \
debuggeritemmanager.cpp \
debuggeritemmodel.cpp \
debuggermainwindow.cpp \
debuggerplugin.cpp \
debuggerprotocol.cpp \
debuggerrunconfigurationaspect.cpp \
debuggerrunner.cpp \
debuggerstreamops.cpp \
debuggeroptionspage.cpp \
debuggerkitconfigwidget.cpp \
debuggerkitinformation.cpp \
disassembleragent.cpp \
......
......@@ -40,9 +40,13 @@ QtcPlugin {
"debuggerdialogs.cpp", "debuggerdialogs.h",
"debuggerengine.cpp", "debuggerengine.h",
"debuggerinternalconstants.h",
"debuggeritem.cpp", "debuggeritem.h",
"debuggeritemmanager.cpp", "debuggeritemmanager.h",
"debuggeritemmodel.cpp", "debuggeritemmodel.h",
"debuggerkitconfigwidget.cpp", "debuggerkitconfigwidget.h",
"debuggerkitinformation.cpp", "debuggerkitinformation.h",
"debuggermainwindow.cpp", "debuggermainwindow.h",
"debuggeroptionspage.cpp", "debuggeroptionspage.h",
"debuggerplugin.cpp", "debuggerplugin.h",
"debuggerprotocol.cpp", "debuggerprotocol.h",
"debuggerruncontrolfactory.h",
......
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "debuggerkitinformation.h"
#include "debuggerkitconfigwidget.h"
#include "debuggeroptionspage.h"
#include <projectexplorer/abi.h>
#include <utils/fileutils.h>
#include <QProcess>
#include <QUuid>
using namespace Debugger::Internal;
using namespace ProjectExplorer;
using namespace Utils;
static const char DEBUGGER_INFORMATION_COMMAND[] = "Binary";
static const char DEBUGGER_INFORMATION_DISPLAYNAME[] = "DisplayName";
static const char DEBUGGER_INFORMATION_ID[] = "Id";
static const char DEBUGGER_INFORMATION_ENGINETYPE[] = "EngineType";
static const char DEBUGGER_INFORMATION_AUTODETECTED[] = "AutoDetected";
static const char DEBUGGER_INFORMATION_ABIS[] = "Abis";
namespace Debugger {
// --------------------------------------------------------------------------
// DebuggerItem
// --------------------------------------------------------------------------
DebuggerItem::DebuggerItem()
{
m_id = QUuid::createUuid().toString();
m_engineType = NoEngineType;
m_isAutoDetected = false;
}
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_isAutoDetected = data.value(QLatin1String(DEBUGGER_INFORMATION_AUTODETECTED), false).toBool();
m_engineType = DebuggerEngineType(data.value(QLatin1String(DEBUGGER_INFORMATION_ENGINETYPE),
static_cast<int>(NoEngineType)).toInt());
foreach (const QString &a, data.value(QLatin1String(DEBUGGER_INFORMATION_ABIS)).toStringList()) {
Abi abi(a);
if (abi.isValid())
m_abis.append(abi);
}
}
void DebuggerItem::reinitializeFromFile()
{
QProcess proc;
proc.start(m_command.toString(), QStringList() << QLatin1String("--version"));
proc.waitForStarted();
proc.waitForFinished();
QByteArray ba = proc.readAll();
if (ba.contains("gdb")) {
m_engineType = GdbEngineType;
const char needle[] = "This GDB was configured as \"";
// E.g. "--host=i686-pc-linux-gnu --target=arm-unknown-nto-qnx6.5.0".
// or "i686-linux-gnu"
int pos1 = ba.indexOf(needle);
if (pos1 != -1) {
pos1 += int(sizeof(needle));
int pos2 = ba.indexOf('"', pos1 + 1);
QByteArray target = ba.mid(pos1, pos2 - pos1);
int pos3 = target.indexOf("--target=");
if (pos3 >= 0)
target = target.mid(pos3 + 9);
m_abis.append(Abi::abiFromTargetTriplet(QString::fromLatin1(target)));
} else {
// Fallback.
m_abis = Abi::abisOfBinary(m_command); // FIXME: Wrong.
}
return;
}
if (ba.contains("lldb") || ba.startsWith("LLDB")) {
m_engineType = LldbEngineType;
m_abis = Abi::abisOfBinary(m_command);
return;
}
if (ba.startsWith("Python")) {
m_engineType = PdbEngineType;
return;
}
m_engineType = NoEngineType;
}
QString DebuggerItem::engineTypeName() const
{
switch (m_engineType) {
case Debugger::NoEngineType:
return DebuggerOptionsPage::tr("Not recognized");
case Debugger::GdbEngineType:
return QLatin1String("GDB");
case Debugger::CdbEngineType:
return QLatin1String("CDB");
case Debugger::LldbEngineType:
return QLatin1String("LLDB");
default:
return QString();
}
}
QStringList DebuggerItem::abiNames() const
{
QStringList list;
foreach (const Abi &abi, m_abis)
list.append(abi.toString());
return list;
}
QVariantMap DebuggerItem::toMap() const
{
QVariantMap data;
data.insert(QLatin1String(DEBUGGER_INFORMATION_DISPLAYNAME), m_displayName);
data.insert(QLatin1String(DEBUGGER_INFORMATION_ID), m_id);
data.insert(QLatin1String(DEBUGGER_INFORMATION_COMMAND), m_command.toUserOutput());
data.insert(QLatin1String(DEBUGGER_INFORMATION_ENGINETYPE), int(m_engineType));
data.insert(QLatin1String(DEBUGGER_INFORMATION_AUTODETECTED), m_isAutoDetected);
data.insert(QLatin1String(DEBUGGER_INFORMATION_ABIS), abiNames());
return data;
}
void DebuggerItem::setDisplayName(const QString &displayName)
{
m_displayName = displayName;
}
void DebuggerItem::setEngineType(const DebuggerEngineType &engineType)
{
m_engineType = engineType;
}
void DebuggerItem::setCommand(const Utils::FileName &command)
{
m_command = command;
}
void DebuggerItem::setAutoDetected(bool isAutoDetected)
{
m_isAutoDetected = isAutoDetected;
}
void DebuggerItem::setAbis(const QList<ProjectExplorer::Abi> &abis)
{
m_abis = abis;
}
void DebuggerItem::setAbi(const Abi &abi)
{
m_abis.clear();
m_abis.append(abi);
}
static DebuggerItem::MatchLevel matchSingle(const Abi &debuggerAbi, const Abi &targetAbi)
{
if (debuggerAbi.architecture() != Abi::UnknownArchitecture
&& debuggerAbi.architecture() != targetAbi.architecture())
return DebuggerItem::DoesNotMatch;
if (debuggerAbi.os() != Abi::UnknownOS
&& debuggerAbi.os() != targetAbi.os())
return DebuggerItem::DoesNotMatch;
if (debuggerAbi.binaryFormat() != Abi::UnknownFormat
&& debuggerAbi.binaryFormat() != targetAbi.binaryFormat())
return DebuggerItem::DoesNotMatch;
if (debuggerAbi.os() == Abi::WindowsOS) {
if (debuggerAbi.osFlavor() == Abi::WindowsMSysFlavor && targetAbi.osFlavor() != Abi::WindowsMSysFlavor)
return DebuggerItem::DoesNotMatch;
if (debuggerAbi.osFlavor() != Abi::WindowsMSysFlavor && targetAbi.osFlavor() == Abi::WindowsMSysFlavor)
return DebuggerItem::DoesNotMatch;
}
if (debuggerAbi.wordWidth() == 64 && targetAbi.wordWidth() == 32)
return DebuggerItem::MatchesSomewhat;
if (debuggerAbi.wordWidth() != 0 && debuggerAbi.wordWidth() != targetAbi.wordWidth())
return DebuggerItem::DoesNotMatch;
return DebuggerItem::MatchesPerfectly;
}
DebuggerItem::MatchLevel DebuggerItem::matchTarget(const Abi &targetAbi) const
{
MatchLevel bestMatch = DoesNotMatch;
foreach (const Abi &debuggerAbi, m_abis) {
MatchLevel currentMatch = matchSingle(debuggerAbi, targetAbi);
if (currentMatch > bestMatch)
bestMatch = currentMatch;
}
return bestMatch;
}
bool Debugger::DebuggerItem::isValid() const
{
return m_engineType != NoEngineType;
}
} // namespace Debugger;
#ifdef WITH_TESTS
# include <QTest>
# include "debuggerplugin.h"
void Debugger::DebuggerPlugin::testDebuggerMatching_data()
{
QTest::addColumn<QStringList>("debugger");
QTest::addColumn<QString>("target");
QTest::addColumn<int>("result");
QTest::newRow("Invalid data")
<< QStringList()
<< QString()
<< int(DebuggerItem::DoesNotMatch);
QTest::newRow("Invalid debugger")
<< QStringList()
<< QString::fromLatin1("x86-linux-generic-elf-32bit")
<< int(DebuggerItem::DoesNotMatch);
QTest::newRow("Invalid target")
<< (QStringList() << QLatin1String("x86-linux-generic-elf-32bit"))
<< QString()
<< int(DebuggerItem::DoesNotMatch);
QTest::newRow("Fuzzy match 1")
<< (QStringList() << QLatin1String("unknown-unknown-unknown-unknown-0bit"))
<< QString::fromLatin1("x86-linux-generic-elf-32bit")
<< int(DebuggerItem::MatchesPerfectly); // Is this the expected behavior?
QTest::newRow("Fuzzy match 2")
<< (QStringList() << QLatin1String("unknown-unknown-unknown-unknown-0bit"))
<< QString::fromLatin1("arm-windows-msys-pe-64bit")
<< int(DebuggerItem::MatchesPerfectly); // Is this the expected behavior?
QTest::newRow("Architecture mismatch")
<< (QStringList() << QLatin1String("x86-linux-generic-elf-32bit"))
<< QString::fromLatin1("arm-linux-generic-elf-32bit")
<< int(DebuggerItem::DoesNotMatch);
QTest::newRow("OS mismatch")
<< (QStringList() << QLatin1String("x86-linux-generic-elf-32bit"))
<< QString::fromLatin1("x86-macosx-generic-elf-32bit")
<< int(DebuggerItem::DoesNotMatch);
QTest::newRow("Format mismatch")
<< (QStringList() << QLatin1String("x86-linux-generic-elf-32bit"))
<< QString::fromLatin1("x86-linux-generic-pe-32bit")
<< int(DebuggerItem::DoesNotMatch);
QTest::newRow("Linux perfect match")
<< (QStringList() << QLatin1String("x86-linux-generic-elf-32bit"))
<< QString::fromLatin1("x86-linux-generic-elf-32bit")
<< int(DebuggerItem::MatchesPerfectly);
QTest::newRow("Linux match")
<< (QStringList() << QLatin1String("x86-linux-generic-elf-64bit"))
<< QString::fromLatin1("x86-linux-generic-elf-32bit")
<< int(DebuggerItem::MatchesSomewhat);
QTest::newRow("Windows perfect match 1")
<< (QStringList() << QLatin1String("x86-windows-msvc2013-pe-64bit"))
<< QString::fromLatin1("x86-windows-msvc2013-pe-64bit")
<< int(DebuggerItem::MatchesPerfectly);
QTest::newRow("Windows perfect match 2")
<< (QStringList() << QLatin1String("x86-windows-msvc2013-pe-64bit"))
<< QString::fromLatin1("x86-windows-msvc2012-pe-64bit")
<< int(DebuggerItem::MatchesPerfectly);
QTest::newRow("Windows match 1")
<< (QStringList() << QLatin1String("x86-windows-msvc2013-pe-64bit"))
<< QString::fromLatin1("x86-windows-msvc2013-pe-32bit")
<< int(DebuggerItem::MatchesSomewhat);
QTest::newRow("Windows match 2")
<< (QStringList() << QLatin1String("x86-windows-msvc2013-pe-64bit"))
<< QString::fromLatin1("x86-windows-msvc2012-pe-32bit")
<< int(DebuggerItem::MatchesSomewhat);
QTest::newRow("Windows mismatch on word size")
<< (QStringList() << QLatin1String("x86-windows-msvc2013-pe-32bit"))
<< QString::fromLatin1("x86-windows-msvc2013-pe-64bit")
<< int(DebuggerItem::DoesNotMatch);
QTest::newRow("Windows mismatch on osflavor 1")
<< (QStringList() << QLatin1String("x86-windows-msvc2013-pe-32bit"))
<< QString::fromLatin1("x86-windows-msys-pe-64bit")
<< int(DebuggerItem::DoesNotMatch);
QTest::newRow("Windows mismatch on osflavor 2")
<< (QStringList() << QLatin1String("x86-windows-msys-pe-32bit"))
<< QString::fromLatin1("x86-windows-msvc2010-pe-64bit")
<< int(DebuggerItem::DoesNotMatch);
}
void Debugger::DebuggerPlugin::testDebuggerMatching()
{
QFETCH(QStringList, debugger);
QFETCH(QString, target);
QFETCH(int, result);
DebuggerItem::MatchLevel expectedLevel = static_cast<DebuggerItem::MatchLevel>(result);
QList<Abi> debuggerAbis;
foreach (const QString &abi, debugger)
debuggerAbis << Abi(abi);
DebuggerItem item;
item.setAbis(debuggerAbis);
DebuggerItem::MatchLevel level = item.matchTarget(Abi(target));
QCOMPARE(expectedLevel, level);
}
#endif
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef DEBUGGER_DEBUGGERITEM_H
#define DEBUGGER_DEBUGGERITEM_H
#include "debugger_global.h"
#include "debuggerconstants.h"
#include <projectexplorer/abi.h>
#include <utils/fileutils.h>
#include <QList>
#include <QVariant>
namespace Debugger {
// -----------------------------------------------------------------------
// DebuggerItem
// -----------------------------------------------------------------------
class DEBUGGER_EXPORT DebuggerItem
{
public:
DebuggerItem();
DebuggerItem(const QVariantMap &data);
bool canClone() const { return true; }
bool isValid() const;
QString engineTypeName() const;
QVariantMap toMap() const;
void reinitializeFromFile();
QVariant id() const { return m_id; }
QString displayName() const { return m_displayName; }
void setDisplayName(const QString &displayName);
DebuggerEngineType engineType() const { return m_engineType; }
void setEngineType(const DebuggerEngineType &engineType);
Utils::FileName command() const { return m_command; }
void setCommand(const Utils::FileName &command);
bool isAutoDetected() const { return m_isAutoDetected; }
void setAutoDetected(bool isAutoDetected);
QList<ProjectExplorer::Abi> abis() const { return m_abis; }
void setAbis(const QList<ProjectExplorer::Abi> &abis);
void setAbi(const ProjectExplorer::Abi &abi);
enum MatchLevel { DoesNotMatch, MatchesSomewhat, MatchesPerfectly };
MatchLevel matchTarget(const ProjectExplorer::Abi &targetAbi) const;
QStringList abiNames() const;
private:
QVariant m_id;
QString m_displayName;
DebuggerEngineType m_engineType;
Utils::FileName m_command;
bool m_isAutoDetected;
QList<ProjectExplorer::Abi> m_abis;
};
} // namespace Debugger
#endif // DEBUGGER_DEBUGGERITEM_H
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "debuggeritemmanager.h"
#include "debuggeritemmodel.h"
#include "debuggerkitinformation.h"
#include <coreplugin/icore.h>
#include <utils/environment.h>
#include <utils/fileutils.h>
#include <utils/persistentsettings.h>
#include <utils/qtcassert.h>
#include <QDebug>
#include <QDir>
#include <QFileInfo>
using namespace ProjectExplorer;
using namespace Utils;
namespace Debugger {
static const char DEBUGGER_COUNT_KEY[] = "DebuggerItem.Count";
static const char DEBUGGER_DATA_KEY[] = "DebuggerItem.";
static const char DEBUGGER_LEGACY_FILENAME[] = "/qtcreator/profiles.xml";
static const char DEBUGGER_FILE_VERSION_KEY[] = "Version";
static const char DEBUGGER_FILENAME[] = "/qtcreator/debuggers.xml";
// --------------------------------------------------------------------------
// DebuggerItemManager
// --------------------------------------------------------------------------
static DebuggerItemManager *m_instance = 0;
static FileName userSettingsFileName()
{
QFileInfo settingsLocation(Core::ICore::settings()->fileName());
return FileName::fromString(settingsLocation.absolutePath() + QLatin1String(DEBUGGER_FILENAME));
}
static void readDebuggers(const FileName &fileName, bool isSystem)
{
PersistentSettingsReader reader;
if (!reader.load(fileName))
return;
QVariantMap data = reader.restoreValues();
// Check version
int version = data.value(QLatin1String(DEBUGGER_FILE_VERSION_KEY), 0).toInt();
if (version < 1)
return;
int count = data.value(QLatin1String(DEBUGGER_COUNT_KEY), 0).toInt();
for (int i = 0; i < count; ++i) {
const QString key = QString::fromLatin1(DEBUGGER_DATA_KEY) + QString::number(i);
if (!data.contains(key))
continue;
const QVariantMap dbMap = data.value(key).toMap();
DebuggerItem item(dbMap);
if (isSystem) {
item.setAutoDetected(true);
// SDK debuggers are always considered to be up-to-date, so no need to recheck them.
} else {
// User settings.
if (item.isAutoDetected() && !item.isValid()) {
qWarning() << QString::fromLatin1("DebuggerItem \"%1\" (%2) dropped since it is not valid")
.arg(item.command().toString()).arg(item.id().toString());
continue;
}
}
DebuggerItemManager::registerDebugger(item);
}
}
QList<DebuggerItem> DebuggerItemManager::m_debuggers;
Internal::DebuggerItemModel* DebuggerItemManager::m_model = 0;
PersistentSettingsWriter * DebuggerItemManager::m_writer = 0;
DebuggerItemManager::DebuggerItemManager(QObject *parent)
: QObject(parent)