summaryrefslogtreecommitdiff
path: root/Source/Core/Common/Src/BreakPoints.cpp
blob: 45a0b52dafe14f2a66ba4d273109c96080b73781 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// Copyright (C) 2003 Dolphin 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
// the Free Software Foundation, version 2.0.

// 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 SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/

#include "Common.h"
#include "DebugInterface.h"
#include "BreakPoints.h"
#include <sstream>

bool BreakPoints::IsAddressBreakPoint(u32 _iAddress)
{
	for (TBreakPoints::iterator i = m_BreakPoints.begin(); i != m_BreakPoints.end(); ++i)
		if (i->iAddress == _iAddress)
			return true;
	return false;
}

bool BreakPoints::IsTempBreakPoint(u32 _iAddress)
{
	for (TBreakPoints::iterator i = m_BreakPoints.begin(); i != m_BreakPoints.end(); ++i)
		if (i->iAddress == _iAddress && i->bTemporary)
			return true;
	return false;
}

BreakPoints::TBreakPointsStr BreakPoints::GetStrings() const
{
	TBreakPointsStr bps;
	for (TBreakPoints::const_iterator i = m_BreakPoints.begin();
		i != m_BreakPoints.end(); ++i)
	{
		if (!i->bTemporary)
		{
			std::stringstream bp;
			bp << std::hex << i->iAddress << " " << (i->bOn ? "n" : "");
			bps.push_back(bp.str());
		}
	}

	return bps;
}

void BreakPoints::AddFromStrings(const TBreakPointsStr& bps)
{
	for (TBreakPointsStr::const_iterator i = bps.begin(); i != bps.end(); ++i)
	{
		TBreakPoint bp;
		std::stringstream bpstr;
		bpstr << std::hex << *i;
		bpstr >> bp.iAddress;
		bp.bOn = i->find("n") != i->npos;
		bp.bTemporary = false;
		Add(bp);
	}
}

void BreakPoints::Add(const TBreakPoint& bp)
{
	if (!IsAddressBreakPoint(bp.iAddress))
		m_BreakPoints.push_back(bp);
}

void BreakPoints::Add(u32 em_address, bool temp)
{
	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);
	}
}

void BreakPoints::Remove(u32 _iAddress)
{
	for (TBreakPoints::iterator i = m_BreakPoints.begin(); i != m_BreakPoints.end(); ++i)
	{
		if (i->iAddress == _iAddress)
		{
			m_BreakPoints.erase(i);
			return;
		}
	}
}


MemChecks::TMemChecksStr MemChecks::GetStrings() const
{
	TMemChecksStr mcs;
	for (TMemChecks::const_iterator i = m_MemChecks.begin();
		i != m_MemChecks.end(); ++i)
	{
		std::stringstream mc;
		mc << std::hex << i->StartAddress;
		mc << " " << (i->bRange ? i->EndAddress : i->StartAddress) << " " <<
			(i->bRange ? "n" : "") << (i->OnRead ? "r" : "") <<
			(i->OnWrite ? "w" : "") << (i->Log ? "l" : "") << (i->Break ? "p" : "");
		mcs.push_back(mc.str());
	}

	return mcs;
}

void MemChecks::AddFromStrings(const TMemChecksStr& mcs)
{
	for (TMemChecksStr::const_iterator i = mcs.begin(); i != mcs.end(); ++i)
	{
		TMemCheck mc;
		std::stringstream mcstr;
		mcstr << std::hex << *i;
		mcstr >> mc.StartAddress;
		mc.bRange	= i->find("n") != i->npos;
		mc.OnRead	= i->find("r") != i->npos;
		mc.OnWrite	= i->find("w") != i->npos;
		mc.Log		= i->find("l") != i->npos;
		mc.Break	= i->find("p") != i->npos;
		if (mc.bRange)
			mcstr >> mc.EndAddress;
		else
			mc.EndAddress = mc.StartAddress;
		Add(mc);
	}
}

void MemChecks::Add(const TMemCheck& _rMemoryCheck)
{
	if (GetMemCheck(_rMemoryCheck.StartAddress) == 0)
		m_MemChecks.push_back(_rMemoryCheck);
}

void MemChecks::Remove(u32 _Address)
{
	for (TMemChecks::iterator i = m_MemChecks.begin(); i != m_MemChecks.end(); ++i)
	{
		if (i->StartAddress == _Address)
		{
			m_MemChecks.erase(i);
			return;
		}
	}
}

TMemCheck *MemChecks::GetMemCheck(u32 address)
{
	for (TMemChecks::iterator i = m_MemChecks.begin(); i != m_MemChecks.end(); ++i)
	{
		if (i->bRange)
		{
			if (address >= i->StartAddress && address <= i->EndAddress)
				return &(*i);
		}
		else if (i->StartAddress == address)
			return &(*i);
	}

	// none found
	return 0;
}

void TMemCheck::Action(DebugInterface *debug_interface, u32 iValue, u32 addr,
						bool write, int size, u32 pc)
{
	if ((write && OnWrite) || (!write && OnRead))
	{
		if (Log)
		{
			INFO_LOG(MEMMAP, "CHK %08x (%s) %s%i %0*x at %08x (%s)",
				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();
	}
}