2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
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"
|
|
|
|
|
|
2016-09-20 14:01:17 +02:00
|
|
|
#include "debuggeractions.h"
|
2016-07-18 12:36:31 +02:00
|
|
|
#include "debuggerconstants.h"
|
|
|
|
|
#include "debuggercore.h"
|
|
|
|
|
#include "debuggerengine.h"
|
|
|
|
|
|
|
|
|
|
#include <utils/basetreeview.h>
|
|
|
|
|
#include <utils/hostosinfo.h>
|
2009-02-17 11:16:23 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2016-09-20 14:01:17 +02:00
|
|
|
#include <utils/savedaction.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>
|
2016-07-18 12:36:31 +02:00
|
|
|
#include <QMenu>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QSortFilterProxyModel>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-07-18 12:36:31 +02:00
|
|
|
#include <functional>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-07-18 12:36:31 +02:00
|
|
|
using namespace Utils;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
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
|
|
|
{
|
2016-07-18 12:36:31 +02:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(Debuggger::Internal::ModulesHandler)
|
|
|
|
|
|
2012-06-01 19:01:37 +02:00
|
|
|
public:
|
2016-07-18 12:36:31 +02:00
|
|
|
QVariant data(int column, int role) const override;
|
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) {
|
2016-07-18 12:36:31 +02:00
|
|
|
case Module::UnknownReadState: return tr("Unknown");
|
|
|
|
|
case Module::ReadFailed: return tr("No");
|
|
|
|
|
case Module::ReadOk: return 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) {
|
2016-07-18 12:36:31 +02:00
|
|
|
case UnknownSymbols: return tr("Unknown");
|
|
|
|
|
case NoSymbols: return tr("None");
|
|
|
|
|
case PlainSymbols: return tr("Plain");
|
|
|
|
|
case FastSymbols: return tr("Fast");
|
|
|
|
|
case LinkedSymbols: return tr("debuglnk");
|
|
|
|
|
case BuildIdSymbols: return 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:
|
2016-07-18 12:36:31 +02:00
|
|
|
return tr("It is unknown whether this module contains debug "
|
|
|
|
|
"information.\nUse \"Examine Symbols\" from the "
|
|
|
|
|
"context menu to initiate a check.");
|
2015-01-13 22:42:30 +01:00
|
|
|
case NoSymbols:
|
2016-07-18 12:36:31 +02:00
|
|
|
return tr("This module neither contains nor references debug "
|
|
|
|
|
"information.\nStepping into the module or setting "
|
|
|
|
|
"breakpoints by file and line will not work.");
|
2015-01-13 22:42:30 +01:00
|
|
|
case PlainSymbols:
|
2016-07-18 12:36:31 +02:00
|
|
|
return tr("This module contains debug information.\nStepping "
|
|
|
|
|
"into the module or setting breakpoints by file and "
|
|
|
|
|
"line is expected to work.");
|
2015-01-13 22:42:30 +01:00
|
|
|
case FastSymbols:
|
2016-07-18 12:36:31 +02:00
|
|
|
return tr("This module contains debug information.\nStepping "
|
|
|
|
|
"into the module or setting breakpoints by file and "
|
|
|
|
|
"line is expected to work.");
|
2015-01-13 22:42:30 +01:00
|
|
|
case LinkedSymbols:
|
|
|
|
|
case BuildIdSymbols:
|
2016-07-18 12:36:31 +02:00
|
|
|
return tr("This module does not contain debug information "
|
|
|
|
|
"itself, but contains a reference to external "
|
|
|
|
|
"debug information.");
|
2015-01-13 22:42:30 +01:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
if (role == Qt::DisplayRole)
|
|
|
|
|
if (module.startAddress)
|
2016-07-18 12:36:31 +02:00
|
|
|
return QString("0x" + QString::number(module.startAddress, 16));
|
2015-01-13 22:42:30 +01:00
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
if (role == Qt::DisplayRole) {
|
|
|
|
|
if (module.endAddress)
|
2016-07-18 12:36:31 +02:00
|
|
|
return QString("0x" + QString::number(module.endAddress, 16));
|
2015-01-13 22:42:30 +01:00
|
|
|
//: End address of loaded module
|
2016-07-18 12:36:31 +02:00
|
|
|
return 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
|
|
|
}
|
|
|
|
|
|
2016-09-20 14:01:17 +02:00
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// ModulesModel
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
class ModulesModel : public TreeModel<TypedTreeItem<ModuleItem>, ModuleItem>
|
2016-07-18 12:36:31 +02:00
|
|
|
{
|
2016-09-20 14:01:17 +02:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(Debuggger::Internal::ModulesHandler)
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
bool setData(const QModelIndex &idx, const QVariant &data, int role) override
|
|
|
|
|
{
|
|
|
|
|
if (role == BaseTreeView::ItemViewEventRole) {
|
|
|
|
|
ItemViewEvent ev = data.value<ItemViewEvent>();
|
|
|
|
|
if (ev.type() == QEvent::ContextMenu)
|
|
|
|
|
return contextMenuEvent(ev);
|
|
|
|
|
}
|
2016-07-18 12:36:31 +02:00
|
|
|
|
2016-09-20 14:01:17 +02:00
|
|
|
return TreeModel::setData(idx, data, role);
|
2016-07-18 12:36:31 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-20 14:01:17 +02:00
|
|
|
bool contextMenuEvent(const ItemViewEvent &ev);
|
|
|
|
|
|
|
|
|
|
DebuggerEngine *engine;
|
|
|
|
|
};
|
2016-07-18 12:36:31 +02:00
|
|
|
|
2016-09-20 14:01:17 +02:00
|
|
|
bool ModulesModel::contextMenuEvent(const ItemViewEvent &ev)
|
2016-07-18 12:36:31 +02:00
|
|
|
{
|
2016-09-20 14:01:17 +02:00
|
|
|
ModuleItem *item = itemForIndexAtLevel<1>(ev.index());
|
2016-07-18 12:36:31 +02:00
|
|
|
|
|
|
|
|
const bool enabled = engine->debuggerActionsEnabled();
|
|
|
|
|
const bool canReload = engine->hasCapability(ReloadModuleCapability);
|
|
|
|
|
const bool canLoadSymbols = engine->hasCapability(ReloadModuleSymbolsCapability);
|
|
|
|
|
const bool canShowSymbols = engine->hasCapability(ShowModuleSymbolsCapability);
|
2016-09-20 14:01:17 +02:00
|
|
|
const bool moduleNameValid = item && !item->module.moduleName.isEmpty();
|
|
|
|
|
const QString moduleName = item ? item->module.moduleName : QString();
|
|
|
|
|
const QString modulePath = item ? item->module.modulePath : QString();
|
|
|
|
|
|
|
|
|
|
auto menu = new QMenu;
|
2016-07-18 12:36:31 +02:00
|
|
|
|
|
|
|
|
addAction(menu, tr("Update Module List"),
|
|
|
|
|
enabled && canReload,
|
|
|
|
|
[this] { engine->reloadModules(); });
|
|
|
|
|
|
2016-09-20 14:01:17 +02:00
|
|
|
addAction(menu, tr("Show Source Files for Module \"%1\"").arg(moduleName),
|
|
|
|
|
tr("Show Source Files for Module"),
|
|
|
|
|
moduleNameValid && enabled && canReload,
|
|
|
|
|
[this, modulePath] { engine->loadSymbols(modulePath); });
|
2016-07-18 12:36:31 +02:00
|
|
|
|
|
|
|
|
// FIXME: Dependencies only available on Windows, when "depends" is installed.
|
2016-09-20 14:01:17 +02:00
|
|
|
addAction(menu, tr("Show Dependencies of \"%1\"").arg(moduleName),
|
2016-07-18 12:36:31 +02:00
|
|
|
tr("Show Dependencies"),
|
2016-09-20 14:01:17 +02:00
|
|
|
moduleNameValid && !moduleName.isEmpty() && HostOsInfo::isWindowsHost(),
|
2017-09-07 17:05:47 +02:00
|
|
|
[modulePath] { QProcess::startDetached("depends", {modulePath}); });
|
2016-07-18 12:36:31 +02:00
|
|
|
|
|
|
|
|
addAction(menu, tr("Load Symbols for All Modules"),
|
|
|
|
|
enabled && canLoadSymbols,
|
|
|
|
|
[this] { engine->loadAllSymbols(); });
|
|
|
|
|
|
|
|
|
|
addAction(menu, tr("Examine All Modules"),
|
|
|
|
|
enabled && canLoadSymbols,
|
|
|
|
|
[this] { engine->examineModules(); });
|
|
|
|
|
|
2016-09-20 14:01:17 +02:00
|
|
|
addAction(menu, tr("Load Symbols for Module \"%1\"").arg(moduleName),
|
2016-07-18 12:36:31 +02:00
|
|
|
tr("Load Symbols for Module"),
|
2016-09-20 14:01:17 +02:00
|
|
|
moduleNameValid && canLoadSymbols,
|
|
|
|
|
[this, modulePath] { engine->loadSymbols(modulePath); });
|
2016-07-18 12:36:31 +02:00
|
|
|
|
2016-09-20 14:01:17 +02:00
|
|
|
addAction(menu, tr("Edit File \"%1\"").arg(moduleName),
|
2016-07-18 12:36:31 +02:00
|
|
|
tr("Edit File"),
|
|
|
|
|
moduleNameValid,
|
2016-09-20 14:01:17 +02:00
|
|
|
[this, modulePath] { engine->gotoLocation(modulePath); });
|
2016-07-18 12:36:31 +02:00
|
|
|
|
2016-09-20 14:01:17 +02:00
|
|
|
addAction(menu, tr("Show Symbols in File \"%1\"").arg(moduleName),
|
2016-07-18 12:36:31 +02:00
|
|
|
tr("Show Symbols"),
|
|
|
|
|
canShowSymbols && moduleNameValid,
|
2016-09-20 14:01:17 +02:00
|
|
|
[this, modulePath] { engine->requestModuleSymbols(modulePath); });
|
2016-07-18 12:36:31 +02:00
|
|
|
|
2016-09-20 14:01:17 +02:00
|
|
|
addAction(menu, tr("Show Sections in File \"%1\"").arg(moduleName),
|
2016-07-18 12:36:31 +02:00
|
|
|
tr("Show Sections"),
|
|
|
|
|
canShowSymbols && moduleNameValid,
|
2016-09-20 14:01:17 +02:00
|
|
|
[this, modulePath] { engine->requestModuleSections(modulePath); });
|
2016-07-18 12:36:31 +02:00
|
|
|
|
2016-09-20 14:01:17 +02:00
|
|
|
menu->addSeparator();
|
|
|
|
|
menu->addAction(action(SettingsDialog));
|
|
|
|
|
|
|
|
|
|
menu->popup(ev.globalPos());
|
2016-07-18 12:36:31 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// ModulesHandler
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2012-08-28 10:53:33 +02:00
|
|
|
ModulesHandler::ModulesHandler(DebuggerEngine *engine)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2016-07-18 12:36:31 +02:00
|
|
|
QString pad = " ";
|
|
|
|
|
m_model = new ModulesModel;
|
2016-09-20 14:01:17 +02:00
|
|
|
m_model->engine = engine;
|
2016-07-18 12:36:31 +02:00
|
|
|
m_model->setObjectName("ModulesModel");
|
|
|
|
|
m_model->setHeader(QStringList({
|
|
|
|
|
tr("Module Name") + pad,
|
|
|
|
|
tr("Module Path") + pad,
|
|
|
|
|
tr("Symbols Read") + pad,
|
|
|
|
|
tr("Symbols Type") + pad,
|
|
|
|
|
tr("Start Address") + pad,
|
|
|
|
|
tr("End Address") + pad}));
|
2015-01-13 22:42:30 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
m_proxyModel = new QSortFilterProxyModel(this);
|
2016-07-18 12:36:31 +02:00
|
|
|
m_proxyModel->setObjectName("ModulesProxyModel");
|
2008-12-02 12:01:29 +01:00
|
|
|
m_proxyModel->setSourceModel(m_model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAbstractItemModel *ModulesHandler::model() const
|
|
|
|
|
{
|
|
|
|
|
return m_proxyModel;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-18 12:36:31 +02:00
|
|
|
ModuleItem *ModulesHandler::moduleFromPath(const QString &modulePath) const
|
|
|
|
|
{
|
|
|
|
|
// Recent modules are more likely to be unloaded first.
|
2016-06-24 09:36:42 +02:00
|
|
|
return m_model->findItemAtLevel<1>([modulePath](ModuleItem *item) {
|
2016-07-18 12:36:31 +02:00
|
|
|
return item->module.modulePath == modulePath;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
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;
|
2016-06-24 09:36:42 +02:00
|
|
|
m_model->forItemsAtLevel<1>([&mods](ModuleItem *item) { mods.append(item->module); });
|
2015-01-13 22:42:30 +01:00
|
|
|
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
|
|
|
{
|
2016-07-18 12:36:31 +02:00
|
|
|
if (ModuleItem *item = moduleFromPath(modulePath))
|
2016-07-04 15:53:53 +02:00
|
|
|
m_model->destroyItem(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;
|
|
|
|
|
|
2016-07-18 12:36:31 +02:00
|
|
|
ModuleItem *item = moduleFromPath(path);
|
2015-01-13 22:42:30 +01:00
|
|
|
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
|
|
|
{
|
2016-06-24 09:36:42 +02:00
|
|
|
m_model->forItemsAtLevel<1>([](ModuleItem *item) { item->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
|
|
|
{
|
2016-07-18 12:36:31 +02:00
|
|
|
QList<TreeItem *> toDestroy;
|
2016-06-24 09:36:42 +02:00
|
|
|
m_model->forItemsAtLevel<1>([&toDestroy](ModuleItem *item) {
|
2015-01-13 22:42:30 +01:00
|
|
|
if (!item->updated)
|
2016-07-18 12:36:31 +02:00
|
|
|
toDestroy.append(item);
|
|
|
|
|
});
|
2017-07-18 08:51:26 +02:00
|
|
|
for (TreeItem *item : toDestroy)
|
|
|
|
|
m_model->destroyItem(item);
|
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
|