diff --git a/sys/amd64/amd64/db_trace.c b/sys/amd64/amd64/db_trace.c index beeb5cd6e9f3..4c569c456e92 100644 --- a/sys/amd64/amd64/db_trace.c +++ b/sys/amd64/amd64/db_trace.c @@ -385,21 +385,6 @@ db_trace_thread(struct thread *thr, int count) ctx->pcb_rip, ctx->pcb_rsp, count)); } -int -db_md_set_watchpoint(db_expr_t addr, db_expr_t size) -{ - - return (dbreg_set_watchpoint((vm_offset_t)addr, (vm_size_t)size, - DBREG_DR7_WRONLY)); -} - -int -db_md_clr_watchpoint(db_expr_t addr, db_expr_t size) -{ - - return (dbreg_clr_watchpoint((vm_offset_t)addr, (vm_size_t)size)); -} - void db_md_list_watchpoints(void) { diff --git a/sys/arm/arm/db_trace.c b/sys/arm/arm/db_trace.c index 195ed0f4e3d9..3f308c9f546c 100644 --- a/sys/arm/arm/db_trace.c +++ b/sys/arm/arm/db_trace.c @@ -134,20 +134,6 @@ db_md_list_watchpoints(void) dbg_show_watchpoint(); } -int -db_md_clr_watchpoint(db_expr_t addr, db_expr_t size) -{ - - return (dbg_remove_watchpoint(addr, size)); -} - -int -db_md_set_watchpoint(db_expr_t addr, db_expr_t size) -{ - - return (dbg_setup_watchpoint(addr, size, HW_WATCHPOINT_RW)); -} - int db_trace_thread(struct thread *thr, int count) { diff --git a/sys/arm64/arm64/db_trace.c b/sys/arm64/arm64/db_trace.c index 268d4ad0d839..5f018f2133b6 100644 --- a/sys/arm64/arm64/db_trace.c +++ b/sys/arm64/arm64/db_trace.c @@ -57,20 +57,6 @@ db_md_list_watchpoints() dbg_show_watchpoint(); } -int -db_md_clr_watchpoint(db_expr_t addr, db_expr_t size) -{ - - return (dbg_remove_watchpoint(NULL, addr, size)); -} - -int -db_md_set_watchpoint(db_expr_t addr, db_expr_t size) -{ - - return (dbg_setup_watchpoint(NULL, addr, size, HW_BREAKPOINT_RW)); -} - static void db_stack_trace_cmd(struct thread *td, struct unwind_state *frame) { diff --git a/sys/ddb/db_watch.c b/sys/ddb/db_watch.c index f0fbb6768c12..3226b050a4c3 100644 --- a/sys/ddb/db_watch.c +++ b/sys/ddb/db_watch.c @@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$"); #include +#include #include #include #include @@ -42,6 +43,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include + #include #include @@ -278,33 +281,57 @@ db_find_watchpoint(vm_map_t map, db_addr_t addr, db_regs_t regs) #endif /* Delete hardware watchpoint */ -/*ARGSUSED*/ void -db_deletehwatch_cmd(db_expr_t addr, bool have_addr, db_expr_t count, +db_deletehwatch_cmd(db_expr_t addr, bool have_addr, db_expr_t size, char *modif) { int rc; - if (count < 0) - count = 4; + if (size < 0) + size = 4; - rc = db_md_clr_watchpoint(addr, count); - if (rc < 0) - db_printf("hardware watchpoint could not be deleted\n"); + rc = kdb_cpu_clr_watchpoint((vm_offset_t)addr, (vm_size_t)size); + switch (rc) { + case ENXIO: + /* Not supported, ignored. */ + break; + case EINVAL: + db_printf("Invalid watchpoint address or size.\n"); + break; + default: + if (rc != 0) + db_printf("Hardware watchpoint could not be deleted, " + "status=%d\n", rc); + break; + } } /* Set hardware watchpoint */ -/*ARGSUSED*/ void -db_hwatchpoint_cmd(db_expr_t addr, bool have_addr, db_expr_t count, +db_hwatchpoint_cmd(db_expr_t addr, bool have_addr, db_expr_t size, char *modif) { int rc; - if (count < 0) - count = 4; + if (size < 0) + size = 4; - rc = db_md_set_watchpoint(addr, count); - if (rc < 0) - db_printf("hardware watchpoint could not be set\n"); + rc = kdb_cpu_set_watchpoint((vm_offset_t)addr, (vm_size_t)size, + KDB_DBG_ACCESS_W); + + switch (rc) { + case EINVAL: + db_printf("Invalid watchpoint size or address.\n"); + break; + case EBUSY: + db_printf("No hardware watchpoints available.\n"); + break; + case ENXIO: + db_printf("Hardware watchpoints are not supported on this platform.\n"); + break; + default: + if (rc != 0) + db_printf("Could not set hardware watchpoint, " + "status=%d\n", rc); + } } diff --git a/sys/ddb/ddb.h b/sys/ddb/ddb.h index 5ae48d21fda9..6218177b3dc2 100644 --- a/sys/ddb/ddb.h +++ b/sys/ddb/ddb.h @@ -205,8 +205,6 @@ struct thread *db_lookup_thread(db_expr_t addr, bool check_pid); struct vm_map *db_map_addr(vm_offset_t); bool db_map_current(struct vm_map *); bool db_map_equal(struct vm_map *, struct vm_map *); -int db_md_set_watchpoint(db_expr_t addr, db_expr_t size); -int db_md_clr_watchpoint(db_expr_t addr, db_expr_t size); void db_md_list_watchpoints(void); void db_print_loc_and_inst(db_addr_t loc); void db_print_thread(void); diff --git a/sys/i386/i386/db_trace.c b/sys/i386/i386/db_trace.c index 50fb1fa6355d..80ef0fe715d8 100644 --- a/sys/i386/i386/db_trace.c +++ b/sys/i386/i386/db_trace.c @@ -612,20 +612,6 @@ db_trace_thread(struct thread *thr, int count) ctx->pcb_eip, ctx->pcb_esp, count)); } -int -db_md_set_watchpoint(db_expr_t addr, db_expr_t size) -{ - - return (dbreg_set_watchpoint((vm_offset_t)addr, (vm_size_t)size)); -} - -int -db_md_clr_watchpoint(db_expr_t addr, db_expr_t size) -{ - - return (dbreg_clr_watchpoint((vm_offset_t)addr, (vm_size_t)size)); -} - void db_md_list_watchpoints(void) { diff --git a/sys/mips/mips/db_trace.c b/sys/mips/mips/db_trace.c index 0762fdb8a1da..4903b6d3d432 100644 --- a/sys/mips/mips/db_trace.c +++ b/sys/mips/mips/db_trace.c @@ -395,20 +395,6 @@ stacktrace_subr(register_t pc, register_t sp, register_t ra) } } -int -db_md_set_watchpoint(db_expr_t addr, db_expr_t size) -{ - - return(0); -} - -int -db_md_clr_watchpoint(db_expr_t addr, db_expr_t size) -{ - - return(0); -} - void db_md_list_watchpoints() { diff --git a/sys/powerpc/powerpc/db_hwwatch.c b/sys/powerpc/powerpc/db_hwwatch.c index 37b4a9148495..aa9018a58417 100644 --- a/sys/powerpc/powerpc/db_hwwatch.c +++ b/sys/powerpc/powerpc/db_hwwatch.c @@ -36,20 +36,6 @@ #include #include -int -db_md_set_watchpoint(db_expr_t addr, db_expr_t size) -{ - - return (0); -} - -int -db_md_clr_watchpoint(db_expr_t addr, db_expr_t size) -{ - - return (0); -} - void db_md_list_watchpoints(void) { diff --git a/sys/riscv/riscv/db_trace.c b/sys/riscv/riscv/db_trace.c index b8421fa3aa7a..dbc2ba92bce3 100644 --- a/sys/riscv/riscv/db_trace.c +++ b/sys/riscv/riscv/db_trace.c @@ -58,20 +58,6 @@ db_md_list_watchpoints() } -int -db_md_clr_watchpoint(db_expr_t addr, db_expr_t size) -{ - - return (0); -} - -int -db_md_set_watchpoint(db_expr_t addr, db_expr_t size) -{ - - return (0); -} - static void db_stack_trace_cmd(struct thread *td, struct unwind_state *frame) {