2020-12-05 13:08:24 +01:00
|
|
|
#include "breakpoint_list.h"
|
2020-02-22 20:42:49 +01:00
|
|
|
#include "breakpoint_handler.h"
|
2018-03-02 22:40:29 +01:00
|
|
|
|
2020-02-22 20:42:49 +01:00
|
|
|
#include "Emu/CPU/CPUDisAsm.h"
|
|
|
|
|
#include "Emu/Cell/PPUThread.h"
|
2021-10-15 01:26:51 +02:00
|
|
|
#include "Emu/Cell/SPUThread.h"
|
2025-04-06 22:55:46 +02:00
|
|
|
#include "debugger_add_bp_window.h"
|
2018-03-02 22:40:29 +01:00
|
|
|
|
|
|
|
|
#include <QMenu>
|
2021-07-30 20:30:29 +02:00
|
|
|
#include <QMessageBox>
|
2024-09-02 21:57:33 +02:00
|
|
|
#include <QMouseEvent>
|
2018-03-02 22:40:29 +01:00
|
|
|
|
2024-05-16 01:28:58 +02:00
|
|
|
extern bool is_using_interpreter(thread_class t_class);
|
2021-07-30 20:30:29 +02:00
|
|
|
|
2021-10-15 01:26:51 +02:00
|
|
|
breakpoint_list::breakpoint_list(QWidget* parent, breakpoint_handler* handler) : QListWidget(parent), m_ppu_breakpoint_handler(handler)
|
2018-03-02 22:40:29 +01:00
|
|
|
{
|
|
|
|
|
setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
|
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|
|
|
|
|
|
|
|
|
connect(this, &QListWidget::itemDoubleClicked, this, &breakpoint_list::OnBreakpointListDoubleClicked);
|
|
|
|
|
connect(this, &QListWidget::customContextMenuRequested, this, &breakpoint_list::OnBreakpointListRightClicked);
|
2021-03-23 23:23:37 +01:00
|
|
|
|
|
|
|
|
m_delete_action = new QAction(tr("&Delete"), this);
|
|
|
|
|
m_delete_action->setShortcut(Qt::Key_Delete);
|
|
|
|
|
m_delete_action->setShortcutContext(Qt::WidgetShortcut);
|
|
|
|
|
connect(m_delete_action, &QAction::triggered, this, &breakpoint_list::OnBreakpointListDelete);
|
|
|
|
|
addAction(m_delete_action);
|
2022-06-21 23:42:42 +02:00
|
|
|
|
|
|
|
|
// Hide until used in order to allow as much space for registers panel as possible
|
|
|
|
|
hide();
|
2018-03-02 22:40:29 +01:00
|
|
|
}
|
|
|
|
|
|
2018-10-11 00:17:19 +02:00
|
|
|
/**
|
2025-04-05 21:50:45 +02:00
|
|
|
* It's unfortunate I need a method like this to sync these. Should ponder a cleaner way to do this.
|
|
|
|
|
*/
|
2024-08-21 18:41:55 +02:00
|
|
|
void breakpoint_list::UpdateCPUData(std::shared_ptr<CPUDisAsm> disasm)
|
2018-03-02 22:40:29 +01:00
|
|
|
{
|
2024-08-21 18:41:55 +02:00
|
|
|
m_disasm = std::move(disasm);
|
2018-03-02 22:40:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void breakpoint_list::ClearBreakpoints()
|
|
|
|
|
{
|
|
|
|
|
while (count())
|
|
|
|
|
{
|
|
|
|
|
auto* currentItem = takeItem(0);
|
2021-04-07 23:05:18 +02:00
|
|
|
const u32 loc = currentItem->data(Qt::UserRole).value<u32>();
|
2021-10-15 01:26:51 +02:00
|
|
|
m_ppu_breakpoint_handler->RemoveBreakpoint(loc);
|
2018-03-02 22:40:29 +01:00
|
|
|
delete currentItem;
|
|
|
|
|
}
|
2022-06-21 23:42:42 +02:00
|
|
|
|
|
|
|
|
hide();
|
2018-03-02 22:40:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void breakpoint_list::RemoveBreakpoint(u32 addr)
|
|
|
|
|
{
|
2021-10-15 01:26:51 +02:00
|
|
|
m_ppu_breakpoint_handler->RemoveBreakpoint(addr);
|
2018-03-02 22:40:29 +01:00
|
|
|
|
|
|
|
|
for (int i = 0; i < count(); i++)
|
|
|
|
|
{
|
|
|
|
|
QListWidgetItem* currentItem = item(i);
|
|
|
|
|
|
|
|
|
|
if (currentItem->data(Qt::UserRole).value<u32>() == addr)
|
|
|
|
|
{
|
|
|
|
|
delete takeItem(i);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-21 23:42:42 +02:00
|
|
|
if (!count())
|
|
|
|
|
{
|
|
|
|
|
hide();
|
|
|
|
|
}
|
2018-03-02 22:40:29 +01:00
|
|
|
}
|
|
|
|
|
|
2025-03-01 17:08:10 +01:00
|
|
|
bool breakpoint_list::AddBreakpoint(u32 pc, bs_t<breakpoint_types> type)
|
2018-03-02 22:40:29 +01:00
|
|
|
{
|
2025-03-01 17:08:10 +01:00
|
|
|
if (!m_ppu_breakpoint_handler->AddBreakpoint(pc, type))
|
2021-07-30 20:30:29 +02:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-03-02 22:40:29 +01:00
|
|
|
|
2025-03-01 17:08:10 +01:00
|
|
|
QString breakpoint_item_text;
|
2018-03-02 22:40:29 +01:00
|
|
|
|
2025-03-01 17:08:10 +01:00
|
|
|
if (type == breakpoint_types::bp_exec)
|
|
|
|
|
{
|
|
|
|
|
m_disasm->disasm(m_disasm->dump_pc = pc);
|
|
|
|
|
breakpoint_item_text = QString::fromStdString(m_disasm->last_opcode);
|
|
|
|
|
breakpoint_item_text.remove(10, 13);
|
|
|
|
|
}
|
|
|
|
|
else if (type == breakpoint_types::bp_read)
|
|
|
|
|
{
|
|
|
|
|
breakpoint_item_text = QString("BPMR: 0x%1").arg(pc, 8, 16, QChar('0'));
|
|
|
|
|
}
|
|
|
|
|
else if (type == breakpoint_types::bp_write)
|
|
|
|
|
{
|
|
|
|
|
breakpoint_item_text = QString("BPMW: 0x%1").arg(pc, 8, 16, QChar('0'));
|
|
|
|
|
}
|
|
|
|
|
else if (type == (breakpoint_types::bp_read + breakpoint_types::bp_write))
|
|
|
|
|
{
|
|
|
|
|
breakpoint_item_text = QString("BPMRW: 0x%1").arg(pc, 8, 16, QChar('0'));
|
|
|
|
|
}
|
2018-03-02 22:40:29 +01:00
|
|
|
|
2025-03-01 17:08:10 +01:00
|
|
|
QListWidgetItem* breakpoint_item = new QListWidgetItem(breakpoint_item_text);
|
2021-03-23 20:39:39 +01:00
|
|
|
breakpoint_item->setForeground(m_text_color_bp);
|
|
|
|
|
breakpoint_item->setBackground(m_color_bp);
|
|
|
|
|
breakpoint_item->setData(Qt::UserRole, pc);
|
|
|
|
|
addItem(breakpoint_item);
|
2020-06-13 18:16:36 +02:00
|
|
|
|
2022-06-21 23:42:42 +02:00
|
|
|
show();
|
|
|
|
|
|
2021-07-30 20:30:29 +02:00
|
|
|
return true;
|
2018-03-02 22:40:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-03-01 17:08:10 +01:00
|
|
|
* If breakpoint exists, we remove it, else add new one. Yeah, it'd be nicer from a code logic to have it be set/reset. But, that logic has to happen somewhere anyhow.
|
|
|
|
|
*/
|
2023-09-25 17:32:50 +02:00
|
|
|
void breakpoint_list::HandleBreakpointRequest(u32 loc, bool only_add)
|
2018-03-02 22:40:29 +01:00
|
|
|
{
|
2024-08-21 18:41:55 +02:00
|
|
|
const auto cpu = m_disasm ? m_disasm->get_cpu() : nullptr;
|
|
|
|
|
|
|
|
|
|
if (!cpu || cpu->state & cpu_flag::exit)
|
2021-07-30 20:30:29 +02:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-21 18:41:55 +02:00
|
|
|
if (!is_using_interpreter(cpu->get_class()))
|
2020-12-16 15:44:41 +01:00
|
|
|
{
|
2021-10-15 01:26:51 +02:00
|
|
|
QMessageBox::warning(this, tr("Interpreters-Only Feature!"), tr("Cannot set breakpoints on non-interpreter decoders."));
|
2021-07-30 20:30:29 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-21 18:41:55 +02:00
|
|
|
switch (cpu->get_class())
|
2021-07-30 20:30:29 +02:00
|
|
|
{
|
2024-05-16 01:28:58 +02:00
|
|
|
case thread_class::spu:
|
2021-10-15 01:26:51 +02:00
|
|
|
{
|
|
|
|
|
if (loc >= SPU_LS_SIZE || loc % 4)
|
|
|
|
|
{
|
|
|
|
|
QMessageBox::warning(this, tr("Invalid Memory For Breakpoints!"), tr("Cannot set breakpoints on non-SPU executable memory!"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-21 18:41:55 +02:00
|
|
|
const auto spu = static_cast<spu_thread*>(cpu);
|
2021-10-15 01:26:51 +02:00
|
|
|
auto& list = spu->local_breakpoints;
|
2024-04-12 15:06:56 +02:00
|
|
|
const u32 pos_at = loc / 4;
|
|
|
|
|
const u32 pos_bit = 1u << (pos_at % 8);
|
2021-10-15 01:26:51 +02:00
|
|
|
|
2024-04-12 15:06:56 +02:00
|
|
|
if (list[pos_at / 8].fetch_xor(pos_bit) & pos_bit)
|
2021-10-15 01:26:51 +02:00
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
if (std::none_of(list.begin(), list.end(), [](auto& val)
|
|
|
|
|
{
|
|
|
|
|
return val.load();
|
|
|
|
|
}))
|
2021-10-15 01:26:51 +02:00
|
|
|
{
|
|
|
|
|
spu->has_active_local_bps = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!spu->has_active_local_bps.exchange(true))
|
|
|
|
|
{
|
|
|
|
|
spu->state.atomic_op([](bs_t<cpu_flag>& flags)
|
|
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
if (flags & cpu_flag::pending)
|
|
|
|
|
{
|
|
|
|
|
flags += cpu_flag::pending_recheck;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
flags += cpu_flag::pending;
|
|
|
|
|
}
|
|
|
|
|
});
|
2021-10-15 01:26:51 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-05-16 01:28:58 +02:00
|
|
|
case thread_class::ppu:
|
|
|
|
|
break;
|
2021-10-15 01:26:51 +02:00
|
|
|
default:
|
|
|
|
|
QMessageBox::warning(this, tr("Unimplemented Breakpoints For Thread Type!"), tr("Cannot set breakpoints on a thread not an PPU/SPU currently, sorry."));
|
2021-07-30 20:30:29 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-15 01:26:51 +02:00
|
|
|
if (!vm::check_addr(loc, vm::page_executable))
|
2021-07-30 20:30:29 +02:00
|
|
|
{
|
2021-10-15 01:26:51 +02:00
|
|
|
QMessageBox::warning(this, tr("Invalid Memory For Breakpoints!"), tr("Cannot set breakpoints on non-executable memory!"));
|
2020-12-16 15:44:41 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-01 17:08:10 +01:00
|
|
|
if (m_ppu_breakpoint_handler->HasBreakpoint(loc, breakpoint_types::bp_exec))
|
2018-03-02 22:40:29 +01:00
|
|
|
{
|
2023-09-25 17:32:50 +02:00
|
|
|
if (!only_add)
|
|
|
|
|
{
|
|
|
|
|
RemoveBreakpoint(loc);
|
|
|
|
|
}
|
2018-03-02 22:40:29 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-03-01 17:08:10 +01:00
|
|
|
if (!AddBreakpoint(loc, breakpoint_types::bp_exec))
|
2021-07-30 20:30:29 +02:00
|
|
|
{
|
|
|
|
|
QMessageBox::warning(this, tr("Unknown error while setting breakpoint!"), tr("Failed to set breakpoints."));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-03-02 22:40:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void breakpoint_list::OnBreakpointListDoubleClicked()
|
|
|
|
|
{
|
2024-09-02 21:57:33 +02:00
|
|
|
if (QListWidgetItem* item = currentItem())
|
|
|
|
|
{
|
|
|
|
|
const u32 address = item->data(Qt::UserRole).value<u32>();
|
|
|
|
|
Q_EMIT RequestShowAddress(address);
|
|
|
|
|
}
|
2018-03-02 22:40:29 +01:00
|
|
|
}
|
|
|
|
|
|
2025-03-01 17:08:10 +01:00
|
|
|
void breakpoint_list::OnBreakpointListRightClicked(const QPoint& pos)
|
2018-03-02 22:40:29 +01:00
|
|
|
{
|
2021-03-23 23:23:37 +01:00
|
|
|
m_context_menu = new QMenu();
|
2018-03-02 22:40:29 +01:00
|
|
|
|
|
|
|
|
if (selectedItems().count() == 1)
|
|
|
|
|
{
|
2021-03-23 23:23:37 +01:00
|
|
|
QAction* rename_action = m_context_menu->addAction(tr("&Rename"));
|
2021-03-23 20:39:39 +01:00
|
|
|
connect(rename_action, &QAction::triggered, this, [this]()
|
2025-04-05 21:50:45 +02:00
|
|
|
{
|
|
|
|
|
QListWidgetItem* current_item = selectedItems().first();
|
|
|
|
|
current_item->setFlags(current_item->flags() | Qt::ItemIsEditable);
|
|
|
|
|
editItem(current_item);
|
|
|
|
|
});
|
2021-03-23 23:23:37 +01:00
|
|
|
m_context_menu->addSeparator();
|
2018-03-02 22:40:29 +01:00
|
|
|
}
|
|
|
|
|
|
2025-03-01 17:08:10 +01:00
|
|
|
if (selectedItems().count() >= 1)
|
|
|
|
|
{
|
|
|
|
|
m_context_menu->addAction(m_delete_action);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAction* m_addbp = new QAction(tr("Add Breakpoint"), this);
|
|
|
|
|
connect(m_addbp, &QAction::triggered, this, [this]
|
|
|
|
|
{
|
|
|
|
|
debugger_add_bp_window dlg(this, this);
|
|
|
|
|
dlg.exec();
|
|
|
|
|
});
|
|
|
|
|
m_context_menu->addAction(m_addbp);
|
|
|
|
|
|
|
|
|
|
#ifdef RPCS3_HAS_MEMORY_BREAKPOINTS
|
|
|
|
|
QAction* m_tglbpmbreak = new QAction(m_ppu_breakpoint_handler->IsBreakOnBPM() ? tr("Disable BPM") : tr("Enable BPM"), this);
|
|
|
|
|
connect(m_tglbpmbreak, &QAction::triggered, [this]
|
|
|
|
|
{
|
|
|
|
|
m_ppu_breakpoint_handler->SetBreakOnBPM(!m_ppu_breakpoint_handler->IsBreakOnBPM());
|
|
|
|
|
});
|
|
|
|
|
m_context_menu->addAction(m_tglbpmbreak);
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-03-23 23:23:37 +01:00
|
|
|
m_context_menu->exec(viewport()->mapToGlobal(pos));
|
|
|
|
|
m_context_menu->deleteLater();
|
|
|
|
|
m_context_menu = nullptr;
|
2018-03-02 22:40:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void breakpoint_list::OnBreakpointListDelete()
|
|
|
|
|
{
|
2021-03-23 20:39:39 +01:00
|
|
|
for (int i = selectedItems().count() - 1; i >= 0; i--)
|
2018-03-02 22:40:29 +01:00
|
|
|
{
|
2022-09-19 14:57:51 +02:00
|
|
|
RemoveBreakpoint(::at32(selectedItems(), i)->data(Qt::UserRole).value<u32>());
|
2021-03-23 23:23:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_context_menu)
|
|
|
|
|
{
|
|
|
|
|
m_context_menu->close();
|
2018-03-02 22:40:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
2024-09-02 21:57:33 +02:00
|
|
|
|
|
|
|
|
void breakpoint_list::mouseDoubleClickEvent(QMouseEvent* ev)
|
|
|
|
|
{
|
2025-04-05 21:50:45 +02:00
|
|
|
if (!ev)
|
|
|
|
|
return;
|
2024-09-02 21:57:33 +02:00
|
|
|
|
|
|
|
|
// Qt's itemDoubleClicked signal doesn't distinguish between mouse buttons and there is no simple way to get the pressed button.
|
|
|
|
|
// So we have to ignore this event when another button is pressed.
|
|
|
|
|
if (ev->button() != Qt::LeftButton)
|
|
|
|
|
{
|
|
|
|
|
ev->ignore();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QListWidget::mouseDoubleClickEvent(ev);
|
|
|
|
|
}
|