Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 11 May 2020 20:41:27 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r360922 - stable/12/sys/riscv/riscv
Message-ID:  <202005112041.04BKfRU1014394@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Mon May 11 20:41:27 2020
New Revision: 360922
URL: https://svnweb.freebsd.org/changeset/base/360922

Log:
  MFC 357630: Fix DDB to unwind across exception frames.
  
  While here, add an extra line of information for exceptions and
  interrupts and compress the per-frame line down to one line to match
  other architectures.

Modified:
  stable/12/sys/riscv/riscv/db_trace.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/riscv/riscv/db_trace.c
==============================================================================
--- stable/12/sys/riscv/riscv/db_trace.c	Mon May 11 20:41:03 2020	(r360921)
+++ stable/12/sys/riscv/riscv/db_trace.c	Mon May 11 20:41:27 2020	(r360922)
@@ -2,6 +2,7 @@
  * Copyright (c) 2015 The FreeBSD Foundation
  * Copyright (c) 2016 Ruslan Bukin <br@bsdpad.com>
  * All rights reserved.
+ * Copyright (c) 2020 John Baldwin <jhb@FreeBSD.org>
  *
  * Portions of this software were developed by Semihalf under
  * the sponsorship of the FreeBSD Foundation.
@@ -38,15 +39,18 @@
 
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
+
 #include <sys/param.h>
-#include <sys/proc.h>
 #include <sys/kdb.h>
-#include <machine/pcb.h>
+#include <sys/proc.h>
+
 #include <ddb/ddb.h>
 #include <ddb/db_sym.h>
 
+#include <machine/pcb.h>
 #include <machine/riscvreg.h>
 #include <machine/stack.h>
+#include <machine/vmparam.h>
 
 void
 db_md_list_watchpoints()
@@ -80,9 +84,6 @@ db_stack_trace_cmd(struct unwind_state *frame)
 	while (1) {
 		pc = frame->pc;
 
-		if (unwind_frame(frame) < 0)
-			break;
-
 		sym = db_search_symbol(pc, DB_STGY_ANY, &offset);
 		if (sym == C_DB_SYM_NULL) {
 			value = 0;
@@ -94,11 +95,32 @@ db_stack_trace_cmd(struct unwind_state *frame)
 		db_printsym(frame->pc, DB_STGY_PROC);
 		db_printf("\n");
 
-		db_printf("\t pc = 0x%016lx ra = 0x%016lx\n",
-		    pc, frame->pc);
-		db_printf("\t sp = 0x%016lx fp = 0x%016lx\n",
-		    frame->sp, frame->fp);
-		db_printf("\n");
+		if (strcmp(name, "cpu_exception_handler_supervisor") == 0 ||
+		    strcmp(name, "cpu_exception_handler_user") == 0) {
+			struct trapframe *tf;
+
+			tf = (struct trapframe *)(uintptr_t)frame->sp;
+
+			if (tf->tf_scause & EXCP_INTR)
+				db_printf("--- interrupt %ld\n",
+				    tf->tf_scause & EXCP_MASK);
+			else
+				db_printf("--- exception %ld, tval = %#lx\n",
+				    tf->tf_scause & EXCP_MASK,
+				    tf->tf_stval);
+			frame->sp = (uint64_t)tf->tf_sp;
+			frame->fp = (uint64_t)tf->tf_s[0];
+			frame->pc = (uint64_t)tf->tf_sepc;
+			if (!INKERNEL(frame->fp))
+				break;
+			continue;
+		}
+
+		if (strcmp(name, "fork_trampoline") == 0)
+			break;
+
+		if (unwind_frame(frame) < 0)
+			break;
 	}
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202005112041.04BKfRU1014394>