-/* $OpenBSD: db_aout.c,v 1.7 1996/05/05 12:23:06 mickey Exp $ */
+/* $OpenBSD: db_aout.c,v 1.8 1996/05/10 13:58:43 mickey Exp $ */
/* $NetBSD: db_aout.c,v 1.14 1996/02/27 20:54:43 gwr Exp $ */
/*
size_t
X_db_nsyms(stab)
- db_symtab_t *stab;
+ db_symtab_t stab;
{
return (struct nlist *)stab->end - (struct nlist *)stab->start;
}
db_sym_t
X_db_isym(stab, i)
- db_symtab_t *stab;
+ db_symtab_t stab;
size_t i;
{
if (i >= X_db_nsyms(stab))
db_sym_t
X_db_lookup(stab, symstr)
- db_symtab_t *stab;
+ db_symtab_t stab;
char * symstr;
{
register struct nlist *sp, *ep;
db_sym_t
X_db_search_symbol(symtab, off, strategy, diffp)
- db_symtab_t * symtab;
+ db_symtab_t symtab;
register
db_addr_t off;
db_strategy_t strategy;
boolean_t
X_db_line_at_pc(symtab, cursym, filename, linenum, off)
- db_symtab_t * symtab;
+ db_symtab_t symtab;
db_sym_t cursym;
char **filename;
int *linenum;
boolean_t
X_db_sym_numargs(symtab, cursym, nargp, argnamep)
- db_symtab_t * symtab;
+ db_symtab_t symtab;
db_sym_t cursym;
int *nargp;
char **argnamep;
extern char *esym;
extern int end;
+ db_sym_init();
+
if (esym > (char *)&end) {
X_db_sym_init((int *)&end, esym, "bsd");
}
#else
+ db_sym_init();
+
X_db_sym_init (db_symtab, 0, "bsd");
#endif
}
-/* $OpenBSD: db_extern.h,v 1.3 1996/05/05 12:23:11 mickey Exp $ */
+/* $OpenBSD: db_extern.h,v 1.4 1996/05/10 13:58:43 mickey Exp $ */
/* $NetBSD: db_extern.h,v 1.1 1996/02/05 01:57:00 christos Exp $ */
/*
/* db_aout.c */
void X_db_sym_init __P((int *, char *, char *));
-size_t X_db_nsyms __P((db_symtab_t *));
-db_sym_t X_db_isym __P((db_symtab_t *, size_t));
-db_sym_t X_db_lookup __P((db_symtab_t *, char *));
-db_sym_t X_db_search_symbol __P((db_symtab_t *, db_addr_t, db_strategy_t,
+size_t X_db_nsyms __P((db_symtab_t));
+db_sym_t X_db_isym __P((db_symtab_t, size_t));
+db_sym_t X_db_lookup __P((db_symtab_t, char *));
+db_sym_t X_db_search_symbol __P((db_symtab_t, db_addr_t, db_strategy_t,
db_expr_t *));
void X_db_symbol_values __P((db_sym_t, char **, db_expr_t *));
void db_printsym __P((db_expr_t, db_strategy_t));
-boolean_t X_db_line_at_pc __P((db_symtab_t *, db_sym_t, char **,
+boolean_t X_db_line_at_pc __P((db_symtab_t, db_sym_t, char **,
int *, db_expr_t));
-int X_db_sym_numargs __P((db_symtab_t *, db_sym_t, int *, char **));
+int X_db_sym_numargs __P((db_symtab_t, db_sym_t, int *, char **));
void ddb_init __P((void));
/* db_examine.c */
-/* $OpenBSD: db_sym.c,v 1.8 1996/05/05 12:23:18 mickey Exp $ */
+/* $OpenBSD: db_sym.c,v 1.9 1996/05/10 13:58:44 mickey Exp $ */
/* $NetBSD: db_sym.c,v 1.12 1996/02/05 01:57:15 christos Exp $ */
/*
#include <sys/param.h>
#include <sys/proc.h>
+#include <sys/malloc.h>
#include <machine/db_machdep.h>
#define MAXNOSYMTABS MAXLKMS+1 /* Room for kernel + LKM's */
#endif
-db_symtab_t db_symtabs[MAXNOSYMTABS] = {{0,},};
-size_t db_nsymtabs = 0;
+static TAILQ_HEAD(, db_symtab) db_symtabs;
+static struct db_symtab db_sym_kernel;
+size_t db_nsymtabs = 0;
-db_symtab_t *db_last_symtab;
+db_symtab_t db_last_symtab;
+
+/*
+ * Init sym module
+ */
+void
+db_sym_init(void)
+{
+ TAILQ_INIT(&db_symtabs);
+}
/*
* Add symbol table, with given name, to list of symbol tables.
char *name;
char *ref;
{
- int slot;
+ db_symtab_t new = db_nsymtabs? NULL : &db_sym_kernel;
- for (slot = 0; slot < MAXNOSYMTABS; slot++) {
- if (db_symtabs[slot].name == NULL)
- break;
- }
- if (slot >= MAXNOSYMTABS) {
- db_printf("No slots left for %s symbol table", name);
- return(-1);
- }
+ if (new == NULL &&
+ (new = malloc(sizeof(*new), M_DEVBUF, M_WAITOK)) == NULL)
+ return -1;
- db_symtabs[slot].start = start;
- db_symtabs[slot].end = end;
- db_symtabs[slot].name = name;
- db_symtabs[slot].private = ref;
- db_nsymtabs++;
+ new->start = start;
+ new->end = end;
+ new->name = name;
+ new->private = ref;
+ TAILQ_INSERT_TAIL(&db_symtabs, new, list);
- return(slot);
+ return ++db_nsymtabs;
}
/*
db_del_symbol_table(name)
char *name;
{
- int slot;
+ db_symtab_t p;
- for (slot = 0; slot < MAXNOSYMTABS; slot++) {
- if (db_symtabs[slot].name &&
- ! strcmp(db_symtabs[slot].name, name))
+ for (p = db_symtabs.tqh_first; p != NULL; p = p->list.tqe_next)
+ if (!strcmp(name, p->name))
break;
- }
- if (slot >= MAXNOSYMTABS) {
- db_printf("Unable to find symbol table slot for %s.", name);
- return;
- }
- db_nsymtabs--;
- db_symtabs[slot].start = 0;
- db_symtabs[slot].end = 0;
- db_symtabs[slot].name = 0;
- db_symtabs[slot].private = 0;
+ if (p == NULL)
+ db_printf("ddb: %s symbol table was not allocated", name);
+
+ if (--db_nsymtabs == 0)
+ panic("ddb: kernel symtab delete");
+
+ TAILQ_REMOVE(&db_symtabs, p, list);
+ free(p, M_DEVBUF);
}
-db_symtab_t *
+db_symtab_t
db_istab(i)
size_t i;
{
- register db_symtab_t *stab;
+ register db_symtab_t p;
+
+ for (p = db_symtabs.tqh_first; i && p != NULL ; p = p->list.tqe_next)
+ i--;
- for (stab = db_symtabs; i ; stab++)
- if (stab->name != NULL)
- i--;
- return stab;
+ return i? NULL : p;
}
/*
db_lookup(symstr)
char *symstr;
{
- db_sym_t sp;
- register int i;
- int symtab_start = 0;
- int symtab_end = MAXNOSYMTABS;
- register char *cp;
+ db_symtab_t st = NULL;
+ db_sym_t sp = NULL;
+ register char *cp;
/*
* Look for, remove, and remember any symbol table specifier.
*/
- for (cp = symstr; *cp; cp++) {
+ for (cp = symstr; *cp; cp++)
if (*cp == ':') {
*cp = '\0';
- for (i = 0; i < MAXNOSYMTABS; i++) {
- if (db_symtabs[i].name &&
- ! strcmp(symstr, db_symtabs[i].name)) {
- symtab_start = i;
- symtab_end = i + 1;
+ for (st = db_symtabs.tqh_first;
+ st != NULL;
+ st = st->list.tqe_next)
+ if (!strcmp(symstr, st->name))
break;
- }
- }
*cp = ':';
- if (i == MAXNOSYMTABS) {
+ if (st == NULL) {
db_error("invalid symbol table name");
- /*NOTREACHED*/
+ /* NOTREACHED */
}
symstr = cp+1;
}
- }
/*
* Look in the specified set of symbol tables.
* Return on first match.
*/
- for (i = symtab_start; i < symtab_end; i++) {
- if (db_symtabs[i].name &&
- (sp = X_db_lookup(&db_symtabs[i], symstr))) {
- db_last_symtab = &db_symtabs[i];
- return sp;
- }
- }
- return 0;
+ if (st != NULL)
+ sp = X_db_lookup(st, symstr);
+ else
+ for (st = db_symtabs.tqh_first;
+ st != NULL;
+ st = st->list.tqe_next)
+ if ((sp = X_db_lookup(st, symstr)) != NULL)
+ break;
+
+ if (sp != NULL && st != NULL)
+ db_last_symtab = st;
+
+ return sp;
}
/*
db_sym_t sym;
{
char *sym_name;
- register int i;
+ register db_symtab_t st;
register
boolean_t found_once = FALSE;
return FALSE;
db_symbol_values(sym, &sym_name, 0);
- for (i = 0; i < MAXNOSYMTABS; i++) {
- if (db_symtabs[i].name &&
- X_db_lookup(&db_symtabs[i], sym_name)) {
+ for (st = db_symtabs.tqh_first; st != NULL; st = st->list.tqe_next) {
+ if (X_db_lookup(st, sym_name) != NULL) {
if (found_once)
return TRUE;
found_once = TRUE;
register
unsigned int diff;
unsigned int newdiff;
- register int i;
+ db_symtab_t st;
db_sym_t ret = DB_SYM_NULL, sym;
newdiff = diff = ~0;
db_last_symtab = 0;
- for (i = 0; i < MAXNOSYMTABS; i++) {
- if (!db_symtabs[i].name)
- continue;
- sym = X_db_search_symbol(&db_symtabs[i], val, strategy, &newdiff);
+ for (st = db_symtabs.tqh_first; st != NULL; st = st->list.tqe_next) {
+ sym = X_db_search_symbol(st, val, strategy, &newdiff);
if (newdiff < diff) {
- db_last_symtab = &db_symtabs[i];
+ db_last_symtab = st;
diff = newdiff;
ret = sym;
}
-/* $OpenBSD: db_sym.h,v 1.5 1996/05/05 12:23:19 mickey Exp $ */
+/* $OpenBSD: db_sym.h,v 1.6 1996/05/10 13:58:44 mickey Exp $ */
/* $NetBSD: db_sym.h,v 1.7 1996/02/05 01:57:16 christos Exp $ */
/*
/*
* This module can handle multiple symbol tables
*/
-typedef struct {
+typedef struct db_symtab {
+ TAILQ_ENTRY(db_symtab) list; /* all the tabs */
char *name; /* symtab name */
char *start; /* symtab location */
char *end;
char *private; /* optional machdep pointer */
-} db_symtab_t;
+} *db_symtab_t;
-extern db_symtab_t *db_last_symtab; /* where last symbol was found */
+extern db_symtab_t db_last_symtab; /* where last symbol was found */
extern size_t db_nsymtabs; /* number of symbol tables */
/*
/*
* Functions exported by the symtable module
*/
+void db_sym_init __P((void));
int db_add_symbol_table __P((char *, char *, char *, char *));
/* extend the list of symbol tables */
void db_del_symbol_table __P((char *));
/* remove a symbol table from list */
-db_symtab_t *db_istab __P((size_t));
+db_symtab_t db_istab __P((size_t));
boolean_t db_eqname __P((char *, char *, int));
/* strcmp, modulo leading char */