1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:47:35 +00:00

SymbolServer: Cache failed ELF loads as well

Remember which paths we've already tried to load. This stops it from
whining about /boot/Kernel not being mappable.
This commit is contained in:
Andreas Kling 2021-02-04 23:44:01 +01:00
parent acabc37c24
commit 72f96941f2

View file

@ -36,7 +36,7 @@ struct CachedELF {
ELF::Image elf;
};
static HashMap<String, CachedELF> s_cache;
static HashMap<String, OwnPtr<CachedELF>> s_cache;
static HashMap<int, RefPtr<ClientConnection>> s_connections;
ClientConnection::ClientConnection(NonnullRefPtr<Core::LocalSocket> socket, int client_id)
@ -66,14 +66,16 @@ OwnPtr<Messages::SymbolServer::SymbolicateResponse> ClientConnection::handle(con
auto mapped_file = MappedFile::map(path);
if (mapped_file.is_error()) {
dbgln("Failed to map {}: {}", path, mapped_file.error().string());
s_cache.set(path, {});
return make<Messages::SymbolServer::SymbolicateResponse>(false, String {}, 0, String {}, 0);
}
auto elf = ELF::Image(mapped_file.value()->bytes());
if (!elf.is_valid()) {
dbgln("ELF not valid: {}", path);
s_cache.set(path, {});
return make<Messages::SymbolServer::SymbolicateResponse>(false, String {}, 0, String {}, 0);
}
auto cached_elf = CachedELF { mapped_file.release_value(), move(elf) };
auto cached_elf = make<CachedELF>(mapped_file.release_value(), move(elf));
s_cache.set(path, move(cached_elf));
}
@ -81,8 +83,11 @@ OwnPtr<Messages::SymbolServer::SymbolicateResponse> ClientConnection::handle(con
ASSERT(it != s_cache.end());
auto& cached_elf = it->value;
if (!cached_elf)
return make<Messages::SymbolServer::SymbolicateResponse>(false, String {}, 0, String {}, 0);
u32 offset = 0;
auto symbol = cached_elf.elf.symbolicate(message.address(), &offset);
auto symbol = cached_elf->elf.symbolicate(message.address(), &offset);
return make<Messages::SymbolServer::SymbolicateResponse>(true, symbol, offset, String {}, 0);
}