Module Name:    src
Committed By:   chs
Date:           Mon Dec 13 01:25:29 UTC 2021

Modified Files:
        src/sys/arch/amd64/amd64: db_machdep.c
        src/sys/arch/i386/i386: db_machdep.c
        src/sys/ddb: db_sym.c

Log Message:
ddb: fix function names of "noreturn" functions in stack traces.

when looking up function names for stack traces (where the addresses are the
return addresses of function calls), if the address is the first instruction
in the function, assume that the function being called is marked "noreturn"
and that the function containing the call is actually the function immediately
before the address that we looked up.  to find the correct function name,
do the lookup again with (address - 1) and then add one to the offset within
the function that we find.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/amd64/amd64/db_machdep.c
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/i386/i386/db_machdep.c
cvs rdiff -u -r1.67 -r1.68 src/sys/ddb/db_sym.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/amd64/amd64/db_machdep.c
diff -u src/sys/arch/amd64/amd64/db_machdep.c:1.8 src/sys/arch/amd64/amd64/db_machdep.c:1.9
--- src/sys/arch/amd64/amd64/db_machdep.c:1.8	Sat Jun  6 07:03:21 2020
+++ src/sys/arch/amd64/amd64/db_machdep.c	Mon Dec 13 01:25:29 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_machdep.c,v 1.8 2020/06/06 07:03:21 maxv Exp $	*/
+/*	$NetBSD: db_machdep.c,v 1.9 2021/12/13 01:25:29 chs Exp $	*/
 
 /*
  * Mach Operating System
@@ -26,7 +26,7 @@
  * rights to redistribute these changes.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.8 2020/06/06 07:03:21 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.9 2021/12/13 01:25:29 chs Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -200,6 +200,10 @@ db_frame_info(long *frame, db_addr_t cal
 	const char *name;
 
 	sym = db_search_symbol(callpc, DB_STGY_ANY, &offset);
+	if (sym != 0 && offset == 0) {
+		sym = db_search_symbol(callpc - 1, DB_STGY_ANY, &offset);
+		offset++;
+	}
 	db_symbol_values(sym, &name, NULL);
 	if (sym == (db_sym_t)0)
 		return (db_sym_t)0;

Index: src/sys/arch/i386/i386/db_machdep.c
diff -u src/sys/arch/i386/i386/db_machdep.c:1.7 src/sys/arch/i386/i386/db_machdep.c:1.8
--- src/sys/arch/i386/i386/db_machdep.c:1.7	Sun Feb 11 08:27:18 2018
+++ src/sys/arch/i386/i386/db_machdep.c	Mon Dec 13 01:25:29 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_machdep.c,v 1.7 2018/02/11 08:27:18 maxv Exp $	*/
+/*	$NetBSD: db_machdep.c,v 1.8 2021/12/13 01:25:29 chs Exp $	*/
 
 /*
  * Mach Operating System
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.7 2018/02/11 08:27:18 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.8 2021/12/13 01:25:29 chs Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -255,6 +255,10 @@ db_frame_info(long *frame, db_addr_t cal
 	const char *name;
 
 	sym = db_search_symbol(callpc, DB_STGY_ANY, &offset);
+	if (sym != 0 && offset == 0) {
+		sym = db_search_symbol(callpc - 1, DB_STGY_ANY, &offset);
+		offset++;
+	}
 	db_symbol_values(sym, &name, NULL);
 	if (sym == (db_sym_t)0)
 		return (db_sym_t)0;

Index: src/sys/ddb/db_sym.c
diff -u src/sys/ddb/db_sym.c:1.67 src/sys/ddb/db_sym.c:1.68
--- src/sys/ddb/db_sym.c:1.67	Mon Apr 12 02:49:02 2021
+++ src/sys/ddb/db_sym.c	Mon Dec 13 01:25:29 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_sym.c,v 1.67 2021/04/12 02:49:02 mrg Exp $	*/
+/*	$NetBSD: db_sym.c,v 1.68 2021/12/13 01:25:29 chs Exp $	*/
 
 /*
  * Mach Operating System
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_sym.c,v 1.67 2021/04/12 02:49:02 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_sym.c,v 1.68 2021/12/13 01:25:29 chs Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddbparam.h"
@@ -347,6 +347,12 @@ db_symstr(char *buf, size_t buflen, db_e
 	if (ksyms_getname(&mod, &name, (vaddr_t)off,
 	    strategy|KSYMS_CLOSEST) == 0) {
 		(void)ksyms_getval_unlocked(mod, name, NULL, &val, KSYMS_ANY);
+		if (strategy & KSYMS_PROC && val == off) {
+			if (ksyms_getname(&mod, &name, (vaddr_t)off - 1,
+					  strategy|KSYMS_CLOSEST) != 0)
+				goto out;
+			(void)ksyms_getval_unlocked(mod, name, NULL, &val, KSYMS_ANY);
+		}
 		if (((off - val) < db_maxoff) && val) {
 			snprintf(buf, buflen, "%s:%s", mod, name);
 			if (off - val) {
@@ -365,6 +371,7 @@ db_symstr(char *buf, size_t buflen, db_e
 			return;
 		}
 	}
+out:
 	strlcpy(buf, db_num_to_str(off), buflen);
 #endif
 }
@@ -418,6 +425,12 @@ db_printsym(db_expr_t off, db_strategy_t
 	if (ksyms_getname(&mod, &name, (vaddr_t)off,
 	    strategy|KSYMS_CLOSEST) == 0) {
 		(void)ksyms_getval_unlocked(mod, name, NULL, &uval, KSYMS_ANY);
+		if (strategy & KSYMS_PROC && uval == off) {
+			if (ksyms_getname(&mod, &name, (vaddr_t)off - 1,
+					  strategy|KSYMS_CLOSEST) != 0)
+				goto out;
+			(void)ksyms_getval_unlocked(mod, name, NULL, &uval, KSYMS_ANY);
+		}
 		val = (long) uval;
 		if (((off - val) < db_maxoff) && val) {
 			(*pr)("%s:%s", mod, name);
@@ -437,6 +450,7 @@ db_printsym(db_expr_t off, db_strategy_t
 		}
 	}
 #endif
+out:
 	(*pr)("%s", db_num_to_str(off));
 	return;
 }

Reply via email to