Date: Mon, 29 Mar 2021 15:06:24 GMT From: Mitchell Horne <mhorne@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 9d81dd5404b3 - main - ddb: replace watchpoint set/clear functions Message-ID: <202103291506.12TF6OMt044459@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=9d81dd5404b3ad7108059d7065814d56a722a96c commit 9d81dd5404b3ad7108059d7065814d56a722a96c Author: Mitchell Horne <mhorne@FreeBSD.org> AuthorDate: 2021-03-08 15:27:19 +0000 Commit: Mitchell Horne <mhorne@FreeBSD.org> CommitDate: 2021-03-29 15:05:44 +0000 ddb: replace watchpoint set/clear functions Use the new kdb variants. Print more specific error messages. Reviewed by: jhb, markj MFC after: 3 weeks Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D29156 --- sys/amd64/amd64/db_trace.c | 15 ---------- sys/arm/arm/db_trace.c | 14 ---------- sys/arm64/arm64/db_trace.c | 14 ---------- sys/ddb/db_watch.c | 59 +++++++++++++++++++++++++++++----------- sys/ddb/ddb.h | 2 -- sys/i386/i386/db_trace.c | 14 ---------- sys/mips/mips/db_trace.c | 14 ---------- sys/powerpc/powerpc/db_hwwatch.c | 14 ---------- sys/riscv/riscv/db_trace.c | 14 ---------- 9 files changed, 43 insertions(+), 117 deletions(-) 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 <sys/param.h> +#include <sys/kdb.h> #include <sys/kernel.h> #include <sys/lock.h> #include <sys/proc.h> @@ -42,6 +43,8 @@ __FBSDID("$FreeBSD$"); #include <vm/pmap.h> #include <vm/vm_map.h> +#include <machine/kdb.h> + #include <ddb/ddb.h> #include <ddb/db_watch.h> @@ -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; - - rc = db_md_clr_watchpoint(addr, count); - if (rc < 0) - db_printf("hardware watchpoint could not be deleted\n"); + if (size < 0) + size = 4; + + 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; - - rc = db_md_set_watchpoint(addr, count); - if (rc < 0) - db_printf("hardware watchpoint could not be set\n"); + if (size < 0) + size = 4; + + 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 @@ done: } } -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 <ddb/db_variables.h> #include <ddb/db_watch.h> -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) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202103291506.12TF6OMt044459>