2015-05-24 06:55:12 +02:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-18 01:08:10 +02:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 23:09:55 -04:00
|
|
|
// Refer to the license.txt file included.
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2016-12-23 14:18:14 -05:00
|
|
|
#include "Core/PowerPC/BreakPoints.h"
|
|
|
|
|
2011-02-25 09:35:56 +00:00
|
|
|
#include <sstream>
|
2014-02-20 04:11:52 +01:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-09-07 20:06:58 -05:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-17 05:18:15 -05:00
|
|
|
#include "Common/DebugInterface.h"
|
|
|
|
#include "Core/PowerPC/JitCommon/JitBase.h"
|
2014-02-20 04:11:52 +01:00
|
|
|
#include "Core/PowerPC/JitCommon/JitCache.h"
|
2014-02-17 05:18:15 -05:00
|
|
|
|
2015-04-15 00:38:21 -04:00
|
|
|
bool BreakPoints::IsAddressBreakPoint(u32 address) const
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
for (const TBreakPoint& bp : m_breakpoints)
|
|
|
|
if (bp.address == address)
|
2016-06-24 10:43:46 +02:00
|
|
|
return true;
|
2014-03-03 00:39:08 -05:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
return false;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2015-04-15 00:38:21 -04:00
|
|
|
bool BreakPoints::IsTempBreakPoint(u32 address) const
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
for (const TBreakPoint& bp : m_breakpoints)
|
|
|
|
if (bp.address == address && bp.is_temporary)
|
2016-06-24 10:43:46 +02:00
|
|
|
return true;
|
2014-03-03 00:39:08 -05:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
return false;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-25 09:35:56 +00:00
|
|
|
BreakPoints::TBreakPointsStr BreakPoints::GetStrings() const
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
TBreakPointsStr bp_strings;
|
|
|
|
for (const TBreakPoint& bp : m_breakpoints)
|
2016-06-24 10:43:46 +02:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
if (!bp.is_temporary)
|
2016-06-24 10:43:46 +02:00
|
|
|
{
|
|
|
|
std::stringstream ss;
|
2017-01-11 08:27:45 -05:00
|
|
|
ss << std::hex << bp.address << " " << (bp.is_enabled ? "n" : "");
|
|
|
|
bp_strings.push_back(ss.str());
|
2016-06-24 10:43:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-11 08:27:45 -05:00
|
|
|
return bp_strings;
|
2011-02-25 09:35:56 +00:00
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2017-01-11 08:27:45 -05:00
|
|
|
void BreakPoints::AddFromStrings(const TBreakPointsStr& bp_strings)
|
2011-02-25 09:35:56 +00:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
for (const std::string& bp_string : bp_strings)
|
2016-06-24 10:43:46 +02:00
|
|
|
{
|
|
|
|
TBreakPoint bp;
|
|
|
|
std::stringstream ss;
|
2017-01-11 08:27:45 -05:00
|
|
|
ss << std::hex << bp_string;
|
|
|
|
ss >> bp.address;
|
2017-01-11 09:41:26 -05:00
|
|
|
bp.is_enabled = bp_string.find('n') != bp_string.npos;
|
2017-01-11 08:27:45 -05:00
|
|
|
bp.is_temporary = false;
|
2016-06-24 10:43:46 +02:00
|
|
|
Add(bp);
|
|
|
|
}
|
2011-02-25 09:35:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BreakPoints::Add(const TBreakPoint& bp)
|
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
if (!IsAddressBreakPoint(bp.address))
|
2016-06-24 10:43:46 +02:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
m_breakpoints.push_back(bp);
|
2017-01-07 23:03:48 +01:00
|
|
|
if (g_jit)
|
2017-01-11 08:27:45 -05:00
|
|
|
g_jit->GetBlockCache()->InvalidateICache(bp.address, 4, true);
|
2016-06-24 10:43:46 +02:00
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 08:27:45 -05:00
|
|
|
void BreakPoints::Add(u32 address, bool temp)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
if (!IsAddressBreakPoint(address)) // only add new addresses
|
2016-06-24 10:43:46 +02:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
TBreakPoint bp; // breakpoint settings
|
|
|
|
bp.is_enabled = true;
|
|
|
|
bp.is_temporary = temp;
|
|
|
|
bp.address = address;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2017-01-11 08:27:45 -05:00
|
|
|
m_breakpoints.push_back(bp);
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2017-01-07 23:03:48 +01:00
|
|
|
if (g_jit)
|
2017-01-11 08:27:45 -05:00
|
|
|
g_jit->GetBlockCache()->InvalidateICache(address, 4, true);
|
2016-06-24 10:43:46 +02:00
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 08:27:45 -05:00
|
|
|
void BreakPoints::Remove(u32 address)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
for (auto i = m_breakpoints.begin(); i != m_breakpoints.end(); ++i)
|
2016-06-24 10:43:46 +02:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
if (i->address == address)
|
2016-06-24 10:43:46 +02:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
m_breakpoints.erase(i);
|
2017-01-07 23:03:48 +01:00
|
|
|
if (g_jit)
|
2017-01-11 08:27:45 -05:00
|
|
|
g_jit->GetBlockCache()->InvalidateICache(address, 4, true);
|
2016-06-24 10:43:46 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2012-03-15 21:48:19 +11:00
|
|
|
void BreakPoints::Clear()
|
|
|
|
{
|
2017-01-07 23:03:48 +01:00
|
|
|
if (g_jit)
|
2016-06-24 10:43:46 +02:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
for (const TBreakPoint& bp : m_breakpoints)
|
2016-06-24 10:43:46 +02:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
g_jit->GetBlockCache()->InvalidateICache(bp.address, 4, true);
|
2016-06-24 10:43:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-11 08:27:45 -05:00
|
|
|
m_breakpoints.clear();
|
2012-03-15 21:48:19 +11:00
|
|
|
}
|
2011-02-25 09:35:56 +00:00
|
|
|
|
2014-10-18 11:02:26 +11:00
|
|
|
void BreakPoints::ClearAllTemporary()
|
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
auto bp = m_breakpoints.begin();
|
|
|
|
while (bp != m_breakpoints.end())
|
2016-06-24 10:43:46 +02:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
if (bp->is_temporary)
|
2016-06-24 10:43:46 +02:00
|
|
|
{
|
2017-01-07 23:03:48 +01:00
|
|
|
if (g_jit)
|
2017-01-11 08:27:45 -05:00
|
|
|
g_jit->GetBlockCache()->InvalidateICache(bp->address, 4, true);
|
|
|
|
bp = m_breakpoints.erase(bp);
|
2016-10-15 18:51:49 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++bp;
|
2016-06-24 10:43:46 +02:00
|
|
|
}
|
|
|
|
}
|
2014-10-18 11:02:26 +11:00
|
|
|
}
|
|
|
|
|
2011-02-25 09:35:56 +00:00
|
|
|
MemChecks::TMemChecksStr MemChecks::GetStrings() const
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
TMemChecksStr mc_strings;
|
|
|
|
for (const TMemCheck& mc : m_mem_checks)
|
2016-06-24 10:43:46 +02:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
std::stringstream ss;
|
|
|
|
ss << std::hex << mc.start_address;
|
|
|
|
ss << " " << (mc.is_ranged ? mc.end_address : mc.start_address) << " "
|
|
|
|
<< (mc.is_ranged ? "n" : "") << (mc.is_break_on_read ? "r" : "")
|
|
|
|
<< (mc.is_break_on_write ? "w" : "") << (mc.log_on_hit ? "l" : "")
|
|
|
|
<< (mc.break_on_hit ? "p" : "");
|
|
|
|
mc_strings.push_back(ss.str());
|
2016-06-24 10:43:46 +02:00
|
|
|
}
|
|
|
|
|
2017-01-11 08:27:45 -05:00
|
|
|
return mc_strings;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 08:27:45 -05:00
|
|
|
void MemChecks::AddFromStrings(const TMemChecksStr& mc_strings)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
for (const std::string& mc_string : mc_strings)
|
2016-06-24 10:43:46 +02:00
|
|
|
{
|
|
|
|
TMemCheck mc;
|
|
|
|
std::stringstream ss;
|
2017-01-11 08:27:45 -05:00
|
|
|
ss << std::hex << mc_string;
|
|
|
|
ss >> mc.start_address;
|
2017-01-11 09:41:26 -05:00
|
|
|
mc.is_ranged = mc_string.find('n') != mc_string.npos;
|
|
|
|
mc.is_break_on_read = mc_string.find('r') != mc_string.npos;
|
|
|
|
mc.is_break_on_write = mc_string.find('w') != mc_string.npos;
|
|
|
|
mc.log_on_hit = mc_string.find('l') != mc_string.npos;
|
|
|
|
mc.break_on_hit = mc_string.find('p') != mc_string.npos;
|
2017-01-11 08:27:45 -05:00
|
|
|
if (mc.is_ranged)
|
|
|
|
ss >> mc.end_address;
|
2016-06-24 10:43:46 +02:00
|
|
|
else
|
2017-01-11 08:27:45 -05:00
|
|
|
mc.end_address = mc.start_address;
|
2016-06-24 10:43:46 +02:00
|
|
|
Add(mc);
|
|
|
|
}
|
2008-12-20 14:00:33 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 08:27:45 -05:00
|
|
|
void MemChecks::Add(const TMemCheck& memory_check)
|
2008-12-20 14:00:33 +00:00
|
|
|
{
|
2016-06-24 10:43:46 +02:00
|
|
|
bool had_any = HasAny();
|
2017-01-11 08:27:45 -05:00
|
|
|
if (GetMemCheck(memory_check.start_address) == nullptr)
|
|
|
|
m_mem_checks.push_back(memory_check);
|
2016-06-24 10:43:46 +02:00
|
|
|
// If this is the first one, clear the JIT cache so it can switch to
|
|
|
|
// watchpoint-compatible code.
|
2017-01-07 23:03:48 +01:00
|
|
|
if (!had_any && g_jit)
|
|
|
|
g_jit->GetBlockCache()->SchedulateClearCacheThreadSafe();
|
2008-12-20 14:00:33 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 08:27:45 -05:00
|
|
|
void MemChecks::Remove(u32 address)
|
2008-12-20 14:00:33 +00:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
for (auto i = m_mem_checks.begin(); i != m_mem_checks.end(); ++i)
|
2016-06-24 10:43:46 +02:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
if (i->start_address == address)
|
2016-06-24 10:43:46 +02:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
m_mem_checks.erase(i);
|
2017-01-07 23:03:48 +01:00
|
|
|
if (!HasAny() && g_jit)
|
|
|
|
g_jit->GetBlockCache()->SchedulateClearCacheThreadSafe();
|
2016-06-24 10:43:46 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-02-25 09:35:56 +00:00
|
|
|
}
|
|
|
|
|
2016-01-21 21:16:51 +01:00
|
|
|
TMemCheck* MemChecks::GetMemCheck(u32 address)
|
2011-02-25 09:35:56 +00:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
for (TMemCheck& mc : m_mem_checks)
|
2016-06-24 10:43:46 +02:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
if (mc.is_ranged)
|
2016-06-24 10:43:46 +02:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
if (address >= mc.start_address && address <= mc.end_address)
|
|
|
|
return &mc;
|
2016-06-24 10:43:46 +02:00
|
|
|
}
|
2017-01-11 08:27:45 -05:00
|
|
|
else if (mc.start_address == address)
|
2016-06-24 10:43:46 +02:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
return &mc;
|
2016-06-24 10:43:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// none found
|
|
|
|
return nullptr;
|
2008-12-20 14:00:33 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 08:27:45 -05:00
|
|
|
bool TMemCheck::Action(DebugInterface* debug_interface, u32 value, u32 addr, bool write, int size,
|
2016-06-24 10:43:46 +02:00
|
|
|
u32 pc)
|
2008-12-20 14:00:33 +00:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
if ((write && is_break_on_write) || (!write && is_break_on_read))
|
2016-06-24 10:43:46 +02:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
if (log_on_hit)
|
2016-06-24 10:43:46 +02:00
|
|
|
{
|
2016-10-06 10:46:09 -04:00
|
|
|
NOTICE_LOG(MEMMAP, "MBP %08x (%s) %s%i %0*x at %08x (%s)", pc,
|
2016-09-24 19:06:47 -04:00
|
|
|
debug_interface->GetDescription(pc).c_str(), write ? "Write" : "Read", size * 8,
|
2017-01-11 08:27:45 -05:00
|
|
|
size * 2, value, addr, debug_interface->GetDescription(addr).c_str());
|
2016-06-24 10:43:46 +02:00
|
|
|
}
|
2017-01-11 08:27:45 -05:00
|
|
|
if (break_on_hit)
|
2016-09-23 21:15:35 -04:00
|
|
|
return true;
|
2016-06-24 10:43:46 +02:00
|
|
|
}
|
|
|
|
return false;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
2014-10-19 21:45:40 +11:00
|
|
|
|
2017-01-11 08:27:45 -05:00
|
|
|
bool Watches::IsAddressWatch(u32 address) const
|
2014-10-19 21:45:40 +11:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
for (const TWatch& watch : m_watches)
|
|
|
|
if (watch.address == address)
|
2016-06-24 10:43:46 +02:00
|
|
|
return true;
|
2014-10-19 21:45:40 +11:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
return false;
|
2014-10-19 21:45:40 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
Watches::TWatchesStr Watches::GetStrings() const
|
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
TWatchesStr watch_strings;
|
|
|
|
for (const TWatch& watch : m_watches)
|
2016-06-24 10:43:46 +02:00
|
|
|
{
|
|
|
|
std::stringstream ss;
|
2017-01-11 08:27:45 -05:00
|
|
|
ss << std::hex << watch.address << " " << watch.name;
|
|
|
|
watch_strings.push_back(ss.str());
|
2016-06-24 10:43:46 +02:00
|
|
|
}
|
|
|
|
|
2017-01-11 08:27:45 -05:00
|
|
|
return watch_strings;
|
2014-10-19 21:45:40 +11:00
|
|
|
}
|
|
|
|
|
2017-01-11 08:27:45 -05:00
|
|
|
void Watches::AddFromStrings(const TWatchesStr& watch_strings)
|
2014-10-19 21:45:40 +11:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
for (const std::string& watch_string : watch_strings)
|
2016-06-24 10:43:46 +02:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
TWatch watch;
|
2016-06-24 10:43:46 +02:00
|
|
|
std::stringstream ss;
|
2017-01-11 08:27:45 -05:00
|
|
|
ss << std::hex << watch_string;
|
|
|
|
ss >> watch.address;
|
2016-06-24 10:43:46 +02:00
|
|
|
ss >> std::ws;
|
2017-01-11 08:27:45 -05:00
|
|
|
std::getline(ss, watch.name);
|
|
|
|
Add(watch);
|
2016-06-24 10:43:46 +02:00
|
|
|
}
|
2014-10-19 21:45:40 +11:00
|
|
|
}
|
|
|
|
|
2017-01-11 08:27:45 -05:00
|
|
|
void Watches::Add(const TWatch& watch)
|
2014-10-19 21:45:40 +11:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
if (!IsAddressWatch(watch.address))
|
2016-06-24 10:43:46 +02:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
m_watches.push_back(watch);
|
2016-06-24 10:43:46 +02:00
|
|
|
}
|
2014-10-19 21:45:40 +11:00
|
|
|
}
|
|
|
|
|
2017-01-11 08:27:45 -05:00
|
|
|
void Watches::Add(u32 address)
|
2014-10-19 21:45:40 +11:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
if (!IsAddressWatch(address)) // only add new addresses
|
2016-06-24 10:43:46 +02:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
TWatch watch; // watch settings
|
|
|
|
watch.is_enabled = true;
|
|
|
|
watch.address = address;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2017-01-11 08:27:45 -05:00
|
|
|
m_watches.push_back(watch);
|
2016-06-24 10:43:46 +02:00
|
|
|
}
|
2014-10-19 21:45:40 +11:00
|
|
|
}
|
|
|
|
|
2017-01-11 08:27:45 -05:00
|
|
|
void Watches::Update(int count, u32 address)
|
2014-10-19 21:45:40 +11:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
m_watches.at(count).address = address;
|
2014-10-19 21:45:40 +11:00
|
|
|
}
|
|
|
|
|
2014-10-26 23:23:45 +11:00
|
|
|
void Watches::UpdateName(int count, const std::string name)
|
2014-10-19 21:45:40 +11:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
m_watches.at(count).name = name;
|
2014-10-19 21:45:40 +11:00
|
|
|
}
|
|
|
|
|
2017-01-11 08:27:45 -05:00
|
|
|
void Watches::Remove(u32 address)
|
2014-10-19 21:45:40 +11:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
for (auto i = m_watches.begin(); i != m_watches.end(); ++i)
|
2016-06-24 10:43:46 +02:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
if (i->address == address)
|
2016-06-24 10:43:46 +02:00
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
m_watches.erase(i);
|
2016-06-24 10:43:46 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-10-19 21:45:40 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
void Watches::Clear()
|
|
|
|
{
|
2017-01-11 08:27:45 -05:00
|
|
|
m_watches.clear();
|
2014-10-19 21:45:40 +11:00
|
|
|
}
|