Debugger: Save symbol tree display options to layout files
Some checks are pending
🐧 Linux Builds / AppImage (push) Waiting to run
🐧 Linux Builds / Flatpak (push) Waiting to run
🍎 MacOS Builds / Defaults (push) Waiting to run
🖥️ Windows Builds / Lint VS Project Files (push) Waiting to run
🖥️ Windows Builds / SSE4 (push) Blocked by required conditions
🖥️ Windows Builds / AVX2 (push) Blocked by required conditions
🖥️ Windows Builds / CMake (push) Waiting to run

This commit is contained in:
chaoticgd 2025-08-19 11:45:14 +01:00 committed by Ty
parent a5537da4df
commit c543c05968
3 changed files with 84 additions and 22 deletions

View File

@ -724,15 +724,43 @@ void SymbolTreeNode::sortChildrenRecursively(bool sort_by_if_type_is_known)
// *****************************************************************************
int SymbolTreeDisplayOptions::integerBase() const
{
return m_integer_base;
}
bool SymbolTreeDisplayOptions::setIntegerBase(int base)
{
if (base == m_integer_base || (base != 2 && base != 8 && base != 10 && base != 16))
return false;
m_integer_base = base;
return true;
}
bool SymbolTreeDisplayOptions::showLeadingZeroes() const
{
return m_show_leading_zeroes;
}
bool SymbolTreeDisplayOptions::setShowLeadingZeroes(bool show)
{
if (show == m_show_leading_zeroes)
return false;
m_show_leading_zeroes = show;
return true;
}
std::optional<u64> SymbolTreeDisplayOptions::stringToUnsignedInteger(QString string) const
{
bool ok;
u64 value = string.toULongLong(&ok, integer_base);
u64 value = string.toULongLong(&ok, m_integer_base);
if (!ok)
{
// Try parsing it as a signed integer too, just in case the user tried
// to use a minus sign.
value = static_cast<u64>(string.toLongLong(&ok, integer_base));
value = static_cast<u64>(string.toLongLong(&ok, m_integer_base));
if (!ok)
return std::nullopt;
}
@ -743,22 +771,22 @@ std::optional<u64> SymbolTreeDisplayOptions::stringToUnsignedInteger(QString str
QString SymbolTreeDisplayOptions::unsignedIntegerToString(u64 value, s32 size_bits) const
{
int field_width = 0;
if (show_leading_zeroes && integer_base > 0)
field_width = static_cast<int>(ceilf(size_bits / log2f(integer_base)));
if (m_show_leading_zeroes)
field_width = static_cast<int>(ceilf(size_bits / log2f(m_integer_base)));
return QStringLiteral("%1").arg(value, field_width, integer_base, QLatin1Char('0'));
return QStringLiteral("%1").arg(value, field_width, m_integer_base, QLatin1Char('0'));
}
std::optional<s64> SymbolTreeDisplayOptions::stringToSignedInteger(QString string) const
{
bool ok;
s64 value = string.toLongLong(&ok, integer_base);
s64 value = string.toLongLong(&ok, m_integer_base);
if (!ok)
{
// Try to parse it as an unsigned integer too to handle bases other than
// decimal (see below), and to handle the case that the user entered a
// value that was too big for a signed integer.
value = static_cast<s64>(string.toULongLong(&ok, integer_base));
value = static_cast<s64>(string.toULongLong(&ok, m_integer_base));
if (!ok)
return std::nullopt;
}
@ -769,8 +797,8 @@ std::optional<s64> SymbolTreeDisplayOptions::stringToSignedInteger(QString strin
QString SymbolTreeDisplayOptions::signedIntegerToString(s64 value, s32 size_bits) const
{
// For bases other than decimal, the user most likely just wants to view the
// underlying representation, so we want to print it as unsigned.
if (integer_base != 10)
// underlying representation, so we want to display it as unsigned.
if (m_integer_base != 10)
{
// Truncate sign extended bits.
u64 mask = (static_cast<u64>(1) << size_bits) - 1;
@ -778,14 +806,14 @@ QString SymbolTreeDisplayOptions::signedIntegerToString(s64 value, s32 size_bits
}
int field_width = 0;
if (show_leading_zeroes && integer_base > 0)
if (m_show_leading_zeroes)
{
field_width = static_cast<int>(ceilf(size_bits / log2f(integer_base)));
field_width = static_cast<int>(ceilf(size_bits / log2f(m_integer_base)));
// An extra character is needed for the minus sign.
if (value < 0)
field_width++;
}
return QStringLiteral("%1").arg(value, field_width, integer_base, QLatin1Char('0'));
return QStringLiteral("%1").arg(value, field_width, m_integer_base, QLatin1Char('0'));
}

View File

@ -9,7 +9,7 @@
#include "SymbolTreeLocation.h"
class DebugInterface;
struct SymbolTreeDisplayOptions;
class SymbolTreeDisplayOptions;
// A node in a symbol tree model.
class SymbolTreeNode
@ -105,15 +105,24 @@ private:
bool m_children_fetched = false;
};
// Settings that control how text in the edit column is displayed, including for
// the editor widgets.
struct SymbolTreeDisplayOptions
// Settings that control how text in the value column is displayed, including
// for the editor widgets.
class SymbolTreeDisplayOptions
{
int integer_base = 10;
bool show_leading_zeroes = false;
public:
int integerBase() const;
bool setIntegerBase(int base);
bool showLeadingZeroes() const;
bool setShowLeadingZeroes(bool show);
std::optional<u64> stringToUnsignedInteger(QString string) const;
QString unsignedIntegerToString(u64 value, s32 size_bits) const;
std::optional<s64> stringToSignedInteger(QString string) const;
QString signedIntegerToString(s64 value, s32 size_bits) const;
private:
int m_integer_base = 10;
bool m_show_leading_zeroes = false;
};

View File

@ -82,6 +82,12 @@ void SymbolTreeView::toJson(JsonValueWrapper& json)
{
json.value().AddMember("sortByIfTypeIsKnown", m_sort_by_if_type_is_known, json.allocator());
}
if (m_flags & ALLOW_TYPE_ACTIONS)
{
json.value().AddMember("integerBase", m_display_options.integerBase(), json.allocator());
json.value().AddMember("showLeadingZeroes", m_display_options.showLeadingZeroes(), json.allocator());
}
}
bool SymbolTreeView::fromJson(const JsonValueWrapper& json)
@ -90,6 +96,7 @@ bool SymbolTreeView::fromJson(const JsonValueWrapper& json)
return false;
bool needs_reset = false;
bool needs_update = false;
auto show_size_column = json.value().FindMember("showSizeColumn");
if (show_size_column != json.value().MemberEnd() && show_size_column->value.IsBool())
@ -132,8 +139,26 @@ bool SymbolTreeView::fromJson(const JsonValueWrapper& json)
}
}
if (m_flags & ALLOW_TYPE_ACTIONS)
{
auto integer_base = json.value().FindMember("integerBase");
if (integer_base != json.value().MemberEnd() && integer_base->value.IsInt())
needs_update |= m_display_options.setIntegerBase(integer_base->value.GetInt());
auto show_leading_zeroes = json.value().FindMember("showLeadingZeroes");
if (show_leading_zeroes != json.value().MemberEnd() && show_leading_zeroes->value.IsBool())
needs_update |= m_display_options.setShowLeadingZeroes(show_leading_zeroes->value.GetBool());
}
if (needs_reset)
{
reset();
}
else if (needs_update && m_model)
{
m_model->setDisplayOptions(m_display_options);
updateVisibleNodes(false);
}
return true;
}
@ -579,9 +604,9 @@ void SymbolTreeView::openContextMenu(QPoint pos)
{
QAction* base_action = integer_base_menu->addAction(name);
base_action->setCheckable(true);
base_action->setChecked(m_model->displayOptions().integer_base == base);
base_action->setChecked(m_model->displayOptions().integerBase() == base);
connect(base_action, &QAction::toggled, this, [this, base](bool checked) {
m_display_options.integer_base = base;
m_display_options.setIntegerBase(base);
m_model->setDisplayOptions(m_display_options);
updateVisibleNodes(false);
@ -592,9 +617,9 @@ void SymbolTreeView::openContextMenu(QPoint pos)
QAction* show_leading_zeroes = menu->addAction(tr("Show Leading Zeroes"));
show_leading_zeroes->setCheckable(true);
show_leading_zeroes->setChecked(m_model->displayOptions().show_leading_zeroes);
show_leading_zeroes->setChecked(m_model->displayOptions().showLeadingZeroes());
connect(show_leading_zeroes, &QAction::toggled, this, [this](bool checked) {
m_display_options.show_leading_zeroes = checked;
m_display_options.setShowLeadingZeroes(checked);
m_model->setDisplayOptions(m_display_options);
updateVisibleNodes(false);