mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 10:22:05 -05:00
LibCoredump: Add Reader::for_each_library
This commit is contained in:
parent
94d68583fb
commit
ac762fbbc3
2 changed files with 31 additions and 0 deletions
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue