| 
									
										
										
										
											2009-07-28 21:32:10 +00:00
										 |  |  | // Copyright (C) 2003 Dolphin Project.
 | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | // 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"
 | 
					
						
							| 
									
										
										
										
											2009-06-28 12:15:31 +00:00
										 |  |  | #include "DebugInterface.h"
 | 
					
						
							|  |  |  | #include "BreakPoints.h"
 | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | #include <sstream>
 | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | bool BreakPoints::IsAddressBreakPoint(u32 _iAddress) | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | 	for (TBreakPoints::iterator i = m_BreakPoints.begin(); i != m_BreakPoints.end(); ++i) | 
					
						
							|  |  |  | 		if (i->iAddress == _iAddress) | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 	return false; | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | bool BreakPoints::IsTempBreakPoint(u32 _iAddress) | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | 	for (TBreakPoints::iterator i = m_BreakPoints.begin(); i != m_BreakPoints.end(); ++i) | 
					
						
							|  |  |  | 		if (i->iAddress == _iAddress && i->bTemporary) | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | 			return true; | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | BreakPoints::TBreakPointsStr BreakPoints::GetStrings() const | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | 	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()); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | 	return bps; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | 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); | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | void BreakPoints::Add(u32 em_address, bool temp) | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2008-12-20 12:10:59 +00:00
										 |  |  | 	if (!IsAddressBreakPoint(em_address)) // only add new addresses
 | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		TBreakPoint pt; // breakpoint settings
 | 
					
						
							|  |  |  | 		pt.bOn = true; | 
					
						
							|  |  |  | 		pt.bTemporary = temp; | 
					
						
							| 
									
										
										
										
											2008-12-20 12:10:59 +00:00
										 |  |  | 		pt.iAddress = em_address; | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		m_BreakPoints.push_back(pt); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | void BreakPoints::Remove(u32 _iAddress) | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-25 12:27:38 +00:00
										 |  |  | 	for (TBreakPoints::iterator i = m_BreakPoints.begin(); i != m_BreakPoints.end(); ++i) | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | 		if (i->iAddress == _iAddress) | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | 			m_BreakPoints.erase(i); | 
					
						
							|  |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | MemChecks::TMemChecksStr MemChecks::GetStrings() const | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | 	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; | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | void MemChecks::AddFromStrings(const TMemChecksStr& mcs) | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | 	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); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-12-20 14:00:33 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MemChecks::Add(const TMemCheck& _rMemoryCheck) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | 	if (GetMemCheck(_rMemoryCheck.StartAddress) == 0) | 
					
						
							|  |  |  | 		m_MemChecks.push_back(_rMemoryCheck); | 
					
						
							| 
									
										
										
										
											2008-12-20 14:00:33 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | void MemChecks::Remove(u32 _Address) | 
					
						
							| 
									
										
										
										
											2008-12-20 14:00:33 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-25 12:27:38 +00:00
										 |  |  | 	for (TMemChecks::iterator i = m_MemChecks.begin(); i != m_MemChecks.end(); ++i) | 
					
						
							| 
									
										
										
										
											2008-12-20 14:00:33 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | 		if (i->StartAddress == _Address) | 
					
						
							| 
									
										
										
										
											2008-12-20 14:00:33 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | 			m_MemChecks.erase(i); | 
					
						
							|  |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2008-12-20 14:00:33 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TMemCheck *MemChecks::GetMemCheck(u32 address) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	for (TMemChecks::iterator i = m_MemChecks.begin(); i != m_MemChecks.end(); ++i) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (i->bRange) | 
					
						
							| 
									
										
										
										
											2008-12-20 14:00:33 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | 			if (address >= i->StartAddress && address <= i->EndAddress) | 
					
						
							|  |  |  | 				return &(*i); | 
					
						
							| 
									
										
										
										
											2008-12-20 14:00:33 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | 		else if (i->StartAddress == address) | 
					
						
							|  |  |  | 			return &(*i); | 
					
						
							| 
									
										
										
										
											2008-12-20 14:00:33 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | 	// none found
 | 
					
						
							| 
									
										
										
										
											2008-12-20 14:00:33 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | void TMemCheck::Action(DebugInterface *debug_interface, u32 iValue, u32 addr, | 
					
						
							|  |  |  | 						bool write, int size, u32 pc) | 
					
						
							| 
									
										
										
										
											2008-12-20 14:00:33 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | 	if ((write && OnWrite) || (!write && OnRead)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (Log) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2011-02-25 11:03:49 +00:00
										 |  |  | 			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() | 
					
						
							| 
									
										
										
										
											2011-02-25 09:35:56 +00:00
										 |  |  | 				); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (Break) | 
					
						
							|  |  |  | 			debug_interface->breakNow(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-12-08 05:30:24 +00:00
										 |  |  | } |