Find the companion ELF when a game is launched by folder, and keep line info

Two things kept the companion ELF from doing its job.

The first is the one that mattered: fileToStart is the game's own *directory*
for folder-launched homebrew (IdentifiedFileType::PSP_PBP_DIRECTORY), which is
the normal case when you pick a homebrew in the UI. The search navigated up from
it regardless, landing in PSP/GAME and listing sibling games - all directories,
all skipped - so app.elf sitting right next to the EBOOT was never found. It only
ever worked when the path pointed at the EBOOT itself, which is how headless is
invoked, which is why it looked fine from there. Searches the directory itself
now when that's what it's given.

The second: line info didn't survive loading a savestate. Modules aren't just
re-registered there, they're destroyed and rebuilt (KernelObjectPool::Clear), so
removing a module's lines in ~PSPModule threw the table away on every state
load. The previous commit worked around it by re-reading the companion, which
was both wasteful and no help at all to an ELF launched directly - those bytes
are long gone by then.

SymbolMap already solves this and line info now does it the same way: keep what
you have, and let whatever next claims the address range replace it. AddModule
replaces by key and is called for every module load, including ones with no line
info of their own, so a range gets retired when it's genuinely reused. The whole
table goes when the game does, in PSP_Shutdown. That also means the savestate
path has nothing to re-read, so state loads no longer pay to re-parse a
multi-megabyte ELF.

The tradeoff is a window between a module unloading and its range being reclaimed
where a lookup can still answer for it. For a debugger that's a stale file:line
on an address nothing owns, against certain and total loss on every state load.

Verified with --auto-save-load-symbols off, launched both ways: by directory
(the case that was broken) and by EBOOT path, both give 3734 symbols and 98383
line rows.

pspautotests 314/314, UnitTest 55/55.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GZq8ZtJmFY7bkX5FVkr3P9
This commit is contained in:
Henrik Rydgård
2026-08-18 14:19:58 +02:00
co-authored by Claude Opus 5
parent 4ffbe80d76
commit 3463789597
4 changed files with 27 additions and 10 deletions
+12 -6
View File
@@ -211,8 +211,14 @@ PSPModule::~PSPModule() {
userMemory.Free(memoryBlockAddr);
}
g_symbolMap->UnloadModule(memoryBlockAddr, memoryBlockSize);
// Keyed identically, so a module going away takes its own line info and nothing else's.
g_lineInfo.RemoveModule(memoryBlockAddr, memoryBlockSize);
// Deliberately *not* dropping this module's line info here. Loading a savestate deletes
// every kernel object and rebuilds it (KernelObjectPool::Clear), so removing on destruction
// threw the line table away every time a state was loaded - and for an ELF launched
// directly there's no file left to read it back from. SymbolMap has the same problem and
// solves it the same way: keep what you have, and let the module that next claims the
// address range replace it (LineInfoMap::AddModule replaces by key, and it's called for
// every module load whether or not that module has any line info to add). The whole thing
// is dropped when the game does, in PSP_Shutdown.
}
if (modulePtr.ptr) {
@@ -308,11 +314,11 @@ void PSPModule::DoState(PointerWrap &p) {
char moduleName[29] = { 0 };
truncate_cpy(moduleName, nm.name);
if (memoryBlockAddr != 0) {
// Re-registering is enough to bring both back: SymbolMap keeps every symbol it has ever
// seen and just rebuilds its active view from the loaded modules, and line info is no
// longer dropped when a module is destroyed (see ~PSPModule). So there's nothing to
// re-read here, and a state load doesn't pay for re-parsing the companion ELF.
g_symbolMap->AddModule(moduleName, memoryBlockAddr, memoryBlockSize, crc);
// Loading a state tears the old module down and re-registers it here, which takes its
// symbols and line info with it. The companion ELF is still sitting next to the game,
// so read it again rather than coming back from a savestate with none.
LoadCompanionElfDebugInfo(PSP_CoreParameter().fileToStart, memoryBlockAddr, memoryBlockSize);
if (g_Config.bAutoSaveLoadSymbols) {
int idx = g_symbolMap->GetModuleIndexByName(moduleName);
if (idx > 0) {