Source-Changes-HG archive

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

[src/trunk]: src/sys/ddb ddb: fix function names of "noreturn" functions in s...



details:   https://anonhg.NetBSD.org/src/rev/e0fe801c7259
branches:  trunk
changeset: 1027603:e0fe801c7259
user:      chs <chs%NetBSD.org@localhost>
date:      Mon Dec 13 01:25:29 2021 +0000

description:
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.

diffstat:

 sys/arch/amd64/amd64/db_machdep.c |   8 ++++++--
 sys/arch/i386/i386/db_machdep.c   |   8 ++++++--
 sys/ddb/db_sym.c                  |  18 ++++++++++++++++--
 3 files changed, 28 insertions(+), 6 deletions(-)

diffs (118 lines):

diff -r 1778142411e8 -r e0fe801c7259 sys/arch/amd64/amd64/db_machdep.c
--- a/sys/arch/amd64/amd64/db_machdep.c Mon Dec 13 01:00:10 2021 +0000
+++ b/sys/arch/amd64/amd64/db_machdep.c Mon Dec 13 01:25:29 2021 +0000
@@ -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 @@
        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;
diff -r 1778142411e8 -r e0fe801c7259 sys/arch/i386/i386/db_machdep.c
--- a/sys/arch/i386/i386/db_machdep.c   Mon Dec 13 01:00:10 2021 +0000
+++ b/sys/arch/i386/i386/db_machdep.c   Mon Dec 13 01:25:29 2021 +0000
@@ -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 @@
        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;
diff -r 1778142411e8 -r e0fe801c7259 sys/ddb/db_sym.c
--- a/sys/ddb/db_sym.c  Mon Dec 13 01:00:10 2021 +0000
+++ b/sys/ddb/db_sym.c  Mon Dec 13 01:25:29 2021 +0000
@@ -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 @@
        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 @@
                        return;
                }
        }
+out:
        strlcpy(buf, db_num_to_str(off), buflen);
 #endif
 }
@@ -418,6 +425,12 @@
        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 @@
                }
        }
 #endif
+out:
        (*pr)("%s", db_num_to_str(off));
        return;
 }



Home | Main Index | Thread Index | Old Index