mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:37:46 +00:00
LibELF+LibCoreDump: Add a ProcessInfo notes entry
This is a new NotesEntry type which contains information related to the coredump's process: - PID - executable path Having these in the coredump explicitly avoids having to parse them from the coredump filename and backtrace, respectively.
This commit is contained in:
parent
9227e66bb4
commit
a28954a882
3 changed files with 39 additions and 9 deletions
|
@ -66,7 +66,8 @@ Reader::NotesEntryIterator::NotesEntryIterator(const u8* notes_data)
|
||||||
|
|
||||||
ELF::Core::NotesEntryHeader::Type Reader::NotesEntryIterator::type() const
|
ELF::Core::NotesEntryHeader::Type Reader::NotesEntryIterator::type() const
|
||||||
{
|
{
|
||||||
ASSERT(m_current->header.type == ELF::Core::NotesEntryHeader::Type::MemoryRegionInfo
|
ASSERT(m_current->header.type == ELF::Core::NotesEntryHeader::Type::ProcessInfo
|
||||||
|
|| m_current->header.type == ELF::Core::NotesEntryHeader::Type::MemoryRegionInfo
|
||||||
|| m_current->header.type == ELF::Core::NotesEntryHeader::Type::ThreadInfo
|
|| m_current->header.type == ELF::Core::NotesEntryHeader::Type::ThreadInfo
|
||||||
|| m_current->header.type == ELF::Core::NotesEntryHeader::Type::Null);
|
|| m_current->header.type == ELF::Core::NotesEntryHeader::Type::Null);
|
||||||
return m_current->header.type;
|
return m_current->header.type;
|
||||||
|
@ -80,15 +81,24 @@ const ELF::Core::NotesEntry* Reader::NotesEntryIterator::current() const
|
||||||
void Reader::NotesEntryIterator::next()
|
void Reader::NotesEntryIterator::next()
|
||||||
{
|
{
|
||||||
ASSERT(!at_end());
|
ASSERT(!at_end());
|
||||||
if (type() == ELF::Core::NotesEntryHeader::Type::ThreadInfo) {
|
switch (type()) {
|
||||||
const ELF::Core::ThreadInfo* current = (const ELF::Core::ThreadInfo*)m_current;
|
case ELF::Core::NotesEntryHeader::Type::ProcessInfo: {
|
||||||
m_current = (const ELF::Core::NotesEntry*)(current + 1);
|
const auto* current = reinterpret_cast<const ELF::Core::ProcessInfo*>(m_current);
|
||||||
return;
|
m_current = reinterpret_cast<const ELF::Core::NotesEntry*>(current->executable_path + strlen(current->executable_path) + 1);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (type() == ELF::Core::NotesEntryHeader::Type::MemoryRegionInfo) {
|
case ELF::Core::NotesEntryHeader::Type::ThreadInfo: {
|
||||||
const ELF::Core::MemoryRegionInfo* current = (const ELF::Core::MemoryRegionInfo*)m_current;
|
const auto* current = reinterpret_cast<const ELF::Core::ThreadInfo*>(m_current);
|
||||||
m_current = (const ELF::Core::NotesEntry*)(current->region_name + strlen(current->region_name) + 1);
|
m_current = reinterpret_cast<const ELF::Core::NotesEntry*>(current + 1);
|
||||||
return;
|
break;
|
||||||
|
}
|
||||||
|
case ELF::Core::NotesEntryHeader::Type::MemoryRegionInfo: {
|
||||||
|
const auto* current = reinterpret_cast<const ELF::Core::MemoryRegionInfo*>(m_current);
|
||||||
|
m_current = reinterpret_cast<const ELF::Core::NotesEntry*>(current->region_name + strlen(current->region_name) + 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,6 +118,16 @@ Optional<uint32_t> Reader::peek_memory(FlatPtr address) const
|
||||||
return *(const uint32_t*)(®ion_data[offset_in_region]);
|
return *(const uint32_t*)(®ion_data[offset_in_region]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ELF::Core::ProcessInfo& Reader::process_info() const
|
||||||
|
{
|
||||||
|
for (NotesEntryIterator it((const u8*)m_coredump_image.program_header(m_notes_segment_index).raw_data()); !it.at_end(); it.next()) {
|
||||||
|
if (it.type() != ELF::Core::NotesEntryHeader::Type::ProcessInfo)
|
||||||
|
continue;
|
||||||
|
return reinterpret_cast<const ELF::Core::ProcessInfo&>(*it.current());
|
||||||
|
}
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
const ELF::Core::MemoryRegionInfo* Reader::region_containing(FlatPtr address) const
|
const ELF::Core::MemoryRegionInfo* Reader::region_containing(FlatPtr address) const
|
||||||
{
|
{
|
||||||
const ELF::Core::MemoryRegionInfo* ret = nullptr;
|
const ELF::Core::MemoryRegionInfo* ret = nullptr;
|
||||||
|
|
|
@ -44,6 +44,8 @@ public:
|
||||||
|
|
||||||
Reader(OwnPtr<MappedFile>&&);
|
Reader(OwnPtr<MappedFile>&&);
|
||||||
|
|
||||||
|
const ELF::Core::ProcessInfo& process_info() const;
|
||||||
|
|
||||||
template<typename Func>
|
template<typename Func>
|
||||||
void for_each_memory_region_info(Func func) const;
|
void for_each_memory_region_info(Func func) const;
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ struct [[gnu::packed]] NotesEntryHeader
|
||||||
{
|
{
|
||||||
enum Type : u8 {
|
enum Type : u8 {
|
||||||
Null = 0, // Terminates segment
|
Null = 0, // Terminates segment
|
||||||
|
ProcessInfo,
|
||||||
ThreadInfo,
|
ThreadInfo,
|
||||||
MemoryRegionInfo,
|
MemoryRegionInfo,
|
||||||
};
|
};
|
||||||
|
@ -48,6 +49,13 @@ struct [[gnu::packed]] NotesEntry
|
||||||
char data[];
|
char data[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct [[gnu::packed]] ProcessInfo
|
||||||
|
{
|
||||||
|
NotesEntryHeader header;
|
||||||
|
int pid;
|
||||||
|
char executable_path[]; // Null terminated
|
||||||
|
};
|
||||||
|
|
||||||
struct [[gnu::packed]] ThreadInfo
|
struct [[gnu::packed]] ThreadInfo
|
||||||
{
|
{
|
||||||
NotesEntryHeader header;
|
NotesEntryHeader header;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue