Skip to content

Commit 2016354

Browse files
gunnarbeutnerawesomekling
authored andcommitted
Kernel+LibCoreDump: Implement more x86_64 coredump functionality
1 parent d3127ef commit 2016354

File tree

4 files changed

+38
-18
lines changed

4 files changed

+38
-18
lines changed

Kernel/CoreDump.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ KResult CoreDump::write_elf_header()
7878
elf_file_header.e_ident[EI_MAG1] = 'E';
7979
elf_file_header.e_ident[EI_MAG2] = 'L';
8080
elf_file_header.e_ident[EI_MAG3] = 'F';
81+
#if ARCH(I386)
8182
elf_file_header.e_ident[EI_CLASS] = ELFCLASS32;
83+
#else
84+
elf_file_header.e_ident[EI_CLASS] = ELFCLASS64;
85+
#endif
8286
elf_file_header.e_ident[EI_DATA] = ELFDATA2LSB;
8387
elf_file_header.e_ident[EI_VERSION] = EV_CURRENT;
8488
elf_file_header.e_ident[EI_OSABI] = 0; // ELFOSABI_NONE
@@ -90,7 +94,11 @@ KResult CoreDump::write_elf_header()
9094
elf_file_header.e_ident[EI_PAD + 5] = 0;
9195
elf_file_header.e_ident[EI_PAD + 6] = 0;
9296
elf_file_header.e_type = ET_CORE;
97+
#if ARCH(I386)
9398
elf_file_header.e_machine = EM_386;
99+
#else
100+
elf_file_header.e_machine = EM_X86_64;
101+
#endif
94102
elf_file_header.e_version = 1;
95103
elf_file_header.e_entry = 0;
96104
elf_file_header.e_phoff = sizeof(ElfW(Ehdr));

Userland/Libraries/LibCoreDump/Backtrace.cpp

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ static const ELFObjectInfo* object_info_for_region(const ELF::Core::MemoryRegion
4343
return nullptr;
4444

4545
auto image = make<ELF::Image>(file_or_error.value()->bytes());
46+
#if !ARCH(I386)
47+
// FIXME: Fix LibDebug
48+
return nullptr;
49+
#endif
4650
auto info = make<ELFObjectInfo>(file_or_error.release_value(), make<Debug::DebugInfo>(move(image)));
4751
auto* info_ptr = info.ptr();
4852
s_debug_info_cache.set(path, move(info));
@@ -52,30 +56,33 @@ static const ELFObjectInfo* object_info_for_region(const ELF::Core::MemoryRegion
5256
Backtrace::Backtrace(const Reader& coredump, const ELF::Core::ThreadInfo& thread_info)
5357
: m_thread_info(move(thread_info))
5458
{
59+
FlatPtr* bp;
60+
FlatPtr* ip;
5561
#if ARCH(I386)
56-
uint32_t* ebp = (uint32_t*)m_thread_info.regs.ebp;
57-
uint32_t* eip = (uint32_t*)m_thread_info.regs.eip;
62+
bp = (FlatPtr*)m_thread_info.regs.ebp;
63+
ip = (FlatPtr*)m_thread_info.regs.eip;
64+
#else
65+
bp = (FlatPtr*)m_thread_info.regs.rbp;
66+
ip = (FlatPtr*)m_thread_info.regs.rip;
67+
#endif
68+
5869
bool first_frame = true;
59-
while (ebp && eip) {
70+
while (bp && ip) {
6071
// We use eip - 1 because the return address from a function frame
6172
// is the instruction that comes after the 'call' instruction.
6273
// However, because the first frame represents the faulting
6374
// instruction rather than the return address we don't subtract
6475
// 1 there.
65-
VERIFY((FlatPtr)eip > 0);
66-
add_entry(coredump, (FlatPtr)eip - (first_frame ? 0 : 1));
76+
VERIFY((FlatPtr)ip > 0);
77+
add_entry(coredump, (FlatPtr)ip - (first_frame ? 0 : 1));
6778
first_frame = false;
68-
auto next_eip = coredump.peek_memory((FlatPtr)(ebp + 1));
69-
auto next_ebp = coredump.peek_memory((FlatPtr)(ebp));
70-
if (!next_eip.has_value() || !next_ebp.has_value())
79+
auto next_ip = coredump.peek_memory((FlatPtr)(bp + 1));
80+
auto next_bp = coredump.peek_memory((FlatPtr)(bp));
81+
if (!next_ip.has_value() || !next_bp.has_value())
7182
break;
72-
eip = (uint32_t*)next_eip.value();
73-
ebp = (uint32_t*)next_ebp.value();
83+
ip = (FlatPtr*)next_ip.value();
84+
bp = (FlatPtr*)next_bp.value();
7485
}
75-
#else
76-
(void)coredump;
77-
TODO();
78-
#endif
7986
}
8087

8188
Backtrace::~Backtrace()
@@ -96,9 +103,14 @@ void Backtrace::add_entry(const Reader& coredump, FlatPtr eip)
96103
if (!object_info)
97104
return;
98105

106+
#if ARCH(I386)
99107
auto function_name = object_info->debug_info->elf().symbolicate(eip - region->region_start);
100108
auto source_position = object_info->debug_info->get_source_position_with_inlines(eip - region->region_start);
101-
109+
#else
110+
// FIXME: Fix symbolication.
111+
auto function_name = "";
112+
Debug::DebugInfo::SourcePositionWithInlines source_position;
113+
#endif
102114
m_entries.append({ eip, object_name, function_name, source_position });
103115
}
104116

Userland/Libraries/LibCoreDump/Reader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ bool Reader::NotesEntryIterator::at_end() const
106106
return type() == ELF::Core::NotesEntryHeader::Type::Null;
107107
}
108108

109-
Optional<uint32_t> Reader::peek_memory(FlatPtr address) const
109+
Optional<FlatPtr> Reader::peek_memory(FlatPtr address) const
110110
{
111111
const auto* region = region_containing(address);
112112
if (!region)
113113
return {};
114114

115115
FlatPtr offset_in_region = address - region->region_start;
116116
const char* region_data = image().program_header(region->program_header_index).raw_data();
117-
return *(const uint32_t*)(&region_data[offset_in_region]);
117+
return *(const FlatPtr*)(&region_data[offset_in_region]);
118118
}
119119

120120
const JsonObject Reader::process_info() const

Userland/Libraries/LibCoreDump/Reader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Reader {
3131

3232
const ELF::Image& image() const { return m_coredump_image; }
3333

34-
Optional<uint32_t> peek_memory(FlatPtr address) const;
34+
Optional<FlatPtr> peek_memory(FlatPtr address) const;
3535
const ELF::Core::MemoryRegionInfo* region_containing(FlatPtr address) const;
3636

3737
struct LibraryData {

0 commit comments

Comments
 (0)