Skip to content

Commit

Permalink
Debugger: Prevent the creation of unaligned functions
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoticgd committed Mar 2, 2024
1 parent 0c6a871 commit 11bf4d8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
4 changes: 4 additions & 0 deletions pcsx2-qt/Debugger/SymbolTree/SymbolTreeDelegates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@

SymbolTreeLocationDelegate::SymbolTreeLocationDelegate(
SymbolGuardian& guardian,
u32 alignment,
QObject* parent)
: QStyledItemDelegate(parent)
, m_guardian(guardian)
, m_alignment(alignment)
{
}

Expand Down Expand Up @@ -75,6 +77,8 @@ void SymbolTreeLocationDelegate::setModelData(QWidget* editor, QAbstractItemMode
if (!ok)
return;

address -= address % m_alignment;

bool success = false;
m_guardian.BlockingReadWrite([&](ccc::SymbolDatabase& database) {
if (node->symbol.move_symbol(address, database))
Expand Down
2 changes: 2 additions & 0 deletions pcsx2-qt/Debugger/SymbolTree/SymbolTreeDelegates.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class SymbolTreeLocationDelegate : public QStyledItemDelegate
public:
SymbolTreeLocationDelegate(
SymbolGuardian& guardian,
u32 alignment,
QObject* parent = nullptr);

QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
Expand All @@ -22,6 +23,7 @@ class SymbolTreeLocationDelegate : public QStyledItemDelegate

protected:
SymbolGuardian& m_guardian;
u32 m_alignment;
};

class SymbolTreeTypeDelegate : public QStyledItemDelegate
Expand Down
14 changes: 7 additions & 7 deletions pcsx2-qt/Debugger/SymbolTree/SymbolTreeWidgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
#include <QtWidgets/QMenu>
#include <QtWidgets/QMessageBox>

#include "common/Assertions.h"
#include "NewSymbolDialogs.h"
#include "SymbolTreeDelegates.h"

SymbolTreeWidget::SymbolTreeWidget(u32 flags, DebugInterface& cpu, QWidget* parent)
SymbolTreeWidget::SymbolTreeWidget(u32 flags, s32 symbol_address_alignment, DebugInterface& cpu, QWidget* parent)
: QWidget(parent)
, m_cpu(cpu)
, m_flags(flags)
, m_symbol_address_alignment(symbol_address_alignment)
{
m_ui.setupUi(this);

Expand Down Expand Up @@ -66,7 +66,7 @@ void SymbolTreeWidget::setupTree()
m_model = new SymbolTreeModel(m_cpu, this);
m_ui.treeView->setModel(m_model);

auto location_delegate = new SymbolTreeLocationDelegate(m_cpu.GetSymbolGuardian(), this);
auto location_delegate = new SymbolTreeLocationDelegate(m_cpu.GetSymbolGuardian(), m_symbol_address_alignment, this);
m_ui.treeView->setItemDelegateForColumn(SymbolTreeModel::LOCATION, location_delegate);

auto type_delegate = new SymbolTreeTypeDelegate(m_cpu.GetSymbolGuardian(), this);
Expand Down Expand Up @@ -448,7 +448,7 @@ SymbolTreeNode* SymbolTreeWidget::currentNode()
}

FunctionTreeWidget::FunctionTreeWidget(DebugInterface& cpu, QWidget* parent)
: SymbolTreeWidget(ALLOW_GROUPING, cpu, parent)
: SymbolTreeWidget(ALLOW_GROUPING, 4, cpu, parent)
{
}

Expand Down Expand Up @@ -535,7 +535,7 @@ void FunctionTreeWidget::onDeleteButtonPressed()
}

GlobalVariableTreeWidget::GlobalVariableTreeWidget(DebugInterface& cpu, QWidget* parent)
: SymbolTreeWidget(ALLOW_GROUPING | ALLOW_SORTING_BY_IF_TYPE_IS_KNOWN | ALLOW_TYPE_ACTIONS, cpu, parent)
: SymbolTreeWidget(ALLOW_GROUPING | ALLOW_SORTING_BY_IF_TYPE_IS_KNOWN | ALLOW_TYPE_ACTIONS, 1, cpu, parent)
{
}

Expand Down Expand Up @@ -649,7 +649,7 @@ void GlobalVariableTreeWidget::onDeleteButtonPressed()
}

LocalVariableTreeWidget::LocalVariableTreeWidget(DebugInterface& cpu, QWidget* parent)
: SymbolTreeWidget(ALLOW_TYPE_ACTIONS, cpu, parent)
: SymbolTreeWidget(ALLOW_TYPE_ACTIONS, 1, cpu, parent)
{
}

Expand Down Expand Up @@ -747,7 +747,7 @@ void LocalVariableTreeWidget::onDeleteButtonPressed()
}

ParameterVariableTreeWidget::ParameterVariableTreeWidget(DebugInterface& cpu, QWidget* parent)
: SymbolTreeWidget(ALLOW_TYPE_ACTIONS, cpu, parent)
: SymbolTreeWidget(ALLOW_TYPE_ACTIONS, 1, cpu, parent)
{
}

Expand Down
3 changes: 2 additions & 1 deletion pcsx2-qt/Debugger/SymbolTree/SymbolTreeWidgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SymbolTreeWidget : public QWidget
void locationColumnClicked(u32 address);

protected:
explicit SymbolTreeWidget(u32 flags, DebugInterface& cpu, QWidget* parent = nullptr);
explicit SymbolTreeWidget(u32 flags, s32 symbol_address_alignment, DebugInterface& cpu, QWidget* parent = nullptr);

void setupTree();
void setupMenu();
Expand Down Expand Up @@ -89,6 +89,7 @@ class SymbolTreeWidget : public QWidget
};

u32 m_flags;
u32 m_symbol_address_alignment;
};

class FunctionTreeWidget : public SymbolTreeWidget
Expand Down

0 comments on commit 11bf4d8

Please sign in to comment.