From a7111e3910a696f93774717cb3be0acd1549bd2d Mon Sep 17 00:00:00 2001 From: TryTwo Date: Sun, 17 Apr 2022 00:47:05 -0700 Subject: [PATCH] Dual View any size. --- .../DolphinQt/Debugger/MemoryViewWidget.cpp | 102 +++++++++++------- .../DolphinQt/Debugger/MemoryViewWidget.h | 3 +- .../Core/DolphinQt/Debugger/MemoryWidget.cpp | 6 +- 3 files changed, 70 insertions(+), 41 deletions(-) diff --git a/Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp b/Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp index 29c62bfe7f..6ecce440f2 100644 --- a/Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp @@ -64,7 +64,7 @@ void MemoryViewWidget::UpdateFont() Update(); } -static int GetTypeSize(MemoryViewWidget::Type type) +constexpr int GetTypeSize(MemoryViewWidget::Type type) { switch (type) { @@ -83,38 +83,41 @@ static int GetTypeSize(MemoryViewWidget::Type type) case MemoryViewWidget::Type::Float32: return 4; case MemoryViewWidget::Type::Double: + case MemoryViewWidget::Type::Hex64: return 8; default: return 1; } } -static int GetCharacterCount(MemoryViewWidget::Type type) +constexpr int GetCharacterCount(MemoryViewWidget::Type type) { // Max number of characters +1 for spacing between columns. switch (type) { - case MemoryViewWidget::Type::ASCII: + case MemoryViewWidget::Type::ASCII: // A return 2; - case MemoryViewWidget::Type::Hex8: + case MemoryViewWidget::Type::Hex8: // Byte = FF return 3; - case MemoryViewWidget::Type::Unsigned8: + case MemoryViewWidget::Type::Unsigned8: // UCHAR_MAX = 255 return 4; - case MemoryViewWidget::Type::Hex16: - case MemoryViewWidget::Type::Signed8: + case MemoryViewWidget::Type::Hex16: // 2 Bytes = FFFF + case MemoryViewWidget::Type::Signed8: // CHAR_MIN = -128 return 5; - case MemoryViewWidget::Type::Unsigned16: + case MemoryViewWidget::Type::Unsigned16: // USHORT_MAX = 65535 return 6; - case MemoryViewWidget::Type::Signed16: + case MemoryViewWidget::Type::Signed16: // SHORT_MIN = -32768 return 7; - case MemoryViewWidget::Type::Hex32: + case MemoryViewWidget::Type::Hex32: // 4 Bytes = FFFFFFFF return 9; - case MemoryViewWidget::Type::Float32: + case MemoryViewWidget::Type::Float32: // Rounded and Negative FLT_MAX = -3.403e+38 + case MemoryViewWidget::Type::Unsigned32: // UINT_MAX = 4294967295 return 11; - case MemoryViewWidget::Type::Double: - case MemoryViewWidget::Type::Unsigned32: - case MemoryViewWidget::Type::Signed32: + case MemoryViewWidget::Type::Double: // Rounded and Negative DBL_MAX = -1.798e+308 + case MemoryViewWidget::Type::Signed32: // INT_MIN = -2147483648 return 12; + case MemoryViewWidget::Type::Hex64: // For dual_view + Double. 8 Bytes = FFFFFFFFFFFFFFFF + return 17; default: return 10; } @@ -130,7 +133,7 @@ void MemoryViewWidget::Update() const int data_columns = m_bytes_per_row / GetTypeSize(m_type); if (m_dual_view) - setColumnCount(2 + 2 * data_columns + (m_bytes_per_row == 8 ? 1 : 0)); + setColumnCount(2 + 2 * data_columns); else setColumnCount(2 + data_columns); @@ -195,15 +198,21 @@ void MemoryViewWidget::Update() left_type = Type::Hex8; else if (GetTypeSize(m_type) == 2) left_type = Type::Hex16; + else if (GetTypeSize(m_type) == 8) + left_type = Type::Hex64; UpdateColumns(left_type, starting_column); - int column_count = m_bytes_per_row / GetTypeSize(left_type); + const int column_count = m_bytes_per_row / GetTypeSize(left_type); // Update column width - for (int i = starting_column; i < starting_column + column_count; i++) + for (int i = starting_column; i < starting_column + column_count - 1; i++) setColumnWidth(i, m_font_width * GetCharacterCount(left_type)); + // Extra spacing between dual views. + setColumnWidth(starting_column + column_count - 1, + m_font_width * (GetCharacterCount(left_type) + 2)); + starting_column += column_count; } @@ -212,7 +221,7 @@ void MemoryViewWidget::Update() setColumnWidth(0, rowHeight(0)); - for (int i = starting_column; i < columnCount(); i++) + for (int i = starting_column; i <= columnCount(); i++) setColumnWidth(i, m_font_width * GetCharacterCount(m_type)); viewport()->update(); @@ -221,13 +230,18 @@ void MemoryViewWidget::Update() void MemoryViewWidget::UpdateColumns(Type type, int first_column) { + if (Core::GetState() != Core::State::Paused) + return; + const int data_columns = m_bytes_per_row / GetTypeSize(type); const AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_address_space); auto text_alignment = Qt::AlignLeft; if (type == Type::Signed32 || type == Type::Unsigned32 || type == Type::Signed16 || type == Type::Unsigned16 || type == Type::Signed8 || type == Type::Unsigned8) + { text_alignment = Qt::AlignRight; + } for (int i = 0; i < rowCount(); i++) { @@ -285,6 +299,12 @@ void MemoryViewWidget::UpdateColumns(Type type, int first_column) return QStringLiteral("%1").arg(value, 8, 16, QLatin1Char('0')); }); break; + case Type::Hex64: + update_values([&accessors](u32 address) { + const u64 value = accessors->ReadU64(address); + return QStringLiteral("%1").arg(value, 16, 16, QLatin1Char('0')); + }); + break; case Type::Unsigned8: update_values( [&accessors](u32 address) { return QString::number(accessors->ReadU8(address)); }); @@ -339,9 +359,12 @@ void MemoryViewWidget::UpdateColumns(Type type, int first_column) void MemoryViewWidget::UpdateBreakpointTags() { + if (Core::GetState() != Core::State::Paused) + return; + for (int i = 0; i < rowCount(); i++) { - bool row_breakpoint = true; + bool row_breakpoint = false; for (int c = 2; c < columnCount(); c++) { @@ -356,21 +379,15 @@ void MemoryViewWidget::UpdateBreakpointTags() } // In dual view the only sizes that dont match up on both left and right views are for - // Double, which uses two columns of hex32. - int type_size = GetTypeSize(m_type); - if (m_dual_view && m_type == Type::Double && c < 4) - type_size = 4; - + // Double, which uses two or four columns of hex32. if (m_address_space == AddressSpace::Type::Effective && - PowerPC::memchecks.GetMemCheck(address, type_size) != nullptr) + PowerPC::memchecks.GetMemCheck(address, GetTypeSize(m_type)) != nullptr) { + row_breakpoint = true; cell->setBackground(Qt::red); } - else - { - row_breakpoint = false; - } } + if (row_breakpoint) { item(i, 0)->setData(Qt::DecorationRole, @@ -467,16 +484,28 @@ u32 MemoryViewWidget::GetContextAddress() const void MemoryViewWidget::ToggleRowBreakpoint(bool row) { - TMemCheck check; + if (m_address_space != AddressSpace::Type::Effective) + return; const u32 addr = row ? m_base_address : GetContextAddress(); - const auto length = row ? m_bytes_per_row : GetTypeSize(m_type); + const auto length = GetTypeSize(m_type); + const int breaks = row ? (m_bytes_per_row / length) : 1; + bool overlap = false; - if (m_address_space == AddressSpace::Type::Effective) + // Row breakpoint should either remove any breakpoint left on the row, or activate all + // breakpoints. + if (row && PowerPC::memchecks.OverlapsMemcheck(addr, m_bytes_per_row)) + overlap = true; + + for (int i = 0; i < breaks; i++) { - if (!PowerPC::memchecks.OverlapsMemcheck(addr, length)) + u32 address = addr + length * i; + TMemCheck* check_ptr = PowerPC::memchecks.GetMemCheck(address, length); + + if (check_ptr == nullptr && !overlap) { - check.start_address = addr; + TMemCheck check; + check.start_address = address; check.end_address = check.start_address + length - 1; check.is_ranged = length > 0; check.is_break_on_read = (m_bp_type == BPType::ReadOnly || m_bp_type == BPType::ReadWrite); @@ -486,9 +515,10 @@ void MemoryViewWidget::ToggleRowBreakpoint(bool row) PowerPC::memchecks.Add(check); } - else + else if (check_ptr != nullptr) { - PowerPC::memchecks.Remove(addr); + // Using the pointer fixes misaligned breakpoints (0x11 breakpoint in 0x10 aligned view). + PowerPC::memchecks.Remove(check_ptr->start_address); } } diff --git a/Source/Core/DolphinQt/Debugger/MemoryViewWidget.h b/Source/Core/DolphinQt/Debugger/MemoryViewWidget.h index c128c1f183..0faaa23b49 100644 --- a/Source/Core/DolphinQt/Debugger/MemoryViewWidget.h +++ b/Source/Core/DolphinQt/Debugger/MemoryViewWidget.h @@ -21,6 +21,7 @@ public: Hex8 = 1, Hex16, Hex32, + Hex64, Unsigned8, Unsigned16, Unsigned32, @@ -74,7 +75,7 @@ private: void UpdateColumns(Type type, int first_column); AddressSpace::Type m_address_space{}; - Type m_type = Type::Hex8; + Type m_type = Type::Hex32; BPType m_bp_type = BPType::ReadWrite; bool m_do_log = true; u32 m_context_address; diff --git a/Source/Core/DolphinQt/Debugger/MemoryWidget.cpp b/Source/Core/DolphinQt/Debugger/MemoryWidget.cpp index 3bff61f66e..8ae1d9aefd 100644 --- a/Source/Core/DolphinQt/Debugger/MemoryWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/MemoryWidget.cpp @@ -215,6 +215,7 @@ void MemoryWidget::CreateWidgets() m_row_length_combo->addItem(tr("8 Bytes"), 8); m_row_length_combo->addItem(tr("16 Bytes"), 16); + m_row_length_combo->setCurrentIndex(2); m_dual_check = new QCheckBox(tr("Dual View")); displaytype_layout->addWidget(m_display_combo); @@ -438,14 +439,11 @@ void MemoryWidget::OnDisplayChanged() int alignment; bool dual_view = m_dual_check->isChecked(); - if (dual_view) - bytes_per_row = 4; - if (type == MemoryViewWidget::Type::Double && bytes_per_row == 4) bytes_per_row = 8; // Alignment: First (fixed) option equals bytes per row. 'currentData' is correct for other - // options. Type-based must be calculated in memoryviewwidget and is left at 0. No alignment is + // options. Type-based must be calculated in memoryviewwidget and is left at 0. "No alignment" is // equivalent to a value of 1. if (m_align_combo->currentIndex() == 0) alignment = bytes_per_row;