From d9243ded6be29c0e3804027b398b45cc9eb57690 Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Tue, 4 Jun 2024 21:18:10 +0100 Subject: [PATCH] The link register points to the next instruction --- agb/src/backtrace.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/agb/src/backtrace.rs b/agb/src/backtrace.rs index 0673761b..2ead7d54 100644 --- a/agb/src/backtrace.rs +++ b/agb/src/backtrace.rs @@ -77,7 +77,10 @@ pub(crate) fn unwind_exception() -> Frames { break; } - frames.push(lr); + // need to subtract 2 here since the link register points to the _next_ instruction + // to execute, not the one that is being branched from which is the one we care about + // in the stack trace. + frames.push(lr - 2); frame_pointer = sp; }