Debugger: Prevent crashing opportunities when there is an empty function list

This commit is contained in:
Ty Lamontagne 2023-10-26 18:35:11 -04:00 committed by refractionpcsx2
parent 46a0c2d5b6
commit ebe6d3cbee
1 changed files with 30 additions and 28 deletions

View File

@ -612,43 +612,45 @@ void CpuWidget::onFuncListContextMenu(QPoint pos)
else else
m_funclistContextMenu->clear(); m_funclistContextMenu->clear();
QAction* copyName = new QAction(tr("Copy Function Name"), m_ui.listFunctions); if (m_ui.listFunctions->selectedItems().count() && m_ui.listFunctions->selectedItems().first()->data(256).isValid())
connect(copyName, &QAction::triggered, [this] { {
// We only store the address in the widget item QAction* copyName = new QAction(tr("Copy Function Name"), m_ui.listFunctions);
// Resolve the function name by fetching the symbolmap and filtering the address connect(copyName, &QAction::triggered, [this] {
// We only store the address in the widget item
// Resolve the function name by fetching the symbolmap and filtering the address
const QListWidgetItem* selectedItem = m_ui.listFunctions->selectedItems().first(); const QListWidgetItem* selectedItem = m_ui.listFunctions->selectedItems().first();
const QString functionName = QString(m_cpu.GetSymbolMap().GetLabelName(selectedItem->data(256).toUInt()).c_str()); const QString functionName = QString(m_cpu.GetSymbolMap().GetLabelName(selectedItem->data(256).toUInt()).c_str());
QApplication::clipboard()->setText(functionName); QApplication::clipboard()->setText(functionName);
}); });
m_funclistContextMenu->addAction(copyName); m_funclistContextMenu->addAction(copyName);
QAction* copyAddress = new QAction(tr("Copy Function Address"), m_ui.listFunctions); QAction* copyAddress = new QAction(tr("Copy Function Address"), m_ui.listFunctions);
connect(copyAddress, &QAction::triggered, [this] { connect(copyAddress, &QAction::triggered, [this] {
const QString addressString = FilledQStringFromValue(m_ui.listFunctions->selectedItems().first()->data(256).toUInt(), 16); const QString addressString = FilledQStringFromValue(m_ui.listFunctions->selectedItems().first()->data(256).toUInt(), 16);
QApplication::clipboard()->setText(addressString); QApplication::clipboard()->setText(addressString);
}); });
m_funclistContextMenu->addAction(copyAddress); m_funclistContextMenu->addAction(copyAddress);
m_funclistContextMenu->addSeparator(); m_funclistContextMenu->addSeparator();
QAction* gotoDisasm = new QAction(tr("Go to in Disassembly"), m_ui.listFunctions); QAction* gotoDisasm = new QAction(tr("Go to in Disassembly"), m_ui.listFunctions);
connect(gotoDisasm, &QAction::triggered, [this] { connect(gotoDisasm, &QAction::triggered, [this] {
m_ui.disassemblyWidget->gotoAddress(m_ui.listFunctions->selectedItems().first()->data(256).toUInt()); m_ui.disassemblyWidget->gotoAddress(m_ui.listFunctions->selectedItems().first()->data(256).toUInt());
}); });
m_funclistContextMenu->addAction(gotoDisasm); m_funclistContextMenu->addAction(gotoDisasm);
QAction* gotoMemory = new QAction(tr("Go to in Memory View"), m_ui.listFunctions); QAction* gotoMemory = new QAction(tr("Go to in Memory View"), m_ui.listFunctions);
connect(gotoMemory, &QAction::triggered, [this] { connect(gotoMemory, &QAction::triggered, [this] {
m_ui.memoryviewWidget->gotoAddress(m_ui.listFunctions->selectedItems().first()->data(256).toUInt()); m_ui.memoryviewWidget->gotoAddress(m_ui.listFunctions->selectedItems().first()->data(256).toUInt());
}); });
m_funclistContextMenu->addSeparator(); m_funclistContextMenu->addAction(gotoMemory);
m_funclistContextMenu->addAction(gotoMemory);
m_funclistContextMenu->addSeparator();
}
//: "Demangling" is the opposite of "Name mangling", which is a process where a compiler takes function names and combines them with other characteristics of the function (e.g. what types of data it accepts) to ensure they stay unique even when multiple functions exist with the same name (but different inputs / const-ness). See here: https://en.wikipedia.org/wiki/Name_mangling#C++ //: "Demangling" is the opposite of "Name mangling", which is a process where a compiler takes function names and combines them with other characteristics of the function (e.g. what types of data it accepts) to ensure they stay unique even when multiple functions exist with the same name (but different inputs / const-ness). See here: https://en.wikipedia.org/wiki/Name_mangling#C++
QAction* demangleAction = new QAction(tr("Demangle Symbols"), m_ui.listFunctions); QAction* demangleAction = new QAction(tr("Demangle Symbols"), m_ui.listFunctions);
demangleAction->setCheckable(true); demangleAction->setCheckable(true);