As explained previously I'm implementing an instrumentation system based on ddb(4) and relying on breakpoints to execute kernel probes.
For debugging purposes I need a way to dump the content of the registers when a breakpoint-not-for-ddb(4) fired. So I hacked the "show regs" to dump the registers at a specified address if one was given. I'd like to put this in, any objection? Comment? While here I merged db_print.c into db_command.c, I'm making some room before adding new files ;) If I get any ok I'll update the manual. Index: ddb/db_command.c =================================================================== RCS file: /cvs/src/sys/ddb/db_command.c,v retrieving revision 1.68 diff -u -p -r1.68 db_command.c --- ddb/db_command.c 25 Jan 2016 14:30:30 -0000 1.68 +++ ddb/db_command.c 1 Mar 2016 22:28:26 -0000 @@ -43,12 +43,14 @@ #include <uvm/uvm_extern.h> #include <machine/db_machdep.h> /* type definitions */ +#include <ddb/db_access.h> #include <ddb/db_lex.h> #include <ddb/db_output.h> #include <ddb/db_command.h> #include <ddb/db_break.h> #include <ddb/db_watch.h> #include <ddb/db_run.h> +#include <ddb/db_sym.h> #include <ddb/db_variables.h> #include <ddb/db_interface.h> #include <ddb/db_extern.h> @@ -788,4 +790,41 @@ db_stack_trace_cmd(db_expr_t addr, boole char *modif) { db_stack_trace_print(addr, have_addr, count, modif, db_printf); +} + +void +db_show_regs(db_expr_t addr, int have_addr, db_expr_t count, char *modif) +{ + struct db_variable *regp; + db_regs_t *regs; + db_expr_t value, offset; + char *name; + char fmt[28]; + + if (have_addr) + regs = (db_regs_t *)addr; + else + regs = &ddb_regs; + + for (regp = db_regs; regp < db_eregs; regp++) { + if (have_addr) { + value = db_get_value(addr, sizeof(long), 0); + addr += sizeof(long); + } else { + db_read_variable(regp, &value); + } + + db_printf("%-12s%s", regp->name, db_format(fmt, sizeof(fmt), + (long)value, DB_FORMAT_N, 1, sizeof(long) * 3)); + db_find_xtrn_sym_and_offset((db_addr_t)value, &name, &offset); + if (name != NULL && offset <= db_maxoff && offset != value) { + db_printf("\t%s", name); + if (offset != 0) { + db_printf("+%s", db_format(fmt, sizeof(fmt), + (long)offset, DB_FORMAT_R, 1, 0)); + } + } + db_printf("\n"); + } + db_print_loc_and_inst(PC_REGS(regs)); } Index: ddb/db_print.c =================================================================== RCS file: /cvs/src/sys/ddb/db_print.c,v retrieving revision 1.16 diff -u -p -r1.16 db_print.c --- ddb/db_print.c 25 Jan 2016 14:30:30 -0000 1.16 +++ ddb/db_print.c 1 Mar 2016 22:23:06 -0000 @@ -1,69 +0,0 @@ -/* $OpenBSD: db_print.c,v 1.16 2016/01/25 14:30:30 mpi Exp $ */ -/* $NetBSD: db_print.c,v 1.5 1996/02/05 01:57:11 christos Exp $ */ - -/* - * Mach Operating System - * Copyright (c) 1993,1992,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 Mellon - * the rights to redistribute these changes. - * - * Author: David B. Golub, Carnegie Mellon University - * Date: 7/90 - */ - -/* - * Miscellaneous printing. - */ -#include <sys/param.h> -#include <sys/systm.h> - -#include <machine/db_machdep.h> - -#include <ddb/db_variables.h> -#include <ddb/db_sym.h> -#include <ddb/db_output.h> -#include <ddb/db_extern.h> - -/*ARGSUSED*/ -void -db_show_regs(db_expr_t addr, int have_addr, db_expr_t count, char *modif) -{ - struct db_variable *regp; - db_expr_t value, offset; - char * name; - char tmpfmt[28]; - - for (regp = db_regs; regp < db_eregs; regp++) { - db_read_variable(regp, &value); - db_printf("%-12s%s", regp->name, db_format(tmpfmt, sizeof tmpfmt, - (long)value, DB_FORMAT_N, 1, sizeof(long) * 3)); - db_find_xtrn_sym_and_offset((db_addr_t)value, &name, &offset); - if (name != 0 && offset <= db_maxoff && offset != value) { - db_printf("\t%s", name); - if (offset != 0) - db_printf("+%s", db_format(tmpfmt, sizeof tmpfmt, - (long)offset, DB_FORMAT_R, 1, 0)); - } - db_printf("\n"); - } - db_print_loc_and_inst(PC_REGS(DDB_REGS)); -} Index: conf/files =================================================================== RCS file: /cvs/src/sys/conf/files,v retrieving revision 1.613 diff -u -p -r1.613 files --- conf/files 1 Mar 2016 16:43:08 -0000 1.613 +++ conf/files 1 Mar 2016 22:24:49 -0000 @@ -601,7 +601,6 @@ file ddb/db_hangman.c ddb file ddb/db_input.c ddb file ddb/db_lex.c ddb file ddb/db_output.c ddb -file ddb/db_print.c ddb file ddb/db_run.c ddb | kgdb file ddb/db_struct.c ddb & ddb_struct file ddb/db_sym.c ddb