Skip to content

Commit

Permalink
Debugger: Bring back the expression parser
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoticgd authored and F0bes committed Sep 2, 2024
1 parent f340b5e commit 90463a4
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 81 deletions.
26 changes: 11 additions & 15 deletions pcsx2-qt/Debugger/BreakpointDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,9 @@ void BreakpointDialog::accept()
PostfixExpression expr;

u64 address;
if (!m_cpu->initExpression(m_ui.txtAddress->text().toLocal8Bit().constData(), expr) ||
!m_cpu->parseExpression(expr, address))
if (!m_cpu->evaluateExpression(m_ui.txtAddress->text().toStdString().c_str(), address))
{
QMessageBox::warning(this, tr("Error"), tr("Invalid address \"%1\"").arg(m_ui.txtAddress->text()));
QMessageBox::warning(this, tr("Invalid Address"), getExpressionError());
return;
}

Expand All @@ -109,9 +108,9 @@ void BreakpointDialog::accept()
bp->hasCond = true;
bp->cond.debug = m_cpu;

if (!m_cpu->initExpression(m_ui.txtCondition->text().toLocal8Bit().constData(), expr))
if (!m_cpu->initExpression(m_ui.txtCondition->text().toStdString().c_str(), expr))
{
QMessageBox::warning(this, tr("Error"), tr("Invalid condition \"%1\"").arg(getExpressionError()));
QMessageBox::warning(this, tr("Invalid Condition"), getExpressionError());
return;
}

Expand All @@ -121,21 +120,17 @@ void BreakpointDialog::accept()
}
if (auto* mc = std::get_if<MemCheck>(&m_bp_mc))
{
PostfixExpression expr;

u64 startAddress;
if (!m_cpu->initExpression(m_ui.txtAddress->text().toLocal8Bit().constData(), expr) ||
!m_cpu->parseExpression(expr, startAddress))
if (!m_cpu->evaluateExpression(m_ui.txtAddress->text().toStdString().c_str(), startAddress))
{
QMessageBox::warning(this, tr("Error"), tr("Invalid address \"%1\"").arg(m_ui.txtAddress->text()));
QMessageBox::warning(this, tr("Invalid Address"), getExpressionError());
return;
}

u64 size;
if (!m_cpu->initExpression(m_ui.txtSize->text().toLocal8Bit(), expr) ||
!m_cpu->parseExpression(expr, size) || !size)
if (!m_cpu->evaluateExpression(m_ui.txtSize->text().toStdString().c_str(), size) || !size)
{
QMessageBox::warning(this, tr("Error"), tr("Invalid size \"%1\"").arg(m_ui.txtSize->text()));
QMessageBox::warning(this, tr("Invalid Size"), getExpressionError());
return;
}

Expand All @@ -147,9 +142,10 @@ void BreakpointDialog::accept()
mc->hasCond = true;
mc->cond.debug = m_cpu;

if (!m_cpu->initExpression(m_ui.txtCondition->text().toLocal8Bit().constData(), expr))
PostfixExpression expr;
if (!m_cpu->initExpression(m_ui.txtCondition->text().toStdString().c_str(), expr))
{
QMessageBox::warning(this, tr("Error"), tr("Invalid condition \"%1\"").arg(getExpressionError()));
QMessageBox::warning(this, tr("Invalid Condition"), getExpressionError());
return;
}

Expand Down
11 changes: 5 additions & 6 deletions pcsx2-qt/Debugger/DisassemblyWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,20 @@ void DisassemblyWidget::contextFollowBranch()
void DisassemblyWidget::contextGoToAddress()
{
bool ok;
const QString targetString = QInputDialog::getText(this, tr("Go to address"), "",
const QString targetString = QInputDialog::getText(this, tr("Go To In Disassembly"), "",
QLineEdit::Normal, "", &ok);

if (!ok)
return;

const u32 targetAddress = targetString.toUInt(&ok, 16) & ~3;

if (!ok)
u64 address = 0;
if (!m_cpu->evaluateExpression(targetString.toStdString().c_str(), address))
{
QMessageBox::warning(this, tr("Go to address error"), tr("Invalid address"));
QMessageBox::warning(this, tr("Cannot Go To"), getExpressionError());
return;
}

gotoAddressAndSetFocus(targetAddress);
gotoAddressAndSetFocus(static_cast<u32>(address) & ~3);
}

void DisassemblyWidget::contextAddFunction()
Expand Down
11 changes: 5 additions & 6 deletions pcsx2-qt/Debugger/MemoryViewWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,21 +592,20 @@ void MemoryViewWidget::contextPaste()
void MemoryViewWidget::contextGoToAddress()
{
bool ok;
QString targetString = QInputDialog::getText(this, tr("Go to address"), "",
QString targetString = QInputDialog::getText(this, tr("Go To In Memory View"), "",
QLineEdit::Normal, "", &ok);

if (!ok)
return;

const u32 targetAddress = targetString.toUInt(&ok, 16);

if (!ok)
u64 address = 0;
if (!m_cpu->evaluateExpression(targetString.toStdString().c_str(), address))
{
QMessageBox::warning(this, "Go to address error", "Invalid address");
QMessageBox::warning(this, tr("Cannot Go To"), getExpressionError());
return;
}

gotoAddress(targetAddress);
gotoAddress(static_cast<u32>(address));
}

void MemoryViewWidget::mouseDoubleClickEvent(QMouseEvent* event)
Expand Down
1 change: 1 addition & 0 deletions pcsx2-qt/Debugger/SymbolTree/SymbolTreeNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct SymbolTreeNode
Tag tag = OBJECT;
ccc::MultiSymbolHandle symbol;
QString name;
QString mangled_name;
SymbolTreeLocation location;
bool is_location_editable = false;
std::optional<u32> size;
Expand Down
25 changes: 23 additions & 2 deletions pcsx2-qt/Debugger/SymbolTree/SymbolTreeWidgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,13 @@ void SymbolTreeWidget::setupMenu()
connect(copy_name, &QAction::triggered, this, &SymbolTreeWidget::onCopyName);
m_context_menu->addAction(copy_name);

if (m_flags & ALLOW_MANGLED_NAME_ACTIONS)
{
QAction* copy_mangled_name = new QAction(tr("Copy Mangled Name"), this);
connect(copy_mangled_name, &QAction::triggered, this, &SymbolTreeWidget::onCopyMangledName);
m_context_menu->addAction(copy_mangled_name);
}

QAction* copy_location = new QAction(tr("Copy Location"), this);
connect(copy_location, &QAction::triggered, this, &SymbolTreeWidget::onCopyLocation);
m_context_menu->addAction(copy_location);
Expand Down Expand Up @@ -484,6 +491,18 @@ void SymbolTreeWidget::onCopyName()
QApplication::clipboard()->setText(node->name);
}

void SymbolTreeWidget::onCopyMangledName()
{
SymbolTreeNode* node = currentNode();
if (!node)
return;

if (!node->mangled_name.isEmpty())
QApplication::clipboard()->setText(node->mangled_name);
else
QApplication::clipboard()->setText(node->name);
}

void SymbolTreeWidget::onCopyLocation()
{
SymbolTreeNode* node = currentNode();
Expand Down Expand Up @@ -611,7 +630,7 @@ SymbolTreeNode* SymbolTreeWidget::currentNode()
// *****************************************************************************

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

Expand Down Expand Up @@ -652,6 +671,7 @@ std::unique_ptr<SymbolTreeNode> FunctionTreeWidget::buildNode(

std::unique_ptr<SymbolTreeNode> node = std::make_unique<SymbolTreeNode>();
node->name = std::move(work.name);
node->mangled_name = QString::fromStdString(function.mangled_name());
node->location = SymbolTreeLocation(SymbolTreeLocation::MEMORY, function.address().value);
node->size = function.size();
node->symbol = ccc::MultiSymbolHandle(function);
Expand Down Expand Up @@ -694,7 +714,7 @@ void FunctionTreeWidget::onNewButtonPressed()
// *****************************************************************************

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

Expand Down Expand Up @@ -777,6 +797,7 @@ std::unique_ptr<SymbolTreeNode> GlobalVariableTreeWidget::buildNode(
{
const ccc::GlobalVariable& global_variable = static_cast<const ccc::GlobalVariable&>(*work.symbol);

node->mangled_name = QString::fromStdString(global_variable.mangled_name());
if (global_variable.type())
node->type = ccc::NodeHandle(global_variable, global_variable.type());
node->location = SymbolTreeLocation(SymbolTreeLocation::MEMORY, global_variable.address().value);
Expand Down
4 changes: 3 additions & 1 deletion pcsx2-qt/Debugger/SymbolTree/SymbolTreeWidgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class SymbolTreeWidget : public QWidget
void onDeleteButtonPressed();

void onCopyName();
void onCopyMangledName();
void onCopyLocation();
void onRenameSymbol();
void onGoToInDisassembly();
Expand Down Expand Up @@ -117,7 +118,8 @@ class SymbolTreeWidget : public QWidget
NO_SYMBOL_TREE_FLAGS = 0,
ALLOW_GROUPING = 1 << 0,
ALLOW_SORTING_BY_IF_TYPE_IS_KNOWN = 1 << 1,
ALLOW_TYPE_ACTIONS = 1 << 2
ALLOW_TYPE_ACTIONS = 1 << 2,
ALLOW_MANGLED_NAME_ACTIONS = 1 << 3
};

u32 m_flags;
Expand Down
Loading

0 comments on commit 90463a4

Please sign in to comment.