summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorGunnar Beutner <gbeutner@serenityos.org>2021-06-29 17:48:01 +0200
committerAndreas Kling <kling@serenityos.org>2021-06-29 20:03:36 +0200
commit2016354c12c131fb42609448fbee089198f46028 (patch)
tree2a5201efed504ae8595c9bbac8831e3e84534f91 /Userland/Libraries
parentd3127efc014baf2417b83a3298c155fd8b9da029 (diff)
downloadserenity-2016354c12c131fb42609448fbee089198f46028.zip
Kernel+LibCoreDump: Implement more x86_64 coredump functionality
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibCoreDump/Backtrace.cpp42
-rw-r--r--Userland/Libraries/LibCoreDump/Reader.cpp4
-rw-r--r--Userland/Libraries/LibCoreDump/Reader.h2
3 files changed, 30 insertions, 18 deletions
diff --git a/Userland/Libraries/LibCoreDump/Backtrace.cpp b/Userland/Libraries/LibCoreDump/Backtrace.cpp
index b388bccef2..a20f721666 100644
--- a/Userland/Libraries/LibCoreDump/Backtrace.cpp
+++ b/Userland/Libraries/LibCoreDump/Backtrace.cpp
@@ -43,6 +43,10 @@ static const ELFObjectInfo* object_info_for_region(const ELF::Core::MemoryRegion
return nullptr;
auto image = make<ELF::Image>(file_or_error.value()->bytes());
+#if !ARCH(I386)
+ // FIXME: Fix LibDebug
+ return nullptr;
+#endif
auto info = make<ELFObjectInfo>(file_or_error.release_value(), make<Debug::DebugInfo>(move(image)));
auto* info_ptr = info.ptr();
s_debug_info_cache.set(path, move(info));
@@ -52,30 +56,33 @@ static const ELFObjectInfo* object_info_for_region(const ELF::Core::MemoryRegion
Backtrace::Backtrace(const Reader& coredump, const ELF::Core::ThreadInfo& thread_info)
: m_thread_info(move(thread_info))
{
+ FlatPtr* bp;
+ FlatPtr* ip;
#if ARCH(I386)
- uint32_t* ebp = (uint32_t*)m_thread_info.regs.ebp;
- uint32_t* eip = (uint32_t*)m_thread_info.regs.eip;
+ bp = (FlatPtr*)m_thread_info.regs.ebp;
+ ip = (FlatPtr*)m_thread_info.regs.eip;
+#else
+ bp = (FlatPtr*)m_thread_info.regs.rbp;
+ ip = (FlatPtr*)m_thread_info.regs.rip;
+#endif
+
bool first_frame = true;
- while (ebp && eip) {
+ while (bp && ip) {
// We use eip - 1 because the return address from a function frame
// is the instruction that comes after the 'call' instruction.
// However, because the first frame represents the faulting
// instruction rather than the return address we don't subtract
// 1 there.
- VERIFY((FlatPtr)eip > 0);
- add_entry(coredump, (FlatPtr)eip - (first_frame ? 0 : 1));
+ VERIFY((FlatPtr)ip > 0);
+ add_entry(coredump, (FlatPtr)ip - (first_frame ? 0 : 1));
first_frame = false;
- auto next_eip = coredump.peek_memory((FlatPtr)(ebp + 1));
- auto next_ebp = coredump.peek_memory((FlatPtr)(ebp));
- if (!next_eip.has_value() || !next_ebp.has_value())
+ auto next_ip = coredump.peek_memory((FlatPtr)(bp + 1));
+ auto next_bp = coredump.peek_memory((FlatPtr)(bp));
+ if (!next_ip.has_value() || !next_bp.has_value())
break;
- eip = (uint32_t*)next_eip.value();
- ebp = (uint32_t*)next_ebp.value();
+ ip = (FlatPtr*)next_ip.value();
+ bp = (FlatPtr*)next_bp.value();
}
-#else
- (void)coredump;
- TODO();
-#endif
}
Backtrace::~Backtrace()
@@ -96,9 +103,14 @@ void Backtrace::add_entry(const Reader& coredump, FlatPtr eip)
if (!object_info)
return;
+#if ARCH(I386)
auto function_name = object_info->debug_info->elf().symbolicate(eip - region->region_start);
auto source_position = object_info->debug_info->get_source_position_with_inlines(eip - region->region_start);
-
+#else
+ // FIXME: Fix symbolication.
+ auto function_name = "";
+ Debug::DebugInfo::SourcePositionWithInlines source_position;
+#endif
m_entries.append({ eip, object_name, function_name, source_position });
}
diff --git a/Userland/Libraries/LibCoreDump/Reader.cpp b/Userland/Libraries/LibCoreDump/Reader.cpp
index 047adcef7a..da4a67b92d 100644
--- a/Userland/Libraries/LibCoreDump/Reader.cpp
+++ b/Userland/Libraries/LibCoreDump/Reader.cpp
@@ -106,7 +106,7 @@ bool Reader::NotesEntryIterator::at_end() const
return type() == ELF::Core::NotesEntryHeader::Type::Null;
}
-Optional<uint32_t> Reader::peek_memory(FlatPtr address) const
+Optional<FlatPtr> Reader::peek_memory(FlatPtr address) const
{
const auto* region = region_containing(address);
if (!region)
@@ -114,7 +114,7 @@ Optional<uint32_t> Reader::peek_memory(FlatPtr address) const
FlatPtr offset_in_region = address - region->region_start;
const char* region_data = image().program_header(region->program_header_index).raw_data();
- return *(const uint32_t*)(&region_data[offset_in_region]);
+ return *(const FlatPtr*)(&region_data[offset_in_region]);
}
const JsonObject Reader::process_info() const
diff --git a/Userland/Libraries/LibCoreDump/Reader.h b/Userland/Libraries/LibCoreDump/Reader.h
index f1cdf01c40..2e6116b7b9 100644
--- a/Userland/Libraries/LibCoreDump/Reader.h
+++ b/Userland/Libraries/LibCoreDump/Reader.h
@@ -31,7 +31,7 @@ public:
const ELF::Image& image() const { return m_coredump_image; }
- Optional<uint32_t> peek_memory(FlatPtr address) const;
+ Optional<FlatPtr> peek_memory(FlatPtr address) const;
const ELF::Core::MemoryRegionInfo* region_containing(FlatPtr address) const;
struct LibraryData {