diff options
Diffstat (limited to 'src/common/break_points.cpp')
| -rw-r--r-- | src/common/break_points.cpp | 203 |
1 files changed, 203 insertions, 0 deletions
diff --git a/src/common/break_points.cpp b/src/common/break_points.cpp new file mode 100644 index 000000000..787263f79 --- /dev/null +++ b/src/common/break_points.cpp | |||
| @@ -0,0 +1,203 @@ | |||
| 1 | // Copyright 2013 Dolphin Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common.h" | ||
| 6 | #include "debug_interface.h" | ||
| 7 | #include "break_points.h" | ||
| 8 | |||
| 9 | #include <sstream> | ||
| 10 | #include <algorithm> | ||
| 11 | |||
| 12 | bool BreakPoints::IsAddressBreakPoint(u32 _iAddress) | ||
| 13 | { | ||
| 14 | for (TBreakPoints::iterator i = m_BreakPoints.begin(); i != m_BreakPoints.end(); ++i) | ||
| 15 | if (i->iAddress == _iAddress) | ||
| 16 | return true; | ||
| 17 | return false; | ||
| 18 | } | ||
| 19 | |||
| 20 | bool BreakPoints::IsTempBreakPoint(u32 _iAddress) | ||
| 21 | { | ||
| 22 | for (TBreakPoints::iterator i = m_BreakPoints.begin(); i != m_BreakPoints.end(); ++i) | ||
| 23 | if (i->iAddress == _iAddress && i->bTemporary) | ||
| 24 | return true; | ||
| 25 | return false; | ||
| 26 | } | ||
| 27 | |||
| 28 | BreakPoints::TBreakPointsStr BreakPoints::GetStrings() const | ||
| 29 | { | ||
| 30 | TBreakPointsStr bps; | ||
| 31 | for (TBreakPoints::const_iterator i = m_BreakPoints.begin(); | ||
| 32 | i != m_BreakPoints.end(); ++i) | ||
| 33 | { | ||
| 34 | if (!i->bTemporary) | ||
| 35 | { | ||
| 36 | std::stringstream bp; | ||
| 37 | bp << std::hex << i->iAddress << " " << (i->bOn ? "n" : ""); | ||
| 38 | bps.push_back(bp.str()); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | return bps; | ||
| 43 | } | ||
| 44 | |||
| 45 | void BreakPoints::AddFromStrings(const TBreakPointsStr& bps) | ||
| 46 | { | ||
| 47 | for (TBreakPointsStr::const_iterator i = bps.begin(); i != bps.end(); ++i) | ||
| 48 | { | ||
| 49 | TBreakPoint bp; | ||
| 50 | std::stringstream bpstr; | ||
| 51 | bpstr << std::hex << *i; | ||
| 52 | bpstr >> bp.iAddress; | ||
| 53 | bp.bOn = i->find("n") != i->npos; | ||
| 54 | bp.bTemporary = false; | ||
| 55 | Add(bp); | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | void BreakPoints::Add(const TBreakPoint& bp) | ||
| 60 | { | ||
| 61 | if (!IsAddressBreakPoint(bp.iAddress)) | ||
| 62 | { | ||
| 63 | m_BreakPoints.push_back(bp); | ||
| 64 | //if (jit) | ||
| 65 | // jit->GetBlockCache()->InvalidateICache(bp.iAddress, 4); | ||
| 66 | } | ||
| 67 | } | ||
| 68 | |||
| 69 | void BreakPoints::Add(u32 em_address, bool temp) | ||
| 70 | { | ||
| 71 | if (!IsAddressBreakPoint(em_address)) // only add new addresses | ||
| 72 | { | ||
| 73 | TBreakPoint pt; // breakpoint settings | ||
| 74 | pt.bOn = true; | ||
| 75 | pt.bTemporary = temp; | ||
| 76 | pt.iAddress = em_address; | ||
| 77 | |||
| 78 | m_BreakPoints.push_back(pt); | ||
| 79 | |||
| 80 | //if (jit) | ||
| 81 | // jit->GetBlockCache()->InvalidateICache(em_address, 4); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | void BreakPoints::Remove(u32 em_address) | ||
| 86 | { | ||
| 87 | for (TBreakPoints::iterator i = m_BreakPoints.begin(); i != m_BreakPoints.end(); ++i) | ||
| 88 | { | ||
| 89 | if (i->iAddress == em_address) | ||
| 90 | { | ||
| 91 | m_BreakPoints.erase(i); | ||
| 92 | //if (jit) | ||
| 93 | // jit->GetBlockCache()->InvalidateICache(em_address, 4); | ||
| 94 | return; | ||
| 95 | } | ||
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 99 | void BreakPoints::Clear() | ||
| 100 | { | ||
| 101 | //if (jit) | ||
| 102 | //{ | ||
| 103 | // std::for_each(m_BreakPoints.begin(), m_BreakPoints.end(), | ||
| 104 | // [](const TBreakPoint& bp) | ||
| 105 | // { | ||
| 106 | // jit->GetBlockCache()->InvalidateICache(bp.iAddress, 4); | ||
| 107 | // } | ||
| 108 | // ); | ||
| 109 | //} | ||
| 110 | |||
| 111 | m_BreakPoints.clear(); | ||
| 112 | } | ||
| 113 | |||
| 114 | MemChecks::TMemChecksStr MemChecks::GetStrings() const | ||
| 115 | { | ||
| 116 | TMemChecksStr mcs; | ||
| 117 | for (TMemChecks::const_iterator i = m_MemChecks.begin(); | ||
| 118 | i != m_MemChecks.end(); ++i) | ||
| 119 | { | ||
| 120 | std::stringstream mc; | ||
| 121 | mc << std::hex << i->StartAddress; | ||
| 122 | mc << " " << (i->bRange ? i->EndAddress : i->StartAddress) << " " << | ||
| 123 | (i->bRange ? "n" : "") << (i->OnRead ? "r" : "") << | ||
| 124 | (i->OnWrite ? "w" : "") << (i->Log ? "l" : "") << (i->Break ? "p" : ""); | ||
| 125 | mcs.push_back(mc.str()); | ||
| 126 | } | ||
| 127 | |||
| 128 | return mcs; | ||
| 129 | } | ||
| 130 | |||
| 131 | void MemChecks::AddFromStrings(const TMemChecksStr& mcs) | ||
| 132 | { | ||
| 133 | for (TMemChecksStr::const_iterator i = mcs.begin(); i != mcs.end(); ++i) | ||
| 134 | { | ||
| 135 | TMemCheck mc; | ||
| 136 | std::stringstream mcstr; | ||
| 137 | mcstr << std::hex << *i; | ||
| 138 | mcstr >> mc.StartAddress; | ||
| 139 | mc.bRange = i->find("n") != i->npos; | ||
| 140 | mc.OnRead = i->find("r") != i->npos; | ||
| 141 | mc.OnWrite = i->find("w") != i->npos; | ||
| 142 | mc.Log = i->find("l") != i->npos; | ||
| 143 | mc.Break = i->find("p") != i->npos; | ||
| 144 | if (mc.bRange) | ||
| 145 | mcstr >> mc.EndAddress; | ||
| 146 | else | ||
| 147 | mc.EndAddress = mc.StartAddress; | ||
| 148 | Add(mc); | ||
| 149 | } | ||
| 150 | } | ||
| 151 | |||
| 152 | void MemChecks::Add(const TMemCheck& _rMemoryCheck) | ||
| 153 | { | ||
| 154 | if (GetMemCheck(_rMemoryCheck.StartAddress) == 0) | ||
| 155 | m_MemChecks.push_back(_rMemoryCheck); | ||
| 156 | } | ||
| 157 | |||
| 158 | void MemChecks::Remove(u32 _Address) | ||
| 159 | { | ||
| 160 | for (TMemChecks::iterator i = m_MemChecks.begin(); i != m_MemChecks.end(); ++i) | ||
| 161 | { | ||
| 162 | if (i->StartAddress == _Address) | ||
| 163 | { | ||
| 164 | m_MemChecks.erase(i); | ||
| 165 | return; | ||
| 166 | } | ||
| 167 | } | ||
| 168 | } | ||
| 169 | |||
| 170 | TMemCheck *MemChecks::GetMemCheck(u32 address) | ||
| 171 | { | ||
| 172 | for (TMemChecks::iterator i = m_MemChecks.begin(); i != m_MemChecks.end(); ++i) | ||
| 173 | { | ||
| 174 | if (i->bRange) | ||
| 175 | { | ||
| 176 | if (address >= i->StartAddress && address <= i->EndAddress) | ||
| 177 | return &(*i); | ||
| 178 | } | ||
| 179 | else if (i->StartAddress == address) | ||
| 180 | return &(*i); | ||
| 181 | } | ||
| 182 | |||
| 183 | // none found | ||
| 184 | return 0; | ||
| 185 | } | ||
| 186 | |||
| 187 | void TMemCheck::Action(DebugInterface *debug_interface, u32 iValue, u32 addr, | ||
| 188 | bool write, int size, u32 pc) | ||
| 189 | { | ||
| 190 | if ((write && OnWrite) || (!write && OnRead)) | ||
| 191 | { | ||
| 192 | if (Log) | ||
| 193 | { | ||
| 194 | INFO_LOG(MEMMAP, "CHK %08x (%s) %s%i %0*x at %08x (%s)", | ||
| 195 | pc, debug_interface->getDescription(pc).c_str(), | ||
| 196 | write ? "Write" : "Read", size*8, size*2, iValue, addr, | ||
| 197 | debug_interface->getDescription(addr).c_str() | ||
| 198 | ); | ||
| 199 | } | ||
| 200 | if (Break) | ||
| 201 | debug_interface->breakNow(); | ||
| 202 | } | ||
| 203 | } | ||