mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:17:45 +00:00
LibCoreDump: Add 'library_containing' API to CoreDump::Reader
This API returns info about the library whose range in memory contains a given address (similar to 'region_containing', but for libraries).
This commit is contained in:
parent
399091dec3
commit
65ffd8de69
2 changed files with 43 additions and 0 deletions
|
@ -29,6 +29,7 @@
|
||||||
#include <LibCoreDump/Backtrace.h>
|
#include <LibCoreDump/Backtrace.h>
|
||||||
#include <LibCoreDump/Reader.h>
|
#include <LibCoreDump/Reader.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
namespace CoreDump {
|
namespace CoreDump {
|
||||||
|
|
||||||
|
@ -177,4 +178,38 @@ const HashMap<String, String> Reader::metadata() const
|
||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct LibraryData {
|
||||||
|
String name;
|
||||||
|
OwnPtr<MappedFile> file;
|
||||||
|
ELF::Image lib_elf;
|
||||||
|
};
|
||||||
|
|
||||||
|
const Reader::LibraryData* Reader::library_containing(FlatPtr address) const
|
||||||
|
{
|
||||||
|
static HashMap<String, OwnPtr<LibraryData>> cached_libs;
|
||||||
|
auto* region = region_containing(address);
|
||||||
|
if (!region)
|
||||||
|
return {};
|
||||||
|
|
||||||
|
auto name = region->object_name();
|
||||||
|
|
||||||
|
String path;
|
||||||
|
if (name.contains(".so"))
|
||||||
|
path = String::format("/usr/lib/%s", name.characters());
|
||||||
|
else {
|
||||||
|
path = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!cached_libs.contains(path)) {
|
||||||
|
auto lib_file = make<MappedFile>(path);
|
||||||
|
if (!lib_file->is_valid())
|
||||||
|
return {};
|
||||||
|
auto image = ELF::Image((const u8*)lib_file->data(), lib_file->size());
|
||||||
|
cached_libs.set(path, make<LibraryData>(name, region->region_start, move(lib_file), move(image)));
|
||||||
|
}
|
||||||
|
|
||||||
|
auto lib_data = cached_libs.get(path).value();
|
||||||
|
return lib_data;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,14 @@ public:
|
||||||
Optional<uint32_t> peek_memory(FlatPtr address) const;
|
Optional<uint32_t> peek_memory(FlatPtr address) const;
|
||||||
const ELF::Core::MemoryRegionInfo* region_containing(FlatPtr address) const;
|
const ELF::Core::MemoryRegionInfo* region_containing(FlatPtr address) const;
|
||||||
|
|
||||||
|
struct LibraryData {
|
||||||
|
String name;
|
||||||
|
FlatPtr base_address { 0 };
|
||||||
|
OwnPtr<MappedFile> file;
|
||||||
|
ELF::Image lib_elf;
|
||||||
|
};
|
||||||
|
const LibraryData* library_containing(FlatPtr address) const;
|
||||||
|
|
||||||
const Backtrace backtrace() const;
|
const Backtrace backtrace() const;
|
||||||
const HashMap<String, String> metadata() const;
|
const HashMap<String, String> metadata() const;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue