forked from qt-creator/qt-creator
debugger: small rework of the modules handler
Use new elfreader, also slimmer interface. Change-Id: Ie6387ff14bdefd109768d1ce4c395a17211da77d Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -3505,24 +3505,18 @@ void GdbEngine::handleModulesList(const GdbResponse &response)
|
|||||||
modulesHandler()->setModules(modules);
|
modulesHandler()->setModules(modules);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GdbEngine::examineModules()
|
void GdbEngine::examineModules()
|
||||||
{
|
{
|
||||||
foreach (Module module, modulesHandler()->modules()) {
|
ModulesHandler *handler = modulesHandler();
|
||||||
|
foreach (Module module, handler->modules()) {
|
||||||
if (module.symbolsType == Module::UnknownType) {
|
if (module.symbolsType == Module::UnknownType) {
|
||||||
QProcess proc;
|
Utils::ElfReader reader(module.modulePath);
|
||||||
qDebug() << _("objdump -h \"%1\"").arg(module.modulePath);
|
QList<QByteArray> names = reader.sectionNames();
|
||||||
proc.start(_("objdump -h \"%1\"").arg(module.modulePath));
|
if (names.contains(".gdb_index"))
|
||||||
if (!proc.waitForStarted())
|
|
||||||
continue;
|
|
||||||
if (!proc.waitForFinished())
|
|
||||||
continue;
|
|
||||||
QByteArray ba = proc.readAllStandardOutput();
|
|
||||||
if (ba.contains(".gdb_index"))
|
|
||||||
module.symbolsType = Module::FastSymbols;
|
module.symbolsType = Module::FastSymbols;
|
||||||
else
|
else
|
||||||
module.symbolsType = Module::PlainSymbols;
|
module.symbolsType = Module::PlainSymbols;
|
||||||
modulesHandler()->updateModule(module.modulePath, module);
|
handler->updateModule(module);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,21 +47,46 @@
|
|||||||
namespace Debugger {
|
namespace Debugger {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
ModulesModel::ModulesModel(ModulesHandler *parent)
|
class ModulesModel : public QAbstractItemModel
|
||||||
: QAbstractItemModel(parent)
|
{
|
||||||
{}
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
QVariant ModulesModel::headerData(int section,
|
QVariant ModulesModel::headerData(int section,
|
||||||
Qt::Orientation orientation, int role) const
|
Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
|
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
|
||||||
static QString headers[] = {
|
static QString headers[] = {
|
||||||
tr("Module name") + QLatin1String(" "),
|
ModulesHandler::tr("Module name") + QLatin1String(" "),
|
||||||
tr("Module path") + QLatin1String(" "),
|
ModulesHandler::tr("Module path") + QLatin1String(" "),
|
||||||
tr("Symbols read") + QLatin1String(" "),
|
ModulesHandler::tr("Symbols read") + QLatin1String(" "),
|
||||||
tr("Symbols type") + QLatin1String(" "),
|
ModulesHandler::tr("Symbols type") + QLatin1String(" "),
|
||||||
tr("Start address") + QLatin1String(" "),
|
ModulesHandler::tr("Start address") + QLatin1String(" "),
|
||||||
tr("End address") + QLatin1String(" ")
|
ModulesHandler::tr("End address") + QLatin1String(" ")
|
||||||
};
|
};
|
||||||
return headers[section];
|
return headers[section];
|
||||||
}
|
}
|
||||||
@@ -91,17 +116,17 @@ QVariant ModulesModel::data(const QModelIndex &index, int role) const
|
|||||||
case 2:
|
case 2:
|
||||||
if (role == Qt::DisplayRole)
|
if (role == Qt::DisplayRole)
|
||||||
switch (module.symbolsRead) {
|
switch (module.symbolsRead) {
|
||||||
case Module::UnknownReadState: return tr("unknown");
|
case Module::UnknownReadState: return ModulesHandler::tr("unknown");
|
||||||
case Module::ReadFailed: return tr("no");
|
case Module::ReadFailed: return ModulesHandler::tr("no");
|
||||||
case Module::ReadOk: return tr("yes");
|
case Module::ReadOk: return ModulesHandler::tr("yes");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
if (role == Qt::DisplayRole)
|
if (role == Qt::DisplayRole)
|
||||||
switch (module.symbolsType) {
|
switch (module.symbolsType) {
|
||||||
case Module::UnknownType: return tr("unknown");
|
case Module::UnknownType: return ModulesHandler::tr("unknown");
|
||||||
case Module::PlainSymbols: return tr("plain");
|
case Module::PlainSymbols: return ModulesHandler::tr("plain");
|
||||||
case Module::FastSymbols: return tr("fast");
|
case Module::FastSymbols: return ModulesHandler::tr("fast");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
@@ -115,7 +140,7 @@ QVariant ModulesModel::data(const QModelIndex &index, int role) const
|
|||||||
return QString(QLatin1String("0x")
|
return QString(QLatin1String("0x")
|
||||||
+ QString::number(module.endAddress, 16));
|
+ QString::number(module.endAddress, 16));
|
||||||
//: End address of loaded module
|
//: End address of loaded module
|
||||||
return tr("<unknown>", "address");
|
return ModulesHandler::tr("<unknown>", "address");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -143,30 +168,30 @@ void ModulesModel::clearModel()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ModulesModel::indexOfModule(const QString &name) const
|
int ModulesModel::indexOfModule(const QString &modulePath) const
|
||||||
{
|
{
|
||||||
// Recent modules are more likely to be unloaded first.
|
// Recent modules are more likely to be unloaded first.
|
||||||
for (int i = m_modules.size() - 1; i >= 0; i--)
|
for (int i = m_modules.size() - 1; i >= 0; i--)
|
||||||
if (m_modules.at(i).moduleName == name)
|
if (m_modules.at(i).modulePath == modulePath)
|
||||||
return i;
|
return i;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModulesModel::removeModule(const QString &moduleName)
|
void ModulesModel::removeModule(const QString &modulePath)
|
||||||
{
|
{
|
||||||
const int index = indexOfModule(moduleName);
|
const int row = indexOfModule(modulePath);
|
||||||
QTC_ASSERT(index != -1, return);
|
QTC_ASSERT(row != -1, return);
|
||||||
beginRemoveRows(QModelIndex(), index, index);
|
beginRemoveRows(QModelIndex(), row, row);
|
||||||
m_modules.remove(index);
|
m_modules.remove(row);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModulesModel::updateModule(const QString &moduleName, const Module &module)
|
void ModulesModel::updateModule(const Module &module)
|
||||||
{
|
{
|
||||||
const int index = indexOfModule(moduleName);
|
const int row = indexOfModule(module.modulePath);
|
||||||
QTC_ASSERT(index != -1, return);
|
QTC_ASSERT(row != -1, return);
|
||||||
m_modules[index] = module;
|
m_modules[row] = module;
|
||||||
reset();
|
dataChanged(index(row, 0, QModelIndex()), index(row, 4, QModelIndex()));
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
@@ -197,14 +222,14 @@ void ModulesHandler::addModule(const Module &module)
|
|||||||
m_model->addModule(module);
|
m_model->addModule(module);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModulesHandler::removeModule(const QString &moduleName)
|
void ModulesHandler::removeModule(const QString &modulePath)
|
||||||
{
|
{
|
||||||
m_model->removeModule(moduleName);
|
m_model->removeModule(modulePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModulesHandler::updateModule(const QString &moduleName, const Module &module)
|
void ModulesHandler::updateModule(const Module &module)
|
||||||
{
|
{
|
||||||
m_model->updateModule(moduleName, module);
|
m_model->updateModule(module);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModulesHandler::setModules(const Modules &modules)
|
void ModulesHandler::setModules(const Modules &modules)
|
||||||
@@ -214,9 +239,8 @@ void ModulesHandler::setModules(const Modules &modules)
|
|||||||
|
|
||||||
Modules ModulesHandler::modules() const
|
Modules ModulesHandler::modules() const
|
||||||
{
|
{
|
||||||
return m_model->modules();
|
return m_model->m_modules;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace Debugger
|
} // namespace Debugger
|
||||||
|
|
||||||
|
|||||||
@@ -33,11 +33,11 @@
|
|||||||
#ifndef DEBUGGER_MODULESHANDLER_H
|
#ifndef DEBUGGER_MODULESHANDLER_H
|
||||||
#define DEBUGGER_MODULESHANDLER_H
|
#define DEBUGGER_MODULESHANDLER_H
|
||||||
|
|
||||||
#include <QAbstractItemModel>
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QAbstractItemModel;
|
||||||
class QSortFilterProxyModel;
|
class QSortFilterProxyModel;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
@@ -45,8 +45,6 @@ namespace Debugger {
|
|||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class ModulesModel;
|
class ModulesModel;
|
||||||
class ModulesHandler;
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
@@ -99,45 +97,6 @@ public:
|
|||||||
typedef QVector<Module> Modules;
|
typedef QVector<Module> Modules;
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// ModulesModel
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
class ModulesModel : public QAbstractItemModel
|
|
||||||
{
|
|
||||||
// Needs tr - context.
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
ModulesModel(ModulesHandler *parent);
|
|
||||||
|
|
||||||
// QAbstractItemModel
|
|
||||||
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 &moduleName);
|
|
||||||
void setModules(const Modules &modules);
|
|
||||||
void updateModule(const QString &moduleName, const Module &module);
|
|
||||||
|
|
||||||
const Modules &modules() const { return m_modules; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
int indexOfModule(const QString &name) const;
|
|
||||||
|
|
||||||
Modules m_modules;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// ModulesHandler
|
// ModulesHandler
|
||||||
@@ -155,8 +114,8 @@ public:
|
|||||||
|
|
||||||
void setModules(const Modules &modules);
|
void setModules(const Modules &modules);
|
||||||
void addModule(const Module &module);
|
void addModule(const Module &module);
|
||||||
void removeModule(const QString &moduleName);
|
void removeModule(const QString &modulePath);
|
||||||
void updateModule(const QString &moduleName, const Module &module);
|
void updateModule(const Module &module);
|
||||||
|
|
||||||
Modules modules() const;
|
Modules modules() const;
|
||||||
void removeAll();
|
void removeAll();
|
||||||
|
|||||||
Reference in New Issue
Block a user