2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2010-05-18 12:12:22 +02:00
|
|
|
|
|
|
|
|
#include "stackframe.h"
|
2014-02-07 18:10:02 +01:00
|
|
|
|
2015-05-27 13:59:56 +02:00
|
|
|
#include "debuggerengine.h"
|
2015-10-08 16:19:57 +02:00
|
|
|
#include "debuggerprotocol.h"
|
2022-07-05 15:37:08 +02:00
|
|
|
#include "debuggertr.h"
|
2012-08-21 16:31:03 +02:00
|
|
|
#include "watchutils.h"
|
2010-05-18 12:12:22 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QDir>
|
2014-02-07 18:10:02 +01:00
|
|
|
#include <QFileInfo>
|
2010-08-13 20:54:17 +02:00
|
|
|
|
2013-02-18 12:11:54 +01:00
|
|
|
#include <utils/hostosinfo.h>
|
|
|
|
|
|
2021-10-26 10:48:43 +02:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2022-07-05 15:37:08 +02:00
|
|
|
namespace Debugger::Internal {
|
2010-05-18 12:12:22 +02:00
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// StackFrame
|
|
|
|
|
//
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2018-07-23 22:28:49 +02:00
|
|
|
StackFrame::StackFrame() = default;
|
2010-05-18 12:12:22 +02:00
|
|
|
|
|
|
|
|
void StackFrame::clear()
|
|
|
|
|
{
|
2015-10-08 16:19:57 +02:00
|
|
|
line = -1;
|
2010-05-18 12:12:22 +02:00
|
|
|
function.clear();
|
|
|
|
|
file.clear();
|
2015-10-08 16:19:57 +02:00
|
|
|
module.clear();
|
|
|
|
|
receiver.clear();
|
2010-09-21 15:12:33 +02:00
|
|
|
address = 0;
|
2010-05-18 12:12:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool StackFrame::isUsable() const
|
|
|
|
|
{
|
2010-12-01 15:57:13 +01:00
|
|
|
return usable;
|
2010-05-18 12:12:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString StackFrame::toString() const
|
|
|
|
|
{
|
|
|
|
|
QString res;
|
|
|
|
|
QTextStream str(&res);
|
2022-07-05 15:37:08 +02:00
|
|
|
str << Tr::tr("Address:") << ' ';
|
2010-09-21 15:12:33 +02:00
|
|
|
str.setIntegerBase(16);
|
|
|
|
|
str << address;
|
|
|
|
|
str.setIntegerBase(10);
|
|
|
|
|
str << ' '
|
2022-07-05 15:37:08 +02:00
|
|
|
<< Tr::tr("Function:") << ' ' << function << ' '
|
|
|
|
|
<< Tr::tr("File:") << ' ' << file << ' '
|
|
|
|
|
<< Tr::tr("Line:") << ' ' << line << ' '
|
|
|
|
|
<< Tr::tr("From:") << ' ' << module << ' '
|
|
|
|
|
<< Tr::tr("To:") << ' ' << receiver;
|
2010-05-18 12:12:22 +02:00
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-08 16:19:57 +02:00
|
|
|
QList<StackFrame> StackFrame::parseFrames(const GdbMi &data, const DebuggerRunParameters &rp)
|
|
|
|
|
{
|
|
|
|
|
StackFrames frames;
|
2018-09-25 18:48:29 +02:00
|
|
|
frames.reserve(data.childCount());
|
|
|
|
|
for (const GdbMi &item : data)
|
2015-10-08 16:19:57 +02:00
|
|
|
frames.append(parseFrame(item, rp));
|
|
|
|
|
return frames;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StackFrame StackFrame::parseFrame(const GdbMi &frameMi, const DebuggerRunParameters &rp)
|
|
|
|
|
{
|
|
|
|
|
StackFrame frame;
|
|
|
|
|
frame.level = frameMi["level"].data();
|
2016-06-07 17:04:53 +02:00
|
|
|
frame.function = frameMi["function"].data();
|
|
|
|
|
frame.module = frameMi["module"].data();
|
2021-10-26 12:35:07 +02:00
|
|
|
const FilePath debugger = rp.debugger.command.executable();
|
|
|
|
|
frame.file = FilePath::fromString(frameMi["file"].data()).onDevice(debugger);
|
2015-10-08 16:19:57 +02:00
|
|
|
frame.line = frameMi["line"].toInt();
|
|
|
|
|
frame.address = frameMi["address"].toAddress();
|
|
|
|
|
frame.context = frameMi["context"].data();
|
|
|
|
|
if (frameMi["language"].data() == "js"
|
2018-10-07 22:38:47 +03:00
|
|
|
|| frame.file.endsWith(".js")
|
|
|
|
|
|| frame.file.endsWith(".qml")) {
|
2015-10-08 16:19:57 +02:00
|
|
|
frame.language = QmlLanguage;
|
|
|
|
|
frame.fixQrcFrame(rp);
|
|
|
|
|
}
|
|
|
|
|
GdbMi usable = frameMi["usable"];
|
|
|
|
|
if (usable.isValid())
|
|
|
|
|
frame.usable = usable.data().toInt();
|
|
|
|
|
else
|
2021-10-26 10:48:43 +02:00
|
|
|
frame.usable = frame.file.isReadableFile();
|
2015-10-08 16:19:57 +02:00
|
|
|
return frame;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-18 12:12:22 +02:00
|
|
|
QString StackFrame::toToolTip() const
|
|
|
|
|
{
|
2021-10-26 10:48:43 +02:00
|
|
|
const QString filePath = file.toUserOutput();
|
2010-05-18 12:12:22 +02:00
|
|
|
QString res;
|
|
|
|
|
QTextStream str(&res);
|
2011-10-17 15:10:16 +02:00
|
|
|
str << "<html><body><table>";
|
2012-08-21 16:31:03 +02:00
|
|
|
if (address)
|
2022-07-05 15:37:08 +02:00
|
|
|
str << "<tr><td>" << Tr::tr("Address:") << "</td><td>"
|
2012-08-21 16:31:03 +02:00
|
|
|
<< formatToolTipAddress(address) << "</td></tr>";
|
2011-10-17 15:10:16 +02:00
|
|
|
if (!function.isEmpty())
|
2014-02-07 18:10:02 +01:00
|
|
|
str << "<tr><td>"
|
2022-07-05 15:37:08 +02:00
|
|
|
<< (language == CppLanguage ? Tr::tr("Function:") : Tr::tr("JS-Function:"))
|
2014-02-07 18:10:02 +01:00
|
|
|
<< "</td><td>" << function << "</td></tr>";
|
2011-10-17 15:10:16 +02:00
|
|
|
if (!file.isEmpty())
|
2022-07-05 15:37:08 +02:00
|
|
|
str << "<tr><td>" << Tr::tr("File:") << "</td><td>" << filePath << "</td></tr>";
|
2011-10-17 15:10:16 +02:00
|
|
|
if (line != -1)
|
2022-07-05 15:37:08 +02:00
|
|
|
str << "<tr><td>" << Tr::tr("Line:") << "</td><td>" << line << "</td></tr>";
|
2015-10-08 16:19:57 +02:00
|
|
|
if (!module.isEmpty())
|
2022-07-05 15:37:08 +02:00
|
|
|
str << "<tr><td>" << Tr::tr("Module:") << "</td><td>" << module << "</td></tr>";
|
2015-10-08 16:19:57 +02:00
|
|
|
if (!receiver.isEmpty())
|
2022-07-05 15:37:08 +02:00
|
|
|
str << "<tr><td>" << Tr::tr("Receiver:") << "</td><td>" << receiver << "</td></tr>";
|
2012-03-29 10:22:05 +02:00
|
|
|
str << "</table>";
|
|
|
|
|
|
2022-07-05 15:37:08 +02:00
|
|
|
str <<"<br> <br><i>" << Tr::tr("Note:") << " </i> ";
|
2013-02-18 12:11:54 +01:00
|
|
|
bool showDistributionNote = false;
|
2012-03-29 10:22:05 +02:00
|
|
|
if (isUsable()) {
|
2022-07-05 15:37:08 +02:00
|
|
|
str << Tr::tr("Sources for this frame are available.<br>Double-click on "
|
2012-03-29 10:22:05 +02:00
|
|
|
"the file name to open an editor.");
|
|
|
|
|
} else if (line <= 0) {
|
2022-07-05 15:37:08 +02:00
|
|
|
str << Tr::tr("Binary debug information is not accessible for this "
|
2012-03-29 10:22:05 +02:00
|
|
|
"frame. This either means the core was not compiled "
|
|
|
|
|
"with debug information, or the debug information is not "
|
2013-02-18 12:11:54 +01:00
|
|
|
"accessible.");
|
|
|
|
|
showDistributionNote = true;
|
2012-03-29 10:22:05 +02:00
|
|
|
} else {
|
2022-07-05 15:37:08 +02:00
|
|
|
str << Tr::tr("Binary debug information is accessible for this "
|
2013-02-18 12:11:54 +01:00
|
|
|
"frame. However, matching sources have not been found.");
|
|
|
|
|
showDistributionNote = true;
|
|
|
|
|
}
|
2021-10-27 08:23:43 +02:00
|
|
|
if (file.osType() != OsTypeWindows && showDistributionNote) {
|
2022-07-05 15:37:08 +02:00
|
|
|
str << ' ' << Tr::tr("Note that most distributions ship debug information "
|
2018-10-07 22:38:47 +03:00
|
|
|
"in separate packages.");
|
2012-03-29 10:22:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
str << "</body></html>";
|
2010-05-18 12:12:22 +02:00
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-26 10:48:43 +02:00
|
|
|
static FilePath findFile(const FilePath &baseDir, const FilePath &relativeFile)
|
2015-10-14 13:26:22 +02:00
|
|
|
{
|
2021-10-26 10:48:43 +02:00
|
|
|
for (FilePath dir(baseDir); !dir.isEmpty(); dir = dir.parentDir()) {
|
|
|
|
|
const FilePath absolutePath = dir.resolvePath(relativeFile);
|
|
|
|
|
if (absolutePath.isFile())
|
|
|
|
|
return absolutePath;
|
2015-10-14 13:26:22 +02:00
|
|
|
}
|
2021-10-26 10:48:43 +02:00
|
|
|
return {};
|
2015-10-14 13:26:22 +02:00
|
|
|
}
|
|
|
|
|
|
2015-10-08 16:19:57 +02:00
|
|
|
// Try to resolve files coming from resource files.
|
|
|
|
|
void StackFrame::fixQrcFrame(const DebuggerRunParameters &rp)
|
2014-02-07 18:10:02 +01:00
|
|
|
{
|
|
|
|
|
if (language != QmlLanguage)
|
|
|
|
|
return;
|
2021-10-26 10:48:43 +02:00
|
|
|
if (file.isAbsolutePath()) {
|
|
|
|
|
usable = file.isFile();
|
2014-02-07 18:10:02 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2018-10-07 22:38:47 +03:00
|
|
|
if (!file.startsWith("qrc:/"))
|
2014-02-07 18:10:02 +01:00
|
|
|
return;
|
2015-10-14 13:26:22 +02:00
|
|
|
|
2021-10-26 10:48:43 +02:00
|
|
|
FilePath relativeFile = file;
|
|
|
|
|
QString relativePath = file.path();
|
|
|
|
|
relativePath = relativePath.right(relativePath.size() - 5);
|
|
|
|
|
while (relativePath.startsWith('/'))
|
|
|
|
|
relativePath = relativePath.mid(1);
|
2022-08-04 15:00:24 +02:00
|
|
|
relativeFile = relativeFile.withNewPath(relativePath);
|
2015-10-14 13:26:22 +02:00
|
|
|
|
2021-10-26 10:48:43 +02:00
|
|
|
FilePath absFile = findFile(rp.projectSourceDirectory, relativeFile);
|
2015-10-14 13:26:22 +02:00
|
|
|
if (absFile.isEmpty())
|
2021-10-26 10:48:43 +02:00
|
|
|
absFile = findFile(FilePath::fromString(QDir::currentPath()), relativeFile);
|
2015-10-14 13:26:22 +02:00
|
|
|
|
|
|
|
|
if (absFile.isEmpty())
|
2015-10-08 16:19:57 +02:00
|
|
|
return;
|
2015-10-14 13:26:22 +02:00
|
|
|
file = absFile;
|
|
|
|
|
usable = true;
|
2014-02-07 18:10:02 +01:00
|
|
|
}
|
|
|
|
|
|
2010-05-18 12:12:22 +02:00
|
|
|
QDebug operator<<(QDebug d, const StackFrame &f)
|
|
|
|
|
{
|
|
|
|
|
QString res;
|
|
|
|
|
QTextStream str(&res);
|
|
|
|
|
str << "level=" << f.level << " address=" << f.address;
|
|
|
|
|
if (!f.function.isEmpty())
|
|
|
|
|
str << ' ' << f.function;
|
|
|
|
|
if (!f.file.isEmpty())
|
|
|
|
|
str << ' ' << f.file << ':' << f.line;
|
2015-10-08 16:19:57 +02:00
|
|
|
if (!f.module.isEmpty())
|
|
|
|
|
str << " from=" << f.module;
|
|
|
|
|
if (!f.receiver.isEmpty())
|
|
|
|
|
str << " to=" << f.receiver;
|
2010-05-18 12:12:22 +02:00
|
|
|
d.nospace() << res;
|
|
|
|
|
return d;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-05 15:37:08 +02:00
|
|
|
} // Debugger::Internal
|