Skip to content

Commit

Permalink
Merge pull request #16389 from unknownbrackets/interp-breakpoint
Browse files Browse the repository at this point in the history
Make breakpoints work better in interpreter
  • Loading branch information
hrydgard authored Nov 14, 2022
2 parents 9443281 + 0f79afa commit 3f133be
Showing 8 changed files with 146 additions and 112 deletions.
27 changes: 21 additions & 6 deletions Core/Debugger/Breakpoints.cpp
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@
#include "Core/MIPS/JitCommon/JitCommon.h"
#include "Core/CoreTiming.h"

std::atomic<bool> anyBreakPoints_(false);
std::atomic<bool> anyMemChecks_(false);

static std::mutex breakPointsMutex_;
@@ -160,13 +161,17 @@ size_t CBreakPoints::FindMemCheck(u32 start, u32 end)

bool CBreakPoints::IsAddressBreakPoint(u32 addr)
{
if (!anyBreakPoints_)
return false;
std::lock_guard<std::mutex> guard(breakPointsMutex_);
size_t bp = FindBreakpoint(addr);
return bp != INVALID_BREAKPOINT && breakPoints_[bp].result != BREAK_ACTION_IGNORE;
}

bool CBreakPoints::IsAddressBreakPoint(u32 addr, bool* enabled)
{
if (!anyBreakPoints_)
return false;
std::lock_guard<std::mutex> guard(breakPointsMutex_);
size_t bp = FindBreakpoint(addr);
if (bp == INVALID_BREAKPOINT) return false;
@@ -184,6 +189,8 @@ bool CBreakPoints::IsTempBreakPoint(u32 addr)

bool CBreakPoints::RangeContainsBreakPoint(u32 addr, u32 size)
{
if (!anyBreakPoints_)
return false;
std::lock_guard<std::mutex> guard(breakPointsMutex_);
const u32 end = addr + size;
for (const auto &bp : breakPoints_)
@@ -207,6 +214,7 @@ void CBreakPoints::AddBreakPoint(u32 addr, bool temp)
pt.addr = addr;

breakPoints_.push_back(pt);
anyBreakPoints_ = true;
guard.unlock();
Update(addr);
}
@@ -232,6 +240,7 @@ void CBreakPoints::RemoveBreakPoint(u32 addr)
if (bp != INVALID_BREAKPOINT)
breakPoints_.erase(breakPoints_.begin() + bp);

anyBreakPoints_ = !breakPoints_.empty();
guard.unlock();
Update(addr);
}
@@ -267,6 +276,8 @@ void CBreakPoints::ChangeBreakPoint(u32 addr, BreakAction result)

void CBreakPoints::ClearAllBreakPoints()
{
if (!anyBreakPoints_)
return;
std::unique_lock<std::mutex> guard(breakPointsMutex_);
if (!breakPoints_.empty())
{
@@ -278,9 +289,9 @@ void CBreakPoints::ClearAllBreakPoints()

void CBreakPoints::ClearTemporaryBreakPoints()
{
std::unique_lock<std::mutex> guard(breakPointsMutex_);
if (breakPoints_.empty())
if (!anyBreakPoints_)
return;
std::unique_lock<std::mutex> guard(breakPointsMutex_);

bool update = false;
for (int i = (int)breakPoints_.size()-1; i >= 0; --i)
@@ -342,6 +353,8 @@ void CBreakPoints::ChangeBreakPointLogFormat(u32 addr, const std::string &fmt) {
}

BreakAction CBreakPoints::ExecBreakPoint(u32 addr) {
if (!anyBreakPoints_)
return BREAK_ACTION_IGNORE;
std::unique_lock<std::mutex> guard(breakPointsMutex_);
size_t bp = FindBreakpoint(addr, false);
if (bp != INVALID_BREAKPOINT) {
@@ -633,10 +646,12 @@ const std::vector<BreakPoint> CBreakPoints::GetBreakpoints()
return breakPoints_;
}

bool CBreakPoints::HasMemChecks()
{
std::lock_guard<std::mutex> guard(memCheckMutex_);
return !memChecks_.empty();
bool CBreakPoints::HasBreakPoints() {
return anyBreakPoints_;
}

bool CBreakPoints::HasMemChecks() {
return anyMemChecks_;
}

void CBreakPoints::Update(u32 addr) {
3 changes: 2 additions & 1 deletion Core/Debugger/Breakpoints.h
Original file line number Diff line number Diff line change
@@ -115,7 +115,7 @@ struct MemCheck {

// BreakPoints cannot overlap, only one is allowed per address.
// MemChecks can overlap, as long as their ends are different.
// WARNING: MemChecks are not used in the interpreter or HLE currently.
// WARNING: MemChecks are not always tracked in HLE currently.
class CBreakPoints
{
public:
@@ -167,6 +167,7 @@ class CBreakPoints
static const std::vector<MemCheck> GetMemChecks();
static const std::vector<BreakPoint> GetBreakpoints();

static bool HasBreakPoints();
static bool HasMemChecks();

static void Update(u32 addr = 0);
18 changes: 2 additions & 16 deletions Core/Debugger/DisassemblyManager.cpp
Original file line number Diff line number Diff line change
@@ -709,22 +709,8 @@ void DisassemblyFunction::load()
case 0x2B: // sw
macro = new DisassemblyMacro(opAddress);

int dataSize;
switch (nextInfo & MEMTYPE_MASK) {
case MEMTYPE_BYTE:
dataSize = 1;
break;
case MEMTYPE_HWORD:
dataSize = 2;
break;
case MEMTYPE_WORD:
case MEMTYPE_FLOAT:
dataSize = 4;
break;
case MEMTYPE_VQUAD:
dataSize = 16;
break;
default:
int dataSize = MIPSGetMemoryAccessSize(next);
if (dataSize == 0) {
delete macro;
return;
}
36 changes: 2 additions & 34 deletions Core/MIPS/MIPSAnalyst.cpp
Original file line number Diff line number Diff line change
@@ -611,25 +611,7 @@ namespace MIPSAnalyst {

int OpMemoryAccessSize(u32 pc) {
const auto op = Memory::Read_Instruction(pc, true);
MIPSInfo info = MIPSGetInfo(op);
if ((info & (IN_MEM | OUT_MEM)) == 0) {
return 0;
}

// TODO: Verify lwl/lwr/etc.?
switch (info & MEMTYPE_MASK) {
case MEMTYPE_BYTE:
return 1;
case MEMTYPE_HWORD:
return 2;
case MEMTYPE_WORD:
case MEMTYPE_FLOAT:
return 4;
case MEMTYPE_VQUAD:
return 16;
}

return 0;
return MIPSGetMemoryAccessSize(op);
}

bool IsOpMemoryWrite(u32 pc) {
@@ -1553,21 +1535,7 @@ namespace MIPSAnalyst {
// lw, sh, ...
if (!IsSyscall(op) && (opInfo & (IN_MEM | OUT_MEM)) != 0) {
info.isDataAccess = true;
switch (opInfo & MEMTYPE_MASK) {
case MEMTYPE_BYTE:
info.dataSize = 1;
break;
case MEMTYPE_HWORD:
info.dataSize = 2;
break;
case MEMTYPE_WORD:
case MEMTYPE_FLOAT:
info.dataSize = 4;
break;

case MEMTYPE_VQUAD:
info.dataSize = 16;
}
info.dataSize = MIPSGetMemoryAccessSize(op);

u32 rs = cpu->GetRegValue(0, (int)MIPS_GET_RS(op));
s16 imm16 = op & 0xFFFF;
2 changes: 0 additions & 2 deletions Core/MIPS/MIPSInt.h
Original file line number Diff line number Diff line change
@@ -23,8 +23,6 @@ int MIPS_SingleStep();

namespace MIPSInt
{
void Int_Unknown(MIPSOpcode op);
void Int_Unimpl(MIPSOpcode op);
void Int_Syscall(MIPSOpcode op);

void Int_mxc1(MIPSOpcode op);
1 change: 0 additions & 1 deletion Core/MIPS/MIPSIntVFPU.h
Original file line number Diff line number Diff line change
@@ -26,7 +26,6 @@ namespace MIPSInt
void Int_SV(MIPSOpcode op);
void Int_SVQ(MIPSOpcode op);
void Int_Mftv(MIPSOpcode op);
void Int_MatrixSet(MIPSOpcode op);
void Int_VecDo3(MIPSOpcode op);
void Int_Vcst(MIPSOpcode op);
void Int_VMatrixInit(MIPSOpcode op);
Loading

0 comments on commit 3f133be

Please sign in to comment.