forked from qt-creator/qt-creator
Debugger: Use FilePath for Modules
Change-Id: Ib3c8cf0de3560fdc77775460aa6282d69dbfef9e Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -1488,12 +1488,13 @@ void CdbEngine::handleModules(const DebuggerResponse &response)
|
|||||||
{
|
{
|
||||||
if (response.resultClass == ResultDone) {
|
if (response.resultClass == ResultDone) {
|
||||||
if (response.data.type() == GdbMi::List) {
|
if (response.data.type() == GdbMi::List) {
|
||||||
|
const FilePath inferior = runParameters().inferior.command.executable();
|
||||||
ModulesHandler *handler = modulesHandler();
|
ModulesHandler *handler = modulesHandler();
|
||||||
handler->beginUpdateAll();
|
handler->beginUpdateAll();
|
||||||
for (const GdbMi &gdbmiModule : response.data) {
|
for (const GdbMi &gdbmiModule : response.data) {
|
||||||
Module module;
|
Module module;
|
||||||
module.moduleName = gdbmiModule["name"].data();
|
module.moduleName = gdbmiModule["name"].data();
|
||||||
module.modulePath = gdbmiModule["image"].data();
|
module.modulePath = inferior.withNewPath(gdbmiModule["image"].data());
|
||||||
module.startAddress = gdbmiModule["start"].data().toULongLong(nullptr, 0);
|
module.startAddress = gdbmiModule["start"].data().toULongLong(nullptr, 0);
|
||||||
module.endAddress = gdbmiModule["end"].data().toULongLong(nullptr, 0);
|
module.endAddress = gdbmiModule["end"].data().toULongLong(nullptr, 0);
|
||||||
if (gdbmiModule["deferred"].type() == GdbMi::Invalid)
|
if (gdbmiModule["deferred"].type() == GdbMi::Invalid)
|
||||||
|
@@ -470,7 +470,8 @@ void GdbEngine::handleAsyncOutput(const QStringView asyncClass, const GdbMi &res
|
|||||||
module.startAddress = 0;
|
module.startAddress = 0;
|
||||||
module.endAddress = 0;
|
module.endAddress = 0;
|
||||||
module.hostPath = result["host-name"].data();
|
module.hostPath = result["host-name"].data();
|
||||||
module.modulePath = result["target-name"].data();
|
const QString target = result["target-name"].data();
|
||||||
|
module.modulePath = runParameters().inferior.command.executable().withNewPath(target);
|
||||||
module.moduleName = QFileInfo(module.hostPath).baseName();
|
module.moduleName = QFileInfo(module.hostPath).baseName();
|
||||||
modulesHandler()->updateModule(module);
|
modulesHandler()->updateModule(module);
|
||||||
} else if (asyncClass == u"library-unloaded") {
|
} else if (asyncClass == u"library-unloaded") {
|
||||||
@@ -478,7 +479,8 @@ void GdbEngine::handleAsyncOutput(const QStringView asyncClass, const GdbMi &res
|
|||||||
// target-name="/usr/lib/libdrm.so.2",
|
// target-name="/usr/lib/libdrm.so.2",
|
||||||
// host-name="/usr/lib/libdrm.so.2"
|
// host-name="/usr/lib/libdrm.so.2"
|
||||||
QString id = result["id"].data();
|
QString id = result["id"].data();
|
||||||
modulesHandler()->removeModule(result["target-name"].data());
|
const QString target = result["target-name"].data();
|
||||||
|
modulesHandler()->removeModule(runParameters().inferior.command.executable().withNewPath(target));
|
||||||
progressPing();
|
progressPing();
|
||||||
showStatusMessage(Tr::tr("Library %1 unloaded.").arg(id), 1000);
|
showStatusMessage(Tr::tr("Library %1 unloaded.").arg(id), 1000);
|
||||||
} else if (asyncClass == u"thread-group-added") {
|
} else if (asyncClass == u"thread-group-added") {
|
||||||
@@ -2811,7 +2813,7 @@ void GdbEngine::loadSymbolsForStack()
|
|||||||
for (const Module &module : modules) {
|
for (const Module &module : modules) {
|
||||||
if (module.startAddress <= frame.address
|
if (module.startAddress <= frame.address
|
||||||
&& frame.address < module.endAddress) {
|
&& frame.address < module.endAddress) {
|
||||||
runCommand({"sharedlibrary " + dotEscape(module.modulePath)});
|
runCommand({"sharedlibrary " + dotEscape(module.modulePath.path())});
|
||||||
needUpdate = true;
|
needUpdate = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2956,11 +2958,6 @@ void GdbEngine::reloadModulesInternal()
|
|||||||
runCommand({"info shared", NeedsTemporaryStop, CB(handleModulesList)});
|
runCommand({"info shared", NeedsTemporaryStop, CB(handleModulesList)});
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString nameFromPath(const QString &path)
|
|
||||||
{
|
|
||||||
return QFileInfo(path).baseName();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GdbEngine::handleModulesList(const DebuggerResponse &response)
|
void GdbEngine::handleModulesList(const DebuggerResponse &response)
|
||||||
{
|
{
|
||||||
if (response.resultClass == ResultDone) {
|
if (response.resultClass == ResultDone) {
|
||||||
@@ -2971,14 +2968,15 @@ void GdbEngine::handleModulesList(const DebuggerResponse &response)
|
|||||||
QString data = response.consoleStreamOutput;
|
QString data = response.consoleStreamOutput;
|
||||||
QTextStream ts(&data, QIODevice::ReadOnly);
|
QTextStream ts(&data, QIODevice::ReadOnly);
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
const FilePath inferior = runParameters().inferior.command.executable();
|
||||||
while (!ts.atEnd()) {
|
while (!ts.atEnd()) {
|
||||||
QString line = ts.readLine();
|
QString line = ts.readLine();
|
||||||
QString symbolsRead;
|
QString symbolsRead;
|
||||||
QTextStream ts(&line, QIODevice::ReadOnly);
|
QTextStream ts(&line, QIODevice::ReadOnly);
|
||||||
if (line.startsWith("0x")) {
|
if (line.startsWith("0x")) {
|
||||||
ts >> module.startAddress >> module.endAddress >> symbolsRead;
|
ts >> module.startAddress >> module.endAddress >> symbolsRead;
|
||||||
module.modulePath = ts.readLine().trimmed();
|
module.modulePath = inferior.withNewPath(ts.readLine().trimmed());
|
||||||
module.moduleName = nameFromPath(module.modulePath);
|
module.moduleName = module.modulePath.baseName();
|
||||||
module.symbolsRead =
|
module.symbolsRead =
|
||||||
(symbolsRead == "Yes" ? Module::ReadOk : Module::ReadFailed);
|
(symbolsRead == "Yes" ? Module::ReadOk : Module::ReadFailed);
|
||||||
handler->updateModule(module);
|
handler->updateModule(module);
|
||||||
@@ -2989,8 +2987,8 @@ void GdbEngine::handleModulesList(const DebuggerResponse &response)
|
|||||||
QTC_ASSERT(symbolsRead == "No", continue);
|
QTC_ASSERT(symbolsRead == "No", continue);
|
||||||
module.startAddress = 0;
|
module.startAddress = 0;
|
||||||
module.endAddress = 0;
|
module.endAddress = 0;
|
||||||
module.modulePath = ts.readLine().trimmed();
|
module.modulePath = inferior.withNewPath(ts.readLine().trimmed());
|
||||||
module.moduleName = nameFromPath(module.modulePath);
|
module.moduleName = module.modulePath.baseName();
|
||||||
handler->updateModule(module);
|
handler->updateModule(module);
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
@@ -3002,8 +3000,8 @@ void GdbEngine::handleModulesList(const DebuggerResponse &response)
|
|||||||
// loaded_addr="0x8fe00000",slide="0x0",prefix="__dyld_"},
|
// loaded_addr="0x8fe00000",slide="0x0",prefix="__dyld_"},
|
||||||
// shlib-info={...}...
|
// shlib-info={...}...
|
||||||
for (const GdbMi &item : response.data) {
|
for (const GdbMi &item : response.data) {
|
||||||
module.modulePath = item["path"].data();
|
module.modulePath = inferior.withNewPath(item["path"].data());
|
||||||
module.moduleName = nameFromPath(module.modulePath);
|
module.moduleName = module.modulePath.baseName();
|
||||||
module.symbolsRead = (item["state"].data() == "Y")
|
module.symbolsRead = (item["state"].data() == "Y")
|
||||||
? Module::ReadOk : Module::ReadFailed;
|
? Module::ReadOk : Module::ReadFailed;
|
||||||
module.startAddress =
|
module.startAddress =
|
||||||
@@ -3922,7 +3920,7 @@ void GdbEngine::handleGdbStarted()
|
|||||||
Module module;
|
Module module;
|
||||||
module.startAddress = 0;
|
module.startAddress = 0;
|
||||||
module.endAddress = 0;
|
module.endAddress = 0;
|
||||||
module.modulePath = rp.inferior.command.executable().toString();
|
module.modulePath = rp.inferior.command.executable();
|
||||||
module.moduleName = "<executable>";
|
module.moduleName = "<executable>";
|
||||||
modulesHandler()->updateModule(module);
|
modulesHandler()->updateModule(module);
|
||||||
|
|
||||||
|
@@ -643,12 +643,13 @@ void LldbEngine::reloadModules()
|
|||||||
{
|
{
|
||||||
DebuggerCommand cmd("fetchModules");
|
DebuggerCommand cmd("fetchModules");
|
||||||
cmd.callback = [this](const DebuggerResponse &response) {
|
cmd.callback = [this](const DebuggerResponse &response) {
|
||||||
|
const FilePath inferior = runParameters().inferior.command.executable();
|
||||||
const GdbMi &modules = response.data["modules"];
|
const GdbMi &modules = response.data["modules"];
|
||||||
ModulesHandler *handler = modulesHandler();
|
ModulesHandler *handler = modulesHandler();
|
||||||
handler->beginUpdateAll();
|
handler->beginUpdateAll();
|
||||||
for (const GdbMi &item : modules) {
|
for (const GdbMi &item : modules) {
|
||||||
Module module;
|
Module module;
|
||||||
module.modulePath = item["file"].data();
|
module.modulePath = inferior.withNewPath(item["file"].data());
|
||||||
module.moduleName = item["name"].data();
|
module.moduleName = item["name"].data();
|
||||||
module.symbolsRead = Module::UnknownReadState;
|
module.symbolsRead = Module::UnknownReadState;
|
||||||
module.startAddress = item["loaded_addr"].toAddress();
|
module.startAddress = item["loaded_addr"].toAddress();
|
||||||
|
@@ -48,7 +48,7 @@ QVariant ModuleItem::data(int column, int role) const
|
|||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
if (role == Qt::DisplayRole)
|
if (role == Qt::DisplayRole)
|
||||||
return module.modulePath;
|
return module.modulePath.toUserOutput();
|
||||||
if (role == Qt::ToolTipRole) {
|
if (role == Qt::ToolTipRole) {
|
||||||
QString msg;
|
QString msg;
|
||||||
if (!module.elfData.buildId.isEmpty())
|
if (!module.elfData.buildId.isEmpty())
|
||||||
@@ -150,7 +150,7 @@ bool ModulesModel::contextMenuEvent(const ItemViewEvent &ev)
|
|||||||
const bool canShowSymbols = engine->hasCapability(ShowModuleSymbolsCapability);
|
const bool canShowSymbols = engine->hasCapability(ShowModuleSymbolsCapability);
|
||||||
const bool moduleNameValid = item && !item->module.moduleName.isEmpty();
|
const bool moduleNameValid = item && !item->module.moduleName.isEmpty();
|
||||||
const QString moduleName = item ? item->module.moduleName : QString();
|
const QString moduleName = item ? item->module.moduleName : QString();
|
||||||
const QString modulePath = item ? item->module.modulePath : QString();
|
const FilePath modulePath = item ? item->module.modulePath : FilePath();
|
||||||
|
|
||||||
auto menu = new QMenu;
|
auto menu = new QMenu;
|
||||||
|
|
||||||
@@ -161,13 +161,13 @@ bool ModulesModel::contextMenuEvent(const ItemViewEvent &ev)
|
|||||||
addAction(this, menu, Tr::tr("Show Source Files for Module \"%1\"").arg(moduleName),
|
addAction(this, menu, Tr::tr("Show Source Files for Module \"%1\"").arg(moduleName),
|
||||||
Tr::tr("Show Source Files for Module"),
|
Tr::tr("Show Source Files for Module"),
|
||||||
moduleNameValid && enabled && canReload,
|
moduleNameValid && enabled && canReload,
|
||||||
[this, modulePath] { engine->loadSymbols(FilePath::fromUserInput(modulePath)); });
|
[this, modulePath] { engine->loadSymbols(modulePath); });
|
||||||
|
|
||||||
// FIXME: Dependencies only available on Windows, when "depends" is installed.
|
// FIXME: Dependencies only available on Windows, when "depends" is installed.
|
||||||
addAction(this, menu, Tr::tr("Show Dependencies of \"%1\"").arg(moduleName),
|
addAction(this, menu, Tr::tr("Show Dependencies of \"%1\"").arg(moduleName),
|
||||||
Tr::tr("Show Dependencies"),
|
Tr::tr("Show Dependencies"),
|
||||||
moduleNameValid && !moduleName.isEmpty() && HostOsInfo::isWindowsHost(),
|
moduleNameValid && !moduleName.isEmpty() && HostOsInfo::isWindowsHost(),
|
||||||
[modulePath] { QtcProcess::startDetached({{"depends"}, {modulePath}}); });
|
[modulePath] { QtcProcess::startDetached({{"depends"}, {modulePath.toString()}}); });
|
||||||
|
|
||||||
addAction(this, menu, Tr::tr("Load Symbols for All Modules"),
|
addAction(this, menu, Tr::tr("Load Symbols for All Modules"),
|
||||||
enabled && canLoadSymbols,
|
enabled && canLoadSymbols,
|
||||||
@@ -180,22 +180,22 @@ bool ModulesModel::contextMenuEvent(const ItemViewEvent &ev)
|
|||||||
addAction(this, menu, Tr::tr("Load Symbols for Module \"%1\"").arg(moduleName),
|
addAction(this, menu, Tr::tr("Load Symbols for Module \"%1\"").arg(moduleName),
|
||||||
Tr::tr("Load Symbols for Module"),
|
Tr::tr("Load Symbols for Module"),
|
||||||
moduleNameValid && canLoadSymbols,
|
moduleNameValid && canLoadSymbols,
|
||||||
[this, modulePath] { engine->loadSymbols(FilePath::fromUserInput(modulePath)); });
|
[this, modulePath] { engine->loadSymbols(modulePath); });
|
||||||
|
|
||||||
addAction(this, menu, Tr::tr("Edit File \"%1\"").arg(moduleName),
|
addAction(this, menu, Tr::tr("Edit File \"%1\"").arg(moduleName),
|
||||||
Tr::tr("Edit File"),
|
Tr::tr("Edit File"),
|
||||||
moduleNameValid,
|
moduleNameValid,
|
||||||
[this, modulePath] { engine->gotoLocation(FilePath::fromString(modulePath)); });
|
[this, modulePath] { engine->gotoLocation(modulePath); });
|
||||||
|
|
||||||
addAction(this, menu, Tr::tr("Show Symbols in File \"%1\"").arg(moduleName),
|
addAction(this, menu, Tr::tr("Show Symbols in File \"%1\"").arg(moduleName),
|
||||||
Tr::tr("Show Symbols"),
|
Tr::tr("Show Symbols"),
|
||||||
canShowSymbols && moduleNameValid,
|
canShowSymbols && moduleNameValid,
|
||||||
[this, modulePath] { engine->requestModuleSymbols(FilePath::fromUserInput(modulePath)); });
|
[this, modulePath] { engine->requestModuleSymbols(modulePath); });
|
||||||
|
|
||||||
addAction(this, menu, Tr::tr("Show Sections in File \"%1\"").arg(moduleName),
|
addAction(this, menu, Tr::tr("Show Sections in File \"%1\"").arg(moduleName),
|
||||||
Tr::tr("Show Sections"),
|
Tr::tr("Show Sections"),
|
||||||
canShowSymbols && moduleNameValid,
|
canShowSymbols && moduleNameValid,
|
||||||
[this, modulePath] { engine->requestModuleSections(FilePath::fromUserInput(modulePath)); });
|
[this, modulePath] { engine->requestModuleSections(modulePath); });
|
||||||
|
|
||||||
menu->addAction(debuggerSettings()->settingsDialog.action());
|
menu->addAction(debuggerSettings()->settingsDialog.action());
|
||||||
|
|
||||||
@@ -239,7 +239,7 @@ QAbstractItemModel *ModulesHandler::model() const
|
|||||||
return m_proxyModel;
|
return m_proxyModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
ModuleItem *ModulesHandler::moduleFromPath(const QString &modulePath) const
|
ModuleItem *ModulesHandler::moduleFromPath(const FilePath &modulePath) const
|
||||||
{
|
{
|
||||||
// Recent modules are more likely to be unloaded first.
|
// Recent modules are more likely to be unloaded first.
|
||||||
return m_model->findItemAtLevel<1>([modulePath](ModuleItem *item) {
|
return m_model->findItemAtLevel<1>([modulePath](ModuleItem *item) {
|
||||||
@@ -259,7 +259,7 @@ const Modules ModulesHandler::modules() const
|
|||||||
return mods;
|
return mods;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModulesHandler::removeModule(const QString &modulePath)
|
void ModulesHandler::removeModule(const FilePath &modulePath)
|
||||||
{
|
{
|
||||||
if (ModuleItem *item = moduleFromPath(modulePath))
|
if (ModuleItem *item = moduleFromPath(modulePath))
|
||||||
m_model->destroyItem(item);
|
m_model->destroyItem(item);
|
||||||
@@ -267,7 +267,7 @@ void ModulesHandler::removeModule(const QString &modulePath)
|
|||||||
|
|
||||||
void ModulesHandler::updateModule(const Module &module)
|
void ModulesHandler::updateModule(const Module &module)
|
||||||
{
|
{
|
||||||
const QString path = module.modulePath;
|
const FilePath path = module.modulePath;
|
||||||
if (path.isEmpty())
|
if (path.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -281,12 +281,12 @@ void ModulesHandler::updateModule(const Module &module)
|
|||||||
}
|
}
|
||||||
|
|
||||||
try { // MinGW occasionallly throws std::bad_alloc.
|
try { // MinGW occasionallly throws std::bad_alloc.
|
||||||
ElfReader reader(FilePath::fromUserInput(path));
|
ElfReader reader(path);
|
||||||
item->module.elfData = reader.readHeaders();
|
item->module.elfData = reader.readHeaders();
|
||||||
item->update();
|
item->update();
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
qWarning("%s: An exception occurred while reading module '%s'",
|
qWarning("%s: An exception occurred while reading module '%s'",
|
||||||
Q_FUNC_INFO, qPrintable(module.modulePath));
|
Q_FUNC_INFO, qPrintable(module.modulePath.toUserOutput()));
|
||||||
}
|
}
|
||||||
item->updated = true;
|
item->updated = true;
|
||||||
}
|
}
|
||||||
|
@@ -70,7 +70,7 @@ public:
|
|||||||
ReadOk // Dwarf index available.
|
ReadOk // Dwarf index available.
|
||||||
};
|
};
|
||||||
QString moduleName;
|
QString moduleName;
|
||||||
QString modulePath;
|
Utils::FilePath modulePath;
|
||||||
QString hostPath;
|
QString hostPath;
|
||||||
SymbolReadState symbolsRead = UnknownReadState;
|
SymbolReadState symbolsRead = UnknownReadState;
|
||||||
quint64 startAddress = 0;
|
quint64 startAddress = 0;
|
||||||
@@ -99,7 +99,7 @@ public:
|
|||||||
|
|
||||||
QAbstractItemModel *model() const;
|
QAbstractItemModel *model() const;
|
||||||
|
|
||||||
void removeModule(const QString &modulePath);
|
void removeModule(const Utils::FilePath &modulePath);
|
||||||
void updateModule(const Module &module);
|
void updateModule(const Module &module);
|
||||||
|
|
||||||
void beginUpdateAll();
|
void beginUpdateAll();
|
||||||
@@ -109,7 +109,7 @@ public:
|
|||||||
const Modules modules() const;
|
const Modules modules() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ModuleItem *moduleFromPath(const QString &modulePath) const;
|
ModuleItem *moduleFromPath(const Utils::FilePath &modulePath) const;
|
||||||
|
|
||||||
ModulesModel *m_model;
|
ModulesModel *m_model;
|
||||||
QSortFilterProxyModel *m_proxyModel;
|
QSortFilterProxyModel *m_proxyModel;
|
||||||
|
@@ -294,7 +294,7 @@ void PdbEngine::refreshModules(const GdbMi &modules)
|
|||||||
&& path.endsWith("' (built-in)>")) {
|
&& path.endsWith("' (built-in)>")) {
|
||||||
path = "(builtin)";
|
path = "(builtin)";
|
||||||
}
|
}
|
||||||
module.modulePath = path;
|
module.modulePath = FilePath::fromString(path);
|
||||||
handler->updateModule(module);
|
handler->updateModule(module);
|
||||||
}
|
}
|
||||||
handler->endUpdateAll();
|
handler->endUpdateAll();
|
||||||
|
@@ -600,7 +600,7 @@ void UvscEngine::handleProjectClosed()
|
|||||||
Module module;
|
Module module;
|
||||||
module.startAddress = 0;
|
module.startAddress = 0;
|
||||||
module.endAddress = 0;
|
module.endAddress = 0;
|
||||||
module.modulePath = rp.inferior.command.executable().toString();
|
module.modulePath = rp.inferior.command.executable();
|
||||||
module.moduleName = "<executable>";
|
module.moduleName = "<executable>";
|
||||||
modulesHandler()->updateModule(module);
|
modulesHandler()->updateModule(module);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user