diff options
author | 2016-01-27 10:37:12 +0000 | |
---|---|---|
committer | 2016-01-27 10:37:12 +0000 | |
commit | fbc22d8d061d6c4a927bc48e14b5db60dc18c486 (patch) | |
tree | b9f5b158513cea0c76f9c87c28ab67c796a0ad81 | |
parent | sync (diff) | |
download | wireguard-openbsd-fbc22d8d061d6c4a927bc48e14b5db60dc18c486.tar.xz wireguard-openbsd-fbc22d8d061d6c4a927bc48e14b5db60dc18c486.zip |
Removes the abstraction layer to support multiple executable binaries.
Simplifies the API to manipulate symbols now that all our architectures
are ELF.
ok tb@
-rw-r--r-- | sys/ddb/db_elf.c | 49 | ||||
-rw-r--r-- | sys/ddb/db_hangman.c | 6 | ||||
-rw-r--r-- | sys/ddb/db_sym.c | 128 | ||||
-rw-r--r-- | sys/ddb/db_sym.h | 33 |
4 files changed, 27 insertions, 189 deletions
diff --git a/sys/ddb/db_elf.c b/sys/ddb/db_elf.c index 92fa255e352..1a158f41768 100644 --- a/sys/ddb/db_elf.c +++ b/sys/ddb/db_elf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_elf.c,v 1.15 2016/01/25 14:56:03 mpi Exp $ */ +/* $OpenBSD: db_elf.c,v 1.16 2016/01/27 10:37:12 mpi Exp $ */ /* $NetBSD: db_elf.c,v 1.13 2000/07/07 21:55:18 jhawk Exp $ */ /*- @@ -53,30 +53,6 @@ static char *db_elf_find_linetab(db_symtab_t *, size_t *); #define STAB_TO_EHDR(stab) ((Elf_Ehdr *)((stab)->private)) #define STAB_TO_SHDR(stab, e) ((Elf_Shdr *)((stab)->private + (e)->e_shoff)) -boolean_t db_elf_sym_init(int, void *, void *, const char *); -db_sym_t db_elf_lookup(db_symtab_t *, char *); -db_sym_t db_elf_search_symbol(db_symtab_t *, db_addr_t, - db_strategy_t, db_expr_t *); -void db_elf_symbol_values(db_symtab_t *, db_sym_t, - char **, db_expr_t *); -boolean_t db_elf_line_at_pc(db_symtab_t *, db_sym_t, - char **, int *, db_expr_t); -boolean_t db_elf_sym_numargs(db_symtab_t *, db_sym_t, int *, - char **); -void db_elf_forall(db_symtab_t *, - db_forall_func_t db_forall_func, void *); - -db_symformat_t db_symformat_elf = { - "ELF", - db_elf_sym_init, - db_elf_lookup, - db_elf_search_symbol, - db_elf_symbol_values, - db_elf_line_at_pc, - db_elf_sym_numargs, - db_elf_forall -}; - /* * Find the symbol table and strings; tell ddb about them. * @@ -261,7 +237,7 @@ db_elf_find_linetab(db_symtab_t *stab, size_t *size) * Lookup the symbol with the given name. */ db_sym_t -db_elf_lookup(db_symtab_t *stab, char *symstr) +db_elf_sym_lookup(db_symtab_t *stab, char *symstr) { Elf_Sym *symp, *symtab_start, *symtab_end; char *strtab; @@ -287,7 +263,7 @@ db_elf_lookup(db_symtab_t *stab, char *symstr) * provided threshold). */ db_sym_t -db_elf_search_symbol(db_symtab_t *symtab, db_addr_t off, db_strategy_t strategy, +db_elf_sym_search(db_symtab_t *symtab, db_addr_t off, db_strategy_t strategy, db_expr_t *diffp) { Elf_Sym *rsymp, *symp, *symtab_start, *symtab_end; @@ -350,7 +326,7 @@ db_elf_search_symbol(db_symtab_t *symtab, db_addr_t off, db_strategy_t strategy, * Return the name and value for a symbol. */ void -db_elf_symbol_values(db_symtab_t *symtab, db_sym_t sym, char **namep, +db_elf_sym_values(db_symtab_t *symtab, db_sym_t sym, char **namep, db_expr_t *valuep) { Elf_Sym *symp = (Elf_Sym *)sym; @@ -396,23 +372,8 @@ db_elf_line_at_pc(db_symtab_t *symtab, db_sym_t cursym, char **filename, return (TRUE); } -/* - * Returns the number of arguments to a function and their - * names if we can find the appropriate debugging symbol. - */ -boolean_t -db_elf_sym_numargs(db_symtab_t *symtab, db_sym_t cursym, int *nargp, - char **argnamep) -{ - - /* - * XXX We don't support this (yet). - */ - return (FALSE); -} - void -db_elf_forall(db_symtab_t *stab, db_forall_func_t db_forall_func, void *arg) +db_elf_sym_forall(db_symtab_t *stab, db_forall_func_t db_forall_func, void *arg) { char *strtab; static char suffix[2]; diff --git a/sys/ddb/db_hangman.c b/sys/ddb/db_hangman.c index bcdad460abc..d8d6f3f6646 100644 --- a/sys/ddb/db_hangman.c +++ b/sys/ddb/db_hangman.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_hangman.c,v 1.32 2015/03/14 03:38:46 jsg Exp $ */ +/* $OpenBSD: db_hangman.c,v 1.33 2016/01/27 10:37:12 mpi Exp $ */ /* * Copyright (c) 1996 Theo de Raadt, Michael Shalayeff @@ -103,14 +103,14 @@ db_randomsym(size_t *lenp) stab = &db_symtabs[arc4random_uniform(nsymtabs)]; dfa.cnt = 0; - X_db_forall(stab, db_hang_forall, &dfa); + db_elf_sym_forall(stab, db_hang_forall, &dfa); nsyms = -dfa.cnt; if (nsyms == 0) return (NULL); dfa.cnt = arc4random_uniform(nsyms); - X_db_forall(stab, db_hang_forall, &dfa); + db_elf_sym_forall(stab, db_hang_forall, &dfa); q = db_qualify(dfa.sym, stab->name); diff --git a/sys/ddb/db_sym.c b/sys/ddb/db_sym.c index 855d9a1c1d5..c72bdb14414 100644 --- a/sys/ddb/db_sym.c +++ b/sys/ddb/db_sym.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_sym.c,v 1.42 2016/01/27 08:03:37 mpi Exp $ */ +/* $OpenBSD: db_sym.c,v 1.43 2016/01/27 10:37:12 mpi Exp $ */ /* $NetBSD: db_sym.c,v 1.24 2000/08/11 22:50:47 tv Exp $ */ /* @@ -55,27 +55,6 @@ db_symtab_t *db_last_symtab; extern char end[]; /* - * Put the most picky symbol table formats at the top! - */ -const db_symformat_t *db_symformats[] = { - &db_symformat_elf, - NULL, -}; - -const db_symformat_t *db_symformat; - -boolean_t X_db_sym_init(int, void *, void *, const char *); -db_sym_t X_db_lookup(db_symtab_t *, char *); -db_sym_t X_db_search_symbol(db_symtab_t *, db_addr_t, - db_strategy_t, db_expr_t *); -void X_db_symbol_values(db_symtab_t *, db_sym_t, char **, - db_expr_t *); -boolean_t X_db_line_at_pc(db_symtab_t *, db_sym_t, char **, - int *, db_expr_t); -int X_db_sym_numargs(db_symtab_t *, db_sym_t, int *, - char **); - -/* * 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. @@ -83,7 +62,6 @@ int X_db_sym_numargs(db_symtab_t *, db_sym_t, int *, void ddb_init(void) { - const db_symformat_t **symf; const char *name = "bsd"; extern char *esym; #if defined(__sparc64__) || defined(__mips__) || defined(__amd64__) || \ @@ -109,15 +87,12 @@ ddb_init(void) return; } - if (xesym != NULL && xesym != xssym) - for (symf = db_symformats; *symf != NULL; symf++) { - db_symformat = *symf; - if (X_db_sym_init((vaddr_t)xesym - (vaddr_t)xssym, - xssym, xesym, name) == TRUE) + if (xesym != NULL && xesym != xssym) { + if (db_elf_sym_init((vaddr_t)xesym - (vaddr_t)xssym, xssym, + xesym, name) == TRUE) return; - } + } - db_symformat = NULL; printf("[ no symbol table formats found ]\n"); } @@ -261,7 +236,7 @@ db_lookup(char *symstr) */ for (i = symtab_start; i < symtab_end; i++) { if (db_symtabs[i].name && - (sp = X_db_lookup(&db_symtabs[i], symstr))) { + (sp = db_elf_sym_lookup(&db_symtabs[i], symstr))) { db_last_symtab = &db_symtabs[i]; return sp; } @@ -288,7 +263,7 @@ db_symbol_is_ambiguous(db_sym_t sym) 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)) { + db_elf_sym_lookup(&db_symtabs[i], sym_name)) { if (found_once) return TRUE; found_once = TRUE; @@ -314,7 +289,7 @@ db_search_symbol(db_addr_t val, db_strategy_t strategy, db_expr_t *offp) for (i = 0; i < MAXNOSYMTABS; i++) { if (!db_symtabs[i].name) continue; - sym = X_db_search_symbol(&db_symtabs[i], val, strategy, &newdiff); + sym = db_elf_sym_search(&db_symtabs[i], val, strategy, &newdiff); if (newdiff < diff) { db_last_symtab = &db_symtabs[i]; diff = newdiff; @@ -338,7 +313,7 @@ db_symbol_values(db_sym_t sym, char **namep, db_expr_t *valuep) return; } - X_db_symbol_values(db_last_symtab, sym, namep, &value); + db_elf_sym_values(db_last_symtab, sym, namep, &value); if (db_symbol_is_ambiguous(sym)) *namep = db_qualify(sym, db_last_symtab->name); @@ -390,8 +365,9 @@ db_printsym(db_expr_t off, db_strategy_t strategy, (*pr)("+%s", db_format(buf, sizeof(buf), d, DB_FORMAT_R, 1, 0)); } - if (strategy == DB_STGY_PROC) { - if (db_line_at_pc(cursym, &filename, &linenum, off)) + if (strategy != DB_STGY_PROC) { + if (db_elf_line_at_pc(db_last_symtab, cursym, + &filename, &linenum, off)) (*pr)(" [%s:%d]", filename, linenum); } return; @@ -401,83 +377,3 @@ db_printsym(db_expr_t off, db_strategy_t strategy, (*pr)("%s", db_format(buf, sizeof(buf), off, DB_FORMAT_N, 1, 0)); return; } - - -boolean_t -db_line_at_pc(db_sym_t sym, char **filename, int *linenum, db_expr_t pc) -{ - return X_db_line_at_pc(db_last_symtab, sym, filename, linenum, pc); -} - -int -db_sym_numargs(db_sym_t sym, int *nargp, char **argnames) -{ - return X_db_sym_numargs(db_last_symtab, sym, nargp, argnames); -} - -boolean_t -X_db_sym_init(int symsize, void *vss, void *vse, const char *name) -{ - - if (db_symformat != NULL) - return ((*db_symformat->sym_init)(symsize, vss, vse, name)); - return (FALSE); -} - -db_sym_t -X_db_lookup(db_symtab_t *stab, char *symstr) -{ - - if (db_symformat != NULL) - return ((*db_symformat->sym_lookup)(stab, symstr)); - return ((db_sym_t)0); -} - -db_sym_t -X_db_search_symbol(db_symtab_t *stab, db_addr_t off, db_strategy_t strategy, - db_expr_t *diffp) -{ - - if (db_symformat != NULL) - return ((*db_symformat->sym_search)(stab, off, strategy, - diffp)); - return ((db_sym_t)0); -} - -void -X_db_symbol_values(db_symtab_t *stab, db_sym_t sym, char **namep, - db_expr_t *valuep) -{ - - if (db_symformat != NULL) - (*db_symformat->sym_value)(stab, sym, namep, valuep); -} - -boolean_t -X_db_line_at_pc(db_symtab_t *stab, db_sym_t cursym, char **filename, - int *linenum, db_expr_t off) -{ - - if (db_symformat != NULL) - return ((*db_symformat->sym_line_at_pc)(stab, cursym, - filename, linenum, off)); - return (FALSE); -} - -boolean_t -X_db_sym_numargs(db_symtab_t *stab, db_sym_t cursym, int *nargp, - char **argnamep) -{ - - if (db_symformat != NULL) - return ((*db_symformat->sym_numargs)(stab, cursym, nargp, - argnamep)); - return (FALSE); -} - -void -X_db_forall(db_symtab_t *stab, db_forall_func_t db_forall_func, void *arg) -{ - if (db_symformat != NULL) - (*db_symformat->sym_forall)(stab, db_forall_func, arg); -} diff --git a/sys/ddb/db_sym.h b/sys/ddb/db_sym.h index 1a3e8f50e6a..66f1d8defaf 100644 --- a/sys/ddb/db_sym.h +++ b/sys/ddb/db_sym.h @@ -74,29 +74,6 @@ typedef int db_strategy_t; /* search strategy */ */ typedef void (db_forall_func_t)(db_symtab_t *, db_sym_t, char *, char *, int, void *); -void X_db_forall(db_symtab_t *, - db_forall_func_t db_forall_func, void *); - -/* - * A symbol table may be in one of many formats. All symbol tables - * must be of the same format as the master kernel symbol table. - */ -typedef struct { - const char *sym_format; - boolean_t (*sym_init)(int, void *, void *, const char *); - db_sym_t (*sym_lookup)(db_symtab_t *, char *); - db_sym_t (*sym_search)(db_symtab_t *, db_addr_t, db_strategy_t, - db_expr_t *); - void (*sym_value)(db_symtab_t *, db_sym_t, char **, - db_expr_t *); - boolean_t (*sym_line_at_pc)(db_symtab_t *, db_sym_t, - char **, int *, db_expr_t); - boolean_t (*sym_numargs)(db_symtab_t *, db_sym_t, int *, - char **); - void (*sym_forall)(db_symtab_t *, - db_forall_func_t *db_forall_func, void *); -} db_symformat_t; - extern boolean_t db_qualify_ambiguous_names; /* if TRUE, check across symbol tables * for multiple occurrences of a name. @@ -139,9 +116,13 @@ void db_symbol_values(db_sym_t, char **, db_expr_t *); void db_printsym(db_expr_t, db_strategy_t, int (*)(const char *, ...)); /* print closest symbol to a value */ -boolean_t db_line_at_pc(db_sym_t, char **, int *, db_expr_t); +#define db_sym_numargs(sym, nargp, argnames) (FALSE) -int db_sym_numargs(db_sym_t, int *, char **); char *db_qualify(db_sym_t, const char *); -extern db_symformat_t db_symformat_elf; +boolean_t db_elf_sym_init(int, void *, void *, const char *); +db_sym_t db_elf_sym_lookup(db_symtab_t *, char *); +void db_elf_sym_values(db_symtab_t *, db_sym_t, char **, db_expr_t *); +db_sym_t db_elf_sym_search(db_symtab_t *, db_addr_t, db_strategy_t, db_expr_t *); +boolean_t db_elf_line_at_pc(db_symtab_t *, db_sym_t, char **, int *, db_expr_t); +void db_elf_sym_forall(db_symtab_t *, db_forall_func_t db_forall_func, void *); |