Skip to content

Commit

Permalink
dd Break On Hit and Log On Hit for instruction breakpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
RenaKunisaki committed Jul 7, 2020
1 parent 0dbe8fb commit 885b8b1
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 18 deletions.
25 changes: 24 additions & 1 deletion Source/Core/Core/PowerPC/BreakPoints.cpp
Expand Up @@ -30,6 +30,19 @@ bool BreakPoints::IsTempBreakPoint(u32 address) const
});
}

bool BreakPoints::IsBreakPointBreakOnHit(u32 address) const
{
return std::any_of(m_breakpoints.begin(), m_breakpoints.end(), [address](const auto& bp) {
return bp.address == address && bp.break_on_hit;
});
}

bool BreakPoints::IsBreakPointLogOnHit(u32 address) const
{
return std::any_of(m_breakpoints.begin(), m_breakpoints.end(),
[address](const auto& bp) { return bp.address == address && bp.log_on_hit; });
}

BreakPoints::TBreakPointsStr BreakPoints::GetStrings() const
{
TBreakPointsStr bp_strings;
Expand All @@ -38,7 +51,8 @@ BreakPoints::TBreakPointsStr BreakPoints::GetStrings() const
if (!bp.is_temporary)
{
std::ostringstream ss;
ss << std::hex << bp.address << " " << (bp.is_enabled ? "n" : "");
ss << std::hex << bp.address << " " << (bp.is_enabled ? "n" : "")
<< (bp.log_on_hit ? "l" : "") << (bp.break_on_hit ? "p" : "");
bp_strings.push_back(ss.str());
}
}
Expand All @@ -55,6 +69,8 @@ void BreakPoints::AddFromStrings(const TBreakPointsStr& bp_strings)
ss << std::hex << bp_string;
ss >> bp.address;
bp.is_enabled = bp_string.find('n') != bp_string.npos;
bp.log_on_hit = bp_string.find('l') != bp_string.npos;
bp.break_on_hit = bp_string.find('p') != bp_string.npos;
bp.is_temporary = false;
Add(bp);
}
Expand All @@ -71,6 +87,11 @@ void BreakPoints::Add(const TBreakPoint& bp)
}

void BreakPoints::Add(u32 address, bool temp)
{
BreakPoints::Add(address, temp, true, false);
}

void BreakPoints::Add(u32 address, bool temp, bool break_on_hit, bool log_on_hit)
{
// Only add new addresses
if (IsAddressBreakPoint(address))
Expand All @@ -79,6 +100,8 @@ void BreakPoints::Add(u32 address, bool temp)
TBreakPoint bp; // breakpoint settings
bp.is_enabled = true;
bp.is_temporary = temp;
bp.break_on_hit = break_on_hit;
bp.log_on_hit = log_on_hit;
bp.address = address;

m_breakpoints.push_back(bp);
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/Core/PowerPC/BreakPoints.h
Expand Up @@ -20,6 +20,8 @@ struct TBreakPoint
u32 address = 0;
bool is_enabled = false;
bool is_temporary = false;
bool log_on_hit = false;
bool break_on_hit = false;
};

struct TMemCheck
Expand Down Expand Up @@ -56,8 +58,11 @@ class BreakPoints
// is address breakpoint
bool IsAddressBreakPoint(u32 address) const;
bool IsTempBreakPoint(u32 address) const;
bool IsBreakPointBreakOnHit(u32 address) const;
bool IsBreakPointLogOnHit(u32 address) const;

// Add BreakPoint
void Add(u32 address, bool temp, bool break_on_hit, bool log_on_hit);
void Add(u32 address, bool temp = false);
void Add(const TBreakPoint& bp);

Expand Down
10 changes: 9 additions & 1 deletion Source/Core/Core/PowerPC/PowerPC.cpp
Expand Up @@ -28,6 +28,7 @@
#include "Core/PowerPC/Interpreter/Interpreter.h"
#include "Core/PowerPC/JitInterface.h"
#include "Core/PowerPC/MMU.h"
#include "Core/PowerPC/PPCSymbolDB.h"

namespace PowerPC
{
Expand Down Expand Up @@ -603,7 +604,14 @@ void CheckBreakPoints()
{
if (PowerPC::breakpoints.IsAddressBreakPoint(PC))
{
CPU::Break();
if (PowerPC::breakpoints.IsBreakPointBreakOnHit(PC))
CPU::Break();
if (PowerPC::breakpoints.IsBreakPointLogOnHit(PC))
{
NOTICE_LOG(MEMMAP, "BP %08x %s(%08x %08x %08x %08x %08x %08x %08x %08x %08x %08x) LR=%08x",
PC, g_symbolDB.GetDescription(PC).c_str(), GPR(3), GPR(4), GPR(5), GPR(6), GPR(7),
GPR(8), GPR(9), GPR(10), GPR(11), GPR(12), LR);
}
if (PowerPC::breakpoints.IsTempBreakPoint(PC))
PowerPC::breakpoints.Remove(PC);
}
Expand Down
16 changes: 14 additions & 2 deletions Source/Core/DolphinQt/Debugger/BreakpointWidget.cpp
Expand Up @@ -188,7 +188,15 @@ void BreakpointWidget::Update()
m_table->setItem(i, 3,
create_item(QStringLiteral("%1").arg(bp.address, 8, 16, QLatin1Char('0'))));

m_table->setItem(i, 4, create_item());
QString flags;

if (bp.break_on_hit)
flags.append(QLatin1Char{'p'});

if (bp.log_on_hit)
flags.append(QLatin1Char{'l'});

m_table->setItem(i, 4, create_item(flags));

i++;
}
Expand Down Expand Up @@ -308,7 +316,11 @@ void BreakpointWidget::OnSave()

void BreakpointWidget::AddBP(u32 addr)
{
PowerPC::breakpoints.Add(addr);
AddBP(addr, false, true, true);
}
void BreakpointWidget::AddBP(u32 addr, bool temp, bool break_on_hit, bool log_on_hit)
{
PowerPC::breakpoints.Add(addr, temp, break_on_hit, log_on_hit);

Update();
}
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DolphinQt/Debugger/BreakpointWidget.h
Expand Up @@ -22,6 +22,7 @@ class BreakpointWidget : public QDockWidget
~BreakpointWidget();

void AddBP(u32 addr);
void AddBP(u32 addr, bool temp, bool break_on_hit, bool log_on_hit);
void AddAddressMBP(u32 addr, bool on_read = true, bool on_write = true, bool do_log = true,
bool do_break = true);
void AddRangedMBP(u32 from, u32 to, bool do_read = true, bool do_write = true, bool do_log = true,
Expand Down
22 changes: 11 additions & 11 deletions Source/Core/DolphinQt/Debugger/NewBreakpointDialog.cpp
Expand Up @@ -62,12 +62,12 @@ void NewBreakpointDialog::CreateWidgets()
m_memory_on_read_and_write = new QRadioButton(tr("Read or Write"));
m_memory_on_write->setChecked(true);
// i18n: This is a selectable action when adding a breakpoint
m_memory_do_log = new QRadioButton(tr("Write to Log"));
m_do_log = new QRadioButton(tr("Write to Log"));
// i18n: This is a selectable action when adding a breakpoint
m_memory_do_break = new QRadioButton(tr("Break"));
m_do_break = new QRadioButton(tr("Break"));
// i18n: This is a selectable action when adding a breakpoint
m_memory_do_log_and_break = new QRadioButton(tr("Write to Log and Break"));
m_memory_do_log_and_break->setChecked(true);
m_do_log_and_break = new QRadioButton(tr("Write to Log and Break"));
m_do_log_and_break->setChecked(true);

auto* memory_layout = new QGridLayout;
m_memory_box->setLayout(memory_layout);
Expand All @@ -89,17 +89,17 @@ void NewBreakpointDialog::CreateWidgets()
QGroupBox* action_box = new QGroupBox(tr("Action"));
auto* action_layout = new QHBoxLayout;
action_box->setLayout(action_layout);
memory_layout->addWidget(action_box, 3, 0, 1, -1);
action_layout->addWidget(m_memory_do_log);
action_layout->addWidget(m_memory_do_break);
action_layout->addWidget(m_memory_do_log_and_break);
action_layout->addWidget(m_do_log);
action_layout->addWidget(m_do_break);
action_layout->addWidget(m_do_log_and_break);

auto* layout = new QVBoxLayout;

layout->addWidget(m_instruction_bp);
layout->addWidget(m_instruction_box);
layout->addWidget(m_memory_bp);
layout->addWidget(m_memory_box);
layout->addWidget(action_box);
layout->addWidget(m_buttons);

setLayout(layout);
Expand Down Expand Up @@ -150,8 +150,8 @@ void NewBreakpointDialog::accept()
bool on_write = m_memory_on_write->isChecked() || m_memory_on_read_and_write->isChecked();

// Actions
bool do_log = m_memory_do_log->isChecked() || m_memory_do_log_and_break->isChecked();
bool do_break = m_memory_do_break->isChecked() || m_memory_do_log_and_break->isChecked();
bool do_log = m_do_log->isChecked() || m_do_log_and_break->isChecked();
bool do_break = m_do_break->isChecked() || m_do_log_and_break->isChecked();

bool good;

Expand All @@ -165,7 +165,7 @@ void NewBreakpointDialog::accept()
return;
}

m_parent->AddBP(address);
m_parent->AddBP(address, false, do_break, do_log);
}
else
{
Expand Down
8 changes: 5 additions & 3 deletions Source/Core/DolphinQt/Debugger/NewBreakpointDialog.h
Expand Up @@ -48,9 +48,11 @@ class NewBreakpointDialog : public QDialog
QRadioButton* m_memory_on_read;
QRadioButton* m_memory_on_read_and_write;
QRadioButton* m_memory_on_write;
QRadioButton* m_memory_do_log;
QRadioButton* m_memory_do_break;
QRadioButton* m_memory_do_log_and_break;

// Action
QRadioButton* m_do_log;
QRadioButton* m_do_break;
QRadioButton* m_do_log_and_break;

QDialogButtonBox* m_buttons;
BreakpointWidget* m_parent;
Expand Down

0 comments on commit 885b8b1

Please sign in to comment.