2013-09-04 19:17:46 +07:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2014-04-08 19:15:08 +07:00
|
|
|
#include "common/common.h"
|
|
|
|
#include "common/debug_interface.h"
|
|
|
|
#include "common/break_points.h"
|
2013-09-04 19:17:46 +07:00
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <algorithm>
|
|
|
|
|
2014-08-12 05:44:12 +07:00
|
|
|
bool BreakPoints::IsAddressBreakPoint(u32 iAddress)
|
2013-09-04 19:17:46 +07:00
|
|
|
{
|
2014-08-12 05:44:12 +07:00
|
|
|
auto cond = [&iAddress](const TBreakPoint& bp) { return bp.iAddress == iAddress; };
|
|
|
|
auto it = std::find_if(m_BreakPoints.begin(), m_BreakPoints.end(), cond);
|
2014-08-12 06:04:54 +07:00
|
|
|
return it != m_BreakPoints.end();
|
2013-09-04 19:17:46 +07:00
|
|
|
}
|
|
|
|
|
2014-08-12 05:44:12 +07:00
|
|
|
bool BreakPoints::IsTempBreakPoint(u32 iAddress)
|
2013-09-04 19:17:46 +07:00
|
|
|
{
|
2014-08-12 05:44:12 +07:00
|
|
|
auto cond = [&iAddress](const TBreakPoint& bp) { return bp.iAddress == iAddress && bp.bTemporary; };
|
|
|
|
auto it = std::find_if(m_BreakPoints.begin(), m_BreakPoints.end(), cond);
|
2014-08-12 06:04:54 +07:00
|
|
|
return it != m_BreakPoints.end();
|
2013-09-04 19:17:46 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
BreakPoints::TBreakPointsStr BreakPoints::GetStrings() const
|
|
|
|
{
|
2014-04-01 17:20:08 +07:00
|
|
|
TBreakPointsStr bps;
|
2014-08-11 19:44:59 +07:00
|
|
|
for (auto breakpoint : m_BreakPoints)
|
2014-04-01 17:20:08 +07:00
|
|
|
{
|
2014-08-11 19:44:59 +07:00
|
|
|
if (!breakpoint.bTemporary)
|
2014-04-01 17:20:08 +07:00
|
|
|
{
|
|
|
|
std::stringstream bp;
|
2014-08-11 19:44:59 +07:00
|
|
|
bp << std::hex << breakpoint.iAddress << " " << (breakpoint.bOn ? "n" : "");
|
2014-04-01 17:20:08 +07:00
|
|
|
bps.push_back(bp.str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bps;
|
2013-09-04 19:17:46 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void BreakPoints::AddFromStrings(const TBreakPointsStr& bps)
|
|
|
|
{
|
2014-08-11 19:44:59 +07:00
|
|
|
for (auto bps_item : bps)
|
2014-04-01 17:20:08 +07:00
|
|
|
{
|
|
|
|
TBreakPoint bp;
|
|
|
|
std::stringstream bpstr;
|
2014-08-11 19:44:59 +07:00
|
|
|
bpstr << std::hex << bps_item;
|
2014-04-01 17:20:08 +07:00
|
|
|
bpstr >> bp.iAddress;
|
2014-08-11 19:44:59 +07:00
|
|
|
bp.bOn = bps_item.find("n") != bps_item.npos;
|
2014-04-01 17:20:08 +07:00
|
|
|
bp.bTemporary = false;
|
|
|
|
Add(bp);
|
|
|
|
}
|
2013-09-04 19:17:46 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void BreakPoints::Add(const TBreakPoint& bp)
|
|
|
|
{
|
2014-04-01 17:20:08 +07:00
|
|
|
if (!IsAddressBreakPoint(bp.iAddress))
|
|
|
|
{
|
|
|
|
m_BreakPoints.push_back(bp);
|
|
|
|
//if (jit)
|
|
|
|
// jit->GetBlockCache()->InvalidateICache(bp.iAddress, 4);
|
|
|
|
}
|
2013-09-04 19:17:46 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void BreakPoints::Add(u32 em_address, bool temp)
|
|
|
|
{
|
2014-04-01 17:20:08 +07:00
|
|
|
if (!IsAddressBreakPoint(em_address)) // only add new addresses
|
|
|
|
{
|
|
|
|
TBreakPoint pt; // breakpoint settings
|
|
|
|
pt.bOn = true;
|
|
|
|
pt.bTemporary = temp;
|
|
|
|
pt.iAddress = em_address;
|
|
|
|
|
|
|
|
m_BreakPoints.push_back(pt);
|
|
|
|
|
|
|
|
//if (jit)
|
|
|
|
// jit->GetBlockCache()->InvalidateICache(em_address, 4);
|
|
|
|
}
|
2013-09-04 19:17:46 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void BreakPoints::Remove(u32 em_address)
|
|
|
|
{
|
2014-08-12 05:44:12 +07:00
|
|
|
auto cond = [&em_address](const TBreakPoint& bp) { return bp.iAddress == em_address; };
|
|
|
|
auto it = std::find_if(m_BreakPoints.begin(), m_BreakPoints.end(), cond);
|
|
|
|
if (it != m_BreakPoints.end())
|
|
|
|
m_BreakPoints.erase(it);
|
2013-09-04 19:17:46 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void BreakPoints::Clear()
|
|
|
|
{
|
2014-04-01 17:20:08 +07:00
|
|
|
//if (jit)
|
|
|
|
//{
|
|
|
|
// std::for_each(m_BreakPoints.begin(), m_BreakPoints.end(),
|
|
|
|
// [](const TBreakPoint& bp)
|
|
|
|
// {
|
|
|
|
// jit->GetBlockCache()->InvalidateICache(bp.iAddress, 4);
|
|
|
|
// }
|
|
|
|
// );
|
|
|
|
//}
|
2014-08-12 05:44:12 +07:00
|
|
|
|
2014-04-01 17:20:08 +07:00
|
|
|
m_BreakPoints.clear();
|
2013-09-04 19:17:46 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
MemChecks::TMemChecksStr MemChecks::GetStrings() const
|
|
|
|
{
|
2014-04-01 17:20:08 +07:00
|
|
|
TMemChecksStr mcs;
|
2014-08-11 19:44:59 +07:00
|
|
|
for (auto memcheck : m_MemChecks)
|
2014-04-01 17:20:08 +07:00
|
|
|
{
|
|
|
|
std::stringstream mc;
|
2014-08-11 19:44:59 +07:00
|
|
|
mc << std::hex << memcheck.StartAddress;
|
|
|
|
mc << " " << (memcheck.bRange ? memcheck.EndAddress : memcheck.StartAddress) << " "
|
2014-08-12 05:44:12 +07:00
|
|
|
<< (memcheck.bRange ? "n" : "")
|
|
|
|
<< (memcheck.OnRead ? "r" : "")
|
|
|
|
<< (memcheck.OnWrite ? "w" : "")
|
|
|
|
<< (memcheck.Log ? "l" : "")
|
2014-08-11 19:44:59 +07:00
|
|
|
<< (memcheck.Break ? "p" : "");
|
2014-04-01 17:20:08 +07:00
|
|
|
mcs.push_back(mc.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
return mcs;
|
2013-09-04 19:17:46 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void MemChecks::AddFromStrings(const TMemChecksStr& mcs)
|
|
|
|
{
|
2014-08-11 19:44:59 +07:00
|
|
|
for (auto mcs_item : mcs)
|
2014-04-01 17:20:08 +07:00
|
|
|
{
|
|
|
|
TMemCheck mc;
|
|
|
|
std::stringstream mcstr;
|
2014-08-11 19:44:59 +07:00
|
|
|
mcstr << std::hex << mcs_item;
|
2014-04-01 17:20:08 +07:00
|
|
|
mcstr >> mc.StartAddress;
|
2014-08-11 19:44:59 +07:00
|
|
|
mc.bRange = mcs_item.find("n") != mcs_item.npos;
|
|
|
|
mc.OnRead = mcs_item.find("r") != mcs_item.npos;
|
|
|
|
mc.OnWrite = mcs_item.find("w") != mcs_item.npos;
|
|
|
|
mc.Log = mcs_item.find("l") != mcs_item.npos;
|
|
|
|
mc.Break = mcs_item.find("p") != mcs_item.npos;
|
2014-04-01 17:20:08 +07:00
|
|
|
if (mc.bRange)
|
|
|
|
mcstr >> mc.EndAddress;
|
|
|
|
else
|
|
|
|
mc.EndAddress = mc.StartAddress;
|
|
|
|
Add(mc);
|
|
|
|
}
|
2013-09-04 19:17:46 +07:00
|
|
|
}
|
|
|
|
|
2014-08-12 05:44:12 +07:00
|
|
|
void MemChecks::Add(const TMemCheck& rMemoryCheck)
|
2013-09-04 19:17:46 +07:00
|
|
|
{
|
2014-08-12 05:44:12 +07:00
|
|
|
if (GetMemCheck(rMemoryCheck.StartAddress) == 0)
|
|
|
|
m_MemChecks.push_back(rMemoryCheck);
|
2013-09-04 19:17:46 +07:00
|
|
|
}
|
|
|
|
|
2014-08-12 05:44:12 +07:00
|
|
|
void MemChecks::Remove(u32 Address)
|
2013-09-04 19:17:46 +07:00
|
|
|
{
|
2014-08-12 05:44:12 +07:00
|
|
|
auto cond = [&Address](const TMemCheck& mc) { return mc.StartAddress == Address; };
|
|
|
|
auto it = std::find_if(m_MemChecks.begin(), m_MemChecks.end(), cond);
|
|
|
|
if (it != m_MemChecks.end())
|
|
|
|
m_MemChecks.erase(it);
|
2013-09-04 19:17:46 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
TMemCheck *MemChecks::GetMemCheck(u32 address)
|
|
|
|
{
|
2014-08-11 19:44:59 +07:00
|
|
|
for (auto i = m_MemChecks.begin(); i != m_MemChecks.end(); ++i)
|
2014-04-01 17:20:08 +07:00
|
|
|
{
|
|
|
|
if (i->bRange)
|
|
|
|
{
|
|
|
|
if (address >= i->StartAddress && address <= i->EndAddress)
|
|
|
|
return &(*i);
|
|
|
|
}
|
|
|
|
else if (i->StartAddress == address)
|
|
|
|
return &(*i);
|
|
|
|
}
|
|
|
|
|
|
|
|
// none found
|
|
|
|
return 0;
|
2013-09-04 19:17:46 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMemCheck::Action(DebugInterface *debug_interface, u32 iValue, u32 addr,
|
2014-04-01 17:20:08 +07:00
|
|
|
bool write, int size, u32 pc)
|
2013-09-04 19:17:46 +07:00
|
|
|
{
|
2014-04-01 17:20:08 +07:00
|
|
|
if ((write && OnWrite) || (!write && OnRead))
|
|
|
|
{
|
|
|
|
if (Log)
|
|
|
|
{
|
2014-12-05 19:53:49 +07:00
|
|
|
LOG_DEBUG(Debug_Breakpoint, "CHK %08x (%s) %s%i %0*x at %08x (%s)",
|
2014-04-01 17:20:08 +07:00
|
|
|
pc, debug_interface->getDescription(pc).c_str(),
|
|
|
|
write ? "Write" : "Read", size*8, size*2, iValue, addr,
|
|
|
|
debug_interface->getDescription(addr).c_str()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (Break)
|
|
|
|
debug_interface->breakNow();
|
|
|
|
}
|
2013-09-04 19:17:46 +07:00
|
|
|
}
|