Merge pull request #12602 from mitaclaw/qt-memory-global-system

Memory(View)Widget: Avoid Global System Accessor
This commit is contained in:
Admiral H. Curtiss 2024-03-12 04:12:52 +01:00 committed by GitHub
commit 551dcec0b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 22 additions and 26 deletions

View File

@ -154,7 +154,7 @@ public:
u32 end_address = address + static_cast<u32>(bytes.size()) - 1;
AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_view->GetAddressSpace());
Core::CPUThreadGuard guard(Core::System::GetInstance());
const Core::CPUThreadGuard guard(m_view->m_system);
if (!bytes.empty() && accessors->IsValidAddress(guard, address) &&
accessors->IsValidAddress(guard, end_address))
@ -170,8 +170,8 @@ private:
MemoryViewWidget* m_view;
};
MemoryViewWidget::MemoryViewWidget(QWidget* parent)
: QWidget(parent), m_system(Core::System::GetInstance())
MemoryViewWidget::MemoryViewWidget(Core::System& system, QWidget* parent)
: QWidget(parent), m_system(system)
{
auto* layout = new QHBoxLayout();
layout->setContentsMargins(0, 0, 0, 0);
@ -443,7 +443,7 @@ void MemoryViewWidget::UpdateColumns()
if (Core::GetState() == Core::State::Paused)
{
Core::CPUThreadGuard guard(Core::System::GetInstance());
const Core::CPUThreadGuard guard(m_system);
UpdateColumns(&guard);
}
else
@ -850,12 +850,8 @@ void MemoryViewWidget::OnCopyHex(u32 addr)
{
const auto length = GetTypeSize(m_type);
const AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_address_space);
const u64 value = [addr, accessors] {
Core::CPUThreadGuard guard(Core::System::GetInstance());
return accessors->ReadU64(guard, addr);
}();
const u64 value =
AddressSpace::GetAccessors(m_address_space)->ReadU64(Core::CPUThreadGuard{m_system}, addr);
QApplication::clipboard()->setText(
QStringLiteral("%1").arg(value, sizeof(u64) * 2, 16, QLatin1Char('0')).left(length * 2));
@ -873,12 +869,8 @@ void MemoryViewWidget::OnContextMenu(const QPoint& pos)
const u32 addr = item_selected->data(USER_ROLE_CELL_ADDRESS).toUInt();
const bool item_has_value =
item_selected->data(USER_ROLE_VALUE_TYPE).toInt() != static_cast<int>(Type::Null) &&
[this, addr] {
const AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_address_space);
Core::CPUThreadGuard guard(Core::System::GetInstance());
return accessors->IsValidAddress(guard, addr);
}();
AddressSpace::GetAccessors(m_address_space)
->IsValidAddress(Core::CPUThreadGuard{m_system}, addr);
auto* menu = new QMenu(this);

View File

@ -53,7 +53,7 @@ public:
WriteOnly
};
explicit MemoryViewWidget(QWidget* parent = nullptr);
explicit MemoryViewWidget(Core::System& system, QWidget* parent = nullptr);
void CreateTable();
void Update();

View File

@ -40,7 +40,8 @@
using Type = MemoryViewWidget::Type;
MemoryWidget::MemoryWidget(QWidget* parent) : QDockWidget(parent)
MemoryWidget::MemoryWidget(Core::System& system, QWidget* parent)
: QDockWidget(parent), m_system(system)
{
setWindowTitle(tr("Memory"));
setObjectName(QStringLiteral("memory"));
@ -287,7 +288,7 @@ void MemoryWidget::CreateWidgets()
sidebar_scroll->setWidget(sidebar);
sidebar_scroll->setWidgetResizable(true);
m_memory_view = new MemoryViewWidget(this);
m_memory_view = new MemoryViewWidget(m_system, this);
m_splitter->addWidget(m_memory_view);
m_splitter->addWidget(sidebar_scroll);
@ -496,7 +497,7 @@ void MemoryWidget::SetAddress(u32 address)
AddressSpace::Accessors* accessors =
AddressSpace::GetAccessors(m_memory_view->GetAddressSpace());
Core::CPUThreadGuard guard(Core::System::GetInstance());
const Core::CPUThreadGuard guard(m_system);
good = accessors->IsValidAddress(guard, current_addr);
}
@ -653,7 +654,7 @@ void MemoryWidget::OnSetValue()
return;
}
Core::CPUThreadGuard guard(Core::System::GetInstance());
const Core::CPUThreadGuard guard(m_system);
AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_memory_view->GetAddressSpace());
u32 end_address = target_addr.address + static_cast<u32>(bytes.size()) - 1;
@ -715,7 +716,7 @@ void MemoryWidget::OnSetValueFromFile()
AddressSpace::Accessors* accessors = AddressSpace::GetAccessors(m_memory_view->GetAddressSpace());
Core::CPUThreadGuard guard(Core::System::GetInstance());
const Core::CPUThreadGuard guard(m_system);
for (u8 b : file_contents)
accessors->WriteU8(guard, target_addr.address++, b);
@ -833,7 +834,7 @@ void MemoryWidget::FindValue(bool next)
AddressSpace::Accessors* accessors =
AddressSpace::GetAccessors(m_memory_view->GetAddressSpace());
Core::CPUThreadGuard guard(Core::System::GetInstance());
const Core::CPUThreadGuard guard(m_system);
return accessors->Search(guard, target_addr.address,
reinterpret_cast<const u8*>(search_for.data()),
static_cast<u32>(search_for.size()), next);

View File

@ -22,14 +22,15 @@ class QSplitter;
namespace Core
{
class System;
class CPUThreadGuard;
}
} // namespace Core
class MemoryWidget : public QDockWidget
{
Q_OBJECT
public:
explicit MemoryWidget(QWidget* parent = nullptr);
explicit MemoryWidget(Core::System& system, QWidget* parent = nullptr);
~MemoryWidget();
void SetAddress(u32 address);
@ -78,6 +79,8 @@ private:
void closeEvent(QCloseEvent*) override;
void showEvent(QShowEvent* event) override;
Core::System& m_system;
MemoryViewWidget* m_memory_view;
QSplitter* m_splitter;
QComboBox* m_search_address;

View File

@ -449,7 +449,7 @@ void MainWindow::CreateComponents()
m_jit_widget = new JITWidget(this);
m_log_widget = new LogWidget(this);
m_log_config_widget = new LogConfigWidget(this);
m_memory_widget = new MemoryWidget(this);
m_memory_widget = new MemoryWidget(Core::System::GetInstance(), this);
m_network_widget = new NetworkWidget(this);
m_register_widget = new RegisterWidget(this);
m_thread_widget = new ThreadWidget(this);