2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "moduleshandler.h"
|
|
|
|
|
|
2009-02-17 11:16:23 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2015-01-13 22:42:30 +01:00
|
|
|
#include <utils/treemodel.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2015-01-13 22:42:30 +01:00
|
|
|
#include <QCoreApplication>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QSortFilterProxyModel>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-06-04 18:06:59 +02:00
|
|
|
using namespace Utils;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// ModulesModel
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2010-06-15 09:13:22 +02:00
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
2009-04-16 19:42:58 +02:00
|
|
|
|
2015-01-13 22:42:30 +01:00
|
|
|
class ModuleItem : public TreeItem
|
2012-06-01 19:01:37 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2015-01-13 22:42:30 +01:00
|
|
|
QVariant data(int column, int role) const;
|
2012-06-01 19:01:37 +02:00
|
|
|
|
2015-01-13 22:42:30 +01:00
|
|
|
public:
|
|
|
|
|
Module module;
|
|
|
|
|
bool updated;
|
2012-06-01 19:01:37 +02:00
|
|
|
};
|
|
|
|
|
|
2015-01-13 22:42:30 +01:00
|
|
|
QVariant ModuleItem::data(int column, int role) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2015-01-13 22:42:30 +01:00
|
|
|
switch (column) {
|
|
|
|
|
case 0:
|
|
|
|
|
if (role == Qt::DisplayRole)
|
|
|
|
|
return module.moduleName;
|
|
|
|
|
// FIXME: add icons
|
|
|
|
|
//if (role == Qt::DecorationRole)
|
|
|
|
|
// return module.symbolsRead ? icon2 : icon;
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
if (role == Qt::DisplayRole)
|
|
|
|
|
return module.modulePath;
|
|
|
|
|
if (role == Qt::ToolTipRole) {
|
|
|
|
|
QString msg;
|
|
|
|
|
if (!module.elfData.buildId.isEmpty())
|
|
|
|
|
msg += QString::fromLatin1("Build Id: " + module.elfData.buildId);
|
|
|
|
|
if (!module.elfData.debugLink.isEmpty())
|
|
|
|
|
msg += QString::fromLatin1("Debug Link: " + module.elfData.debugLink);
|
|
|
|
|
return msg;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
if (role == Qt::DisplayRole)
|
|
|
|
|
switch (module.symbolsRead) {
|
|
|
|
|
case Module::UnknownReadState: return ModulesHandler::tr("Unknown");
|
|
|
|
|
case Module::ReadFailed: return ModulesHandler::tr("No");
|
|
|
|
|
case Module::ReadOk: return ModulesHandler::tr("Yes");
|
2012-06-06 16:08:59 +02:00
|
|
|
}
|
2015-01-13 22:42:30 +01:00
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
if (role == Qt::DisplayRole)
|
|
|
|
|
switch (module.elfData.symbolsType) {
|
|
|
|
|
case UnknownSymbols:
|
|
|
|
|
return ModulesHandler::tr("Unknown");
|
|
|
|
|
case NoSymbols:
|
|
|
|
|
return ModulesHandler::tr("None");
|
|
|
|
|
case PlainSymbols:
|
|
|
|
|
return ModulesHandler::tr("Plain");
|
|
|
|
|
case FastSymbols:
|
|
|
|
|
return ModulesHandler::tr("Fast");
|
|
|
|
|
case LinkedSymbols:
|
|
|
|
|
return ModulesHandler::tr("debuglnk");
|
|
|
|
|
case BuildIdSymbols:
|
|
|
|
|
return ModulesHandler::tr("buildid");
|
2010-12-21 13:34:59 +01:00
|
|
|
}
|
2015-01-13 22:42:30 +01:00
|
|
|
else if (role == Qt::ToolTipRole)
|
|
|
|
|
switch (module.elfData.symbolsType) {
|
|
|
|
|
case UnknownSymbols:
|
|
|
|
|
return ModulesHandler::tr(
|
|
|
|
|
"It is unknown whether this module contains debug "
|
|
|
|
|
"information.\nUse \"Examine Symbols\" from the "
|
|
|
|
|
"context menu to initiate a check.");
|
|
|
|
|
case NoSymbols:
|
|
|
|
|
return ModulesHandler::tr(
|
|
|
|
|
"This module neither contains nor references debug "
|
|
|
|
|
"information.\nStepping into the module or setting "
|
|
|
|
|
"breakpoints by file and line will not work.");
|
|
|
|
|
case PlainSymbols:
|
|
|
|
|
return ModulesHandler::tr(
|
|
|
|
|
"This module contains debug information.\nStepping "
|
|
|
|
|
"into the module or setting breakpoints by file and "
|
|
|
|
|
"line is expected to work.");
|
|
|
|
|
case FastSymbols:
|
|
|
|
|
return ModulesHandler::tr(
|
|
|
|
|
"This module contains debug information.\nStepping "
|
|
|
|
|
"into the module or setting breakpoints by file and "
|
|
|
|
|
"line is expected to work.");
|
|
|
|
|
case LinkedSymbols:
|
|
|
|
|
case BuildIdSymbols:
|
|
|
|
|
return ModulesHandler::tr(
|
|
|
|
|
"This module does not contain debug information "
|
|
|
|
|
"itself, but contains a reference to external "
|
|
|
|
|
"debug information.");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
if (role == Qt::DisplayRole)
|
|
|
|
|
if (module.startAddress)
|
|
|
|
|
return QString(QLatin1String("0x")
|
|
|
|
|
+ QString::number(module.startAddress, 16));
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
if (role == Qt::DisplayRole) {
|
|
|
|
|
if (module.endAddress)
|
|
|
|
|
return QString(QLatin1String("0x")
|
|
|
|
|
+ QString::number(module.endAddress, 16));
|
|
|
|
|
//: End address of loaded module
|
|
|
|
|
return ModulesHandler::tr("<unknown>", "address");
|
2012-08-28 10:44:19 +02:00
|
|
|
}
|
2015-01-13 22:42:30 +01:00
|
|
|
break;
|
2012-06-02 03:30:21 +02:00
|
|
|
}
|
2015-01-13 22:42:30 +01:00
|
|
|
return QVariant();
|
2010-07-22 16:53:01 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// ModulesHandler
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2015-01-13 22:42:30 +01:00
|
|
|
static ModuleItem *moduleFromPath(TreeItem *root, const QString &modulePath)
|
|
|
|
|
{
|
|
|
|
|
// Recent modules are more likely to be unloaded first.
|
|
|
|
|
for (int i = root->rowCount(); --i >= 0; ) {
|
|
|
|
|
auto item = static_cast<ModuleItem *>(root->child(i));
|
|
|
|
|
if (item->module.modulePath == modulePath)
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-28 10:53:33 +02:00
|
|
|
ModulesHandler::ModulesHandler(DebuggerEngine *engine)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2012-08-28 10:53:33 +02:00
|
|
|
m_engine = engine;
|
2015-01-13 22:42:30 +01:00
|
|
|
|
|
|
|
|
QString pad = QLatin1String(" ");
|
|
|
|
|
m_model = new TreeModel(this);
|
2013-08-19 13:30:10 +02:00
|
|
|
m_model->setObjectName(QLatin1String("ModulesModel"));
|
2015-01-16 15:24:53 +01:00
|
|
|
m_model->setHeader(QStringList()
|
2015-01-13 22:42:30 +01:00
|
|
|
<< ModulesHandler::tr("Module Name") + pad
|
|
|
|
|
<< ModulesHandler::tr("Module Path") + pad
|
|
|
|
|
<< ModulesHandler::tr("Symbols Read") + pad
|
|
|
|
|
<< ModulesHandler::tr("Symbols Type") + pad
|
|
|
|
|
<< ModulesHandler::tr("Start Address") + pad
|
|
|
|
|
<< ModulesHandler::tr("End Address") + pad);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
m_proxyModel = new QSortFilterProxyModel(this);
|
2013-08-19 13:30:10 +02:00
|
|
|
m_proxyModel->setObjectName(QLatin1String("ModulesProxyModel"));
|
2008-12-02 12:01:29 +01:00
|
|
|
m_proxyModel->setSourceModel(m_model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAbstractItemModel *ModulesHandler::model() const
|
|
|
|
|
{
|
|
|
|
|
return m_proxyModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModulesHandler::removeAll()
|
|
|
|
|
{
|
2015-04-22 14:49:14 +02:00
|
|
|
m_model->clear();
|
2015-01-13 22:42:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Modules ModulesHandler::modules() const
|
|
|
|
|
{
|
|
|
|
|
Modules mods;
|
|
|
|
|
TreeItem *root = m_model->rootItem();
|
|
|
|
|
for (int i = root->rowCount(); --i >= 0; )
|
|
|
|
|
mods.append(static_cast<ModuleItem *>(root->child(i))->module);
|
|
|
|
|
return mods;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2012-06-01 19:01:37 +02:00
|
|
|
void ModulesHandler::removeModule(const QString &modulePath)
|
2010-05-19 15:14:15 +02:00
|
|
|
{
|
2015-01-13 22:42:30 +01:00
|
|
|
if (ModuleItem *item = moduleFromPath(m_model->rootItem(), modulePath))
|
2015-04-22 14:49:14 +02:00
|
|
|
m_model->takeItem(item);
|
2010-05-19 15:14:15 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-06-01 19:01:37 +02:00
|
|
|
void ModulesHandler::updateModule(const Module &module)
|
2010-07-22 16:53:01 +02:00
|
|
|
{
|
2015-01-13 22:42:30 +01:00
|
|
|
const QString path = module.modulePath;
|
|
|
|
|
if (path.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ModuleItem *item = moduleFromPath(m_model->rootItem(), path);
|
|
|
|
|
if (item) {
|
|
|
|
|
item->module = module;
|
|
|
|
|
} else {
|
|
|
|
|
item = new ModuleItem;
|
|
|
|
|
item->module = module;
|
2015-01-14 09:09:15 +01:00
|
|
|
m_model->rootItem()->appendChild(item);
|
2015-01-13 22:42:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try { // MinGW occasionallly throws std::bad_alloc.
|
|
|
|
|
ElfReader reader(path);
|
|
|
|
|
item->module.elfData = reader.readHeaders();
|
2015-01-14 09:09:15 +01:00
|
|
|
item->update();
|
2015-01-13 22:42:30 +01:00
|
|
|
} catch(...) {
|
|
|
|
|
qWarning("%s: An exception occurred while reading module '%s'",
|
|
|
|
|
Q_FUNC_INFO, qPrintable(module.modulePath));
|
|
|
|
|
}
|
|
|
|
|
item->updated = true;
|
2010-07-22 16:53:01 +02:00
|
|
|
}
|
|
|
|
|
|
2015-01-13 22:42:30 +01:00
|
|
|
void ModulesHandler::beginUpdateAll()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2015-01-13 22:42:30 +01:00
|
|
|
TreeItem *root = m_model->rootItem();
|
|
|
|
|
for (int i = root->rowCount(); --i >= 0; )
|
|
|
|
|
static_cast<ModuleItem *>(root->child(i))->updated = false;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2015-01-13 22:42:30 +01:00
|
|
|
void ModulesHandler::endUpdateAll()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2015-01-13 22:42:30 +01:00
|
|
|
TreeItem *root = m_model->rootItem();
|
|
|
|
|
for (int i = root->rowCount(); --i >= 0; ) {
|
|
|
|
|
auto item = static_cast<ModuleItem *>(root->child(i));
|
|
|
|
|
if (!item->updated)
|
2015-04-22 14:49:14 +02:00
|
|
|
m_model->takeItem(item);
|
2015-01-13 22:42:30 +01:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2009-04-16 19:42:58 +02:00
|
|
|
|
2010-06-15 09:13:22 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Debugger
|