2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01: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>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QSortFilterProxyModel>
|
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
|
|
|
|
2012-06-01 19:01:37 +02:00
|
|
|
class ModulesModel : public QAbstractItemModel
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit ModulesModel(QObject *parent)
|
|
|
|
|
: QAbstractItemModel(parent)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
int columnCount(const QModelIndex &parent) const
|
|
|
|
|
{ return parent.isValid() ? 0 : 5; }
|
|
|
|
|
int rowCount(const QModelIndex &parent) const
|
|
|
|
|
{ return parent.isValid() ? 0 : m_modules.size(); }
|
|
|
|
|
QModelIndex parent(const QModelIndex &) const { return QModelIndex(); }
|
|
|
|
|
QModelIndex index(int row, int column, const QModelIndex &) const
|
|
|
|
|
{ return createIndex(row, column); }
|
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
|
|
|
|
QVariant data(const QModelIndex &index, int role) const;
|
|
|
|
|
|
|
|
|
|
void clearModel();
|
|
|
|
|
void addModule(const Module &module);
|
|
|
|
|
void removeModule(const QString &modulePath);
|
|
|
|
|
void setModules(const Modules &modules);
|
|
|
|
|
void updateModule(const Module &module);
|
|
|
|
|
|
|
|
|
|
int indexOfModule(const QString &modulePath) const;
|
|
|
|
|
|
|
|
|
|
Modules m_modules;
|
|
|
|
|
};
|
|
|
|
|
|
2010-05-19 15:14:15 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QVariant ModulesModel::headerData(int section,
|
|
|
|
|
Qt::Orientation orientation, int role) const
|
|
|
|
|
{
|
|
|
|
|
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
|
|
|
|
|
static QString headers[] = {
|
2012-06-01 19:01:37 +02:00
|
|
|
ModulesHandler::tr("Module name") + QLatin1String(" "),
|
|
|
|
|
ModulesHandler::tr("Module path") + QLatin1String(" "),
|
|
|
|
|
ModulesHandler::tr("Symbols read") + QLatin1String(" "),
|
|
|
|
|
ModulesHandler::tr("Symbols type") + QLatin1String(" "),
|
|
|
|
|
ModulesHandler::tr("Start address") + QLatin1String(" "),
|
|
|
|
|
ModulesHandler::tr("End address") + QLatin1String(" ")
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
return headers[section];
|
|
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant ModulesModel::data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
|
|
|
|
int row = index.row();
|
|
|
|
|
if (row < 0 || row >= m_modules.size())
|
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
|
|
const Module &module = m_modules.at(row);
|
|
|
|
|
|
|
|
|
|
switch (index.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)
|
2010-05-03 19:12:52 +02:00
|
|
|
return module.modulePath;
|
2008-12-02 12:01:29 +01:00
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
if (role == Qt::DisplayRole)
|
2010-07-22 16:15:50 +02:00
|
|
|
switch (module.symbolsRead) {
|
2012-06-01 19:01:37 +02:00
|
|
|
case Module::UnknownReadState: return ModulesHandler::tr("unknown");
|
|
|
|
|
case Module::ReadFailed: return ModulesHandler::tr("no");
|
|
|
|
|
case Module::ReadOk: return ModulesHandler::tr("yes");
|
2010-07-22 16:15:50 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
break;
|
|
|
|
|
case 3:
|
2010-05-03 19:12:52 +02:00
|
|
|
if (role == Qt::DisplayRole)
|
2010-07-22 16:15:50 +02:00
|
|
|
switch (module.symbolsType) {
|
2012-06-02 03:30:21 +02:00
|
|
|
case Module::UnknownSymbols:
|
|
|
|
|
return ModulesHandler::tr("unknown");
|
|
|
|
|
case Module::NoSymbols:
|
|
|
|
|
return ModulesHandler::tr("none");
|
|
|
|
|
case Module::PlainSymbols:
|
|
|
|
|
return ModulesHandler::tr("plain");
|
|
|
|
|
case Module::FastSymbols:
|
|
|
|
|
return ModulesHandler::tr("fast");
|
|
|
|
|
case Module::SeparateSymbols:
|
|
|
|
|
return ModulesHandler::tr("separate");
|
|
|
|
|
}
|
|
|
|
|
else if (role == Qt::ToolTipRole)
|
|
|
|
|
switch (module.symbolsType) {
|
|
|
|
|
case Module::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 Module::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 Module::PlainSymbols:
|
|
|
|
|
return ModulesHandler::tr(
|
|
|
|
|
"This module contains debug information.\nStepping "
|
|
|
|
|
"into the module or setting breakpoints by file and "
|
|
|
|
|
"is expected to work.");
|
|
|
|
|
case Module::FastSymbols:
|
|
|
|
|
return ModulesHandler::tr(
|
|
|
|
|
"This module contains debug information.\nStepping "
|
|
|
|
|
"into the module or setting breakpoints by file and "
|
|
|
|
|
"is expected to work.");
|
|
|
|
|
case Module::SeparateSymbols:
|
|
|
|
|
return ModulesHandler::tr(
|
|
|
|
|
"This module does not contains debug information "
|
|
|
|
|
"itself, but contains a reference to external "
|
|
|
|
|
"debug information.");
|
2010-07-22 16:15:50 +02:00
|
|
|
}
|
2010-05-03 19:12:52 +02:00
|
|
|
break;
|
|
|
|
|
case 4:
|
2010-07-22 16:15:50 +02:00
|
|
|
if (role == Qt::DisplayRole)
|
2012-06-02 03:30:21 +02:00
|
|
|
if (module.startAddress)
|
|
|
|
|
return QString(QLatin1String("0x")
|
|
|
|
|
+ QString::number(module.startAddress, 16));
|
2010-07-22 16:15:50 +02:00
|
|
|
break;
|
|
|
|
|
case 5:
|
2010-12-21 13:34:59 +01:00
|
|
|
if (role == Qt::DisplayRole) {
|
|
|
|
|
if (module.endAddress)
|
|
|
|
|
return QString(QLatin1String("0x")
|
|
|
|
|
+ QString::number(module.endAddress, 16));
|
|
|
|
|
//: End address of loaded module
|
2012-06-01 19:01:37 +02:00
|
|
|
return ModulesHandler::tr("<unknown>", "address");
|
2010-12-21 13:34:59 +01:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-19 15:14:15 +02:00
|
|
|
void ModulesModel::addModule(const Module &m)
|
|
|
|
|
{
|
|
|
|
|
beginInsertRows(QModelIndex(), m_modules.size(), m_modules.size());
|
|
|
|
|
m_modules.push_back(m);
|
|
|
|
|
endInsertRows();
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-15 11:14:44 +02:00
|
|
|
void ModulesModel::setModules(const Modules &m)
|
2010-05-19 15:14:15 +02:00
|
|
|
{
|
|
|
|
|
m_modules = m;
|
|
|
|
|
reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModulesModel::clearModel()
|
|
|
|
|
{
|
|
|
|
|
if (!m_modules.isEmpty()) {
|
|
|
|
|
m_modules.clear();
|
|
|
|
|
reset();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-01 19:01:37 +02:00
|
|
|
int ModulesModel::indexOfModule(const QString &modulePath) const
|
2010-05-19 15:14:15 +02:00
|
|
|
{
|
|
|
|
|
// Recent modules are more likely to be unloaded first.
|
|
|
|
|
for (int i = m_modules.size() - 1; i >= 0; i--)
|
2012-06-01 19:01:37 +02:00
|
|
|
if (m_modules.at(i).modulePath == modulePath)
|
2010-05-19 15:14:15 +02:00
|
|
|
return i;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-01 19:01:37 +02:00
|
|
|
void ModulesModel::removeModule(const QString &modulePath)
|
2010-05-19 15:14:15 +02:00
|
|
|
{
|
2012-06-01 19:01:37 +02:00
|
|
|
const int row = indexOfModule(modulePath);
|
|
|
|
|
QTC_ASSERT(row != -1, return);
|
|
|
|
|
beginRemoveRows(QModelIndex(), row, row);
|
|
|
|
|
m_modules.remove(row);
|
2010-05-19 15:14:15 +02:00
|
|
|
endRemoveRows();
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-06-01 19:01:37 +02:00
|
|
|
void ModulesModel::updateModule(const Module &module)
|
2010-07-22 16:53:01 +02:00
|
|
|
{
|
2012-06-01 19:01:37 +02:00
|
|
|
const int row = indexOfModule(module.modulePath);
|
2012-06-02 03:30:21 +02:00
|
|
|
if (row == -1) {
|
|
|
|
|
addModule(module);
|
|
|
|
|
} else {
|
|
|
|
|
m_modules[row] = module;
|
|
|
|
|
dataChanged(index(row, 0, QModelIndex()), index(row, 4, QModelIndex()));
|
|
|
|
|
}
|
2010-07-22 16:53:01 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// ModulesHandler
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2010-11-05 19:38:40 +01:00
|
|
|
ModulesHandler::ModulesHandler()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-11-05 19:38:40 +01:00
|
|
|
m_model = new ModulesModel(this);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_proxyModel = new QSortFilterProxyModel(this);
|
|
|
|
|
m_proxyModel->setSourceModel(m_model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAbstractItemModel *ModulesHandler::model() const
|
|
|
|
|
{
|
|
|
|
|
return m_proxyModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModulesHandler::removeAll()
|
|
|
|
|
{
|
|
|
|
|
m_model->clearModel();
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-19 15:14:15 +02:00
|
|
|
void ModulesHandler::addModule(const Module &module)
|
|
|
|
|
{
|
|
|
|
|
m_model->addModule(module);
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-01 19:01:37 +02:00
|
|
|
void ModulesHandler::removeModule(const QString &modulePath)
|
2010-05-19 15:14:15 +02:00
|
|
|
{
|
2012-06-01 19:01:37 +02:00
|
|
|
m_model->removeModule(modulePath);
|
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
|
|
|
{
|
2012-06-01 19:01:37 +02:00
|
|
|
m_model->updateModule(module);
|
2010-07-22 16:53:01 +02:00
|
|
|
}
|
|
|
|
|
|
2010-06-15 11:14:44 +02:00
|
|
|
void ModulesHandler::setModules(const Modules &modules)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-05-19 15:14:15 +02:00
|
|
|
m_model->setModules(modules);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-06-15 11:14:44 +02:00
|
|
|
Modules ModulesHandler::modules() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2012-06-01 19:01:37 +02:00
|
|
|
return m_model->m_modules;
|
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
|