Module Name: src Committed By: maxv Date: Sun Feb 11 08:27:18 UTC 2018
Modified Files: src/sys/arch/amd64/amd64: db_machdep.c src/sys/arch/i386/i386: db_machdep.c src/sys/arch/x86/x86: db_trace.c Log Message: Style, and reduce the diff between i386 and amd64. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/sys/arch/amd64/amd64/db_machdep.c cvs rdiff -u -r1.6 -r1.7 src/sys/arch/i386/i386/db_machdep.c cvs rdiff -u -r1.3 -r1.4 src/sys/arch/x86/x86/db_trace.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/amd64/amd64/db_machdep.c diff -u src/sys/arch/amd64/amd64/db_machdep.c:1.4 src/sys/arch/amd64/amd64/db_machdep.c:1.5 --- src/sys/arch/amd64/amd64/db_machdep.c:1.4 Wed Oct 3 17:43:22 2012 +++ src/sys/arch/amd64/amd64/db_machdep.c Sun Feb 11 08:27:18 2018 @@ -1,32 +1,32 @@ -/* $NetBSD: db_machdep.c,v 1.4 2012/10/03 17:43:22 riastradh Exp $ */ +/* $NetBSD: db_machdep.c,v 1.5 2018/02/11 08:27:18 maxv Exp $ */ -/* +/* * Mach Operating System * Copyright (c) 1991,1990 Carnegie Mellon University * All Rights Reserved. - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. - * + * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * + * * Carnegie Mellon requests users of this software to return to - * + * * Software Distribution Coordinator or software.distribut...@cs.cmu.edu * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 - * + * * any improvements or extensions that they make and grant Carnegie the * rights to redistribute these changes. */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.4 2012/10/03 17:43:22 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.5 2018/02/11 08:27:18 maxv Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -79,7 +79,7 @@ const struct db_variable db_regs[] = { { "ss", dbreg(ss), db_x86_regop, NULL }, }; const struct db_variable * const db_eregs = - db_regs + sizeof(db_regs)/sizeof(db_regs[0]); + db_regs + sizeof(db_regs)/sizeof(db_regs[0]); /* * Figure out how many arguments were passed into the frame at "fp". @@ -93,19 +93,19 @@ db_numargs(long *retaddrp) return 0; } -/* - * Figure out the next frame up in the call stack. - * For trap(), we print the address of the faulting instruction and +/* + * Figure out the next frame up in the call stack. + * For trap(), we print the address of the faulting instruction and * proceed with the calling frame. We return the ip that faulted. * If the trap was caused by jumping through a bogus pointer, then - * the next line in the backtrace will list some random function as - * being called. It should get the argument list correct, though. + * the next line in the backtrace will list some random function as + * being called. It should get the argument list correct, though. * It might be possible to dig out from the next frame up the name * of the function that faulted, but that could get hairy. */ int db_nextframe(long **nextframe, long **retaddr, long **arg0, db_addr_t *ip, - long *argp, int is_trap, void (*pr)(const char *, ...)) + long *argp, int is_trap, void (*pr)(const char *, ...)) { struct trapframe *tf; struct x86_64_frame *fp; @@ -189,10 +189,10 @@ db_nextframe(long **nextframe, long **re db_sym_t db_frame_info(long *frame, db_addr_t callpc, const char **namep, - db_expr_t *offp, int *is_trap, int *nargp) + db_expr_t *offp, int *is_trap, int *nargp) { - db_expr_t offset; - db_sym_t sym; + db_expr_t offset; + db_sym_t sym; int narg; const char *name; Index: src/sys/arch/i386/i386/db_machdep.c diff -u src/sys/arch/i386/i386/db_machdep.c:1.6 src/sys/arch/i386/i386/db_machdep.c:1.7 --- src/sys/arch/i386/i386/db_machdep.c:1.6 Tue Aug 15 06:39:37 2017 +++ src/sys/arch/i386/i386/db_machdep.c Sun Feb 11 08:27:18 2018 @@ -1,33 +1,33 @@ -/* $NetBSD: db_machdep.c,v 1.6 2017/08/15 06:39:37 maxv Exp $ */ +/* $NetBSD: db_machdep.c,v 1.7 2018/02/11 08:27:18 maxv Exp $ */ -/* +/* * Mach Operating System * Copyright (c) 1991,1990 Carnegie Mellon University * All Rights Reserved. - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. - * + * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * + * * Carnegie Mellon requests users of this software to return to - * + * * Software Distribution Coordinator or software.distribut...@cs.cmu.edu * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 - * + * * any improvements or extensions that they make and grant Carnegie the * rights to redistribute these changes. */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.6 2017/08/15 06:39:37 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.7 2018/02/11 08:27:18 maxv Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -61,6 +61,9 @@ __KERNEL_RCSID(0, "$NetBSD: db_machdep.c #define dbreg(xx) (long *)offsetof(db_regs_t, tf_ ## xx) +/* + * Machine register set. + */ const struct db_variable db_regs[] = { { "ds", dbreg(ds), db_x86_regop, NULL }, { "es", dbreg(es), db_x86_regop, NULL }, @@ -108,85 +111,19 @@ db_numargs(long *retaddrp) return (args); } -db_sym_t -db_frame_info(long *frame, db_addr_t callpc, const char **namep, db_expr_t *offp, - int *is_trap, int *nargp) -{ - db_expr_t offset; - db_sym_t sym; - int narg; - const char *name; - - sym = db_search_symbol(callpc, DB_STGY_ANY, &offset); - db_symbol_values(sym, &name, NULL); - if (sym == (db_sym_t)0) - return (db_sym_t)0; - - *is_trap = NONE; - narg = MAXNARG; - - if (INKERNEL((int)frame) && name) { - /* - * XXX traps should be based off of the Xtrap* - * locations rather than on trap, since some traps - * (e.g., npxdna) don't go through trap() - */ - if (!strcmp(name, "trap_tss")) { - *is_trap = TRAP_TSS; - narg = 0; - } else if (!strcmp(name, "trap")) { - *is_trap = TRAP; - narg = 0; - } else if (!strcmp(name, "syscall")) { - *is_trap = SYSCALL; - narg = 0; - } else if (name[0] == 'X') { - if (!strncmp(name, "Xintr", 5) || - !strncmp(name, "Xresume", 7) || - !strncmp(name, "Xstray", 6) || - !strncmp(name, "Xhold", 5) || - !strncmp(name, "Xrecurse", 8) || - !strcmp(name, "Xdoreti")) { - *is_trap = INTERRUPT; - narg = 0; - } else if (!strcmp(name, "Xsoftintr")) { - *is_trap = SOFTINTR; - narg = 0; - } else if (!strncmp(name, "Xtss_", 5)) { - *is_trap = INTERRUPT_TSS; - narg = 0; - } - } - } - - if (offp != NULL) - *offp = offset; - if (nargp != NULL) - *nargp = narg; - if (namep != NULL) - *namep = name; - return sym; -} - -/* - * Figure out the next frame up in the call stack. - * For trap(), we print the address of the faulting instruction and +/* + * Figure out the next frame up in the call stack. + * For trap(), we print the address of the faulting instruction and * proceed with the calling frame. We return the ip that faulted. * If the trap was caused by jumping through a bogus pointer, then - * the next line in the backtrace will list some random function as - * being called. It should get the argument list correct, though. + * the next line in the backtrace will list some random function as + * being called. It should get the argument list correct, though. * It might be possible to dig out from the next frame up the name * of the function that faulted, but that could get hairy. */ - int -db_nextframe( - long **nextframe, /* IN/OUT */ - long **retaddr, /* IN/OUT */ - long **arg0, /* OUT */ - db_addr_t *ip, /* OUT */ - long *argp, /* IN */ - int is_trap, void (*pr)(const char *, ...)) +db_nextframe(long **nextframe, long **retaddr, long **arg0, db_addr_t *ip, + long *argp, int is_trap, void (*pr)(const char *, ...)) { static struct trapframe tf; static struct i386tss tss; @@ -308,6 +245,66 @@ db_nextframe( return 1; } +db_sym_t +db_frame_info(long *frame, db_addr_t callpc, const char **namep, + db_expr_t *offp, int *is_trap, int *nargp) +{ + db_expr_t offset; + db_sym_t sym; + int narg; + const char *name; + + sym = db_search_symbol(callpc, DB_STGY_ANY, &offset); + db_symbol_values(sym, &name, NULL); + if (sym == (db_sym_t)0) + return (db_sym_t)0; + + *is_trap = NONE; + narg = MAXNARG; + + if (INKERNEL((int)frame) && name) { + /* + * XXX traps should be based off of the Xtrap* + * locations rather than on trap, since some traps + * (e.g., npxdna) don't go through trap() + */ + if (!strcmp(name, "trap_tss")) { + *is_trap = TRAP_TSS; + narg = 0; + } else if (!strcmp(name, "trap")) { + *is_trap = TRAP; + narg = 0; + } else if (!strcmp(name, "syscall")) { + *is_trap = SYSCALL; + narg = 0; + } else if (name[0] == 'X') { + if (!strncmp(name, "Xintr", 5) || + !strncmp(name, "Xresume", 7) || + !strncmp(name, "Xstray", 6) || + !strncmp(name, "Xhold", 5) || + !strncmp(name, "Xrecurse", 8) || + !strcmp(name, "Xdoreti")) { + *is_trap = INTERRUPT; + narg = 0; + } else if (!strcmp(name, "Xsoftintr")) { + *is_trap = SOFTINTR; + narg = 0; + } else if (!strncmp(name, "Xtss_", 5)) { + *is_trap = INTERRUPT_TSS; + narg = 0; + } + } + } + + if (offp != NULL) + *offp = offset; + if (nargp != NULL) + *nargp = narg; + if (namep != NULL) + *namep = name; + return sym; +} + bool db_intrstack_p(const void *vp) { Index: src/sys/arch/x86/x86/db_trace.c diff -u src/sys/arch/x86/x86/db_trace.c:1.3 src/sys/arch/x86/x86/db_trace.c:1.4 --- src/sys/arch/x86/x86/db_trace.c:1.3 Thu Apr 21 00:24:07 2011 +++ src/sys/arch/x86/x86/db_trace.c Sun Feb 11 08:27:18 2018 @@ -1,33 +1,33 @@ -/* $NetBSD: db_trace.c,v 1.3 2011/04/21 00:24:07 enami Exp $ */ +/* $NetBSD: db_trace.c,v 1.4 2018/02/11 08:27:18 maxv Exp $ */ -/* +/* * Mach Operating System * Copyright (c) 1991,1990 Carnegie Mellon University * All Rights Reserved. - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. - * + * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * + * * Carnegie Mellon requests users of this software to return to - * + * * Software Distribution Coordinator or software.distribut...@cs.cmu.edu * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 - * + * * any improvements or extensions that they make and grant Carnegie the * rights to redistribute these changes. */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.3 2011/04/21 00:24:07 enami Exp $"); +__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.4 2018/02/11 08:27:18 maxv Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -55,21 +55,21 @@ __KERNEL_RCSID(0, "$NetBSD: db_trace.c,v int db_x86_regop(const struct db_variable *vp, db_expr_t *val, int opcode) { - db_expr_t *regaddr = - (db_expr_t *)(((uint8_t *)DDB_REGS) + ((size_t)vp->valuep)); - - switch (opcode) { - case DB_VAR_GET: - *val = *regaddr; - break; - case DB_VAR_SET: - *regaddr = *val; - break; - default: + db_expr_t *regaddr = + (db_expr_t *)(((uint8_t *)DDB_REGS) + ((size_t)vp->valuep)); + + switch (opcode) { + case DB_VAR_GET: + *val = *regaddr; + break; + case DB_VAR_SET: + *regaddr = *val; + break; + default: db_printf("db_x86_regop: unknown op %d", opcode); db_error(NULL); - } - return 0; + } + return 0; } /* @@ -77,17 +77,17 @@ db_x86_regop(const struct db_variable *v */ #if 0 -db_addr_t db_trap_symbol_value = 0; -db_addr_t db_syscall_symbol_value = 0; -db_addr_t db_kdintr_symbol_value = 0; -bool db_trace_symbols_found = false; +db_addr_t db_trap_symbol_value = 0; +db_addr_t db_syscall_symbol_value = 0; +db_addr_t db_kdintr_symbol_value = 0; +bool db_trace_symbols_found = false; void db_find_trace_symbols(void); void db_find_trace_symbols(void) { - db_expr_t value; + db_expr_t value; if (db_value_of_name("_trap", &value)) db_trap_symbol_value = (db_addr_t) value; @@ -99,18 +99,23 @@ db_find_trace_symbols(void) } #endif +#define set_frame_callpc() do { \ + frame = (long *)ddb_regs.tf_bp; \ + callpc = (db_addr_t)ddb_regs.tf_ip; \ + } while (/*CONSTCCOND*/0) + void db_stack_trace_print(db_expr_t addr, bool have_addr, db_expr_t count, - const char *modif, void (*pr)(const char *, ...)) + const char *modif, void (*pr)(const char *, ...)) { - long *frame, *lastframe; - long *retaddr, *arg0; - long *argp; - db_addr_t callpc; - int is_trap; - bool kernel_only = true; - bool trace_thread = false; - bool lwpaddr = false; + long *frame, *lastframe; + long *retaddr, *arg0; + long *argp; + db_addr_t callpc; + int is_trap; + bool kernel_only = true; + bool trace_thread = false; + bool lwpaddr = false; #if 0 if (!db_trace_symbols_found) @@ -133,11 +138,6 @@ db_stack_trace_print(db_expr_t addr, boo } } -#define set_frame_callpc() do { \ - frame = (long *)ddb_regs.tf_bp; \ - callpc = (db_addr_t)ddb_regs.tf_ip; \ - } while (/*CONSTCCOND*/0) - if (have_addr && trace_thread) { struct pcb *pcb; proc_t p; @@ -183,29 +183,31 @@ db_stack_trace_print(db_expr_t addr, boo sizeof(callpc), (char *)&callpc); db_read_bytes((db_addr_t)frame, sizeof(frame), (char *)&frame); - } else + } else { set_frame_callpc(); + } + retaddr = frame + 1; arg0 = frame + 2; - lastframe = 0; + lastframe = NULL; while (count && frame != 0) { - int narg; - const char * name; - db_expr_t offset; - db_sym_t sym; - char *argnames[MAXNARG], **argnp = NULL; - db_addr_t lastcallpc; + int narg; + const char *name; + db_expr_t offset; + db_sym_t sym; + char *argnames[MAXNARG], **argnp = NULL; + db_addr_t lastcallpc; name = "?"; is_trap = NONE; offset = 0; sym = db_frame_info(frame, callpc, &name, &offset, &is_trap, - &narg); + &narg); - if (lastframe == 0 && sym == (db_sym_t)0 && callpc != 0) { + if (lastframe == NULL && sym == (db_sym_t)0 && callpc != 0) { /* Symbol not found, peek at code */ - u_long instr = db_get_value(callpc, 4, false); + u_long instr = db_get_value(callpc, 4, false); offset = 1; if ( @@ -234,7 +236,7 @@ db_stack_trace_print(db_expr_t addr, boo (*pr)("%s(", name); - if (lastframe == 0 && offset == 0 && !have_addr) { + if (lastframe == NULL && offset == 0 && !have_addr) { /* * We have a breakpoint before the frame is set up * Use %[er]sp instead @@ -258,7 +260,7 @@ db_stack_trace_print(db_expr_t addr, boo db_printsym(callpc, DB_STGY_PROC, pr); (*pr)("\n"); - if (lastframe == 0 && offset == 0 && !have_addr) { + if (lastframe == NULL && offset == 0 && !have_addr) { /* Frame really belongs to next callpc */ struct x86_frame *fp = (void *) (ddb_regs.tf_sp-sizeof(long)); @@ -272,15 +274,15 @@ db_stack_trace_print(db_expr_t addr, boo lastframe = frame; lastcallpc = callpc; - if (!db_nextframe(&frame, &retaddr, &arg0, - &callpc, frame + 2, is_trap, pr)) + if (!db_nextframe(&frame, &retaddr, &arg0, &callpc, + frame + 2, is_trap, pr)) break; if (INKERNEL((long)frame)) { /* staying in kernel */ #ifdef __i386__ - if (!db_intrstack_p(frame) - && db_intrstack_p(lastframe)) { + if (!db_intrstack_p(frame) && + db_intrstack_p(lastframe)) { (*pr)("--- switch to interrupt stack ---\n"); } else #endif @@ -307,5 +309,4 @@ db_stack_trace_print(db_expr_t addr, boo db_printsym(callpc, DB_STGY_XTRN, pr); (*pr)(":\n"); } -#undef set_frame_callpc }