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