Index: ddb/db_sym.c =================================================================== RCS file: /cvs/src/sys/ddb/db_sym.c,v retrieving revision 1.54 diff -u -p -r1.54 db_sym.c --- ddb/db_sym.c 7 Nov 2019 13:16:25 -0000 1.54 +++ ddb/db_sym.c 14 Nov 2019 03:13:23 -0000 @@ -133,6 +133,26 @@ db_search_symbol(vaddr_t val, db_strateg unsigned long db_lastsym = (unsigned long)end; unsigned int db_maxoff = 0x10000000; +char * +db_symname(db_expr_t off, db_expr_t *offp, db_strategy_t strategy) +{ + db_expr_t d, value; + Elf_Sym *cursym; + char *name; + + if (off > db_lastsym) + return (NULL); + + cursym = db_search_symbol(off, strategy, &d); + db_symbol_values(cursym, &name, &value); + if (name != NULL && (d < db_maxoff) && value) { + if (offp != NULL) + *offp = d; + return (name); + } + + return (NULL); +} void db_printsym(db_expr_t off, db_strategy_t strategy, @@ -145,7 +165,7 @@ db_printsym(db_expr_t off, db_strategy_t int linenum; Elf_Sym *cursym; char buf[DB_FORMAT_BUF_SIZE]; - + if (off <= db_lastsym) { cursym = db_search_symbol(off, strategy, &d); db_symbol_values(cursym, &name, &value); @@ -165,5 +185,4 @@ db_printsym(db_expr_t off, db_strategy_t } (*pr)("%s", db_format(buf, sizeof(buf), off, DB_FORMAT_N, 1, 0)); - return; } Index: ddb/db_sym.h =================================================================== RCS file: /cvs/src/sys/ddb/db_sym.h,v retrieving revision 1.35 diff -u -p -r1.35 db_sym.h --- ddb/db_sym.h 7 Nov 2019 13:16:25 -0000 1.35 +++ ddb/db_sym.h 14 Nov 2019 03:13:23 -0000 @@ -82,6 +82,7 @@ void db_symbol_values(Elf_Sym *, char ** db_symbol_values(db_search_symbol(val,DB_STGY_XTRN,offp),namep,0) /* ditto, but no locals */ +char *db_symname(db_expr_t, db_expr_t *, db_strategy_t); void db_printsym(db_expr_t, db_strategy_t, int (*)(const char *, ...)); /* print closest symbol to a value */ Index: kern/subr_prf.c =================================================================== RCS file: /cvs/src/sys/kern/subr_prf.c,v retrieving revision 1.99 diff -u -p -r1.99 subr_prf.c --- kern/subr_prf.c 20 Jul 2019 23:06:51 -0000 1.99 +++ kern/subr_prf.c 14 Nov 2019 03:13:23 -0000 @@ -61,8 +61,10 @@ #include #ifdef DDB +#include #include /* db_printf, db_putchar prototypes */ #include /* db_log, db_radix */ +#include /* %P */ #endif @@ -878,6 +880,32 @@ reswitch: switch (ch) { _uquad = UARG(); base = OCT; goto nosign; + case 'P': +#ifdef DDB + { + void *ptr = va_arg(ap, void *); + db_expr_t off; + + cp = db_symname((db_expr_t)ptr, &off, DB_STGY_ANY); + if (cp != NULL) { + while (*cp) + KPRINTF_PUTCHAR(*cp++); + if (off == 0) { + /* no more output */ + continue; + } + KPRINTF_PUTCHAR('+'); + _uquad = (u_long)off; + } else + _uquad = (u_long)ptr; + + base = HEX; + xdigs = "0123456789abcdef"; + flags |= HEXPREFIX; + ch = 'x'; + goto nosign; + } +#endif /* ifdef DDB, otherwise fallthrough to %p */ case 'p': /* * ``The argument shall be a pointer to void. The