From 3dc63949be62474aa625116c0cb77d19ddfc539c Mon Sep 17 00:00:00 2001 From: mpi Date: Mon, 29 May 2017 06:14:10 +0000 Subject: [PATCH] Pass the symbol instead of its name when looking for CTF infos. ok jasper@ --- sys/arch/amd64/amd64/db_trace.c | 11 ++++------- sys/arch/i386/i386/db_trace.c | 11 ++++------- sys/ddb/db_ctf.c | 20 ++++++++++---------- sys/ddb/db_extern.h | 3 +-- sys/ddb/db_sym.h | 4 ++++ 5 files changed, 23 insertions(+), 26 deletions(-) diff --git a/sys/arch/amd64/amd64/db_trace.c b/sys/arch/amd64/amd64/db_trace.c index 7cf1e1828f8..1fac964070a 100644 --- a/sys/arch/amd64/amd64/db_trace.c +++ b/sys/arch/amd64/amd64/db_trace.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_trace.c,v 1.29 2017/05/28 14:24:19 mpi Exp $ */ +/* $OpenBSD: db_trace.c,v 1.30 2017/05/29 06:14:10 mpi Exp $ */ /* $NetBSD: db_trace.c,v 1.1 2003/04/26 18:39:27 fvdl Exp $ */ /* @@ -36,9 +36,6 @@ #include #include -#ifdef DDBCTF -#include -#endif #include #include #include @@ -82,7 +79,7 @@ struct db_variable * db_eregs = db_regs + nitems(db_regs); #define INTERRUPT 3 #define AST 4 -int db_numargs(struct callframe *, const char *); +int db_numargs(struct callframe *, db_sym_t); void db_nextframe(struct callframe **, db_addr_t *, long *, int, int (*) (const char *, ...)); @@ -95,7 +92,7 @@ void db_nextframe(struct callframe **, db_addr_t *, long *, int, * reliably determine the values currently, just return 0. */ int -db_numargs(struct callframe *fp, const char *sym) +db_numargs(struct callframe *fp, db_sym_t sym) { #ifdef DDBCTF int args; @@ -255,7 +252,7 @@ db_stack_trace_print(db_expr_t addr, boolean_t have_addr, db_expr_t count, narg = 0; else { is_trap = NONE; - narg = db_numargs(frame, name); + narg = db_numargs(frame, sym); } (*pr)("%s(", name); diff --git a/sys/arch/i386/i386/db_trace.c b/sys/arch/i386/i386/db_trace.c index 6faee2bb169..7e522d484b3 100644 --- a/sys/arch/i386/i386/db_trace.c +++ b/sys/arch/i386/i386/db_trace.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_trace.c,v 1.26 2017/05/28 14:24:19 mpi Exp $ */ +/* $OpenBSD: db_trace.c,v 1.27 2017/05/29 06:14:10 mpi Exp $ */ /* $NetBSD: db_trace.c,v 1.18 1996/05/03 19:42:01 christos Exp $ */ /* @@ -34,9 +34,6 @@ #include -#ifdef DDBCTF -#include -#endif #include #include #include @@ -77,7 +74,7 @@ struct db_variable *db_eregs = db_regs + nitems(db_regs); #define INTERRUPT 3 #define AST 4 -int db_numargs(struct callframe *, const char *); +int db_numargs(struct callframe *, db_sym_t); void db_nextframe(struct callframe **, db_addr_t *, int *, int, int (*pr)(const char *, ...)); @@ -85,7 +82,7 @@ void db_nextframe(struct callframe **, db_addr_t *, int *, int, * Figure out how many arguments were passed into the frame at "fp". */ int -db_numargs(struct callframe *fp, const char *sym) +db_numargs(struct callframe *fp, db_sym_t sym) { int *argp; int inst; @@ -260,7 +257,7 @@ db_stack_trace_print(db_expr_t addr, boolean_t have_addr, db_expr_t count, narg = 0; else { is_trap = NONE; - narg = db_numargs(frame, name); + narg = db_numargs(frame, sym); } (*pr)("%s(", name); diff --git a/sys/ddb/db_ctf.c b/sys/ddb/db_ctf.c index fa2f04656e1..09809762daa 100644 --- a/sys/ddb/db_ctf.c +++ b/sys/ddb/db_ctf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: db_ctf.c,v 1.8 2017/05/28 14:24:19 mpi Exp $ */ +/* $OpenBSD: db_ctf.c,v 1.9 2017/05/29 06:14:10 mpi Exp $ */ /* * Copyright (c) 2016 Jasper Lievisse Adriaanse @@ -50,7 +50,7 @@ struct ddb_ctf { struct ddb_ctf db_ctf; static const char *db_ctf_lookup_name(uint32_t); -static const char *db_ctf_idx2sym(size_t *, uint8_t); +static Elf_Sym *db_ctf_idx2sym(size_t *, uint8_t); static char *db_ctf_decompress(const char *, size_t, off_t); /* @@ -128,7 +128,7 @@ db_dump_ctf_header(void) * It must be noted this only works if the CTF table has the same order * as the symbol table. */ -static const char * +Elf_Sym * db_ctf_idx2sym(size_t *idx, uint8_t type) { Elf_Sym *symp, *symtab_start, *symtab_end; @@ -142,7 +142,7 @@ db_ctf_idx2sym(size_t *idx, uint8_t type) continue; *idx = i; - return db_ctf.strtab + symp->st_name; + return symp; } return NULL; @@ -152,14 +152,14 @@ db_ctf_idx2sym(size_t *idx, uint8_t type) * For a given function name, return the number of arguments. */ int -db_ctf_func_numargs(const char *funcname) +db_ctf_func_numargs(db_sym_t st) { + Elf_Sym *symp, *stp = (Elf_Sym *)st; uint16_t *fstart, *fend; - const char *fname; uint16_t *fsp, kind, vlen; size_t i, idx = 0; - if (!db_ctf.ctf_found) + if (!db_ctf.ctf_found || stp == NULL) return -1; fstart = (uint16_t *)(db_ctf.data + db_ctf.cth->cth_funcoff); @@ -167,8 +167,8 @@ db_ctf_func_numargs(const char *funcname) fsp = fstart; while (fsp < fend) { - fname = db_ctf_idx2sym(&idx, STT_FUNC); - if (fname == NULL) + symp = db_ctf_idx2sym(&idx, STT_FUNC); + if (symp == NULL) break; kind = CTF_INFO_KIND(*fsp); @@ -185,7 +185,7 @@ db_ctf_func_numargs(const char *funcname) for (i = 0; i < vlen; i++) fsp++; - if (strcmp(funcname, fname) == 0) + if (symp == stp) return vlen; } diff --git a/sys/ddb/db_extern.h b/sys/ddb/db_extern.h index 313542d30ba..42f00ef8dc7 100644 --- a/sys/ddb/db_extern.h +++ b/sys/ddb/db_extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: db_extern.h,v 1.18 2016/09/16 19:13:17 jasper Exp $ */ +/* $OpenBSD: db_extern.h,v 1.19 2017/05/29 06:14:10 mpi Exp $ */ /* $NetBSD: db_extern.h,v 1.1 1996/02/05 01:57:00 christos Exp $ */ /* @@ -60,7 +60,6 @@ int db_prof_enable(void); void db_prof_disable(void); /* db_ctf.c */ -int db_ctf_func_numargs(const char *); void db_ctf_init(void); #endif /* _DDB_DB_EXTERN_H_ */ diff --git a/sys/ddb/db_sym.h b/sys/ddb/db_sym.h index f15f742f443..fc590eeea41 100644 --- a/sys/ddb/db_sym.h +++ b/sys/ddb/db_sym.h @@ -99,4 +99,8 @@ void db_elf_sym_forall(db_forall_func_t db_forall_func, void *); bool db_dwarf_line_at_pc(const char *, size_t, uintptr_t, const char **, const char **, int *); +#ifdef DDBCTF +int db_ctf_func_numargs(db_sym_t); +#endif + #endif /* _DDB_DB_SYM_H_ */ -- 2.20.1