From af8c871411893a9ef88cd660227e642c6c55f78c Mon Sep 17 00:00:00 2001 From: Eladash Date: Sun, 2 Oct 2022 12:59:41 +0300 Subject: [PATCH] Add origin PRX names for log messages --- rpcs3/Emu/Cell/PPUModule.cpp | 74 ++++++++++++++++++++++++++++++++++++ rpcs3/Emu/Cell/PPUThread.cpp | 7 ++++ 2 files changed, 81 insertions(+) diff --git a/rpcs3/Emu/Cell/PPUModule.cpp b/rpcs3/Emu/Cell/PPUModule.cpp index 0ca4100768..430338662b 100644 --- a/rpcs3/Emu/Cell/PPUModule.cpp +++ b/rpcs3/Emu/Cell/PPUModule.cpp @@ -1071,6 +1071,77 @@ void try_spawn_ppu_if_exclusive_program(const ppu_module& m) } } +struct prx_names_table +{ + shared_mutex mutex; + std::set> registered; + atomic_t lut[0x1000'0000 / 0x1'0000]{}; + + SAVESTATE_INIT_POS(4.1); // Dependency on lv2_obj + + prx_names_table() noexcept + { + idm::select([this](u32, lv2_prx& prx) + { + install(prx.name, prx); + }); + } + + void install(std::string_view name, lv2_prx& prx) + { + if (name.empty()) + { + return; + } + + if (name.ends_with(".sprx"sv) && name.size() > (".sprx"sv).size()) + { + name = name.substr(0, name.size() - (".sprx"sv).size()); + } + + std::lock_guard lock(mutex); + + const auto ptr = registered.emplace(name).first->c_str(); + + for (auto& seg : prx.segs) + { + if (!seg.size) + { + continue; + } + + // Doesn't support addresses above 256MB because it wastes memory and is very unlikely (if somehow does occur increase it) + const u32 max0 = (seg.addr + seg.size - 1) >> 16; + const u32 max = std::min(std::size(lut), max0); + + if (max0 > max) + { + ppu_loader.error("Skipping PRX name registeration: %s, max=0x%x", name, max0 << 16); + } + + for (u32 i = seg.addr >> 16; i <= max; i++) + { + lut[i].release(ptr); + } + } + } +}; + +const char* get_prx_name_by_cia(u32 addr) +{ + if (auto t = g_fxo->try_get()) + { + addr >>= 16; + + if (addr < std::size(t->lut)) + { + return t->lut[addr]; + } + } + + return nullptr; +} + std::shared_ptr ppu_load_prx(const ppu_prx_object& elf, const std::string& path, s64 file_offset, utils::serial* ar) { if (elf != elf_error::ok) @@ -1364,6 +1435,9 @@ std::shared_ptr ppu_load_prx(const ppu_prx_object& elf, const std::stri prx->path = path; prx->offset = file_offset; + g_fxo->need(); + g_fxo->get().install(prx->name, *prx); + sha1_finish(&sha, prx->sha1); // Format patch name diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index 74645aa19a..74a462feea 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -1953,6 +1953,13 @@ void ppu_thread::fast_call(u32 addr, u64 rtoc) return fmt::format("PPU[0x%x] Thread (%s) [HLE:0x%08x, LR:0x%08x]", _this->id, *name_cache.get(), cia, _this->lr); } + extern const char* get_prx_name_by_cia(u32 addr); + + if (auto name = get_prx_name_by_cia(cia)) + { + return fmt::format("PPU[0x%x] Thread (%s) [%s: 0x%08x]", _this->id, *name_cache.get(), name, cia); + } + return fmt::format("PPU[0x%x] Thread (%s) [0x%08x]", _this->id, *name_cache.get(), cia); };