summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjasper <jasper@openbsd.org>2017-10-17 19:23:09 +0000
committerjasper <jasper@openbsd.org>2017-10-17 19:23:09 +0000
commitd165a357d09223f05daad75a2c2f09c628cf5b5d (patch)
tree6a970950f047de6456380b097428e8d613ab6673
parentsync (diff)
downloadwireguard-openbsd-d165a357d09223f05daad75a2c2f09c628cf5b5d.tar.xz
wireguard-openbsd-d165a357d09223f05daad75a2c2f09c628cf5b5d.zip
Simplify code that determines the number of arguments for a given function.
For amd64 this means removing db_numargs() and directly setting narg to the correct value (instead of capping it during iteration). On i386 rename db_numargs() to db_i386_numargs() and only call it when we fail to get the correct number out of CTF. discussed with an ok mpi@
-rw-r--r--sys/arch/amd64/amd64/db_trace.c22
-rw-r--r--sys/arch/i386/i386/db_trace.c13
2 files changed, 12 insertions, 23 deletions
diff --git a/sys/arch/amd64/amd64/db_trace.c b/sys/arch/amd64/amd64/db_trace.c
index 8760bd70d20..44a5228bbc3 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.34 2017/08/14 16:32:37 mpi Exp $ */
+/* $OpenBSD: db_trace.c,v 1.35 2017/10/17 19:23:09 jasper Exp $ */
/* $NetBSD: db_trace.c,v 1.1 2003/04/26 18:39:27 fvdl Exp $ */
/*
@@ -79,21 +79,9 @@ struct db_variable * db_eregs = db_regs + nitems(db_regs);
#define INTERRUPT 3
#define AST 4
-int db_numargs(struct callframe *, Elf_Sym *);
void db_nextframe(struct callframe **, db_addr_t *, long *, int,
int (*) (const char *, ...));
-int
-db_numargs(struct callframe *fp, Elf_Sym *sym)
-{
- int args;
-
- if ((args = db_ctf_func_numargs(sym)) != -1)
- return args;
-
- return 6;
-}
-
/*
* Figure out the next frame up in the call stack.
* For trap(), we print the address of the faulting instruction and
@@ -243,14 +231,16 @@ 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, sym);
+ narg = db_ctf_func_numargs(sym);
+ if (narg < 0 || narg > 6)
+ narg = 6;
}
(*pr)("%s(", name);
if (lastframe == 0 && offset == 0 && !have_addr) {
/* We have a breakpoint before the frame is set up */
- for (i = 0; i < min(6, narg); i++) {
+ for (i = 0; i < narg; i++) {
(*pr)("%lx", *db_reg_args[i]);
if (--narg != 0)
(*pr)(",");
@@ -261,7 +251,7 @@ db_stack_trace_print(db_expr_t addr, boolean_t have_addr, db_expr_t count,
&((struct callframe *)(ddb_regs.tf_rsp-8))->f_arg0;
} else {
argp = (unsigned long *)frame;
- for (i = min(6, narg); i > 0; i--) {
+ for (i = narg; i > 0; i--) {
argp--;
(*pr)("%lx", db_get_value((db_addr_t)argp,
sizeof(*argp), FALSE));
diff --git a/sys/arch/i386/i386/db_trace.c b/sys/arch/i386/i386/db_trace.c
index f65102128a2..2389c9e26df 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.29 2017/08/11 20:50:15 mpi Exp $ */
+/* $OpenBSD: db_trace.c,v 1.30 2017/10/17 19:23:09 jasper Exp $ */
/* $NetBSD: db_trace.c,v 1.18 1996/05/03 19:42:01 christos Exp $ */
/*
@@ -74,7 +74,7 @@ struct db_variable *db_eregs = db_regs + nitems(db_regs);
#define INTERRUPT 3
#define AST 4
-int db_numargs(struct callframe *, Elf_Sym *);
+int db_i386_numargs(struct callframe *);
void db_nextframe(struct callframe **, db_addr_t *, int *, int,
int (*pr)(const char *, ...));
@@ -82,16 +82,13 @@ 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, Elf_Sym *sym)
+db_i386_numargs(struct callframe *fp)
{
int *argp;
int inst;
int args;
extern char etext[];
- if ((args = db_ctf_func_numargs(sym)) != -1)
- return args;
-
argp = (int *)db_get_value((int)&fp->f_retaddr, 4, FALSE);
if (argp < (int *)VM_MIN_KERNEL_ADDRESS || argp > (int *)etext) {
args = 5;
@@ -255,7 +252,9 @@ 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, sym);
+ narg = db_ctf_func_numargs(sym);
+ if (narg < 0)
+ narg = db_i386_numargs(frame);
}
(*pr)("%s(", name);