2013-04-17 21:09:55 -06:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2011-02-25 02:35:56 -07:00
|
|
|
#include <sstream>
|
2014-02-19 20:11:52 -07:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Common/BreakPoints.h"
|
2014-09-07 19:06:58 -06:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Common/DebugInterface.h"
|
|
|
|
#include "Core/PowerPC/JitCommon/JitBase.h"
|
2014-02-19 20:11:52 -07:00
|
|
|
#include "Core/PowerPC/JitCommon/JitCache.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
|
2015-04-14 22:38:21 -06:00
|
|
|
bool BreakPoints::IsAddressBreakPoint(u32 address) const
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2014-02-12 08:00:34 -07:00
|
|
|
for (const TBreakPoint& bp : m_BreakPoints)
|
2015-04-14 22:38:21 -06:00
|
|
|
if (bp.iAddress == address)
|
2011-02-25 02:35:56 -07:00
|
|
|
return true;
|
2014-03-02 22:39:08 -07:00
|
|
|
|
2011-02-25 02:35:56 -07:00
|
|
|
return false;
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
2015-04-14 22:38:21 -06:00
|
|
|
bool BreakPoints::IsTempBreakPoint(u32 address) const
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2014-02-12 08:00:34 -07:00
|
|
|
for (const TBreakPoint& bp : m_BreakPoints)
|
2015-04-14 22:38:21 -06:00
|
|
|
if (bp.iAddress == address && bp.bTemporary)
|
2008-12-07 22:30:24 -07:00
|
|
|
return true;
|
2014-03-02 22:39:08 -07:00
|
|
|
|
2008-12-07 22:30:24 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-25 02:35:56 -07:00
|
|
|
BreakPoints::TBreakPointsStr BreakPoints::GetStrings() const
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2011-02-25 02:35:56 -07:00
|
|
|
TBreakPointsStr bps;
|
2014-02-12 08:00:34 -07:00
|
|
|
for (const TBreakPoint& bp : m_BreakPoints)
|
2011-02-25 02:35:56 -07:00
|
|
|
{
|
2013-10-28 23:09:01 -06:00
|
|
|
if (!bp.bTemporary)
|
2011-02-25 02:35:56 -07:00
|
|
|
{
|
2013-10-28 23:09:01 -06:00
|
|
|
std::stringstream ss;
|
|
|
|
ss << std::hex << bp.iAddress << " " << (bp.bOn ? "n" : "");
|
|
|
|
bps.push_back(ss.str());
|
2011-02-25 02:35:56 -07:00
|
|
|
}
|
|
|
|
}
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2011-02-25 02:35:56 -07:00
|
|
|
return bps;
|
|
|
|
}
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2013-10-28 23:09:01 -06:00
|
|
|
void BreakPoints::AddFromStrings(const TBreakPointsStr& bpstrs)
|
2011-02-25 02:35:56 -07:00
|
|
|
{
|
2014-02-12 08:00:34 -07:00
|
|
|
for (const std::string& bpstr : bpstrs)
|
2011-02-25 02:35:56 -07:00
|
|
|
{
|
|
|
|
TBreakPoint bp;
|
2013-10-28 23:09:01 -06:00
|
|
|
std::stringstream ss;
|
|
|
|
ss << std::hex << bpstr;
|
|
|
|
ss >> bp.iAddress;
|
|
|
|
bp.bOn = bpstr.find("n") != bpstr.npos;
|
2011-02-25 02:35:56 -07:00
|
|
|
bp.bTemporary = false;
|
|
|
|
Add(bp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakPoints::Add(const TBreakPoint& bp)
|
|
|
|
{
|
|
|
|
if (!IsAddressBreakPoint(bp.iAddress))
|
2012-03-15 04:48:19 -06:00
|
|
|
{
|
2011-02-25 02:35:56 -07:00
|
|
|
m_BreakPoints.push_back(bp);
|
2012-03-15 04:48:19 -06:00
|
|
|
if (jit)
|
2014-09-26 14:45:24 -06:00
|
|
|
jit->GetBlockCache()->InvalidateICache(bp.iAddress, 4, true);
|
2012-03-15 04:48:19 -06:00
|
|
|
}
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
2011-02-25 02:35:56 -07:00
|
|
|
void BreakPoints::Add(u32 em_address, bool temp)
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2008-12-20 05:10:59 -07:00
|
|
|
if (!IsAddressBreakPoint(em_address)) // only add new addresses
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
|
|
|
TBreakPoint pt; // breakpoint settings
|
|
|
|
pt.bOn = true;
|
|
|
|
pt.bTemporary = temp;
|
2008-12-20 05:10:59 -07:00
|
|
|
pt.iAddress = em_address;
|
2008-12-07 22:30:24 -07:00
|
|
|
|
|
|
|
m_BreakPoints.push_back(pt);
|
2012-03-15 04:48:19 -06:00
|
|
|
|
|
|
|
if (jit)
|
2014-09-26 14:45:24 -06:00
|
|
|
jit->GetBlockCache()->InvalidateICache(em_address, 4, true);
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-15 04:48:19 -06:00
|
|
|
void BreakPoints::Remove(u32 em_address)
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2014-02-12 08:00:34 -07:00
|
|
|
for (auto i = m_BreakPoints.begin(); i != m_BreakPoints.end(); ++i)
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2012-03-15 04:48:19 -06:00
|
|
|
if (i->iAddress == em_address)
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2011-02-25 02:35:56 -07:00
|
|
|
m_BreakPoints.erase(i);
|
2012-03-15 04:48:19 -06:00
|
|
|
if (jit)
|
2014-09-26 14:45:24 -06:00
|
|
|
jit->GetBlockCache()->InvalidateICache(em_address, 4, true);
|
2011-02-25 02:35:56 -07:00
|
|
|
return;
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-15 04:48:19 -06:00
|
|
|
void BreakPoints::Clear()
|
|
|
|
{
|
2013-01-08 14:02:50 -07:00
|
|
|
if (jit)
|
2012-03-15 04:48:19 -06:00
|
|
|
{
|
2014-02-12 08:00:34 -07:00
|
|
|
for (const TBreakPoint& bp : m_BreakPoints)
|
|
|
|
{
|
2014-09-26 14:45:24 -06:00
|
|
|
jit->GetBlockCache()->InvalidateICache(bp.iAddress, 4, true);
|
2014-02-12 08:00:34 -07:00
|
|
|
}
|
2012-03-15 04:48:19 -06:00
|
|
|
}
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2013-01-08 14:02:50 -07:00
|
|
|
m_BreakPoints.clear();
|
2012-03-15 04:48:19 -06:00
|
|
|
}
|
2011-02-25 02:35:56 -07:00
|
|
|
|
2014-10-17 18:02:26 -06:00
|
|
|
void BreakPoints::ClearAllTemporary()
|
|
|
|
{
|
|
|
|
for (const TBreakPoint& bp : m_BreakPoints)
|
|
|
|
{
|
|
|
|
if (bp.bTemporary)
|
|
|
|
{
|
|
|
|
if (jit)
|
|
|
|
jit->GetBlockCache()->InvalidateICache(bp.iAddress, 4, true);
|
|
|
|
Remove(bp.iAddress);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-25 02:35:56 -07:00
|
|
|
MemChecks::TMemChecksStr MemChecks::GetStrings() const
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2011-02-25 02:35:56 -07:00
|
|
|
TMemChecksStr mcs;
|
2014-02-12 08:00:34 -07:00
|
|
|
for (const TMemCheck& bp : m_MemChecks)
|
2011-02-25 02:35:56 -07:00
|
|
|
{
|
|
|
|
std::stringstream mc;
|
2013-10-28 23:09:01 -06:00
|
|
|
mc << std::hex << bp.StartAddress;
|
|
|
|
mc << " " << (bp.bRange ? bp.EndAddress : bp.StartAddress) << " " <<
|
|
|
|
(bp.bRange ? "n" : "") << (bp.OnRead ? "r" : "") <<
|
|
|
|
(bp.OnWrite ? "w" : "") << (bp.Log ? "l" : "") << (bp.Break ? "p" : "");
|
2011-02-25 02:35:56 -07:00
|
|
|
mcs.push_back(mc.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
return mcs;
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
2013-10-28 23:09:01 -06:00
|
|
|
void MemChecks::AddFromStrings(const TMemChecksStr& mcstrs)
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2014-02-12 08:00:34 -07:00
|
|
|
for (const std::string& mcstr : mcstrs)
|
2011-02-25 02:35:56 -07:00
|
|
|
{
|
|
|
|
TMemCheck mc;
|
2013-10-28 23:09:01 -06:00
|
|
|
std::stringstream ss;
|
|
|
|
ss << std::hex << mcstr;
|
|
|
|
ss >> mc.StartAddress;
|
2014-02-16 21:51:41 -07:00
|
|
|
mc.bRange = mcstr.find("n") != mcstr.npos;
|
|
|
|
mc.OnRead = mcstr.find("r") != mcstr.npos;
|
|
|
|
mc.OnWrite = mcstr.find("w") != mcstr.npos;
|
|
|
|
mc.Log = mcstr.find("l") != mcstr.npos;
|
|
|
|
mc.Break = mcstr.find("p") != mcstr.npos;
|
2011-02-25 02:35:56 -07:00
|
|
|
if (mc.bRange)
|
2013-10-28 23:09:01 -06:00
|
|
|
ss >> mc.EndAddress;
|
2011-02-25 02:35:56 -07:00
|
|
|
else
|
|
|
|
mc.EndAddress = mc.StartAddress;
|
|
|
|
Add(mc);
|
|
|
|
}
|
2008-12-20 07:00:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void MemChecks::Add(const TMemCheck& _rMemoryCheck)
|
|
|
|
{
|
2014-03-09 14:14:26 -06:00
|
|
|
if (GetMemCheck(_rMemoryCheck.StartAddress) == nullptr)
|
2011-02-25 02:35:56 -07:00
|
|
|
m_MemChecks.push_back(_rMemoryCheck);
|
2008-12-20 07:00:33 -07:00
|
|
|
}
|
|
|
|
|
2011-02-25 02:35:56 -07:00
|
|
|
void MemChecks::Remove(u32 _Address)
|
2008-12-20 07:00:33 -07:00
|
|
|
{
|
2014-02-12 08:00:34 -07:00
|
|
|
for (auto i = m_MemChecks.begin(); i != m_MemChecks.end(); ++i)
|
2008-12-20 07:00:33 -07:00
|
|
|
{
|
2011-02-25 02:35:56 -07:00
|
|
|
if (i->StartAddress == _Address)
|
2008-12-20 07:00:33 -07:00
|
|
|
{
|
2011-02-25 02:35:56 -07:00
|
|
|
m_MemChecks.erase(i);
|
|
|
|
return;
|
2008-12-20 07:00:33 -07:00
|
|
|
}
|
2011-02-25 02:35:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TMemCheck *MemChecks::GetMemCheck(u32 address)
|
|
|
|
{
|
2014-02-12 08:00:34 -07:00
|
|
|
for (TMemCheck& bp : m_MemChecks)
|
2011-02-25 02:35:56 -07:00
|
|
|
{
|
2013-10-28 23:09:01 -06:00
|
|
|
if (bp.bRange)
|
2008-12-20 07:00:33 -07:00
|
|
|
{
|
2013-10-28 23:09:01 -06:00
|
|
|
if (address >= bp.StartAddress && address <= bp.EndAddress)
|
|
|
|
return &(bp);
|
2008-12-20 07:00:33 -07:00
|
|
|
}
|
2013-10-28 23:09:01 -06:00
|
|
|
else if (bp.StartAddress == address)
|
2014-03-02 22:39:08 -07:00
|
|
|
{
|
2013-10-28 23:09:01 -06:00
|
|
|
return &(bp);
|
2014-03-02 22:39:08 -07:00
|
|
|
}
|
2008-12-20 07:00:33 -07:00
|
|
|
}
|
|
|
|
|
2011-02-25 02:35:56 -07:00
|
|
|
// none found
|
2014-03-09 14:14:26 -06:00
|
|
|
return nullptr;
|
2008-12-20 07:00:33 -07:00
|
|
|
}
|
|
|
|
|
2014-03-02 22:39:08 -07:00
|
|
|
void TMemCheck::Action(DebugInterface *debug_interface, u32 iValue, u32 addr, bool write, int size, u32 pc)
|
2008-12-20 07:00:33 -07:00
|
|
|
{
|
2011-02-25 02:35:56 -07:00
|
|
|
if ((write && OnWrite) || (!write && OnRead))
|
|
|
|
{
|
|
|
|
if (Log)
|
|
|
|
{
|
2011-02-25 04:03:49 -07:00
|
|
|
INFO_LOG(MEMMAP, "CHK %08x (%s) %s%i %0*x at %08x (%s)",
|
2014-03-02 22:39:08 -07:00
|
|
|
pc, debug_interface->GetDescription(pc).c_str(),
|
2011-02-25 04:03:49 -07:00
|
|
|
write ? "Write" : "Read", size*8, size*2, iValue, addr,
|
2014-03-02 22:39:08 -07:00
|
|
|
debug_interface->GetDescription(addr).c_str()
|
2011-02-25 02:35:56 -07:00
|
|
|
);
|
|
|
|
}
|
2014-03-02 22:39:08 -07:00
|
|
|
|
2011-02-25 02:35:56 -07:00
|
|
|
if (Break)
|
2014-03-02 22:39:08 -07:00
|
|
|
debug_interface->BreakNow();
|
2011-02-25 02:35:56 -07:00
|
|
|
}
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
2014-10-19 04:45:40 -06:00
|
|
|
|
|
|
|
|
2014-10-28 05:28:50 -06:00
|
|
|
bool Watches::IsAddressWatch(u32 _iAddress) const
|
2014-10-19 04:45:40 -06:00
|
|
|
{
|
|
|
|
for (const TWatch& bp : m_Watches)
|
|
|
|
if (bp.iAddress == _iAddress)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Watches::TWatchesStr Watches::GetStrings() const
|
|
|
|
{
|
|
|
|
TWatchesStr bps;
|
|
|
|
for (const TWatch& bp : m_Watches)
|
|
|
|
{
|
|
|
|
std::stringstream ss;
|
2014-10-24 05:24:17 -06:00
|
|
|
ss << std::hex << bp.iAddress << " " << bp.name;
|
2014-10-19 04:45:40 -06:00
|
|
|
bps.push_back(ss.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
return bps;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Watches::AddFromStrings(const TWatchesStr& bpstrs)
|
|
|
|
{
|
|
|
|
for (const std::string& bpstr : bpstrs)
|
|
|
|
{
|
|
|
|
TWatch bp;
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << std::hex << bpstr;
|
|
|
|
ss >> bp.iAddress;
|
2014-10-25 23:14:17 -06:00
|
|
|
ss >> std::ws;
|
|
|
|
getline(ss, bp.name);
|
2014-10-19 04:45:40 -06:00
|
|
|
Add(bp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Watches::Add(const TWatch& bp)
|
|
|
|
{
|
|
|
|
if (!IsAddressWatch(bp.iAddress))
|
|
|
|
{
|
|
|
|
m_Watches.push_back(bp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Watches::Add(u32 em_address)
|
|
|
|
{
|
|
|
|
if (!IsAddressWatch(em_address)) // only add new addresses
|
|
|
|
{
|
|
|
|
TWatch pt; // breakpoint settings
|
|
|
|
pt.bOn = true;
|
|
|
|
pt.iAddress = em_address;
|
|
|
|
|
|
|
|
m_Watches.push_back(pt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Watches::Update(int count, u32 em_address)
|
|
|
|
{
|
|
|
|
m_Watches.at(count).iAddress = em_address;
|
|
|
|
}
|
|
|
|
|
2014-10-26 06:23:45 -06:00
|
|
|
void Watches::UpdateName(int count, const std::string name)
|
2014-10-19 04:45:40 -06:00
|
|
|
{
|
|
|
|
m_Watches.at(count).name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Watches::Remove(u32 em_address)
|
|
|
|
{
|
|
|
|
for (auto i = m_Watches.begin(); i != m_Watches.end(); ++i)
|
|
|
|
{
|
|
|
|
if (i->iAddress == em_address)
|
|
|
|
{
|
|
|
|
m_Watches.erase(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Watches::Clear()
|
|
|
|
{
|
|
|
|
m_Watches.clear();
|
|
|
|
}
|