Valgrind: Replace global toolTipForFrame() with Frame::toolTip()

Change-Id: I66cc481d588c468b9388e3b3863ed35aab406fa2
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Jarek Kobus
2023-08-08 13:58:56 +02:00
parent bb6c26cac9
commit 3970a834bc
11 changed files with 52 additions and 100 deletions

View File

@@ -34,7 +34,6 @@ add_qtc_plugin(Valgrind
xmlprotocol/error.cpp xmlprotocol/error.h xmlprotocol/error.cpp xmlprotocol/error.h
xmlprotocol/errorlistmodel.cpp xmlprotocol/errorlistmodel.h xmlprotocol/errorlistmodel.cpp xmlprotocol/errorlistmodel.h
xmlprotocol/frame.cpp xmlprotocol/frame.h xmlprotocol/frame.cpp xmlprotocol/frame.h
xmlprotocol/modelhelpers.cpp xmlprotocol/modelhelpers.h
xmlprotocol/parser.cpp xmlprotocol/parser.h xmlprotocol/parser.cpp xmlprotocol/parser.h
xmlprotocol/stack.cpp xmlprotocol/stack.h xmlprotocol/stack.cpp xmlprotocol/stack.h
xmlprotocol/stackmodel.cpp xmlprotocol/stackmodel.h xmlprotocol/stackmodel.cpp xmlprotocol/stackmodel.h

View File

@@ -64,7 +64,6 @@ QtcPlugin {
"error.cpp", "error.h", "error.cpp", "error.h",
"errorlistmodel.cpp", "errorlistmodel.h", "errorlistmodel.cpp", "errorlistmodel.h",
"frame.cpp", "frame.h", "frame.cpp", "frame.h",
"modelhelpers.cpp", "modelhelpers.h",
"parser.cpp", "parser.h", "parser.cpp", "parser.h",
"stack.cpp", "stack.h", "stack.cpp", "stack.h",
"stackmodel.cpp", "stackmodel.h", "stackmodel.cpp", "stackmodel.h",

View File

@@ -5,7 +5,6 @@
#include "error.h" #include "error.h"
#include "frame.h" #include "frame.h"
#include "stack.h" #include "stack.h"
#include "modelhelpers.h"
#include "../valgrindtr.h" #include "../valgrindtr.h"
#include <debugger/analyzer/diagnosticlocation.h> #include <debugger/analyzer/diagnosticlocation.h>
@@ -201,7 +200,7 @@ QVariant ErrorItem::data(int column, int role) const
return Tr::tr("%1 in function %2") return Tr::tr("%1 in function %2")
.arg(m_error.what(), m_error.stacks().constFirst().frames().constFirst().functionName()); .arg(m_error.what(), m_error.stacks().constFirst().frames().constFirst().functionName());
case Qt::ToolTipRole: case Qt::ToolTipRole:
return toolTipForFrame(m_model->findRelevantFrame(m_error)); return m_model->findRelevantFrame(m_error).toolTip();
default: default:
return QVariant(); return QVariant();
} }
@@ -228,7 +227,7 @@ QVariant StackItem::data(int column, int role) const
case Qt::DisplayRole: case Qt::DisplayRole:
return m_stack.auxWhat().isEmpty() ? errorItem->error().what() : m_stack.auxWhat(); return m_stack.auxWhat().isEmpty() ? errorItem->error().what() : m_stack.auxWhat();
case Qt::ToolTipRole: case Qt::ToolTipRole:
return toolTipForFrame(errorItem->modelPrivate()->findRelevantFrame(errorItem->error())); return errorItem->modelPrivate()->findRelevantFrame(errorItem->error()).toolTip();
default: default:
return QVariant(); return QVariant();
} }
@@ -263,7 +262,7 @@ QVariant FrameItem::data(int column, int role) const
.arg(makeFrameName(m_frame, false)); .arg(makeFrameName(m_frame, false));
} }
case Qt::ToolTipRole: case Qt::ToolTipRole:
return toolTipForFrame(m_frame); return m_frame.toolTip();
default: default:
return QVariant(); return QVariant();
} }

View File

@@ -3,12 +3,15 @@
#include "frame.h" #include "frame.h"
#include "../valgrindtr.h"
#include <QList>
#include <QPair>
#include <QString> #include <QString>
#include <algorithm> #include <algorithm>
namespace Valgrind { namespace Valgrind::XmlProtocol {
namespace XmlProtocol {
class Frame::Private : public QSharedData class Frame::Private : public QSharedData
{ {
@@ -129,5 +132,42 @@ void Frame::setLine(int line)
d->line = line; d->line = line;
} }
} // namespace XmlProtocol QString Frame::toolTip() const
} // namespace Valgrind {
QString location;
if (!fileName().isEmpty()) {
location = filePath();
if (line() > 0)
location += ':' + QString::number(line());
}
using StringPair = QPair<QString, QString>;
QList<StringPair> lines;
if (!functionName().isEmpty())
lines.append({Tr::tr("Function:"), functionName()});
if (!location.isEmpty())
lines.append({Tr::tr("Location:"), location});
if (instructionPointer()) {
lines.append({Tr::tr("Instruction pointer:"),
QString("0x%1").arg(instructionPointer(), 0, 16)});
}
if (!object().isEmpty())
lines.append({Tr::tr("Object:"), object()});
QString html = "<html><head>"
"<style>dt { font-weight:bold; } dd { font-family: monospace; }</style>\n"
"</head><body><dl>";
for (const StringPair &pair : std::as_const(lines)) {
html += "<dt>";
html += pair.first;
html += "</dt><dd>";
html += pair.second;
html += "</dd>\n";
}
html += "</dl></body></html>";
return html;
}
} // namespace Valgrind::XmlProtocol

View File

@@ -5,8 +5,7 @@
#include <QSharedDataPointer> #include <QSharedDataPointer>
namespace Valgrind { namespace Valgrind::XmlProtocol {
namespace XmlProtocol {
class Frame class Frame
{ {
@@ -41,10 +40,11 @@ public:
int line() const; int line() const;
void setLine(int line); void setLine(int line);
QString toolTip() const;
private: private:
class Private; class Private;
QSharedDataPointer<Private> d; QSharedDataPointer<Private> d;
}; };
} // namespace XmlProtocol } // namespace Valgrind::XmlProtocol
} // namespace Valgrind

View File

@@ -1,53 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "modelhelpers.h"
#include "frame.h"
#include "../valgrindtr.h"
#include <QString>
#include <QDir>
#include <QPair>
namespace Valgrind {
namespace XmlProtocol {
QString toolTipForFrame(const Frame &frame)
{
QString location;
if (!frame.fileName().isEmpty()) {
location = frame.filePath();
if (frame.line() > 0)
location += ':' + QString::number(frame.line());
}
using StringPair = QPair<QString, QString>;
QList<StringPair> lines;
if (!frame.functionName().isEmpty())
lines << qMakePair(Tr::tr("Function:"), frame.functionName());
if (!location.isEmpty())
lines << qMakePair(Tr::tr("Location:"), location);
if (frame.instructionPointer())
lines << qMakePair(Tr::tr("Instruction pointer:"),
QString("0x%1").arg(frame.instructionPointer(), 0, 16));
if (!frame.object().isEmpty())
lines << qMakePair(Tr::tr("Object:"), frame.object());
QString html = "<html><head>"
"<style>dt { font-weight:bold; } dd { font-family: monospace; }</style>\n"
"</head><body><dl>";
for (const StringPair &pair : std::as_const(lines)) {
html += "<dt>";
html += pair.first;
html += "</dt><dd>";
html += pair.second;
html += "</dd>\n";
}
html += "</dl></body></html>";
return html;
}
} // namespace XmlProtocol
} // namespace Valgrind

View File

@@ -1,20 +0,0 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include <QtGlobal>
QT_BEGIN_NAMESPACE
class QString;
QT_END_NAMESPACE
namespace Valgrind {
namespace XmlProtocol {
class Frame;
QString toolTipForFrame(const Frame &frame);
} // namespace XmlProtocol
} // namespace Valgrind

View File

@@ -5,7 +5,6 @@
#include "error.h" #include "error.h"
#include "frame.h" #include "frame.h"
#include "stack.h" #include "stack.h"
#include "modelhelpers.h"
#include "../valgrindtr.h" #include "../valgrindtr.h"
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
@@ -106,7 +105,7 @@ QVariant StackModel::data(const QModelIndex &index, int role) const
break; break;
} }
case Qt::ToolTipRole: case Qt::ToolTipRole:
return toolTipForFrame(frame); return frame.toolTip();
case ObjectRole: case ObjectRole:
return frame.object(); return frame.object();
case FunctionNameRole: case FunctionNameRole:

View File

@@ -19,7 +19,6 @@ function(extend_valgrind_test targetName)
xmlprotocol/error.h xmlprotocol/error.cpp xmlprotocol/error.h xmlprotocol/error.cpp
xmlprotocol/errorlistmodel.h xmlprotocol/errorlistmodel.cpp xmlprotocol/errorlistmodel.h xmlprotocol/errorlistmodel.cpp
xmlprotocol/frame.h xmlprotocol/frame.cpp xmlprotocol/frame.h xmlprotocol/frame.cpp
xmlprotocol/modelhelpers.h xmlprotocol/modelhelpers.cpp
xmlprotocol/parser.h xmlprotocol/parser.cpp xmlprotocol/parser.h xmlprotocol/parser.cpp
xmlprotocol/stack.h xmlprotocol/stack.cpp xmlprotocol/stack.h xmlprotocol/stack.cpp
xmlprotocol/stackmodel.h xmlprotocol/stackmodel.cpp xmlprotocol/stackmodel.h xmlprotocol/stackmodel.cpp

View File

@@ -12738,8 +12738,6 @@
"errorlistmodel.h" "4" "errorlistmodel.h" "4"
"frame.cpp" "4" "frame.cpp" "4"
"frame.h" "4" "frame.h" "4"
"modelhelpers.cpp" "4"
"modelhelpers.h" "4"
"parser.cpp" "4" "parser.cpp" "4"
"parser.h" "4" "parser.h" "4"
"stack.cpp" "4" "stack.cpp" "4"
@@ -14811,8 +14809,6 @@
"errorlistmodel.h" "6" "errorlistmodel.h" "6"
"frame.cpp" "6" "frame.cpp" "6"
"frame.h" "6" "frame.h" "6"
"modelhelpers.cpp" "6"
"modelhelpers.h" "6"
"parser.cpp" "6" "parser.cpp" "6"
"parser.h" "6" "parser.h" "6"
"stack.cpp" "6" "stack.cpp" "6"
1 text nestinglevel
12738 errorlistmodel.h 4
12739 frame.cpp 4
12740 frame.h 4
modelhelpers.cpp 4
modelhelpers.h 4
12741 parser.cpp 4
12742 parser.h 4
12743 stack.cpp 4
14809 errorlistmodel.h 6
14810 frame.cpp 6
14811 frame.h 6
modelhelpers.cpp 6
modelhelpers.h 6
14812 parser.cpp 6
14813 parser.h 6
14814 stack.cpp 6

View File

@@ -15805,7 +15805,6 @@
"error.h" "5" "error.h" "5"
"errorlistmodel.h" "5" "errorlistmodel.h" "5"
"frame.h" "5" "frame.h" "5"
"modelhelpers.h" "5"
"parser.h" "5" "parser.h" "5"
"stack.h" "5" "stack.h" "5"
"stackmodel.h" "5" "stackmodel.h" "5"
@@ -15817,7 +15816,6 @@
"error.cpp" "5" "error.cpp" "5"
"errorlistmodel.cpp" "5" "errorlistmodel.cpp" "5"
"frame.cpp" "5" "frame.cpp" "5"
"modelhelpers.cpp" "5"
"parser.cpp" "5" "parser.cpp" "5"
"stack.cpp" "5" "stack.cpp" "5"
"stackmodel.cpp" "5" "stackmodel.cpp" "5"
@@ -20145,7 +20143,6 @@
"error.h" "8" "error.h" "8"
"errorlistmodel.h" "8" "errorlistmodel.h" "8"
"frame.h" "8" "frame.h" "8"
"modelhelpers.h" "8"
"parser.h" "8" "parser.h" "8"
"stack.h" "8" "stack.h" "8"
"stackmodel.h" "8" "stackmodel.h" "8"
@@ -20172,7 +20169,6 @@
"error.cpp" "8" "error.cpp" "8"
"errorlistmodel.cpp" "8" "errorlistmodel.cpp" "8"
"frame.cpp" "8" "frame.cpp" "8"
"modelhelpers.cpp" "8"
"parser.cpp" "8" "parser.cpp" "8"
"stack.cpp" "8" "stack.cpp" "8"
"stackmodel.cpp" "8" "stackmodel.cpp" "8"
@@ -20258,7 +20254,6 @@
"error.h" "8" "error.h" "8"
"errorlistmodel.h" "8" "errorlistmodel.h" "8"
"frame.h" "8" "frame.h" "8"
"modelhelpers.h" "8"
"parser.h" "8" "parser.h" "8"
"stack.h" "8" "stack.h" "8"
"stackmodel.h" "8" "stackmodel.h" "8"
@@ -20285,7 +20280,6 @@
"error.cpp" "8" "error.cpp" "8"
"errorlistmodel.cpp" "8" "errorlistmodel.cpp" "8"
"frame.cpp" "8" "frame.cpp" "8"
"modelhelpers.cpp" "8"
"parser.cpp" "8" "parser.cpp" "8"
"stack.cpp" "8" "stack.cpp" "8"
"stackmodel.cpp" "8" "stackmodel.cpp" "8"
Can't render this file because it is too large.