From d9243ded6be29c0e3804027b398b45cc9eb57690 Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Tue, 4 Jun 2024 21:18:10 +0100 Subject: [PATCH 1/3] 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; } From b405a04a4aecaa092aab26c8bf4da6d7f8660cba Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Tue, 4 Jun 2024 21:19:29 +0100 Subject: [PATCH 2/3] Add a changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18180cad..36bd4098 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Affine background center position didn't work outside of the upper left quadrant of the gba's screen. +- Fixed backtrace pointing to the wrong line of code (being out by one). ## [0.20.2] - 2024/05/25 From 32c6ed4e358652ac64972541740eb0e34bf58690 Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Tue, 4 Jun 2024 21:39:58 +0100 Subject: [PATCH 3/3] Ensure the frame pointer is always 0 --- agb/src/entrypoint.s | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/agb/src/entrypoint.s b/agb/src/entrypoint.s index 45ebe74d..9f2ea49a 100644 --- a/agb/src/entrypoint.s +++ b/agb/src/entrypoint.s @@ -80,8 +80,12 @@ CommonInit: ldr r0, =0 mov r1, r0 + @ ensure the frame pointer is zero so that stack traces are guaranteed to terminate + mov r7, r0 + @ load main and branch ldr r2, =main + mov lr, pc bx r2 @ loop if we end up here