Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/mips On MIPS use a helper function to work out the ...



details:   https://anonhg.NetBSD.org/src/rev/85961f69401e
branches:  trunk
changeset: 959368:85961f69401e
user:      simonb <simonb%NetBSD.org@localhost>
date:      Wed Feb 10 07:19:54 2021 +0000

description:
On MIPS use a helper function to work out the current PC and then
call stacktrace_subr() directly for displaying a stacktrace with
db_stacktrace() and friends.

diffstat:

 sys/arch/mips/include/db_machdep.h |   7 ++++++-
 sys/arch/mips/mips/db_trace.c      |  26 +++++++++++++++++---------
 2 files changed, 23 insertions(+), 10 deletions(-)

diffs (83 lines):

diff -r 17b267a6813b -r 85961f69401e sys/arch/mips/include/db_machdep.h
--- a/sys/arch/mips/include/db_machdep.h        Wed Feb 10 07:17:39 2021 +0000
+++ b/sys/arch/mips/include/db_machdep.h        Wed Feb 10 07:19:54 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: db_machdep.h,v 1.33 2020/08/17 03:19:35 mrg Exp $ */
+/* $NetBSD: db_machdep.h,v 1.34 2021/02/10 07:19:54 simonb Exp $ */
 
 /*
  * Copyright (c) 1997 Jonathan Stone (hereinafter referred to as the author)
@@ -127,6 +127,7 @@
 bool ddb_running_on_this_cpu_p(void);
 bool ddb_running_on_any_cpu_p(void);
 void db_resume_others(void);
+void db_mips_stack_trace(void *, void *, void (*pr)(const char *, ...));
 
 extern void (*cpu_reset_address)(void);
 
@@ -137,4 +138,8 @@
 #define        DB_MACHINE_COMMANDS
 #endif
 
+#define        db_stacktrace_print(prfunc) \
+    db_mips_stack_trace(__builtin_return_address(0), \
+       __builtin_frame_address(0), prfunc)
+
 #endif /* _MIPS_DB_MACHDEP_H_ */
diff -r 17b267a6813b -r 85961f69401e sys/arch/mips/mips/db_trace.c
--- a/sys/arch/mips/mips/db_trace.c     Wed Feb 10 07:17:39 2021 +0000
+++ b/sys/arch/mips/mips/db_trace.c     Wed Feb 10 07:19:54 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: db_trace.c,v 1.49 2021/02/09 13:28:47 simonb Exp $     */
+/*     $NetBSD: db_trace.c,v 1.50 2021/02/10 07:19:54 simonb Exp $     */
 
 /*
  * Mach Operating System
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.49 2021/02/09 13:28:47 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.50 2021/02/10 07:19:54 simonb Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -74,10 +74,6 @@
  */
 struct mips_saved_state *db_cur_exc_frame = 0;
 
-/*
- * Stack trace helper.
- */
-void db_mips_stack_trace(int, vaddr_t, vaddr_t, vaddr_t, int, vaddr_t);
 int db_mips_variable_func(const struct db_variable *, db_expr_t *, int);
 
 #define DB_SETF_REGS db_mips_variable_func
@@ -289,12 +285,24 @@
 #endif
 }
 
+/*
+ * Helper function for db_stacktrace() and friends, used to get the
+ * pc via the return address.
+ */
 void
-db_mips_stack_trace(int count, vaddr_t stackp, vaddr_t the_pc, vaddr_t the_ra,
-    int flags, vaddr_t kstackp)
+db_mips_stack_trace(void *ra, void *fp, void (*pr)(const char *, ...))
 {
+       vaddr_t pc;
 
-       /* nothing... */
+       /*
+        * The jal instruction for our caller is two insns before the
+        * return address.
+        */
+       pc = (vaddr_t)__builtin_return_address(0) - sizeof(uint32_t) * 2;
+
+       stacktrace_subr(0, 0, 0, 0,     /* no args known */
+           pc, (intptr_t)fp, (intptr_t)fp, (intptr_t)ra,
+           pr);
 }
 
 int



Home | Main Index | Thread Index | Old Index