2022-08-31 01:38:01 +03:00
|
|
|
/* $NetBSD: db_sym.c,v 1.71 2022/08/30 22:38:01 riastradh Exp $ */
|
1994-06-29 10:29:24 +04:00
|
|
|
|
2002-02-15 10:33:48 +03:00
|
|
|
/*
|
1993-03-21 12:45:37 +03:00
|
|
|
* Mach Operating System
|
|
|
|
* Copyright (c) 1991,1990 Carnegie Mellon University
|
|
|
|
* All Rights Reserved.
|
2002-02-15 10:33:48 +03:00
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
* Permission to use, copy, modify and distribute this software and its
|
|
|
|
* documentation is hereby granted, provided that both the copyright
|
|
|
|
* notice and this permission notice appear in all copies of the
|
|
|
|
* software, derivative works or modified versions, and any portions
|
|
|
|
* thereof, and that both notices appear in supporting documentation.
|
2002-02-15 10:33:48 +03:00
|
|
|
*
|
1999-04-13 00:38:17 +04:00
|
|
|
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
|
1993-03-21 12:45:37 +03:00
|
|
|
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
|
|
|
|
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
2002-02-15 10:33:48 +03:00
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
* Carnegie Mellon requests users of this software to return to
|
2002-02-15 10:33:48 +03:00
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
|
|
|
* School of Computer Science
|
|
|
|
* Carnegie Mellon University
|
|
|
|
* Pittsburgh PA 15213-3890
|
2002-02-15 10:33:48 +03:00
|
|
|
*
|
1993-03-21 12:45:37 +03:00
|
|
|
* any improvements or extensions that they make and grant Carnegie the
|
|
|
|
* rights to redistribute these changes.
|
|
|
|
*/
|
1993-08-02 21:48:44 +04:00
|
|
|
|
2001-11-13 01:54:03 +03:00
|
|
|
#include <sys/cdefs.h>
|
2022-08-31 01:38:01 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: db_sym.c,v 1.71 2022/08/30 22:38:01 riastradh Exp $");
|
2001-11-13 01:54:03 +03:00
|
|
|
|
2009-03-08 01:02:16 +03:00
|
|
|
#ifdef _KERNEL_OPT
|
2002-11-04 09:24:38 +03:00
|
|
|
#include "opt_ddbparam.h"
|
2009-03-08 01:02:16 +03:00
|
|
|
#endif
|
2001-06-13 10:01:44 +04:00
|
|
|
|
1993-12-18 07:46:25 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/proc.h>
|
1998-12-04 23:18:05 +03:00
|
|
|
#include <sys/systm.h>
|
2003-04-25 00:00:48 +04:00
|
|
|
#include <sys/ksyms.h>
|
2022-08-31 01:38:01 +03:00
|
|
|
#include <sys/pserialize.h>
|
1993-12-18 07:46:25 +03:00
|
|
|
|
2009-03-08 01:02:16 +03:00
|
|
|
#include <ddb/ddb.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2003-04-25 00:00:48 +04:00
|
|
|
static void db_symsplit(char *, char **, char **);
|
2002-02-15 10:33:48 +03:00
|
|
|
|
1998-12-04 23:18:05 +03:00
|
|
|
|
2011-04-11 08:22:30 +04:00
|
|
|
#ifndef _KERNEL
|
2003-04-25 00:00:48 +04:00
|
|
|
#define TBLNAME "netbsd"
|
1998-12-04 23:18:05 +03:00
|
|
|
|
2011-04-11 08:26:18 +04:00
|
|
|
#define use_ksyms 0
|
|
|
|
|
1998-12-04 23:18:05 +03:00
|
|
|
const db_symformat_t *db_symformat;
|
2003-04-25 00:00:48 +04:00
|
|
|
static db_forall_func_t db_sift;
|
2009-03-08 01:02:16 +03:00
|
|
|
extern db_symformat_t db_symformat_elf;
|
2003-04-25 00:00:48 +04:00
|
|
|
#endif
|
1998-12-04 23:18:05 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the kernel debugger by initializing the master symbol
|
|
|
|
* table. Note that if initializing the master symbol table fails,
|
|
|
|
* no other symbol tables can be loaded.
|
|
|
|
*/
|
|
|
|
void
|
2002-02-15 10:33:48 +03:00
|
|
|
ddb_init(int symsize, void *vss, void *vse)
|
1998-12-04 23:18:05 +03:00
|
|
|
{
|
2009-03-08 01:02:16 +03:00
|
|
|
#ifdef _KERNEL
|
2008-11-30 21:21:31 +03:00
|
|
|
ksyms_addsyms_elf(symsize, vss, vse); /* Will complain if necessary */
|
2009-03-08 01:02:16 +03:00
|
|
|
#else /* _KERNEL */
|
|
|
|
db_symformat = &db_symformat_elf;
|
2011-04-11 08:26:18 +04:00
|
|
|
if ((*db_symformat->sym_init)(symsize, vss, vse, TBLNAME) != true)
|
|
|
|
printf("sym_init failed");
|
2009-03-08 01:02:16 +03:00
|
|
|
#endif /* _KERNEL */
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2007-02-22 01:59:35 +03:00
|
|
|
bool
|
2005-05-30 01:31:05 +04:00
|
|
|
db_eqname(const char *src, const char *dst, int c)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2002-02-15 10:33:48 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
if (!strcmp(src, dst))
|
2007-02-22 09:34:42 +03:00
|
|
|
return (true);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (src[0] == c)
|
2002-02-15 10:33:48 +03:00
|
|
|
return (!strcmp(src+1,dst));
|
2007-02-22 09:34:42 +03:00
|
|
|
return (false);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2007-02-22 01:59:35 +03:00
|
|
|
bool
|
2005-05-30 01:31:05 +04:00
|
|
|
db_value_of_name(const char *name, db_expr_t *valuep)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2005-05-30 01:31:05 +04:00
|
|
|
char symbol[128];
|
2003-04-25 00:00:48 +04:00
|
|
|
char *mod, *sym;
|
2009-03-08 01:02:16 +03:00
|
|
|
#ifdef _KERNEL
|
2003-10-05 15:17:47 +04:00
|
|
|
unsigned long uval;
|
|
|
|
long val;
|
2009-03-08 01:02:16 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2011-04-11 08:22:30 +04:00
|
|
|
#ifndef _KERNEL
|
|
|
|
if (!use_ksyms) {
|
|
|
|
db_sym_t ssym;
|
2003-04-25 00:00:48 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Cannot load symtabs in a.out kernels, so the ':'
|
|
|
|
* style of selecting modules is irrelevant.
|
|
|
|
*/
|
|
|
|
ssym = (*db_symformat->sym_lookup)(NULL, name);
|
|
|
|
if (ssym == DB_SYM_NULL)
|
2007-02-22 09:34:42 +03:00
|
|
|
return (false);
|
2003-04-25 00:00:48 +04:00
|
|
|
db_symbol_values(ssym, &name, valuep);
|
2007-02-22 09:34:42 +03:00
|
|
|
return (true);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2003-04-25 00:00:48 +04:00
|
|
|
#endif
|
2011-04-11 08:22:30 +04:00
|
|
|
|
2005-05-30 01:31:05 +04:00
|
|
|
(void)strlcpy(symbol, name, sizeof(symbol));
|
|
|
|
db_symsplit(symbol, &mod, &sym);
|
2009-03-08 01:02:16 +03:00
|
|
|
#ifdef _KERNEL
|
2017-11-03 12:59:07 +03:00
|
|
|
if (ksyms_getval_unlocked(mod, sym, NULL, &uval, KSYMS_EXTERN) == 0) {
|
2003-10-05 15:17:47 +04:00
|
|
|
val = (long) uval;
|
2003-05-17 13:48:05 +04:00
|
|
|
*valuep = (db_expr_t)val;
|
2007-02-22 09:34:42 +03:00
|
|
|
return true;
|
2003-05-17 13:48:05 +04:00
|
|
|
}
|
2017-11-03 12:59:07 +03:00
|
|
|
if (ksyms_getval_unlocked(mod, sym, NULL, &uval, KSYMS_ANY) == 0) {
|
2003-10-05 15:17:47 +04:00
|
|
|
val = (long) uval;
|
2003-05-17 13:48:05 +04:00
|
|
|
*valuep = (db_expr_t)val;
|
2007-02-22 09:34:42 +03:00
|
|
|
return true;
|
2003-05-17 13:48:05 +04:00
|
|
|
}
|
2009-03-08 01:02:16 +03:00
|
|
|
#endif
|
2007-02-22 09:34:42 +03:00
|
|
|
return false;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2011-04-11 08:22:30 +04:00
|
|
|
#ifndef _KERNEL
|
2000-05-22 18:49:10 +04:00
|
|
|
/* Private structure for passing args to db_sift() from db_sifting(). */
|
|
|
|
struct db_sift_args {
|
|
|
|
char *symstr;
|
|
|
|
int mode;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Does the work of db_sifting(), called once for each
|
2003-04-25 00:00:48 +04:00
|
|
|
* symbol via db_forall(), prints out symbols matching
|
2000-05-22 18:49:10 +04:00
|
|
|
* criteria.
|
|
|
|
*/
|
|
|
|
static void
|
2006-11-16 04:32:37 +03:00
|
|
|
db_sift(db_symtab_t *stab, db_sym_t sym, char *name,
|
|
|
|
char *suffix, int prefix, void *arg)
|
2000-05-22 18:49:10 +04:00
|
|
|
{
|
|
|
|
char c, sc;
|
|
|
|
char *find, *p;
|
|
|
|
size_t len;
|
|
|
|
struct db_sift_args *dsa;
|
|
|
|
|
|
|
|
dsa = (struct db_sift_args*)arg;
|
|
|
|
|
|
|
|
find = dsa->symstr; /* String we're looking for. */
|
|
|
|
p = name; /* String we're searching within. */
|
2002-02-15 10:33:48 +03:00
|
|
|
|
2000-05-22 18:49:10 +04:00
|
|
|
/* Matching algorithm cribbed from strstr(), which is not
|
|
|
|
in the kernel. */
|
|
|
|
if ((c = *find++) != 0) {
|
|
|
|
len = strlen(find);
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
if ((sc = *p++) == 0)
|
|
|
|
return;
|
|
|
|
} while (sc != c);
|
|
|
|
} while (strncmp(p, find, len) != 0);
|
|
|
|
}
|
|
|
|
if (dsa->mode=='F') /* ala ls -F */
|
|
|
|
db_printf("%s%s ", name, suffix);
|
|
|
|
else
|
|
|
|
db_printf("%s ", name);
|
|
|
|
}
|
2003-04-25 00:00:48 +04:00
|
|
|
#endif
|
2000-05-22 18:49:10 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* "Sift" for a partial symbol.
|
|
|
|
* Named for the Sun OpenPROM command ("sifting").
|
|
|
|
* If the symbol has a qualifier (e.g., ux:vm_map),
|
|
|
|
* then only the specified symbol table will be searched;
|
|
|
|
* otherwise, all symbol tables will be searched..
|
|
|
|
*
|
|
|
|
* "mode" is how-to-display, set from modifiers.
|
|
|
|
*/
|
|
|
|
void
|
2002-02-15 10:33:48 +03:00
|
|
|
db_sifting(char *symstr, int mode)
|
2000-05-22 18:49:10 +04:00
|
|
|
{
|
2009-03-08 01:02:16 +03:00
|
|
|
#ifdef _KERNEL
|
2003-04-25 00:00:48 +04:00
|
|
|
char *mod, *sym;
|
2009-03-08 01:02:16 +03:00
|
|
|
#endif
|
2003-04-25 00:00:48 +04:00
|
|
|
|
2011-04-11 08:22:30 +04:00
|
|
|
#ifndef _KERNEL
|
2000-05-22 18:49:10 +04:00
|
|
|
struct db_sift_args dsa;
|
|
|
|
|
2011-04-11 08:22:30 +04:00
|
|
|
if (!use_ksyms) {
|
2003-04-25 00:00:48 +04:00
|
|
|
dsa.symstr = symstr;
|
|
|
|
dsa.mode = mode;
|
|
|
|
(*db_symformat->sym_forall)(NULL, db_sift, &dsa);
|
|
|
|
db_printf("\n");
|
|
|
|
return;
|
2000-05-22 18:49:10 +04:00
|
|
|
}
|
2003-04-25 00:00:48 +04:00
|
|
|
#endif
|
2000-05-22 18:49:10 +04:00
|
|
|
|
2009-03-08 01:02:16 +03:00
|
|
|
#ifdef _KERNEL
|
2003-04-25 00:00:48 +04:00
|
|
|
db_symsplit(symstr, &mod, &sym);
|
|
|
|
if (ksyms_sift(mod, sym, mode) == ENODEV)
|
|
|
|
db_error("invalid symbol table name");
|
2009-03-08 01:02:16 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the closest symbol to val, and return its name
|
|
|
|
* and the difference between val and the symbol found.
|
|
|
|
*/
|
|
|
|
db_sym_t
|
2002-02-15 10:33:48 +03:00
|
|
|
db_search_symbol(db_addr_t val, db_strategy_t strategy, db_expr_t *offp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2003-04-25 00:00:48 +04:00
|
|
|
unsigned int diff;
|
|
|
|
db_sym_t ret = DB_SYM_NULL;
|
2009-03-08 01:02:16 +03:00
|
|
|
#ifdef _KERNEL
|
|
|
|
unsigned long naddr;
|
2003-05-11 12:23:22 +04:00
|
|
|
const char *mod;
|
2005-05-30 01:31:05 +04:00
|
|
|
const char *sym;
|
2009-03-08 01:02:16 +03:00
|
|
|
#endif
|
2003-04-25 00:00:48 +04:00
|
|
|
|
2011-04-11 08:22:30 +04:00
|
|
|
#ifndef _KERNEL
|
|
|
|
if (!use_ksyms) {
|
|
|
|
db_expr_t newdiff;
|
|
|
|
db_sym_t ssym;
|
2003-04-25 00:00:48 +04:00
|
|
|
|
2021-04-12 05:49:02 +03:00
|
|
|
diff = ~0u;
|
|
|
|
newdiff = ~0;
|
2003-04-25 00:00:48 +04:00
|
|
|
ssym = (*db_symformat->sym_search)
|
|
|
|
(NULL, val, strategy, &newdiff);
|
2002-11-10 06:22:28 +03:00
|
|
|
if ((unsigned int) newdiff < diff) {
|
2002-02-15 10:33:48 +03:00
|
|
|
diff = newdiff;
|
2003-04-25 00:00:48 +04:00
|
|
|
ret = ssym;
|
2002-02-15 10:33:48 +03:00
|
|
|
}
|
2003-04-25 00:00:48 +04:00
|
|
|
*offp = diff;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-03-08 01:02:16 +03:00
|
|
|
#ifdef _KERNEL
|
2003-05-17 13:48:05 +04:00
|
|
|
if (ksyms_getname(&mod, &sym, (vaddr_t)val, strategy) == 0) {
|
2017-11-03 12:59:07 +03:00
|
|
|
(void)ksyms_getval_unlocked(mod, sym, NULL, &naddr, KSYMS_ANY);
|
2003-05-17 13:48:05 +04:00
|
|
|
diff = val - (db_addr_t)naddr;
|
|
|
|
ret = (db_sym_t)naddr;
|
2003-10-25 12:48:11 +04:00
|
|
|
} else
|
2009-03-08 01:02:16 +03:00
|
|
|
#endif
|
2003-10-25 12:48:11 +04:00
|
|
|
diff = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
*offp = diff;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return name and value of a symbol
|
|
|
|
*/
|
|
|
|
void
|
2005-05-30 01:31:05 +04:00
|
|
|
db_symbol_values(db_sym_t sym, const char **namep, db_expr_t *valuep)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2009-03-08 01:02:16 +03:00
|
|
|
#ifdef _KERNEL
|
2003-05-11 12:23:22 +04:00
|
|
|
const char *mod;
|
2009-03-08 01:02:16 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
if (sym == DB_SYM_NULL) {
|
|
|
|
*namep = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-11 08:22:30 +04:00
|
|
|
#ifndef _KERNEL
|
|
|
|
if (!use_ksyms) {
|
2003-04-25 00:00:48 +04:00
|
|
|
db_expr_t value;
|
2011-04-11 08:22:30 +04:00
|
|
|
|
2003-04-25 00:00:48 +04:00
|
|
|
(*db_symformat->sym_value)(NULL, sym, namep, &value);
|
|
|
|
if (valuep)
|
|
|
|
*valuep = value;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2009-03-08 01:02:16 +03:00
|
|
|
#ifdef _KERNEL
|
2003-05-17 13:48:05 +04:00
|
|
|
if (ksyms_getname(&mod, namep, (vaddr_t)sym,
|
|
|
|
KSYMS_ANY|KSYMS_EXACT) == 0) {
|
2003-04-25 00:00:48 +04:00
|
|
|
if (valuep)
|
|
|
|
*valuep = sym;
|
|
|
|
} else
|
2009-03-08 01:02:16 +03:00
|
|
|
#endif
|
2003-04-25 00:00:48 +04:00
|
|
|
*namep = NULL;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print a the closest symbol to value
|
|
|
|
*
|
|
|
|
* After matching the symbol according to the given strategy
|
|
|
|
* we print it in the name+offset format, provided the symbol's
|
|
|
|
* value is close enough (eg smaller than db_maxoff).
|
|
|
|
* We also attempt to print [filename:linenum] when applicable
|
|
|
|
* (eg for procedure names).
|
|
|
|
*
|
|
|
|
* If we could not find a reasonable name+offset representation,
|
|
|
|
* then we just print the value in hex. Small values might get
|
|
|
|
* bogus symbol associations, e.g. 3 might get some absolute
|
|
|
|
* value like _INCLUDE_VERSION or something, therefore we do
|
|
|
|
* not accept symbols whose value is zero (and use plain hex).
|
|
|
|
*/
|
2005-01-17 02:38:47 +03:00
|
|
|
unsigned int db_maxoff = 0x100000;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2002-01-05 23:09:52 +03:00
|
|
|
void
|
2003-05-16 19:02:08 +04:00
|
|
|
db_symstr(char *buf, size_t buflen, db_expr_t off, db_strategy_t strategy)
|
2002-01-05 23:09:52 +03:00
|
|
|
{
|
2005-05-30 01:31:05 +04:00
|
|
|
const char *name;
|
2009-03-08 01:02:16 +03:00
|
|
|
#ifdef _KERNEL
|
2003-05-11 12:23:22 +04:00
|
|
|
const char *mod;
|
2003-09-03 14:45:10 +04:00
|
|
|
unsigned long val;
|
2009-03-08 01:02:16 +03:00
|
|
|
#endif
|
2003-04-28 19:55:45 +04:00
|
|
|
|
2011-04-11 08:22:30 +04:00
|
|
|
#ifndef _KERNEL
|
|
|
|
if (!use_ksyms) {
|
2003-04-28 19:55:45 +04:00
|
|
|
db_expr_t d;
|
|
|
|
char *filename;
|
|
|
|
db_expr_t value;
|
|
|
|
int linenum;
|
|
|
|
db_sym_t cursym;
|
|
|
|
|
2012-02-09 04:21:23 +04:00
|
|
|
cursym = db_search_symbol(off, strategy, &d);
|
|
|
|
db_symbol_values(cursym, &name, &value);
|
2012-02-09 21:07:07 +04:00
|
|
|
if (name != NULL && ((unsigned int)d < db_maxoff) &&
|
2012-02-09 04:21:23 +04:00
|
|
|
value != 0) {
|
|
|
|
strlcpy(buf, name, buflen);
|
|
|
|
if (d) {
|
|
|
|
strlcat(buf, "+", buflen);
|
2012-02-09 21:07:07 +04:00
|
|
|
db_format_radix(buf + strlen(buf), 24, d, true);
|
2012-02-09 04:21:23 +04:00
|
|
|
}
|
|
|
|
if (strategy == DB_STGY_PROC) {
|
|
|
|
if ((*db_symformat->sym_line_at_pc)
|
2012-02-09 21:07:07 +04:00
|
|
|
(NULL, cursym, &filename, &linenum, off)) {
|
|
|
|
size_t len = strlen(buf);
|
|
|
|
snprintf(buf + len, buflen - len,
|
|
|
|
" [%s:%d]", filename, linenum);
|
|
|
|
}
|
2003-04-28 19:55:45 +04:00
|
|
|
}
|
2012-02-09 04:21:23 +04:00
|
|
|
return;
|
2003-04-28 19:55:45 +04:00
|
|
|
}
|
2003-05-16 19:02:08 +04:00
|
|
|
strlcpy(buf, db_num_to_str(off), buflen);
|
2003-04-28 19:55:45 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2009-03-08 01:02:16 +03:00
|
|
|
#ifdef _KERNEL
|
2022-08-31 01:38:01 +03:00
|
|
|
const int s = pserialize_read_enter();
|
2003-05-17 13:48:05 +04:00
|
|
|
if (ksyms_getname(&mod, &name, (vaddr_t)off,
|
|
|
|
strategy|KSYMS_CLOSEST) == 0) {
|
2017-11-03 12:59:07 +03:00
|
|
|
(void)ksyms_getval_unlocked(mod, name, NULL, &val, KSYMS_ANY);
|
2021-12-13 04:25:29 +03:00
|
|
|
if (strategy & KSYMS_PROC && val == off) {
|
|
|
|
if (ksyms_getname(&mod, &name, (vaddr_t)off - 1,
|
|
|
|
strategy|KSYMS_CLOSEST) != 0)
|
2022-08-31 01:38:01 +03:00
|
|
|
goto hex_fallback;
|
2021-12-13 04:25:29 +03:00
|
|
|
(void)ksyms_getval_unlocked(mod, name, NULL, &val, KSYMS_ANY);
|
|
|
|
}
|
2003-04-28 19:55:45 +04:00
|
|
|
if (((off - val) < db_maxoff) && val) {
|
2004-04-21 22:40:37 +04:00
|
|
|
snprintf(buf, buflen, "%s:%s", mod, name);
|
2003-04-28 19:55:45 +04:00
|
|
|
if (off - val) {
|
2003-05-16 19:02:08 +04:00
|
|
|
strlcat(buf, "+", buflen);
|
2003-04-28 19:55:45 +04:00
|
|
|
db_format_radix(buf+strlen(buf),
|
2007-02-22 09:34:42 +03:00
|
|
|
24, off - val, true);
|
2002-01-05 23:09:52 +03:00
|
|
|
}
|
2003-04-28 19:55:45 +04:00
|
|
|
#ifdef notyet
|
|
|
|
if (strategy & KSYMS_PROC) {
|
2004-04-21 22:40:37 +04:00
|
|
|
if (ksyms_fmaddr(off, &filename, &linenum) == 0)
|
|
|
|
snprintf(buf + strlen(buf),
|
|
|
|
buflen - strlen(buf),
|
2002-01-05 23:09:52 +03:00
|
|
|
" [%s:%d]", filename, linenum);
|
|
|
|
}
|
2003-04-28 19:55:45 +04:00
|
|
|
#endif
|
2022-08-31 01:38:01 +03:00
|
|
|
goto out;
|
2002-01-05 23:09:52 +03:00
|
|
|
}
|
|
|
|
}
|
2022-08-31 01:38:01 +03:00
|
|
|
hex_fallback:
|
2022-08-31 01:37:36 +03:00
|
|
|
db_num_to_strbuf(off, buf, buflen);
|
2022-08-31 01:38:01 +03:00
|
|
|
out: pserialize_read_exit(s);
|
2009-03-08 01:02:16 +03:00
|
|
|
#endif
|
2002-01-05 23:09:52 +03:00
|
|
|
}
|
1995-05-25 00:21:00 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
void
|
2002-02-15 10:33:48 +03:00
|
|
|
db_printsym(db_expr_t off, db_strategy_t strategy,
|
|
|
|
void (*pr)(const char *, ...))
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2005-05-30 01:31:05 +04:00
|
|
|
const char *name;
|
2009-03-08 01:02:16 +03:00
|
|
|
#ifdef _KERNEL
|
2003-05-11 12:23:22 +04:00
|
|
|
const char *mod;
|
2003-10-05 15:17:47 +04:00
|
|
|
unsigned long uval;
|
|
|
|
long val;
|
2009-03-08 01:02:16 +03:00
|
|
|
#endif
|
2003-04-25 00:00:48 +04:00
|
|
|
#ifdef notyet
|
|
|
|
char *filename;
|
|
|
|
int linenum;
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2011-04-11 08:22:30 +04:00
|
|
|
#ifndef _KERNEL
|
|
|
|
if (!use_ksyms) {
|
2003-04-25 00:00:48 +04:00
|
|
|
db_expr_t d;
|
|
|
|
char *filename;
|
|
|
|
db_expr_t value;
|
|
|
|
int linenum;
|
|
|
|
db_sym_t cursym;
|
2011-04-11 08:22:30 +04:00
|
|
|
|
2012-02-09 04:21:23 +04:00
|
|
|
cursym = db_search_symbol(off, strategy, &d);
|
|
|
|
db_symbol_values(cursym, &name, &value);
|
2012-02-09 21:07:07 +04:00
|
|
|
if (name != NULL && ((unsigned int)d < db_maxoff) &&
|
2012-02-09 04:21:23 +04:00
|
|
|
value != 0) {
|
|
|
|
(*pr)("%s", name);
|
|
|
|
if (d) {
|
|
|
|
char tbuf[24];
|
|
|
|
|
|
|
|
db_format_radix(tbuf, 24, d, true);
|
|
|
|
(*pr)("+%s", tbuf);
|
2003-04-25 00:00:48 +04:00
|
|
|
}
|
2012-02-09 04:21:23 +04:00
|
|
|
if (strategy == DB_STGY_PROC) {
|
|
|
|
if ((*db_symformat->sym_line_at_pc)
|
2012-02-09 21:07:07 +04:00
|
|
|
(NULL, cursym, &filename, &linenum, off))
|
|
|
|
(*pr)(" [%s:%d]", filename, linenum);
|
2012-02-09 04:21:23 +04:00
|
|
|
}
|
|
|
|
return;
|
2003-04-25 00:00:48 +04:00
|
|
|
}
|
2012-02-10 06:14:04 +04:00
|
|
|
(*pr)("%s", db_num_to_str(off));
|
2003-04-25 00:00:48 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2009-03-08 01:02:16 +03:00
|
|
|
#ifdef _KERNEL
|
2003-05-17 13:48:05 +04:00
|
|
|
if (ksyms_getname(&mod, &name, (vaddr_t)off,
|
|
|
|
strategy|KSYMS_CLOSEST) == 0) {
|
2017-11-03 12:59:07 +03:00
|
|
|
(void)ksyms_getval_unlocked(mod, name, NULL, &uval, KSYMS_ANY);
|
2021-12-13 04:25:29 +03:00
|
|
|
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);
|
|
|
|
}
|
2003-10-05 15:17:47 +04:00
|
|
|
val = (long) uval;
|
2003-04-25 00:00:48 +04:00
|
|
|
if (((off - val) < db_maxoff) && val) {
|
|
|
|
(*pr)("%s:%s", mod, name);
|
|
|
|
if (off - val) {
|
2000-08-09 23:51:44 +04:00
|
|
|
char tbuf[24];
|
|
|
|
|
2007-02-22 09:34:42 +03:00
|
|
|
db_format_radix(tbuf, 24, off - val, true);
|
2000-08-12 02:50:47 +04:00
|
|
|
(*pr)("+%s", tbuf);
|
2000-08-09 23:51:44 +04:00
|
|
|
}
|
2003-04-25 00:00:48 +04:00
|
|
|
#ifdef notyet
|
|
|
|
if (strategy & KSYMS_PROC) {
|
|
|
|
if (ksyms_fmaddr(off, &filename, &linenum) == 0)
|
2000-05-25 23:57:30 +04:00
|
|
|
(*pr)(" [%s:%d]", filename, linenum);
|
1995-05-25 00:21:00 +04:00
|
|
|
}
|
2003-04-25 00:00:48 +04:00
|
|
|
#endif
|
1995-05-25 00:21:00 +04:00
|
|
|
return;
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2021-12-13 06:17:50 +03:00
|
|
|
out:;
|
2009-03-08 01:02:16 +03:00
|
|
|
#endif
|
2012-02-10 06:14:04 +04:00
|
|
|
(*pr)("%s", db_num_to_str(off));
|
1995-05-25 00:21:00 +04:00
|
|
|
return;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2003-04-25 00:00:48 +04:00
|
|
|
/*
|
|
|
|
* Splits a string in the form "mod:sym" to two strings.
|
|
|
|
*/
|
2002-02-15 10:33:48 +03:00
|
|
|
static void
|
2003-04-25 00:00:48 +04:00
|
|
|
db_symsplit(char *str, char **mod, char **sym)
|
2000-05-22 18:49:10 +04:00
|
|
|
{
|
2003-04-25 00:00:48 +04:00
|
|
|
char *cp;
|
2002-02-15 10:33:48 +03:00
|
|
|
|
2003-04-25 00:00:48 +04:00
|
|
|
if ((cp = strchr(str, ':')) != NULL) {
|
|
|
|
*cp++ = '\0';
|
|
|
|
*mod = str;
|
|
|
|
*sym = cp;
|
|
|
|
} else {
|
|
|
|
*mod = NULL;
|
|
|
|
*sym = str;
|
|
|
|
}
|
2000-05-22 18:49:10 +04:00
|
|
|
}
|
2003-04-25 01:18:34 +04:00
|
|
|
|
2007-02-22 01:59:35 +03:00
|
|
|
bool
|
2003-04-25 01:18:34 +04:00
|
|
|
db_sym_numargs(db_sym_t cursym, int *nargp, char **argnamep)
|
|
|
|
{
|
2011-04-11 08:22:30 +04:00
|
|
|
#ifndef _KERNEL
|
|
|
|
if (!use_ksyms)
|
2003-04-25 01:18:34 +04:00
|
|
|
return ((*db_symformat->sym_numargs)(NULL, cursym, nargp,
|
|
|
|
argnamep));
|
|
|
|
#endif
|
2007-02-22 09:34:42 +03:00
|
|
|
return (false);
|
2005-02-27 01:58:54 +03:00
|
|
|
}
|
2003-04-25 01:18:34 +04:00
|
|
|
|