mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 09:49:15 +03:00
LibDebug+Everywhere: Make DebugInfo not own the ELF image
This is required to avoid copying the image where otherwise a reference would be enough.
This commit is contained in:
parent
521217735b
commit
c4437e19bd
Notes:
sideshowbarker
2024-07-18 07:25:13 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/c4437e19bdb Pull-request: https://github.com/SerenityOS/serenity/pull/9227
@ -419,8 +419,9 @@ MmapRegion const* Emulator::load_library_from_adress(FlatPtr address)
|
||||
if (file_or_error.is_error())
|
||||
return {};
|
||||
|
||||
auto debug_info = make<Debug::DebugInfo>(make<ELF::Image>(file_or_error.value()->bytes()));
|
||||
m_dynamic_library_cache.set(lib_path, CachedELF { file_or_error.release_value(), move(debug_info) });
|
||||
auto image = make<ELF::Image>(file_or_error.value()->bytes());
|
||||
auto debug_info = make<Debug::DebugInfo>(*image);
|
||||
m_dynamic_library_cache.set(lib_path, CachedELF { file_or_error.release_value(), move(debug_info), move(image) });
|
||||
}
|
||||
return region;
|
||||
}
|
||||
|
@ -257,6 +257,7 @@ private:
|
||||
struct CachedELF {
|
||||
NonnullRefPtr<MappedFile> mapped_file;
|
||||
NonnullOwnPtr<Debug::DebugInfo> debug_info;
|
||||
NonnullOwnPtr<ELF::Image> image;
|
||||
};
|
||||
|
||||
HashMap<String, CachedELF> m_dynamic_library_cache;
|
||||
|
@ -35,7 +35,8 @@ ELFObjectInfo const* Backtrace::object_info_for_region(ELF::Core::MemoryRegionIn
|
||||
return nullptr;
|
||||
|
||||
auto image = make<ELF::Image>(file_or_error.value()->bytes());
|
||||
auto info = make<ELFObjectInfo>(file_or_error.release_value(), make<Debug::DebugInfo>(move(image)));
|
||||
auto& image_reference = *image;
|
||||
auto info = make<ELFObjectInfo>(file_or_error.release_value(), make<Debug::DebugInfo>(image_reference), move(image));
|
||||
auto* info_ptr = info.ptr();
|
||||
m_debug_info_cache.set(path, move(info));
|
||||
return info_ptr;
|
||||
|
@ -14,14 +14,16 @@
|
||||
namespace CoreDump {
|
||||
|
||||
struct ELFObjectInfo {
|
||||
ELFObjectInfo(NonnullRefPtr<MappedFile> file, NonnullOwnPtr<Debug::DebugInfo>&& debug_info)
|
||||
ELFObjectInfo(NonnullRefPtr<MappedFile> file, NonnullOwnPtr<Debug::DebugInfo>&& debug_info, NonnullOwnPtr<ELF::Image> image)
|
||||
: file(move(file))
|
||||
, debug_info(move(debug_info))
|
||||
, image(move(image))
|
||||
{
|
||||
}
|
||||
|
||||
NonnullRefPtr<MappedFile> file;
|
||||
NonnullOwnPtr<Debug::DebugInfo> debug_info;
|
||||
NonnullOwnPtr<ELF::Image> image;
|
||||
};
|
||||
|
||||
class Backtrace {
|
||||
|
@ -15,11 +15,11 @@
|
||||
|
||||
namespace Debug {
|
||||
|
||||
DebugInfo::DebugInfo(NonnullOwnPtr<const ELF::Image> elf, String source_root, FlatPtr base_address)
|
||||
: m_elf(move(elf))
|
||||
DebugInfo::DebugInfo(ELF::Image const& elf, String source_root, FlatPtr base_address)
|
||||
: m_elf(elf)
|
||||
, m_source_root(move(source_root))
|
||||
, m_base_address(base_address)
|
||||
, m_dwarf_info(*m_elf)
|
||||
, m_dwarf_info(m_elf)
|
||||
{
|
||||
prepare_variable_scopes();
|
||||
prepare_lines();
|
||||
|
@ -24,9 +24,9 @@ class DebugInfo {
|
||||
AK_MAKE_NONMOVABLE(DebugInfo);
|
||||
|
||||
public:
|
||||
explicit DebugInfo(NonnullOwnPtr<const ELF::Image>, String source_root = {}, FlatPtr base_address = 0);
|
||||
explicit DebugInfo(ELF::Image const&, String source_root = {}, FlatPtr base_address = 0);
|
||||
|
||||
ELF::Image const& elf() const { return *m_elf; }
|
||||
ELF::Image const& elf() const { return m_elf; }
|
||||
|
||||
struct SourcePosition {
|
||||
FlyString file_path;
|
||||
@ -124,7 +124,7 @@ private:
|
||||
Optional<Dwarf::LineProgram::DirectoryAndFile> get_source_path_of_inline(const Dwarf::DIE&) const;
|
||||
Optional<uint32_t> get_line_of_inline(const Dwarf::DIE&) const;
|
||||
|
||||
NonnullOwnPtr<const ELF::Image> m_elf;
|
||||
ELF::Image const& m_elf;
|
||||
String m_source_root;
|
||||
FlatPtr m_base_address { 0 };
|
||||
Dwarf::DwarfInfo m_dwarf_info;
|
||||
|
@ -448,8 +448,9 @@ void DebugSession::update_loaded_libs()
|
||||
return IterationDecision::Continue;
|
||||
|
||||
FlatPtr base_address = entry.as_object().get("address").to_addr();
|
||||
auto debug_info = make<DebugInfo>(make<ELF::Image>(file_or_error.value()->bytes()), m_source_root, base_address);
|
||||
auto lib = make<LoadedLibrary>(lib_name, file_or_error.release_value(), move(debug_info), base_address);
|
||||
auto image = make<ELF::Image>(file_or_error.value()->bytes());
|
||||
auto debug_info = make<DebugInfo>(*image, m_source_root, base_address);
|
||||
auto lib = make<LoadedLibrary>(lib_name, file_or_error.release_value(), move(image), move(debug_info), base_address);
|
||||
m_loaded_libraries.set(lib_name, move(lib));
|
||||
|
||||
return IterationDecision::Continue;
|
||||
|
@ -129,12 +129,14 @@ public:
|
||||
struct LoadedLibrary {
|
||||
String name;
|
||||
NonnullRefPtr<MappedFile> file;
|
||||
NonnullOwnPtr<ELF::Image> image;
|
||||
NonnullOwnPtr<DebugInfo> debug_info;
|
||||
FlatPtr base_address;
|
||||
|
||||
LoadedLibrary(String const& name, NonnullRefPtr<MappedFile> file, NonnullOwnPtr<DebugInfo>&& debug_info, FlatPtr base_address)
|
||||
LoadedLibrary(String const& name, NonnullRefPtr<MappedFile> file, NonnullOwnPtr<ELF::Image> image, NonnullOwnPtr<DebugInfo>&& debug_info, FlatPtr base_address)
|
||||
: name(name)
|
||||
, file(move(file))
|
||||
, image(move(image))
|
||||
, debug_info(move(debug_info))
|
||||
, base_address(base_address)
|
||||
{
|
||||
|
@ -18,6 +18,7 @@ namespace Symbolication {
|
||||
struct CachedELF {
|
||||
NonnullRefPtr<MappedFile> mapped_file;
|
||||
NonnullOwnPtr<Debug::DebugInfo> debug_info;
|
||||
NonnullOwnPtr<ELF::Image> image;
|
||||
};
|
||||
|
||||
static HashMap<String, OwnPtr<CachedELF>> s_cache;
|
||||
@ -73,7 +74,7 @@ Optional<Symbol> symbolicate(String const& path, FlatPtr address)
|
||||
s_cache.set(path, {});
|
||||
{};
|
||||
}
|
||||
auto cached_elf = make<CachedELF>(mapped_file.release_value(), make<Debug::DebugInfo>(move(elf)));
|
||||
auto cached_elf = make<CachedELF>(mapped_file.release_value(), make<Debug::DebugInfo>(*elf), move(elf));
|
||||
s_cache.set(path, move(cached_elf));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user