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
This commit is contained in:
Mitchell Horne 2021-03-08 11:27:19 -04:00
parent 5a2933d0bf
commit 9d81dd5404
9 changed files with 41 additions and 115 deletions

View File

@ -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)
{

View File

@ -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)
{

View File

@ -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)
{

View File

@ -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;
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);
}
}

View File

@ -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);

View File

@ -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)
{

View File

@ -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()
{

View File

@ -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)
{

View File

@ -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)
{