summaryrefslogtreecommitdiff
path: root/sys/ddb
diff options
context:
space:
mode:
authorMichael Shalayeff <mickey@cvs.openbsd.org>1996-05-10 13:58:45 +0000
committerMichael Shalayeff <mickey@cvs.openbsd.org>1996-05-10 13:58:45 +0000
commit2319b3532d3706171dd28861d0758c455fbdf400 (patch)
treed8cfcfc48ae6df645ceb1eb4502908579f55a106 /sys/ddb
parent7afb6a8263f1352e0e6504a2b01051ebee6fcdd4 (diff)
do dynamic symtab allocattion.
Diffstat (limited to 'sys/ddb')
-rw-r--r--sys/ddb/db_aout.c18
-rw-r--r--sys/ddb/db_extern.h14
-rw-r--r--sys/ddb/db_hangman.c4
-rw-r--r--sys/ddb/db_sym.c145
-rw-r--r--sys/ddb/db_sym.h12
5 files changed, 99 insertions, 94 deletions
diff --git a/sys/ddb/db_aout.c b/sys/ddb/db_aout.c
index 667f62f0bb9..edba6dc76fe 100644
--- a/sys/ddb/db_aout.c
+++ b/sys/ddb/db_aout.c
@@ -1,4 +1,4 @@
-/* $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 $ */
/*
@@ -139,14 +139,14 @@ X_db_sym_init(symtab, esymtab, name)
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))
@@ -157,7 +157,7 @@ X_db_isym(stab, i)
db_sym_t
X_db_lookup(stab, symstr)
- db_symtab_t *stab;
+ db_symtab_t stab;
char * symstr;
{
register struct nlist *sp, *ep;
@@ -180,7 +180,7 @@ X_db_lookup(stab, symstr)
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;
@@ -249,7 +249,7 @@ X_db_symbol_values(sym, namep, valuep)
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;
@@ -313,7 +313,7 @@ X_db_line_at_pc(symtab, cursym, filename, linenum, off)
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;
@@ -360,10 +360,14 @@ ddb_init()
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
}
diff --git a/sys/ddb/db_extern.h b/sys/ddb/db_extern.h
index 60a01b927c0..c8dbe2fffcc 100644
--- a/sys/ddb/db_extern.h
+++ b/sys/ddb/db_extern.h
@@ -1,4 +1,4 @@
-/* $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 $ */
/*
@@ -34,16 +34,16 @@
/* 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 */
diff --git a/sys/ddb/db_hangman.c b/sys/ddb/db_hangman.c
index 9c0a330387a..d4b70d4ccac 100644
--- a/sys/ddb/db_hangman.c
+++ b/sys/ddb/db_hangman.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: db_hangman.c,v 1.2 1996/05/07 12:34:37 mickey Exp $ */
+/* $OpenBSD: db_hangman.c,v 1.3 1996/05/10 13:58:43 mickey Exp $ */
/*
* Copyright (c) 1996 Theo de Raadt, Michael Shalayeff
@@ -67,7 +67,7 @@ db_randomsym(lenp)
{
register char *p, *q;
/* choose random symtab */
- register db_symtab_t *stab = db_istab(db_random(db_nsymtabs));
+ register db_symtab_t stab = db_istab(db_random(db_nsymtabs));
/* choose random symbol from the table */
q = db_qualify(X_db_isym(stab, db_random(X_db_nsyms(stab))),stab->name);
diff --git a/sys/ddb/db_sym.c b/sys/ddb/db_sym.c
index bb99d313ba9..983bf32d14c 100644
--- a/sys/ddb/db_sym.c
+++ b/sys/ddb/db_sym.c
@@ -1,4 +1,4 @@
-/* $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 $ */
/*
@@ -29,6 +29,7 @@
#include <sys/param.h>
#include <sys/proc.h>
+#include <sys/malloc.h>
#include <machine/db_machdep.h>
@@ -48,10 +49,20 @@
#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.
@@ -63,24 +74,19 @@ db_add_symbol_table(start, end, name, ref)
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;
}
/*
@@ -90,35 +96,32 @@ void
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;
}
/*
@@ -185,47 +188,46 @@ db_sym_t
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;
}
/*
@@ -239,7 +241,7 @@ db_symbol_is_ambiguous(sym)
db_sym_t sym;
{
char *sym_name;
- register int i;
+ register db_symtab_t st;
register
boolean_t found_once = FALSE;
@@ -247,9 +249,8 @@ db_symbol_is_ambiguous(sym)
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;
@@ -271,17 +272,15 @@ db_search_symbol( val, strategy, offp)
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;
}
diff --git a/sys/ddb/db_sym.h b/sys/ddb/db_sym.h
index b76aeb31353..a1ff4df586e 100644
--- a/sys/ddb/db_sym.h
+++ b/sys/ddb/db_sym.h
@@ -1,4 +1,4 @@
-/* $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 $ */
/*
@@ -33,14 +33,15 @@
/*
* 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 */
/*
@@ -71,12 +72,13 @@ extern boolean_t db_qualify_ambiguous_names;
/*
* 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 */