2012-11-01 15:19:01 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
2012-11-04 22:01:49 +00:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
#include "../Core.h"
|
2012-11-02 16:34:42 +00:00
|
|
|
#include "Breakpoints.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
#include "SymbolMap.h"
|
|
|
|
#include "FixedSizeUnorderedSet.h"
|
2013-03-09 10:39:12 +00:00
|
|
|
#include "Core/Host.h"
|
2013-01-18 18:43:40 +00:00
|
|
|
#include "../MIPS/JitCommon/JitCommon.h"
|
2012-11-03 02:33:24 +00:00
|
|
|
#include <cstdio>
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-06-30 22:16:58 +00:00
|
|
|
std::vector<BreakPoint> CBreakPoints::breakPoints_;
|
2013-06-29 18:22:58 +00:00
|
|
|
u32 CBreakPoints::breakSkipFirstAt_ = 0;
|
2013-06-30 22:16:58 +00:00
|
|
|
std::vector<MemCheck> CBreakPoints::memChecks_;
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
MemCheck::MemCheck(void)
|
|
|
|
{
|
|
|
|
numHits=0;
|
|
|
|
}
|
|
|
|
|
2013-03-09 08:40:33 +00:00
|
|
|
void MemCheck::Action(u32 addr, bool write, int size, u32 pc)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-06-30 22:16:58 +00:00
|
|
|
int mask = write ? MEMCHECK_WRITE : MEMCHECK_READ;
|
|
|
|
if (cond & mask)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-03-09 08:35:08 +00:00
|
|
|
++numHits;
|
|
|
|
|
2013-06-30 22:16:58 +00:00
|
|
|
if (result & MEMCHECK_LOG)
|
2013-03-09 08:40:33 +00:00
|
|
|
NOTICE_LOG(MEMMAP, "CHK %s%i at %08x (%s), PC=%08x (%s)", write ? "Write" : "Read", size * 8, addr, symbolMap.GetDescription(addr), pc, symbolMap.GetDescription(pc));
|
2013-06-30 22:16:58 +00:00
|
|
|
if (result & MEMCHECK_BREAK)
|
2013-03-09 10:39:12 +00:00
|
|
|
{
|
2013-03-29 21:56:57 +00:00
|
|
|
Core_EnableStepping(true);
|
2013-03-09 10:39:12 +00:00
|
|
|
host->SetDebugMode(true);
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-30 22:16:58 +00:00
|
|
|
size_t CBreakPoints::FindBreakpoint(u32 addr, bool matchTemp, bool temp)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-06-30 22:16:58 +00:00
|
|
|
for (size_t i = 0; i < breakPoints_.size(); ++i)
|
|
|
|
{
|
2013-06-30 22:51:50 +00:00
|
|
|
if (breakPoints_[i].addr == addr && (!matchTemp || breakPoints_[i].temporary == temp))
|
2013-06-30 22:16:58 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return INVALID_BREAKPOINT;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t CBreakPoints::FindMemCheck(u32 start, u32 end)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < memChecks_.size(); ++i)
|
|
|
|
{
|
|
|
|
if (memChecks_[i].start == start && memChecks_[i].end == end)
|
|
|
|
return i;
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-06-30 22:16:58 +00:00
|
|
|
return INVALID_MEMCHECK;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-06-30 22:16:58 +00:00
|
|
|
bool CBreakPoints::IsAddressBreakPoint(u32 addr)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-06-30 22:16:58 +00:00
|
|
|
size_t bp = FindBreakpoint(addr);
|
2013-06-30 22:51:50 +00:00
|
|
|
return bp != INVALID_BREAKPOINT && breakPoints_[bp].enabled;
|
2013-06-30 22:16:58 +00:00
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-06-30 22:16:58 +00:00
|
|
|
bool CBreakPoints::IsTempBreakPoint(u32 addr)
|
|
|
|
{
|
|
|
|
size_t bp = FindBreakpoint(addr, true, true);
|
|
|
|
return bp != INVALID_BREAKPOINT;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-06-30 22:16:58 +00:00
|
|
|
void CBreakPoints::AddBreakPoint(u32 addr, bool temp)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-06-30 22:16:58 +00:00
|
|
|
size_t bp = FindBreakpoint(addr, true, temp);
|
|
|
|
if (bp == INVALID_BREAKPOINT)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-06-30 22:16:58 +00:00
|
|
|
BreakPoint pt;
|
2013-06-30 22:51:50 +00:00
|
|
|
pt.enabled = true;
|
|
|
|
pt.temporary = temp;
|
|
|
|
pt.addr = addr;
|
2013-06-30 22:16:58 +00:00
|
|
|
|
|
|
|
breakPoints_.push_back(pt);
|
|
|
|
Update(addr);
|
|
|
|
}
|
2013-06-30 22:51:50 +00:00
|
|
|
else if (!breakPoints_[bp].enabled)
|
2013-06-30 22:16:58 +00:00
|
|
|
{
|
2013-06-30 22:51:50 +00:00
|
|
|
breakPoints_[bp].enabled = true;
|
2013-06-30 22:16:58 +00:00
|
|
|
Update(addr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBreakPoints::RemoveBreakPoint(u32 addr)
|
|
|
|
{
|
|
|
|
size_t bp = FindBreakpoint(addr);
|
|
|
|
if (bp != INVALID_BREAKPOINT)
|
|
|
|
{
|
|
|
|
breakPoints_.erase(breakPoints_.begin() + bp);
|
|
|
|
|
|
|
|
// Check again, there might've been an overlapping temp breakpoint.
|
|
|
|
bp = FindBreakpoint(addr);
|
|
|
|
if (bp != INVALID_BREAKPOINT)
|
|
|
|
breakPoints_.erase(breakPoints_.begin() + bp);
|
|
|
|
|
|
|
|
Update(addr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBreakPoints::ChangeBreakPoint(u32 addr, bool status)
|
|
|
|
{
|
|
|
|
size_t bp = FindBreakpoint(addr);
|
|
|
|
if (bp != INVALID_BREAKPOINT)
|
|
|
|
{
|
2013-06-30 22:51:50 +00:00
|
|
|
breakPoints_[bp].enabled = status;
|
2013-06-30 22:16:58 +00:00
|
|
|
Update(addr);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBreakPoints::ClearAllBreakPoints()
|
|
|
|
{
|
2013-06-30 22:16:58 +00:00
|
|
|
if (!breakPoints_.empty())
|
|
|
|
{
|
|
|
|
breakPoints_.clear();
|
|
|
|
Update();
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2013-06-26 21:14:15 +00:00
|
|
|
void CBreakPoints::ClearTemporaryBreakPoints()
|
|
|
|
{
|
2013-06-30 22:16:58 +00:00
|
|
|
if (breakPoints_.empty())
|
|
|
|
return;
|
2013-06-26 21:14:15 +00:00
|
|
|
|
|
|
|
bool update = false;
|
2013-06-30 22:16:58 +00:00
|
|
|
for (int i = (int)breakPoints_.size()-1; i >= 0; --i)
|
2013-06-26 21:14:15 +00:00
|
|
|
{
|
2013-06-30 22:51:50 +00:00
|
|
|
if (breakPoints_[i].temporary)
|
2013-06-26 21:14:15 +00:00
|
|
|
{
|
2013-06-30 22:16:58 +00:00
|
|
|
breakPoints_.erase(breakPoints_.begin() + i);
|
2013-06-26 21:14:15 +00:00
|
|
|
update = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-30 22:16:58 +00:00
|
|
|
if (update)
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
|
2013-06-30 22:35:03 +00:00
|
|
|
void CBreakPoints::ChangeBreakPointAddCond(u32 addr, const BreakPointCond &cond)
|
|
|
|
{
|
|
|
|
size_t bp = FindBreakpoint(addr);
|
|
|
|
if (bp != INVALID_BREAKPOINT)
|
|
|
|
{
|
|
|
|
breakPoints_[bp].hasCond = true;
|
|
|
|
breakPoints_[bp].cond = cond;
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBreakPoints::ChangeBreakPointRemoveCond(u32 addr)
|
|
|
|
{
|
|
|
|
size_t bp = FindBreakpoint(addr);
|
|
|
|
if (bp != INVALID_BREAKPOINT)
|
|
|
|
{
|
|
|
|
breakPoints_[bp].hasCond = false;
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BreakPointCond *CBreakPoints::GetBreakPointCondition(u32 addr)
|
|
|
|
{
|
|
|
|
size_t bp = FindBreakpoint(addr);
|
|
|
|
if (bp != INVALID_BREAKPOINT && breakPoints_[bp].hasCond)
|
|
|
|
return &breakPoints_[bp].cond;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-30 22:16:58 +00:00
|
|
|
void CBreakPoints::AddMemCheck(u32 start, u32 end, MemCheckCondition cond, MemCheckResult result)
|
|
|
|
{
|
|
|
|
size_t mc = FindMemCheck(start, end);
|
|
|
|
if (mc == INVALID_MEMCHECK)
|
|
|
|
{
|
|
|
|
MemCheck check;
|
|
|
|
check.start = start;
|
|
|
|
check.end = end;
|
|
|
|
check.cond = cond;
|
|
|
|
check.result = result;
|
|
|
|
|
|
|
|
memChecks_.push_back(check);
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memChecks_[mc].cond = (MemCheckCondition)(memChecks_[mc].cond | cond);
|
|
|
|
memChecks_[mc].result = (MemCheckResult)(memChecks_[mc].result | result);
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBreakPoints::RemoveMemCheck(u32 start, u32 end)
|
|
|
|
{
|
|
|
|
size_t mc = FindMemCheck(start, end);
|
|
|
|
if (mc != INVALID_MEMCHECK)
|
|
|
|
{
|
|
|
|
memChecks_.erase(memChecks_.begin() + mc);
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBreakPoints::ChangeMemCheck(u32 start, u32 end, MemCheckCondition cond, MemCheckResult result)
|
|
|
|
{
|
|
|
|
size_t mc = FindMemCheck(start, end);
|
|
|
|
if (mc != INVALID_MEMCHECK)
|
|
|
|
{
|
|
|
|
memChecks_[mc].cond = cond;
|
|
|
|
memChecks_[mc].result = result;
|
|
|
|
Update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBreakPoints::ClearAllMemChecks()
|
|
|
|
{
|
|
|
|
if (!memChecks_.empty())
|
|
|
|
{
|
|
|
|
memChecks_.clear();
|
|
|
|
Update();
|
|
|
|
}
|
2013-06-26 21:14:15 +00:00
|
|
|
}
|
|
|
|
|
2013-03-09 08:35:08 +00:00
|
|
|
MemCheck *CBreakPoints::GetMemCheck(u32 address, int size)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
|
|
|
std::vector<MemCheck>::iterator iter;
|
2013-06-30 22:16:58 +00:00
|
|
|
for (iter = memChecks_.begin(); iter != memChecks_.end(); ++iter)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-03-09 08:35:08 +00:00
|
|
|
MemCheck &check = *iter;
|
2013-06-30 22:16:58 +00:00
|
|
|
if (check.end != 0)
|
2012-11-01 15:19:01 +00:00
|
|
|
{
|
2013-06-30 22:16:58 +00:00
|
|
|
if (address >= check.start && address + size < check.end)
|
2013-03-09 08:35:08 +00:00
|
|
|
return ✓
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-30 22:16:58 +00:00
|
|
|
if (check.start==address)
|
2013-03-09 08:35:08 +00:00
|
|
|
return ✓
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//none found
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-30 22:16:58 +00:00
|
|
|
const std::vector<MemCheck> CBreakPoints::GetMemChecks()
|
2013-02-10 15:36:06 +00:00
|
|
|
{
|
2013-06-30 22:16:58 +00:00
|
|
|
return memChecks_;
|
2013-02-10 15:36:06 +00:00
|
|
|
}
|
|
|
|
|
2013-06-30 22:16:58 +00:00
|
|
|
const std::vector<BreakPoint> CBreakPoints::GetBreakpoints()
|
2013-06-27 19:07:49 +00:00
|
|
|
{
|
2013-06-30 22:16:58 +00:00
|
|
|
return breakPoints_;
|
2013-06-27 19:07:49 +00:00
|
|
|
}
|
|
|
|
|
2013-06-30 22:16:58 +00:00
|
|
|
void CBreakPoints::Update(u32 addr)
|
2013-02-10 15:36:06 +00:00
|
|
|
{
|
2013-06-30 22:16:58 +00:00
|
|
|
if (MIPSComp::jit && Core_IsInactive())
|
|
|
|
{
|
|
|
|
if (addr != 0)
|
|
|
|
MIPSComp::jit->ClearCacheAt(addr);
|
|
|
|
else
|
|
|
|
MIPSComp::jit->ClearCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redraw in order to show the breakpoint.
|
|
|
|
host->UpdateDisassembly();
|
2013-02-10 15:36:06 +00:00
|
|
|
}
|