2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 21:09:55 -06:00
|
|
|
// Refer to the license.txt file included.
|
2009-07-05 20:10:26 -06:00
|
|
|
|
|
|
|
// This file contains a generic symbol map implementation. For CPU-specific
|
|
|
|
// magic, derive and extend.
|
|
|
|
|
2014-02-10 11:54:46 -07:00
|
|
|
#pragma once
|
2009-07-05 20:10:26 -06:00
|
|
|
|
|
|
|
#include <map>
|
2016-10-10 16:35:33 -06:00
|
|
|
#include <set>
|
2014-02-17 03:18:15 -07:00
|
|
|
#include <string>
|
2014-02-19 20:11:52 -07:00
|
|
|
#include <utility>
|
2009-07-12 15:58:32 -06:00
|
|
|
#include <vector>
|
2009-07-05 20:10:26 -06:00
|
|
|
|
2014-09-07 19:06:58 -06:00
|
|
|
#include "Common/CommonTypes.h"
|
2009-07-05 20:10:26 -06:00
|
|
|
|
|
|
|
struct SCall
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
SCall(u32 a, u32 b) : function(a), callAddress(b) {}
|
|
|
|
u32 function;
|
|
|
|
u32 callAddress;
|
2009-07-05 20:10:26 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Symbol
|
|
|
|
{
|
2016-09-13 19:01:35 -06:00
|
|
|
enum class Type
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2016-09-13 19:01:35 -06:00
|
|
|
Function,
|
|
|
|
Data,
|
2016-06-24 02:43:46 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
std::string name;
|
2016-09-26 07:41:57 -06:00
|
|
|
std::string function_name; // stripped function name
|
2016-06-24 02:43:46 -06:00
|
|
|
std::vector<SCall> callers; // addresses of functions that call this function
|
|
|
|
std::vector<SCall> calls; // addresses of functions that are called by this function
|
2016-09-13 18:47:00 -06:00
|
|
|
u32 hash = 0; // use for HLE function finding
|
|
|
|
u32 address = 0;
|
|
|
|
u32 flags = 0;
|
|
|
|
int size = 0;
|
|
|
|
int numCalls = 0;
|
2016-09-13 19:01:35 -06:00
|
|
|
Type type = Type::Function;
|
2016-09-13 18:47:00 -06:00
|
|
|
int index = 0; // only used for coloring the disasm view
|
2016-09-13 19:16:04 -06:00
|
|
|
bool analyzed = false;
|
2009-07-05 20:10:26 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
FFLAG_TIMERINSTRUCTIONS = (1 << 0),
|
|
|
|
FFLAG_LEAF = (1 << 1),
|
|
|
|
FFLAG_ONLYCALLSNICELEAFS = (1 << 2),
|
|
|
|
FFLAG_EVIL = (1 << 3),
|
|
|
|
FFLAG_RFI = (1 << 4),
|
|
|
|
FFLAG_STRAIGHT = (1 << 5)
|
2009-07-05 20:10:26 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
class SymbolDB
|
|
|
|
{
|
|
|
|
public:
|
2016-06-24 02:43:46 -06:00
|
|
|
typedef std::map<u32, Symbol> XFuncMap;
|
2016-10-10 16:35:33 -06:00
|
|
|
typedef std::map<u32, std::set<Symbol*>> XFuncPtrMap;
|
2009-07-05 20:10:26 -06:00
|
|
|
|
|
|
|
protected:
|
2016-06-24 02:43:46 -06:00
|
|
|
XFuncMap functions;
|
|
|
|
XFuncPtrMap checksumToFunction;
|
2009-07-05 20:10:26 -06:00
|
|
|
|
|
|
|
public:
|
2016-06-24 02:43:46 -06:00
|
|
|
SymbolDB() {}
|
|
|
|
virtual ~SymbolDB() {}
|
|
|
|
virtual Symbol* GetSymbolFromAddr(u32 addr) { return nullptr; }
|
|
|
|
virtual Symbol* AddFunction(u32 startAddr) { return nullptr; }
|
|
|
|
void AddCompleteSymbol(const Symbol& symbol);
|
|
|
|
|
|
|
|
Symbol* GetSymbolFromName(const std::string& name);
|
2016-10-04 10:33:25 -06:00
|
|
|
std::vector<Symbol*> GetSymbolsFromName(const std::string& name);
|
2016-10-05 08:51:12 -06:00
|
|
|
Symbol* GetSymbolFromHash(u32 hash);
|
|
|
|
std::vector<Symbol*> GetSymbolsFromHash(u32 hash);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
const XFuncMap& Symbols() const { return functions; }
|
|
|
|
XFuncMap& AccessSymbols() { return functions; }
|
|
|
|
void Clear(const char* prefix = "");
|
|
|
|
void List();
|
|
|
|
void Index();
|
2009-07-05 20:10:26 -06:00
|
|
|
};
|