diff options
author | Max Wipfli <mail@maxwipfli.ch> | 2021-06-30 14:46:49 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-30 15:15:15 +0200 |
commit | c1fbfdc164ce8a1e977ca43279a70d2243aa6c61 (patch) | |
tree | 5e60ce29a2e8e1a5176ab06350ce9303ff9a0536 | |
parent | fe2716df216ec4a31818f6f1c0a47d64454a23f0 (diff) | |
download | serenity-c1fbfdc164ce8a1e977ca43279a70d2243aa6c61.zip |
LibCoreDump: Change Backtrace debug info cache to member variable
This changes the previously static s_debug_info_cache to a member
variable. This is required so the cache is not kept alive if the
Backtrace object is destroyed.
Previously, the cache object would keep alive MappedFile objects and
other data, resulting in CrashReporter and CrashDaemon using more than
100 MB of memory even after the Backtrace objects have been destroyed
(and the data is thus no longer needed). This was especially the case
when handling crashes from Browser (due to libweb.so and libjs.so).
Due to this change, object_info_for_region has been promoted to a
instance method. It has also been cleaned up somewhat.
-rw-r--r-- | Userland/Libraries/LibCoreDump/Backtrace.cpp | 26 | ||||
-rw-r--r-- | Userland/Libraries/LibCoreDump/Backtrace.h | 2 |
2 files changed, 11 insertions, 17 deletions
diff --git a/Userland/Libraries/LibCoreDump/Backtrace.cpp b/Userland/Libraries/LibCoreDump/Backtrace.cpp index e96b396050..f13d415f94 100644 --- a/Userland/Libraries/LibCoreDump/Backtrace.cpp +++ b/Userland/Libraries/LibCoreDump/Backtrace.cpp @@ -17,25 +17,17 @@ namespace CoreDump { -// FIXME: This cache has to be invalidated when libraries/programs are re-compiled. -// We can store the last-modified timestamp of the elf files in ELFObjectInfo to invalidate cache entries. -static HashMap<String, NonnullOwnPtr<ELFObjectInfo>> s_debug_info_cache; - -static const ELFObjectInfo* object_info_for_region(const ELF::Core::MemoryRegionInfo& region) +ELFObjectInfo const* Backtrace::object_info_for_region(ELF::Core::MemoryRegionInfo const& region) { - auto name = region.object_name(); - - String path; - if (name.contains(".so")) - path = String::formatted("/usr/lib/{}", name); - else { - path = name; - } + auto path = region.object_name(); + if (!path.starts_with('/') && path.ends_with(".so"sv)) + path = LexicalPath::join("/usr/lib", path).string(); - if (auto it = s_debug_info_cache.find(path); it != s_debug_info_cache.end()) - return it->value.ptr(); + auto maybe_ptr = m_debug_info_cache.get(path); + if (maybe_ptr.has_value()) + return *maybe_ptr; - if (!Core::File::exists(path.characters())) + if (!Core::File::exists(path)) return nullptr; auto file_or_error = MappedFile::map(path); @@ -49,7 +41,7 @@ static const ELFObjectInfo* object_info_for_region(const ELF::Core::MemoryRegion #endif auto info = make<ELFObjectInfo>(file_or_error.release_value(), make<Debug::DebugInfo>(move(image))); auto* info_ptr = info.ptr(); - s_debug_info_cache.set(path, move(info)); + m_debug_info_cache.set(path, move(info)); return info_ptr; } diff --git a/Userland/Libraries/LibCoreDump/Backtrace.h b/Userland/Libraries/LibCoreDump/Backtrace.h index a1a008213b..769bddd47a 100644 --- a/Userland/Libraries/LibCoreDump/Backtrace.h +++ b/Userland/Libraries/LibCoreDump/Backtrace.h @@ -43,9 +43,11 @@ public: private: void add_entry(const Reader&, FlatPtr eip); + ELFObjectInfo const* object_info_for_region(ELF::Core::MemoryRegionInfo const&); ELF::Core::ThreadInfo m_thread_info; Vector<Entry> m_entries; + HashMap<String, NonnullOwnPtr<ELFObjectInfo>> m_debug_info_cache; }; } |