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

LibDebug: Store LibDebug objects on the heap & make them non-copyable

This fixes an issue were some LibDebug objects (for example,
Dwarf::CompilationUnit) held a reference to their parent
Dwarf::DwarfInfo object, which was constructed on the stack and later
moved to the heap.
This commit is contained in:
Itamar 2021-06-18 14:31:03 +03:00 committed by Andreas Kling
parent edd79ddd00
commit e9e4358a93
7 changed files with 19 additions and 10 deletions

View file

@ -16,7 +16,7 @@ namespace Symbolication {
struct CachedELF {
NonnullRefPtr<MappedFile> mapped_file;
Debug::DebugInfo debug_info;
NonnullOwnPtr<Debug::DebugInfo> debug_info;
};
static HashMap<String, OwnPtr<CachedELF>> s_cache;
@ -36,8 +36,7 @@ Optional<Symbol> symbolicate(String const& path, u32 address)
s_cache.set(path, {});
{};
}
Debug::DebugInfo debug_info(move(elf));
auto cached_elf = make<CachedELF>(mapped_file.release_value(), move(debug_info));
auto cached_elf = make<CachedELF>(mapped_file.release_value(), make<Debug::DebugInfo>(move(elf)));
s_cache.set(path, move(cached_elf));
}
@ -49,8 +48,8 @@ Optional<Symbol> symbolicate(String const& path, u32 address)
return {};
u32 offset = 0;
auto symbol = cached_elf->debug_info.elf().symbolicate(address, &offset);
auto source_position = cached_elf->debug_info.get_source_position(address);
auto symbol = cached_elf->debug_info->elf().symbolicate(address, &offset);
auto source_position = cached_elf->debug_info->get_source_position(address);
String filename;
u32 line_number = 0;
if (source_position.has_value()) {