Skip to content

Commit

Permalink
Debugger: Avoid resetting symbol trees while single stepping
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoticgd authored and F0bes committed Oct 23, 2024
1 parent 56a2b3b commit 7d63a9e
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 7 deletions.
10 changes: 4 additions & 6 deletions pcsx2-qt/Debugger/CpuWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,6 @@ void CpuWidget::setupSymbolTrees()
m_ui.tabLocalVariables->layout()->addWidget(m_local_variable_tree);
m_ui.tabParameterVariables->layout()->addWidget(m_parameter_variable_tree);

connect(m_ui.tabWidgetRegFunc, &QTabWidget::currentChanged, m_function_tree, &SymbolTreeWidget::updateModel);
connect(m_ui.tabWidget, &QTabWidget::currentChanged, m_global_variable_tree, &SymbolTreeWidget::updateModel);
connect(m_ui.tabWidget, &QTabWidget::currentChanged, m_local_variable_tree, &SymbolTreeWidget::updateModel);

connect(m_function_tree, &SymbolTreeWidget::goToInDisassembly, m_ui.disassemblyWidget, &DisassemblyWidget::gotoAddressAndSetFocus);
connect(m_global_variable_tree, &SymbolTreeWidget::goToInDisassembly, m_ui.disassemblyWidget, &DisassemblyWidget::gotoAddressAndSetFocus);
connect(m_local_variable_tree, &SymbolTreeWidget::goToInDisassembly, m_ui.disassemblyWidget, &DisassemblyWidget::gotoAddressAndSetFocus);
Expand Down Expand Up @@ -207,8 +203,10 @@ void CpuWidget::reloadCPUWidgets()
m_ui.disassemblyWidget->update();
m_ui.memoryviewWidget->update();

m_local_variable_tree->reset();
m_parameter_variable_tree->reset();
m_function_tree->updateModel();
m_global_variable_tree->updateModel();
m_local_variable_tree->updateModel();
m_parameter_variable_tree->updateModel();
}

void CpuWidget::paintEvent(QPaintEvent* event)
Expand Down
65 changes: 64 additions & 1 deletion pcsx2-qt/Debugger/SymbolTree/SymbolTreeWidgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void SymbolTreeWidget::resizeEvent(QResizeEvent* event)

void SymbolTreeWidget::updateModel()
{
if (!m_model || m_model->needsReset())
if (needsReset())
reset();
else
updateVisibleNodes(true);
Expand Down Expand Up @@ -489,6 +489,11 @@ void SymbolTreeWidget::openMenu(QPoint pos)
m_context_menu->exec(m_ui.treeView->viewport()->mapToGlobal(pos));
}

bool SymbolTreeWidget::needsReset() const
{
return !m_model || m_model->needsReset();
}

void SymbolTreeWidget::onDeleteButtonPressed()
{
SymbolTreeNode* node = currentNode();
Expand Down Expand Up @@ -885,14 +890,43 @@ LocalVariableTreeWidget::LocalVariableTreeWidget(DebugInterface& cpu, QWidget* p

LocalVariableTreeWidget::~LocalVariableTreeWidget() = default;

bool LocalVariableTreeWidget::needsReset() const
{
if (!m_function.valid())
return true;

u32 program_counter = m_cpu.getPC();

bool left_function = true;
m_cpu.GetSymbolGuardian().Read([&](const ccc::SymbolDatabase& database) {
const ccc::Function* function = database.functions.symbol_from_handle(m_function);
if (!function || !function->address().valid())
return;

u32 begin = function->address().value;
u32 end = function->address().value + function->size();

left_function = program_counter < begin || program_counter >= end;
});

if (left_function)
return true;

return SymbolTreeWidget::needsReset();
}

std::vector<SymbolTreeWidget::SymbolWork> LocalVariableTreeWidget::getSymbols(
const QString& filter, const ccc::SymbolDatabase& database)
{
u32 program_counter = m_cpu.getPC();
const ccc::Function* function = database.functions.symbol_overlapping_address(program_counter);
if (!function || !function->local_variables().has_value())
{
m_function = ccc::FunctionHandle();
return std::vector<SymbolWork>();
}

m_function = function->handle();
m_caller_stack_pointer = m_cpu.getCallerStackPointer(*function);

std::vector<SymbolTreeWidget::SymbolWork> symbols;
Expand Down Expand Up @@ -981,6 +1015,31 @@ ParameterVariableTreeWidget::ParameterVariableTreeWidget(DebugInterface& cpu, QW

ParameterVariableTreeWidget::~ParameterVariableTreeWidget() = default;

bool ParameterVariableTreeWidget::needsReset() const
{
if (!m_function.valid())
return true;

u32 program_counter = m_cpu.getPC();

bool left_function = true;
m_cpu.GetSymbolGuardian().Read([&](const ccc::SymbolDatabase& database) {
const ccc::Function* function = database.functions.symbol_from_handle(m_function);
if (!function || !function->address().valid())
return;

u32 begin = function->address().value;
u32 end = function->address().value + function->size();

left_function = program_counter < begin || program_counter >= end;
});

if (left_function)
return true;

return SymbolTreeWidget::needsReset();
}

std::vector<SymbolTreeWidget::SymbolWork> ParameterVariableTreeWidget::getSymbols(
const QString& filter, const ccc::SymbolDatabase& database)
{
Expand All @@ -989,8 +1048,12 @@ std::vector<SymbolTreeWidget::SymbolWork> ParameterVariableTreeWidget::getSymbol
u32 program_counter = m_cpu.getPC();
const ccc::Function* function = database.functions.symbol_overlapping_address(program_counter);
if (!function || !function->parameter_variables().has_value())
{
m_function = ccc::FunctionHandle();
return std::vector<SymbolWork>();
}

m_function = function->handle();
m_caller_stack_pointer = m_cpu.getCallerStackPointer(*function);

for (const ccc::ParameterVariableHandle parameter_variable_handle : *function->parameter_variables())
Expand Down
8 changes: 8 additions & 0 deletions pcsx2-qt/Debugger/SymbolTree/SymbolTreeWidgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class SymbolTreeWidget : public QWidget
void setupMenu();
void openMenu(QPoint pos);

virtual bool needsReset() const;

virtual std::vector<SymbolWork> getSymbols(
const QString& filter, const ccc::SymbolDatabase& database) = 0;

Expand Down Expand Up @@ -172,6 +174,8 @@ class LocalVariableTreeWidget : public SymbolTreeWidget
virtual ~LocalVariableTreeWidget();

protected:
bool needsReset() const override;

std::vector<SymbolWork> getSymbols(
const QString& filter, const ccc::SymbolDatabase& database) override;

Expand All @@ -182,6 +186,7 @@ class LocalVariableTreeWidget : public SymbolTreeWidget

void onNewButtonPressed() override;

ccc::FunctionHandle m_function;
std::optional<u32> m_caller_stack_pointer;
};

Expand All @@ -193,6 +198,8 @@ class ParameterVariableTreeWidget : public SymbolTreeWidget
virtual ~ParameterVariableTreeWidget();

protected:
bool needsReset() const override;

std::vector<SymbolWork> getSymbols(
const QString& filter, const ccc::SymbolDatabase& database) override;

Expand All @@ -203,6 +210,7 @@ class ParameterVariableTreeWidget : public SymbolTreeWidget

void onNewButtonPressed() override;

ccc::FunctionHandle m_function;
std::optional<u32> m_caller_stack_pointer;
};

Expand Down

0 comments on commit 7d63a9e

Please sign in to comment.