Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add origin PRX names for log messages #12743

Merged
merged 1 commit into from Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
74 changes: 74 additions & 0 deletions rpcs3/Emu/Cell/PPUModule.cpp
Expand Up @@ -1071,6 +1071,77 @@ void try_spawn_ppu_if_exclusive_program(const ppu_module& m)
}
}

struct prx_names_table
{
shared_mutex mutex;
std::set<std::string, std::less<>> registered;
atomic_t<const char*> lut[0x1000'0000 / 0x1'0000]{};

SAVESTATE_INIT_POS(4.1); // Dependency on lv2_obj

prx_names_table() noexcept
{
idm::select<lv2_obj, lv2_prx>([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<u32>(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<prx_names_table>())
{
addr >>= 16;

if (addr < std::size(t->lut))
{
return t->lut[addr];
}
}

return nullptr;
}

std::shared_ptr<lv2_prx> ppu_load_prx(const ppu_prx_object& elf, const std::string& path, s64 file_offset, utils::serial* ar)
{
if (elf != elf_error::ok)
Expand Down Expand Up @@ -1364,6 +1435,9 @@ std::shared_ptr<lv2_prx> ppu_load_prx(const ppu_prx_object& elf, const std::stri
prx->path = path;
prx->offset = file_offset;

g_fxo->need<prx_names_table>();
g_fxo->get<prx_names_table>().install(prx->name, *prx);

sha1_finish(&sha, prx->sha1);

// Format patch name
Expand Down
7 changes: 7 additions & 0 deletions rpcs3/Emu/Cell/PPUThread.cpp
Expand Up @@ -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);
};

Expand Down