Skip to content

Commit

Permalink
MemoryViewWidget: Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
TryTwo committed Jun 24, 2024
1 parent 2e8d3ac commit 5976698
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 71 deletions.
124 changes: 58 additions & 66 deletions Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ class MemoryViewTable final : public QTableWidget
{
const u32 address = item->data(USER_ROLE_CELL_ADDRESS).toUInt();
m_view->ToggleBreakpoint(address, true);
m_view->UpdateDisbatcher(MemoryViewWidget::UpdateType::Addresses);
}
else
{
Expand Down Expand Up @@ -315,52 +314,33 @@ void MemoryViewWidget::UpdateDisbatcher(UpdateType type)
if (!isVisible() || (m_updating.test() && type != UpdateType::Full))
return;

// A full update may change parameters like row count, so make sure it goes through.
while (m_updating.test_and_set())
; // spin

// Check if table is created
// Check if table needs to be created.
if (m_table->item(2, 1) == nullptr)
type = UpdateType::Full;

Core::State state = Core::GetState(m_system);
if (type == UpdateType::Auto && m_values.size() != 0)
switch (type)
{
case UpdateType::Full:
CreateTable();
[[fallthrough]];
case UpdateType::Addresses:
Update();
[[fallthrough]];
case UpdateType::Values:
if (Core::GetState(m_system) == Core::State::Paused)
GetValues();
UpdateColumns();
else if (state != Core::State::Running)
switch (type)
{
case UpdateType::Full:
CreateTable();
[[fallthrough]];
case UpdateType::Addresses:
Update();
[[fallthrough]];
case UpdateType::Values:
if (state == Core::State::Paused)
GetBytes();
break;
case UpdateType::Auto:
// Values were captured on CPU thread while doing a callback.
if (m_values.size() != 0)
UpdateColumns();
break;
default:
break;
}
else
{
switch (type)
{
case UpdateType::Full:
CreateTable();
[[fallthrough]];
case UpdateType::Addresses:
Update();
// Add UpdateColumns(nullptr) if not auto updating.
break;
case UpdateType::Values:
{
// UpdateColumns();
}
default:
break;
default:
break;
}
}

m_updating.clear();
Expand Down Expand Up @@ -475,8 +455,6 @@ void MemoryViewWidget::CreateTable()

void MemoryViewWidget::Update()
{
// Check if table is created

m_table->clearSelection();

// Update addresses
Expand All @@ -490,21 +468,27 @@ void MemoryViewWidget::Update()
for (int i = 0; i < m_table->rowCount(); i++, row_address += m_bytes_per_row)
{
auto* bp_item = m_table->item(i, 0);

if (!bp_item)
return;

bp_item->setData(USER_ROLE_CELL_ADDRESS, row_address);

auto* row_item = m_table->item(i, 1);

if (!row_item)
return;

row_item->setText(QStringLiteral("%1").arg(row_address, 8, 16, QLatin1Char('0')));
row_item->setData(USER_ROLE_CELL_ADDRESS, row_address);

for (int c = 0; c < m_data_columns; c++)
{
auto* item = m_table->item(i, c + MISC_COLUMNS);

if (!item)
return;

u32 item_address;
if (m_dual_view && c >= data_span)
item_address = row_address + (c - data_span) * GetTypeSize(m_type);
Expand All @@ -523,8 +507,6 @@ void MemoryViewWidget::Update()

void MemoryViewWidget::UpdateColumns()
{
// Check if table is created

for (int i = 0; i < m_table->rowCount(); i++)
{
for (int c = 0; c < m_data_columns; c++)
Expand All @@ -537,15 +519,18 @@ void MemoryViewWidget::UpdateColumns()
const Type type = static_cast<Type>(cell_item->data(USER_ROLE_VALUE_TYPE).toInt());
std::optional<QString> new_text;

// Dual view auto sets the type of the left-side based on m_type. Only time type and m_type
// differ.
// Dual view auto sets the type of the left-side based on m_type. Only time type and
// m_type differ.
if (type != m_type)
{
new_text = m_values_dual_view.empty() ? std::nullopt : m_values_dual_view[cell_address];
new_text = m_values_dual_view.empty() || !m_values_dual_view.contains(cell_address) ?
std::nullopt :
m_values_dual_view.at(cell_address);
}
else
{
new_text = m_values.empty() ? std::nullopt : m_values[cell_address];
new_text = m_values.empty() || !m_values.contains(cell_address) ? std::nullopt :
m_values.at(cell_address);
}

// Set search address to selected / colored
Expand Down Expand Up @@ -589,43 +574,50 @@ void MemoryViewWidget::UpdateColumns()
}
}
}
m_values.clear();
if (m_dual_view)
m_values_dual_view.clear();
}

// Always runs on CPU thread from a callback.
void MemoryViewWidget::UpdateOnFrameEnd()
{
// Core::System::GetInstance().GetCPU().Break();
if (!m_updating.test_and_set())
{
GetBytes();
// Should not trigger widget updates on a cpu thread.
GetValues();
// Should not directly trigger widget updates on a cpu thread. Signal main thread to do it.
emit AutoUpdate();
m_updating.clear();
}
}

void MemoryViewWidget::GetBytes()
void MemoryViewWidget::GetValues()
{
Core::CPUThreadGuard guard(Core::System::GetInstance());
m_values.clear();
m_values_dual_view.clear();

// Check for dual view type
Type type = Type::Null;

if (m_dual_view)
{
if (GetTypeSize(m_type) == 1)
type = Type::Hex8;
else if (GetTypeSize(m_type) == 2)
type = Type::Hex16;
else if (GetTypeSize(m_type) == 8)
type = Type::Hex64;
else
type = Type::Hex32;
}

// Grab memory values as QStrings
Core::CPUThreadGuard guard(m_system);

for (u32 address = m_address_range.first; address <= m_address_range.second;
address += GetTypeSize(m_type))
{
m_values.insert(std::pair(address, ValueToString(guard, address, m_type)));

if (m_dual_view)
{
Type type;
if (GetTypeSize(m_type) == 1)
type = Type::Hex8;
else if (GetTypeSize(m_type) == 2)
type = Type::Hex16;
else if (GetTypeSize(m_type) == 8)
type = Type::Hex64;
else
type = Type::Hex32;
m_values_dual_view.insert(std::pair(address, ValueToString(guard, address, type)));
}
}
}

Expand Down Expand Up @@ -930,7 +922,7 @@ void MemoryViewWidget::SetDisplay(Type type, int bytes_per_row, int alignment, b
void MemoryViewWidget::ToggleHighlights(bool enabled)
{
// m_highlight_color should hold the current highlight color even when disabled, so it can
// be used if re-enabled. If modifying the enabled alpha, change in .h file as well.
// be used if re-enabled.
if (enabled)
{
m_highlight_color.setAlpha(100);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/Debugger/MemoryViewWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class MemoryViewWidget final : public QWidget
void UpdateDisbatcher(UpdateType type = UpdateType::Addresses);
void Update();
void UpdateOnFrameEnd();
void GetBytes();
void GetValues();
void UpdateFont(const QFont& font);
void ToggleBreakpoint(u32 addr, bool row);

Expand Down
4 changes: 0 additions & 4 deletions Source/Core/DolphinQt/Debugger/MemoryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ MemoryWidget::MemoryWidget(Core::System& system, QWidget* parent)
connect(&Settings::Instance(), &Settings::DebugModeToggled, this,
[this](bool enabled) { setHidden(!enabled || !Settings::Instance().IsMemoryVisible()); });

// Not really necessary
// connect(&Settings::Instance(), &Settings::EmulationStateChanged, this, &MemoryWidget::Update);
// connect(Host::GetInstance(), &Host::UpdateDisasmDialog, this, &MemoryWidget::Update);

LoadSettings();

ConnectWidgets();
Expand Down

0 comments on commit 5976698

Please sign in to comment.