summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorItamar <itamar8910@gmail.com>2021-11-20 11:48:45 +0200
committerLinus Groh <mail@linusgroh.de>2021-11-20 21:22:24 +0000
commitac762fbbc3d67d2af22fca157846a03fb3f1c145 (patch)
treee47e7b63ddd8e490610cb899c9c0e87a6e458de3 /Userland
parent94d68583fb6daa25ad7d912f487e006e5f161718 (diff)
downloadserenity-ac762fbbc3d67d2af22fca157846a03fb3f1c145.zip
LibCoredump: Add Reader::for_each_library
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibCoredump/Reader.cpp23
-rw-r--r--Userland/Libraries/LibCoredump/Reader.h8
2 files changed, 31 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCoredump/Reader.cpp b/Userland/Libraries/LibCoredump/Reader.cpp
index c5126e689a..ae3ddbaa1c 100644
--- a/Userland/Libraries/LibCoredump/Reader.cpp
+++ b/Userland/Libraries/LibCoredump/Reader.cpp
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/HashTable.h>
#include <AK/JsonObject.h>
#include <AK/JsonValue.h>
#include <LibCompress/Gzip.h>
@@ -292,4 +293,26 @@ const Reader::LibraryData* Reader::library_containing(FlatPtr address) const
return lib_data;
}
+void Reader::for_each_library(Function<void(LibraryInfo)> func) const
+{
+ HashTable<String> libraries;
+ for_each_memory_region_info([&](ELF::Core::MemoryRegionInfo const& region) {
+ auto name = region.object_name();
+ if (name.is_null() || libraries.contains(name))
+ return IterationDecision::Continue;
+
+ libraries.set(name);
+
+ String path;
+ if (Core::File::looks_like_shared_library(name))
+ path = String::formatted("/usr/lib/{}", name);
+ else {
+ path = name;
+ }
+
+ func(LibraryInfo { name, path, (FlatPtr)region.region_start });
+ return IterationDecision::Continue;
+ });
+}
+
}
diff --git a/Userland/Libraries/LibCoredump/Reader.h b/Userland/Libraries/LibCoredump/Reader.h
index 9263cf13b4..911e1e4ed6 100644
--- a/Userland/Libraries/LibCoredump/Reader.h
+++ b/Userland/Libraries/LibCoredump/Reader.h
@@ -26,6 +26,14 @@ public:
template<typename Func>
void for_each_memory_region_info(Func func) const;
+ struct LibraryInfo {
+ String name;
+ String path;
+ FlatPtr base_address { 0 };
+ };
+
+ void for_each_library(Function<void(LibraryInfo)> func) const;
+
template<typename Func>
void for_each_thread_info(Func func) const;