Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/aarch64/aarch64 If there was a "bl <func>" instruct...



details:   https://anonhg.NetBSD.org/src/rev/845de4955b01
branches:  trunk
changeset: 370653:845de4955b01
user:      ryo <ryo%NetBSD.org@localhost>
date:      Thu Sep 22 19:33:00 2022 +0000

description:
If there was a "bl <func>" instruction at the end of a function block,
the stack analysis backtrace (bt/s) would fail because $lr would point
to the beginning of the next function.

diffstat:

 sys/arch/aarch64/aarch64/db_trace.c |  16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diffs (59 lines):

diff -r 630aea053dfd -r 845de4955b01 sys/arch/aarch64/aarch64/db_trace.c
--- a/sys/arch/aarch64/aarch64/db_trace.c       Thu Sep 22 16:21:34 2022 +0000
+++ b/sys/arch/aarch64/aarch64/db_trace.c       Thu Sep 22 19:33:00 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: db_trace.c,v 1.20 2022/09/19 17:24:23 ryo Exp $ */
+/* $NetBSD: db_trace.c,v 1.21 2022/09/22 19:33:00 ryo Exp $ */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.20 2022/09/19 17:24:23 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.21 2022/09/22 19:33:00 ryo Exp $");
 
 #include <sys/param.h>
 #include <sys/bitops.h>
@@ -512,7 +512,7 @@
        if (tf_buf.tf_sp == 0) {
                /* switchframe */
                lr0 = 0;
-               pc = aarch64_strip_pac(tf_buf.tf_lr);
+               pc = aarch64_strip_pac(tf_buf.tf_lr) - 4;
                sp = (uint64_t)(tf + 1);
        } else {
                /* trapframe */
@@ -527,10 +527,10 @@
        TRACE_DEBUG("lr0=%016lx\n", lr0);
 
        for (; (count > 0) && (sp != 0); count--) {
-               if (((pc - 4) == (db_addr_t)el0_trap) ||
-                   ((pc - 4) == (db_addr_t)el1_trap)) {
+               if ((pc == (db_addr_t)el0_trap) ||
+                   (pc == (db_addr_t)el1_trap)) {
 
-                       pr_traceaddr("tf", sp, pc - 4, flags, pr);
+                       pr_traceaddr("tf", sp, pc, flags, pr);
 
                        db_read_bytes((db_addr_t)sp, sizeof(tf_buf),
                            (char *)&tf_buf);
@@ -541,7 +541,7 @@
                        sp = tf_buf.tf_sp;
                        pc = tf_buf.tf_pc;
                        if (pc == 0)
-                               pc = aarch64_strip_pac(tf_buf.tf_lr);
+                               pc = aarch64_strip_pac(tf_buf.tf_lr) - 4;
                        if (pc == 0)
                                break;
                        lr0 = aarch64_strip_pac(tf_buf.tf_lr);
@@ -593,7 +593,7 @@
                        }
 
                        sp += stacksize;
-                       pc = lr;
+                       pc = lr - 4;
                }
        }
 }



Home | Main Index | Thread Index | Old Index