LibELF: Add MemoryRegionInfo::object_name()

We had multiple implementations of this function, and it's a small
helper related to MemoryRegionInfo's region_name, so let's move it
there.
This commit is contained in:
Linus Groh 2020-12-29 13:02:36 +01:00 committed by Andreas Kling
parent c39323401c
commit e2e2b2c08e
Notes: sideshowbarker 2024-07-19 00:26:46 +09:00
2 changed files with 12 additions and 12 deletions

View file

@ -47,15 +47,6 @@ static void sort_profile_nodes(Vector<NonnullRefPtr<ProfileNode>>& nodes)
child->sort_children();
}
static String object_name(StringView memory_region_name)
{
if (memory_region_name.contains("Loader.so"))
return "Loader.so";
if (!memory_region_name.contains(":"))
return {};
return memory_region_name.substring_view(0, memory_region_name.find_first_of(":").value()).to_string();
}
struct CachedLibData {
OwnPtr<MappedFile> file;
ELF::Image lib_elf;
@ -66,9 +57,7 @@ static String symbolicate(FlatPtr eip, const ELF::Core::MemoryRegionInfo* region
static HashMap<String, OwnPtr<CachedLibData>> cached_libs;
StringView region_name { region->region_name };
auto name = object_name(region_name);
auto name = region->object_name();
String path;
if (name.contains(".so"))

View file

@ -26,6 +26,7 @@
#pragma once
#include <AK/String.h>
#include <AK/Types.h>
#include <LibC/sys/arch/i386/regs.h>
@ -61,6 +62,16 @@ struct [[gnu::packed]] MemoryRegionInfo
uint32_t region_end;
uint16_t program_header_index;
char region_name[]; // Null terminated
String object_name() const
{
StringView memory_region_name { region_name };
if (memory_region_name.contains("Loader.so"))
return "Loader.so";
if (!memory_region_name.contains(":"))
return {};
return memory_region_name.substring_view(0, memory_region_name.find_first_of(":").value()).to_string();
}
};
}