summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGunnar Beutner <gbeutner@serenityos.org>2021-06-20 02:35:58 +0200
committerLinus Groh <mail@linusgroh.de>2021-06-20 10:19:02 +0100
commit25c73159ce7dad7f1899eb50474f1c69ade00f18 (patch)
tree99204daf9cc171f5a8a4234bf68e1fb6db42ce09
parent995594b40330c46a8679c99b2ab24c87ecb0a985 (diff)
downloadserenity-25c73159ce7dad7f1899eb50474f1c69ade00f18.zip
LibCoreDump: Don't subtract one from the first stack frame's EIP
The first stack frame represents the current instruction pointer rather than the return address so we shouldn't subtract one from it. Fixes #8162.
-rw-r--r--Userland/Libraries/LibCoreDump/Backtrace.cpp7
-rw-r--r--Userland/Libraries/LibSymbolication/Symbolication.cpp7
2 files changed, 12 insertions, 2 deletions
diff --git a/Userland/Libraries/LibCoreDump/Backtrace.cpp b/Userland/Libraries/LibCoreDump/Backtrace.cpp
index c91922a3e2..ad542e7668 100644
--- a/Userland/Libraries/LibCoreDump/Backtrace.cpp
+++ b/Userland/Libraries/LibCoreDump/Backtrace.cpp
@@ -53,11 +53,16 @@ Backtrace::Backtrace(const Reader& coredump, const ELF::Core::ThreadInfo& thread
{
uint32_t* ebp = (uint32_t*)m_thread_info.regs.ebp;
uint32_t* eip = (uint32_t*)m_thread_info.regs.eip;
+ bool first_frame = true;
while (ebp && eip) {
// 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 - 1);
+ add_entry(coredump, (FlatPtr)eip - (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())
diff --git a/Userland/Libraries/LibSymbolication/Symbolication.cpp b/Userland/Libraries/LibSymbolication/Symbolication.cpp
index c331e568d1..5f17a60951 100644
--- a/Userland/Libraries/LibSymbolication/Symbolication.cpp
+++ b/Userland/Libraries/LibSymbolication/Symbolication.cpp
@@ -148,6 +148,7 @@ Vector<Symbol> symbolicate_thread(pid_t pid, pid_t tid)
}
Vector<Symbol> symbols;
+ bool first_frame = true;
for (auto address : stack) {
const RegionWithSymbols* found_region = nullptr;
@@ -171,7 +172,11 @@ Vector<Symbol> symbolicate_thread(pid_t pid, pid_t tid)
// We're subtracting 1 from the address because this is the return address,
// i.e. it is one instruction past the call instruction.
- auto result = symbolicate(found_region->path, adjusted_address - 1);
+ // However, because the first frame represents the current
+ // instruction pointer rather than the return address we don't
+ // subtract 1 for that.
+ auto result = symbolicate(found_region->path, adjusted_address - (first_frame ? 0 : 1));
+ first_frame = false;
if (!result.has_value()) {
symbols.append(Symbol {
.address = address,