2015-05-24 06:55:12 +02:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2021-07-05 03:22:19 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2009-07-06 04:10:26 +02:00
|
|
|
|
2009-06-21 10:39:21 +02:00
|
|
|
// This file contains a generic symbol map implementation. For CPU-specific
|
|
|
|
// magic, derive and extend.
|
2009-07-06 04:10:26 +02:00
|
|
|
|
2014-02-10 19:54:46 +01:00
|
|
|
#pragma once
|
2009-07-06 04:10:26 +02:00
|
|
|
|
2009-06-21 10:39:21 +02:00
|
|
|
#include <map>
|
2016-10-11 00:35:33 +02:00
|
|
|
#include <set>
|
2014-02-17 11:18:15 +01:00
|
|
|
#include <string>
|
2019-06-16 07:09:58 +02:00
|
|
|
#include <string_view>
|
2014-02-20 04:11:52 +01:00
|
|
|
#include <utility>
|
2009-07-12 23:58:32 +02:00
|
|
|
#include <vector>
|
2009-07-06 04:10:26 +02:00
|
|
|
|
2014-09-08 03:06:58 +02:00
|
|
|
#include "Common/CommonTypes.h"
|
2009-07-06 04:10:26 +02:00
|
|
|
|
2018-05-27 23:37:52 +02:00
|
|
|
namespace Common
|
|
|
|
{
|
2009-06-21 10:39:21 +02:00
|
|
|
struct SCall
|
|
|
|
{
|
2018-05-27 23:15:20 +02:00
|
|
|
SCall(u32 a, u32 b) : function(a), call_address(b) {}
|
2009-06-21 10:39:21 +02:00
|
|
|
u32 function;
|
2018-05-27 23:15:20 +02:00
|
|
|
u32 call_address;
|
2009-06-21 10:39:21 +02:00
|
|
|
};
|
2009-07-06 04:10:26 +02:00
|
|
|
|
2009-06-21 10:39:21 +02:00
|
|
|
struct Symbol
|
|
|
|
{
|
2016-09-14 03:01:35 +02:00
|
|
|
enum class Type
|
2009-06-21 10:39:21 +02:00
|
|
|
{
|
2016-09-14 03:01:35 +02:00
|
|
|
Function,
|
|
|
|
Data,
|
2009-06-21 10:39:21 +02:00
|
|
|
};
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2017-08-16 03:40:24 +02:00
|
|
|
void Rename(const std::string& symbol_name);
|
|
|
|
|
2009-06-21 10:39:21 +02:00
|
|
|
std::string name;
|
2016-09-26 15:41:57 +02:00
|
|
|
std::string function_name; // stripped function name
|
2009-06-21 10:39:21 +02: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-14 02:47:00 +02:00
|
|
|
u32 hash = 0; // use for HLE function finding
|
|
|
|
u32 address = 0;
|
|
|
|
u32 flags = 0;
|
2018-04-10 07:58:35 +02:00
|
|
|
u32 size = 0;
|
2018-05-27 23:15:20 +02:00
|
|
|
int num_calls = 0;
|
2016-09-14 03:01:35 +02:00
|
|
|
Type type = Type::Function;
|
2016-09-14 02:47:00 +02:00
|
|
|
int index = 0; // only used for coloring the disasm view
|
2016-09-14 03:16:04 +02:00
|
|
|
bool analyzed = false;
|
2009-06-21 10:39:21 +02:00
|
|
|
};
|
2009-07-06 04:10:26 +02:00
|
|
|
|
2009-06-21 10:39:21 +02:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
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-06 04:10:26 +02:00
|
|
|
|
2009-06-21 10:39:21 +02:00
|
|
|
class SymbolDB
|
|
|
|
{
|
|
|
|
public:
|
2018-05-27 23:23:55 +02:00
|
|
|
using XFuncMap = std::map<u32, Symbol>;
|
|
|
|
using XFuncPtrMap = std::map<u32, std::set<Symbol*>>;
|
2009-07-06 04:10:26 +02:00
|
|
|
|
2018-05-27 23:25:20 +02:00
|
|
|
SymbolDB();
|
|
|
|
virtual ~SymbolDB();
|
|
|
|
|
2016-01-21 21:16:51 +01:00
|
|
|
virtual Symbol* GetSymbolFromAddr(u32 addr) { return nullptr; }
|
2018-05-27 23:15:20 +02:00
|
|
|
virtual Symbol* AddFunction(u32 start_addr) { return nullptr; }
|
2016-01-21 21:27:56 +01:00
|
|
|
void AddCompleteSymbol(const Symbol& symbol);
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2019-06-16 07:09:58 +02:00
|
|
|
Symbol* GetSymbolFromName(std::string_view name);
|
|
|
|
std::vector<Symbol*> GetSymbolsFromName(std::string_view name);
|
2016-10-05 16:51:12 +02:00
|
|
|
Symbol* GetSymbolFromHash(u32 hash);
|
|
|
|
std::vector<Symbol*> GetSymbolsFromHash(u32 hash);
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2018-05-27 23:15:20 +02:00
|
|
|
const XFuncMap& Symbols() const { return m_functions; }
|
|
|
|
XFuncMap& AccessSymbols() { return m_functions; }
|
2019-05-01 17:32:45 +02:00
|
|
|
bool IsEmpty() const;
|
2016-01-21 20:46:25 +01:00
|
|
|
void Clear(const char* prefix = "");
|
2009-06-21 10:39:21 +02:00
|
|
|
void List();
|
|
|
|
void Index();
|
2018-05-27 23:15:20 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
XFuncMap m_functions;
|
|
|
|
XFuncPtrMap m_checksum_to_function;
|
2009-06-21 10:39:21 +02:00
|
|
|
};
|
2018-05-27 23:37:52 +02:00
|
|
|
} // namespace Common
|