Module Name:    src
Committed By:   simonb
Date:           Wed Feb 10 07:19:54 UTC 2021

Modified Files:
        src/sys/arch/mips/include: db_machdep.h
        src/sys/arch/mips/mips: db_trace.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/mips/include/db_machdep.h
cvs rdiff -u -r1.49 -r1.50 src/sys/arch/mips/mips/db_trace.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/mips/include/db_machdep.h
diff -u src/sys/arch/mips/include/db_machdep.h:1.33 src/sys/arch/mips/include/db_machdep.h:1.34
--- src/sys/arch/mips/include/db_machdep.h:1.33	Mon Aug 17 03:19:35 2020
+++ src/sys/arch/mips/include/db_machdep.h	Wed Feb 10 07:19:54 2021
@@ -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 @@ db_addr_t next_instr_address(db_addr_t p
 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 @@ extern void (*cpu_reset_address)(void);
 #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_ */

Index: src/sys/arch/mips/mips/db_trace.c
diff -u src/sys/arch/mips/mips/db_trace.c:1.49 src/sys/arch/mips/mips/db_trace.c:1.50
--- src/sys/arch/mips/mips/db_trace.c:1.49	Tue Feb  9 13:28:47 2021
+++ src/sys/arch/mips/mips/db_trace.c	Wed Feb 10 07:19:54 2021
@@ -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 @@ db_sym_t localsym(db_sym_t sym, bool isr
  */
 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 @@ db_stack_trace_print(db_expr_t addr, boo
 #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

Reply via email to