| 
									
										
										
										
											2015-05-24 06:55:12 +02:00
										 |  |  | // Copyright 2009 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.
 | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-20 04:11:52 +01:00
										 |  |  | #include <cstring>
 | 
					
						
							|  |  |  | #include <map>
 | 
					
						
							|  |  |  | #include <string>
 | 
					
						
							|  |  |  | #include <utility>
 | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-07 20:06:58 -05:00
										 |  |  | #include "Common/CommonTypes.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-20 04:11:52 +01:00
										 |  |  | #include "Common/SymbolDB.h"
 | 
					
						
							| 
									
										
										
										
											2014-09-18 23:17:41 -05:00
										 |  |  | #include "Common/Logging/Log.h"
 | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | void SymbolDB::List() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-03-03 06:25:15 +01:00
										 |  |  | 	for (const auto& func : functions) | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2010-12-05 15:59:11 +00:00
										 |  |  | 		DEBUG_LOG(OSHLE, "%s @ %08x: %i bytes (hash %08x) : %i calls", | 
					
						
							| 
									
										
										
										
											2014-03-03 06:25:15 +01:00
										 |  |  | 		          func.second.name.c_str(), func.second.address, | 
					
						
							|  |  |  | 		          func.second.size, func.second.hash, | 
					
						
							|  |  |  | 		          func.second.numCalls); | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-12-05 15:59:11 +00:00
										 |  |  | 	INFO_LOG(OSHLE, "%lu functions known in this program above.", | 
					
						
							| 
									
										
										
										
											2014-03-03 06:25:15 +01:00
										 |  |  | 	         (unsigned long)functions.size()); | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SymbolDB::Clear(const char *prefix) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// TODO: honor prefix
 | 
					
						
							|  |  |  | 	functions.clear(); | 
					
						
							|  |  |  | 	checksumToFunction.clear(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SymbolDB::Index() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i = 0; | 
					
						
							| 
									
										
										
										
											2013-10-29 01:09:01 -04:00
										 |  |  | 	for (auto& func : functions) | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2013-10-29 01:09:01 -04:00
										 |  |  | 		func.second.index = i++; | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-12 15:33:41 -04:00
										 |  |  | Symbol* SymbolDB::GetSymbolFromName(const std::string& name) | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-10-29 01:09:01 -04:00
										 |  |  | 	for (auto& func : functions) | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-03-12 15:33:41 -04:00
										 |  |  | 		if (func.second.name == name) | 
					
						
							| 
									
										
										
										
											2013-10-29 01:09:01 -04:00
										 |  |  | 			return &func.second; | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-03-12 15:33:41 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-09 21:14:26 +01:00
										 |  |  | 	return nullptr; | 
					
						
							| 
									
										
										
										
											2009-07-06 02:10:26 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SymbolDB::AddCompleteSymbol(const Symbol &symbol) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	functions.insert(std::pair<u32, Symbol>(symbol.address, symbol)); | 
					
						
							|  |  |  | } |