diff options
-rw-r--r-- | sys/ddb/db_ctf.c | 70 |
1 files changed, 31 insertions, 39 deletions
diff --git a/sys/ddb/db_ctf.c b/sys/ddb/db_ctf.c index ac56698106d..16369771d71 100644 --- a/sys/ddb/db_ctf.c +++ b/sys/ddb/db_ctf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_ctf.c,v 1.3 2016/09/17 17:45:37 jasper Exp $ */ +/* $OpenBSD: db_ctf.c,v 1.4 2016/09/18 13:31:12 jasper Exp $ */ /* * Copyright (c) 2016 Jasper Lievisse Adriaanse <jasper@openbsd.org> @@ -49,12 +49,21 @@ struct ddb_ctf { struct ddb_ctf db_ctf; +/* + * We need a way to get the number of symbols, so (ab)use db_elf_sym_forall() + * to give us the count. + */ +struct db_ctf_forall_arg { + int cnt; + db_sym_t sym; +}; + static const char *db_ctf_lookup_name(unsigned int); static const char *db_ctf_idx2sym(size_t *, unsigned char); static const char *db_elf_find_ctftab(db_symtab_t *, size_t *); static char *db_ctf_decompress(const char *, size_t, off_t); static int db_ctf_print_functions(); -static int db_ctf_nsyms(void); +static void db_ctf_forall(db_sym_t, char *, char *, int, void *); /* * Entrypoint to verify CTF presence, initialize the header, decompress @@ -63,6 +72,7 @@ static int db_ctf_nsyms(void); void db_ctf_init(void) { + struct db_ctf_forall_arg dfa; db_symtab_t *stab = &db_symtab; const char *ctftab; size_t ctftab_size; @@ -93,8 +103,16 @@ db_ctf_init(void) return; } - /* Lookup the total number of kernel symbols. */ - if ((nsyms = db_ctf_nsyms()) == 0) + /* + * Lookup the total number of kernel symbols. It's unlikely for the + * kernel to have zero symbols so bail out if that's what we end + * up finding. + */ + dfa.cnt = 0; + db_elf_sym_forall(db_ctf_forall, &dfa); + nsyms = -dfa.cnt; + + if (nsyms == 0) return; else db_ctf.nsyms = nsyms; @@ -103,6 +121,15 @@ db_ctf_init(void) db_ctf.ctf_found = 1; } +static void +db_ctf_forall(db_sym_t sym, char *name, char *suff, int pre, void *varg) +{ + struct db_ctf_forall_arg *arg = varg; + + if (arg->cnt-- == 0) + arg->sym = sym; +} + /* * Internal helper function - return a pointer to the CTF table * for the current symbol table (and update the size). @@ -157,41 +184,6 @@ db_dump_ctf_header(void) #if 1 db_ctf_print_functions(); #endif - return; -} - -/* - * We need a way to get the number of symbols, so (ab)use db_elf_sym_forall() - * to give us the count. - */ -struct db_ctf_forall_arg { - int cnt; - db_sym_t sym; -}; - -static void db_ctf_forall(db_sym_t, char *, char *, int, void *); - -static void -db_ctf_forall(db_sym_t sym, char *name, char *suff, int pre, void *varg) -{ - struct db_ctf_forall_arg *arg = varg; - - if (arg->cnt-- == 0) - arg->sym = sym; -} - -static int -db_ctf_nsyms(void) -{ - int nsyms; - struct db_ctf_forall_arg dfa; - - dfa.cnt = 0; - db_elf_sym_forall(db_ctf_forall, &dfa); - nsyms = -dfa.cnt; - - /* The caller must make sure to handle zero symbols. */ - return nsyms; } /* |