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