From b087d79a082dfe4d74da469eb87238a7917630c5 Mon Sep 17 00:00:00 2001 From: Eladash Date: Sun, 18 Jul 2021 12:18:02 +0300 Subject: [PATCH] PPU debugger: Implement function names at the starting instruction --- rpcs3/Emu/Cell/PPUDisAsm.cpp | 10 +++++++ rpcs3/Emu/Cell/PPUModule.cpp | 55 +++++++++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/rpcs3/Emu/Cell/PPUDisAsm.cpp b/rpcs3/Emu/Cell/PPUDisAsm.cpp index 15a5db0049..7ff38b88c2 100644 --- a/rpcs3/Emu/Cell/PPUDisAsm.cpp +++ b/rpcs3/Emu/Cell/PPUDisAsm.cpp @@ -4,6 +4,7 @@ #include "Emu/IdManager.h" const ppu_decoder s_ppu_disasm; +extern const std::unordered_map& get_exported_function_names_as_addr_indexed_map(); u32 PPUDisAsm::disasm(u32 pc) { @@ -12,6 +13,15 @@ u32 PPUDisAsm::disasm(u32 pc) std::memcpy(&op, m_offset + pc, 4); m_op = op; (this->*(s_ppu_disasm.decode(m_op)))({ m_op }); + + const auto& map = get_exported_function_names_as_addr_indexed_map(); + + if (auto it = map.find(pc); it != map.end()) + { + last_opcode += " #"; + last_opcode += it->second; + } + return 4; } diff --git a/rpcs3/Emu/Cell/PPUModule.cpp b/rpcs3/Emu/Cell/PPUModule.cpp index e0ca883781..9c005d097c 100644 --- a/rpcs3/Emu/Cell/PPUModule.cpp +++ b/rpcs3/Emu/Cell/PPUModule.cpp @@ -307,7 +307,7 @@ static void ppu_initialize_modules(ppu_linkage_info* link) if (is_first) { - g_ppu_function_names[function.second.index] = fmt::format("%s.%s", _module->name, function.second.name); + g_ppu_function_names[function.second.index] = fmt::format("%s:%s", function.second.name, _module->name); } if ((function.second.flags & MFF_HIDDEN) == 0) @@ -368,6 +368,59 @@ static void ppu_initialize_modules(ppu_linkage_info* link) } } +// For the debugger (g_ppu_function_names shouldn't change, string_view should suffice) +extern const std::unordered_map& get_exported_function_names_as_addr_indexed_map() +{ + static std::unordered_map res; + static u64 update_time = 0; + + const auto link = g_fxo->try_get(); + const auto hle_funcs = g_fxo->try_get(); + + if (!link || !hle_funcs) + { + res.clear(); + return res; + } + + const u64 current_time = get_system_time(); + + // Update list every >=0.1 seconds + if (current_time - update_time < 100'000) + { + return res; + } + + update_time = current_time; + + res.clear(); + res.reserve(ppu_module_manager::get().size()); + + for (auto& pair : ppu_module_manager::get()) + { + const auto _module = pair.second; + auto& linkage = link->modules[_module->name]; + + for (auto& function : _module->functions) + { + auto& flink = linkage.functions[function.first]; + u32 addr = flink.export_addr; + + if (vm::check_addr<4>(addr, vm::page_readable) && addr != hle_funcs->func_addr(function.second.index)) + { + addr = vm::read32(addr); + + if (!(addr % 4) && vm::check_addr<4>(addr, vm::page_executable)) + { + res.try_emplace(addr, g_ppu_function_names[function.second.index]); + } + } + } + } + + return res; +} + // Resolve relocations for variable/function linkage. static void ppu_patch_refs(std::vector* out_relocs, u32 fref, u32 faddr) {