mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 21:07:34 +00: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
9 changed files with 23 additions and 14 deletions
|
@ -419,8 +419,9 @@ MmapRegion const* Emulator::load_library_from_adress(FlatPtr address)
|
||||||
if (file_or_error.is_error())
|
if (file_or_error.is_error())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto debug_info = make<Debug::DebugInfo>(make<ELF::Image>(file_or_error.value()->bytes()));
|
auto image = 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 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;
|
return region;
|
||||||
}
|
}
|
||||||
|
|
|
@ -257,6 +257,7 @@ private:
|
||||||
struct CachedELF {
|
struct CachedELF {
|
||||||
NonnullRefPtr<MappedFile> mapped_file;
|
NonnullRefPtr<MappedFile> mapped_file;
|
||||||
NonnullOwnPtr<Debug::DebugInfo> debug_info;
|
NonnullOwnPtr<Debug::DebugInfo> debug_info;
|
||||||
|
NonnullOwnPtr<ELF::Image> image;
|
||||||
};
|
};
|
||||||
|
|
||||||
HashMap<String, CachedELF> m_dynamic_library_cache;
|
HashMap<String, CachedELF> m_dynamic_library_cache;
|
||||||
|
|
|
@ -35,7 +35,8 @@ ELFObjectInfo const* Backtrace::object_info_for_region(ELF::Core::MemoryRegionIn
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
auto image = make<ELF::Image>(file_or_error.value()->bytes());
|
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();
|
auto* info_ptr = info.ptr();
|
||||||
m_debug_info_cache.set(path, move(info));
|
m_debug_info_cache.set(path, move(info));
|
||||||
return info_ptr;
|
return info_ptr;
|
||||||
|
|
|
@ -14,14 +14,16 @@
|
||||||
namespace CoreDump {
|
namespace CoreDump {
|
||||||
|
|
||||||
struct ELFObjectInfo {
|
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))
|
: file(move(file))
|
||||||
, debug_info(move(debug_info))
|
, debug_info(move(debug_info))
|
||||||
|
, image(move(image))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
NonnullRefPtr<MappedFile> file;
|
NonnullRefPtr<MappedFile> file;
|
||||||
NonnullOwnPtr<Debug::DebugInfo> debug_info;
|
NonnullOwnPtr<Debug::DebugInfo> debug_info;
|
||||||
|
NonnullOwnPtr<ELF::Image> image;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Backtrace {
|
class Backtrace {
|
||||||
|
|
|
@ -15,11 +15,11 @@
|
||||||
|
|
||||||
namespace Debug {
|
namespace Debug {
|
||||||
|
|
||||||
DebugInfo::DebugInfo(NonnullOwnPtr<const ELF::Image> elf, String source_root, FlatPtr base_address)
|
DebugInfo::DebugInfo(ELF::Image const& elf, String source_root, FlatPtr base_address)
|
||||||
: m_elf(move(elf))
|
: m_elf(elf)
|
||||||
, m_source_root(move(source_root))
|
, m_source_root(move(source_root))
|
||||||
, m_base_address(base_address)
|
, m_base_address(base_address)
|
||||||
, m_dwarf_info(*m_elf)
|
, m_dwarf_info(m_elf)
|
||||||
{
|
{
|
||||||
prepare_variable_scopes();
|
prepare_variable_scopes();
|
||||||
prepare_lines();
|
prepare_lines();
|
||||||
|
|
|
@ -24,9 +24,9 @@ class DebugInfo {
|
||||||
AK_MAKE_NONMOVABLE(DebugInfo);
|
AK_MAKE_NONMOVABLE(DebugInfo);
|
||||||
|
|
||||||
public:
|
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 {
|
struct SourcePosition {
|
||||||
FlyString file_path;
|
FlyString file_path;
|
||||||
|
@ -124,7 +124,7 @@ private:
|
||||||
Optional<Dwarf::LineProgram::DirectoryAndFile> get_source_path_of_inline(const Dwarf::DIE&) const;
|
Optional<Dwarf::LineProgram::DirectoryAndFile> get_source_path_of_inline(const Dwarf::DIE&) const;
|
||||||
Optional<uint32_t> get_line_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;
|
String m_source_root;
|
||||||
FlatPtr m_base_address { 0 };
|
FlatPtr m_base_address { 0 };
|
||||||
Dwarf::DwarfInfo m_dwarf_info;
|
Dwarf::DwarfInfo m_dwarf_info;
|
||||||
|
|
|
@ -448,8 +448,9 @@ void DebugSession::update_loaded_libs()
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
|
|
||||||
FlatPtr base_address = entry.as_object().get("address").to_addr();
|
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 image = make<ELF::Image>(file_or_error.value()->bytes());
|
||||||
auto lib = make<LoadedLibrary>(lib_name, file_or_error.release_value(), move(debug_info), base_address);
|
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));
|
m_loaded_libraries.set(lib_name, move(lib));
|
||||||
|
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
|
|
|
@ -129,12 +129,14 @@ public:
|
||||||
struct LoadedLibrary {
|
struct LoadedLibrary {
|
||||||
String name;
|
String name;
|
||||||
NonnullRefPtr<MappedFile> file;
|
NonnullRefPtr<MappedFile> file;
|
||||||
|
NonnullOwnPtr<ELF::Image> image;
|
||||||
NonnullOwnPtr<DebugInfo> debug_info;
|
NonnullOwnPtr<DebugInfo> debug_info;
|
||||||
FlatPtr base_address;
|
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)
|
: name(name)
|
||||||
, file(move(file))
|
, file(move(file))
|
||||||
|
, image(move(image))
|
||||||
, debug_info(move(debug_info))
|
, debug_info(move(debug_info))
|
||||||
, base_address(base_address)
|
, base_address(base_address)
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,6 +18,7 @@ namespace Symbolication {
|
||||||
struct CachedELF {
|
struct CachedELF {
|
||||||
NonnullRefPtr<MappedFile> mapped_file;
|
NonnullRefPtr<MappedFile> mapped_file;
|
||||||
NonnullOwnPtr<Debug::DebugInfo> debug_info;
|
NonnullOwnPtr<Debug::DebugInfo> debug_info;
|
||||||
|
NonnullOwnPtr<ELF::Image> image;
|
||||||
};
|
};
|
||||||
|
|
||||||
static HashMap<String, OwnPtr<CachedELF>> s_cache;
|
static HashMap<String, OwnPtr<CachedELF>> s_cache;
|
||||||
|
@ -73,7 +74,7 @@ Optional<Symbol> symbolicate(String const& path, FlatPtr address)
|
||||||
s_cache.set(path, {});
|
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));
|
s_cache.set(path, move(cached_elf));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue