SymbolDB.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Copyright 2008 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. // This file contains a generic symbol map implementation. For CPU-specific
  4. // magic, derive and extend.
  5. #pragma once
  6. #include <map>
  7. #include <set>
  8. #include <string>
  9. #include <string_view>
  10. #include <utility>
  11. #include <vector>
  12. #include "Common/CommonTypes.h"
  13. namespace Core
  14. {
  15. class CPUThreadGuard;
  16. }
  17. namespace Common
  18. {
  19. struct SCall
  20. {
  21. SCall(u32 a, u32 b) : function(a), call_address(b) {}
  22. u32 function;
  23. u32 call_address;
  24. };
  25. struct Symbol
  26. {
  27. enum class Type
  28. {
  29. Function,
  30. Data,
  31. };
  32. Symbol() = default;
  33. explicit Symbol(const std::string& symbol_name) { Rename(symbol_name); }
  34. void Rename(const std::string& symbol_name);
  35. std::string name;
  36. std::string function_name; // stripped function name
  37. std::string object_name; // name of object/source file symbol belongs to
  38. std::vector<SCall> callers; // addresses of functions that call this function
  39. std::vector<SCall> calls; // addresses of functions that are called by this function
  40. u32 hash = 0; // use for HLE function finding
  41. u32 address = 0;
  42. u32 flags = 0;
  43. u32 size = 0;
  44. int num_calls = 0;
  45. Type type = Type::Function;
  46. int index = 0; // only used for coloring the disasm view
  47. bool analyzed = false;
  48. };
  49. enum
  50. {
  51. FFLAG_TIMERINSTRUCTIONS = (1 << 0),
  52. FFLAG_LEAF = (1 << 1),
  53. FFLAG_ONLYCALLSNICELEAFS = (1 << 2),
  54. FFLAG_EVIL = (1 << 3),
  55. FFLAG_RFI = (1 << 4),
  56. FFLAG_STRAIGHT = (1 << 5)
  57. };
  58. class SymbolDB
  59. {
  60. public:
  61. using XFuncMap = std::map<u32, Symbol>;
  62. using XFuncPtrMap = std::map<u32, std::set<Symbol*>>;
  63. SymbolDB();
  64. virtual ~SymbolDB();
  65. virtual Symbol* GetSymbolFromAddr(u32 addr) { return nullptr; }
  66. virtual Symbol* AddFunction(const Core::CPUThreadGuard& guard, u32 start_addr) { return nullptr; }
  67. void AddCompleteSymbol(const Symbol& symbol);
  68. Symbol* GetSymbolFromName(std::string_view name);
  69. std::vector<Symbol*> GetSymbolsFromName(std::string_view name);
  70. Symbol* GetSymbolFromHash(u32 hash);
  71. std::vector<Symbol*> GetSymbolsFromHash(u32 hash);
  72. const XFuncMap& Symbols() const { return m_functions; }
  73. XFuncMap& AccessSymbols() { return m_functions; }
  74. bool IsEmpty() const;
  75. void Clear(const char* prefix = "");
  76. void List();
  77. void Index();
  78. protected:
  79. XFuncMap m_functions;
  80. XFuncPtrMap m_checksum_to_function;
  81. };
  82. } // namespace Common