summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2010-11-27 19:59:12 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2010-11-27 19:59:12 +0000
commit94df2bf27bc7395872312d0e9e7f4689692aefcb (patch)
treebd2d940902ab8d277dd16d778036c02ca31849f6
parent0ed7bf7b63c6099fc1205fa39502c78fba9d94c0 (diff)
Get rid of the vm_map field of ddb breakpoints and watchpoints, and do not
pretend these could work on userland addresses.
-rw-r--r--share/man/man4/ddb.43
-rw-r--r--sys/ddb/db_break.c160
-rw-r--r--sys/ddb/db_break.h13
-rw-r--r--sys/ddb/db_run.c6
-rw-r--r--sys/ddb/db_watch.c110
-rw-r--r--sys/ddb/db_watch.h8
6 files changed, 81 insertions, 219 deletions
diff --git a/share/man/man4/ddb.4 b/share/man/man4/ddb.4
index 9214aaf4fb5..a14c454602c 100644
--- a/share/man/man4/ddb.4
+++ b/share/man/man4/ddb.4
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ddb.4,v 1.70 2010/11/27 19:57:21 miod Exp $
+.\" $OpenBSD: ddb.4,v 1.71 2010/11/27 19:59:10 miod Exp $
.\" $NetBSD: ddb.4,v 1.5 1994/11/30 16:22:09 jtc Exp $
.\"
.\" Mach Operating System
@@ -481,7 +481,6 @@ with an error message.
.Sy Warning:
attempts to watch wired kernel memory
may cause an unrecoverable error on some systems (e.g., i386).
-Watchpoints on user addresses work best.
.\" --------------------
.It Ic dwatch Ar addr
Delete the watchpoint at address
diff --git a/sys/ddb/db_break.c b/sys/ddb/db_break.c
index 14f24cbfca4..04706be4540 100644
--- a/sys/ddb/db_break.c
+++ b/sys/ddb/db_break.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: db_break.c,v 1.13 2006/03/13 06:23:20 jsg Exp $ */
+/* $OpenBSD: db_break.c,v 1.14 2010/11/27 19:59:11 miod Exp $ */
/* $NetBSD: db_break.c,v 1.7 1996/03/30 22:30:03 christos Exp $ */
/*
@@ -79,13 +79,13 @@ db_breakpoint_free(db_breakpoint_t bkpt)
}
void
-db_set_breakpoint(struct vm_map *map, db_addr_t addr, int count)
+db_set_breakpoint(db_addr_t addr, int count)
{
db_breakpoint_t bkpt;
- if (db_find_breakpoint(map, addr)) {
- db_printf("Already set.\n");
- return;
+ if (db_find_breakpoint(addr)) {
+ db_printf("Already set.\n");
+ return;
}
#ifdef DB_VALID_BREAKPOINT
@@ -97,11 +97,10 @@ db_set_breakpoint(struct vm_map *map, db_addr_t addr, int count)
bkpt = db_breakpoint_alloc();
if (bkpt == 0) {
- db_printf("Too many breakpoints.\n");
- return;
+ db_printf("Too many breakpoints.\n");
+ return;
}
- bkpt->map = map;
bkpt->address = addr;
bkpt->flags = 0;
bkpt->init_count = count;
@@ -112,48 +111,36 @@ db_set_breakpoint(struct vm_map *map, db_addr_t addr, int count)
}
void
-db_delete_breakpoint(struct vm_map *map, db_addr_t addr)
+db_delete_breakpoint(db_addr_t addr)
{
db_breakpoint_t bkpt;
db_breakpoint_t *prev;
- for (prev = &db_breakpoint_list;
- (bkpt = *prev) != 0;
- prev = &bkpt->link) {
- if (db_map_equal(bkpt->map, map) &&
- (bkpt->address == addr)) {
- *prev = bkpt->link;
- break;
- }
+ for (prev = &db_breakpoint_list; (bkpt = *prev) != 0;
+ prev = &bkpt->link) {
+ if (bkpt->address == addr) {
+ *prev = bkpt->link;
+ break;
+ }
}
if (bkpt == 0) {
- db_printf("Not set.\n");
- return;
+ db_printf("Not set.\n");
+ return;
}
db_breakpoint_free(bkpt);
}
db_breakpoint_t
-db_find_breakpoint(struct vm_map *map, db_addr_t addr)
+db_find_breakpoint(db_addr_t addr)
{
db_breakpoint_t bkpt;
- for (bkpt = db_breakpoint_list;
- bkpt != 0;
- bkpt = bkpt->link)
- {
- if (db_map_equal(bkpt->map, map) &&
- (bkpt->address == addr))
- return (bkpt);
- }
- return (0);
-}
+ for (bkpt = db_breakpoint_list; bkpt != 0; bkpt = bkpt->link)
+ if (bkpt->address == addr)
+ return (bkpt);
-db_breakpoint_t
-db_find_breakpoint_here(db_addr_t addr)
-{
- return db_find_breakpoint(db_map_addr(addr), addr);
+ return (0);
}
boolean_t db_breakpoints_inserted = TRUE;
@@ -164,17 +151,13 @@ db_set_breakpoints(void)
db_breakpoint_t bkpt;
if (!db_breakpoints_inserted) {
-
- for (bkpt = db_breakpoint_list;
- bkpt != 0;
- bkpt = bkpt->link)
- if (db_map_current(bkpt->map)) {
- bkpt->bkpt_inst = db_get_value(bkpt->address, BKPT_SIZE,
- FALSE);
- db_put_value(bkpt->address, BKPT_SIZE,
- BKPT_SET(bkpt->bkpt_inst));
+ for (bkpt = db_breakpoint_list; bkpt != 0; bkpt = bkpt->link) {
+ bkpt->bkpt_inst =
+ db_get_value(bkpt->address, BKPT_SIZE, FALSE);
+ db_put_value(bkpt->address, BKPT_SIZE,
+ BKPT_SET(bkpt->bkpt_inst));
}
- db_breakpoints_inserted = TRUE;
+ db_breakpoints_inserted = TRUE;
}
}
@@ -184,14 +167,9 @@ db_clear_breakpoints(void)
db_breakpoint_t bkpt;
if (db_breakpoints_inserted) {
-
- for (bkpt = db_breakpoint_list;
- bkpt != 0;
- bkpt = bkpt->link)
- if (db_map_current(bkpt->map)) {
- db_put_value(bkpt->address, BKPT_SIZE, bkpt->bkpt_inst);
- }
- db_breakpoints_inserted = FALSE;
+ for (bkpt = db_breakpoint_list; bkpt != 0; bkpt = bkpt->link)
+ db_put_value(bkpt->address, BKPT_SIZE, bkpt->bkpt_inst);
+ db_breakpoints_inserted = FALSE;
}
}
@@ -218,7 +196,6 @@ db_set_temp_breakpoint(db_addr_t addr)
return (0);
}
- bkpt->map = NULL;
bkpt->address = addr;
bkpt->flags = BKPT_TEMP;
bkpt->init_count = 1;
@@ -244,21 +221,16 @@ db_list_breakpoints(void)
{
db_breakpoint_t bkpt;
- if (db_breakpoint_list == 0) {
- db_printf("No breakpoints set\n");
- return;
+ if (db_breakpoint_list == NULL) {
+ db_printf("No breakpoints set\n");
+ return;
}
- db_printf(" Map Count Address\n");
- for (bkpt = db_breakpoint_list;
- bkpt != 0;
- bkpt = bkpt->link)
- {
- db_printf("%s%p %5d ",
- db_map_current(bkpt->map) ? "*" : " ",
- bkpt->map, bkpt->init_count);
- db_printsym(bkpt->address, DB_STGY_PROC, db_printf);
- db_printf("\n");
+ db_printf(" Count Address\n");
+ for (bkpt = db_breakpoint_list; bkpt != 0; bkpt = bkpt->link) {
+ db_printf(" %5d ", bkpt->init_count);
+ db_printsym(bkpt->address, DB_STGY_PROC, db_printf);
+ db_printf("\n");
}
}
@@ -267,7 +239,7 @@ db_list_breakpoints(void)
void
db_delete_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
{
- db_delete_breakpoint(db_map_addr(addr), (db_addr_t)addr);
+ db_delete_breakpoint((db_addr_t)addr);
}
/* Set breakpoint with skip count */
@@ -276,9 +248,9 @@ void
db_breakpoint_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
{
if (count == -1)
- count = 1;
+ count = 1;
- db_set_breakpoint(db_map_addr(addr), (db_addr_t)addr, count);
+ db_set_breakpoint((db_addr_t)addr, count);
}
/* list breakpoints */
@@ -288,53 +260,3 @@ db_listbreak_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
{
db_list_breakpoints();
}
-
-/*
- * We want ddb to be usable before most of the kernel has been
- * initialized. In particular, current_thread() or kernel_map
- * (or both) may be null.
- */
-
-boolean_t
-db_map_equal(struct vm_map *map1, struct vm_map *map2)
-{
- return ((map1 == map2) ||
- ((map1 == NULL) && (map2 == kernel_map)) ||
- ((map1 == kernel_map) && (map2 == NULL)));
-}
-
-boolean_t
-db_map_current(struct vm_map *map)
-{
-#if 0
- thread_t thread;
-
- return ((map == NULL) ||
- (map == kernel_map) ||
- (((thread = current_thread()) != NULL) &&
- (map == thread->proc->map)));
-#else
- return (1);
-#endif
-}
-
-struct vm_map *
-db_map_addr(vaddr_t addr)
-{
-#if 0
- thread_t thread;
-
- /*
- * We want to return kernel_map for all
- * non-user addresses, even when debugging
- * kernel tasks with their own maps.
- */
-
- if ((VM_MIN_ADDRESS <= addr) &&
- (addr < VM_MAX_ADDRESS) &&
- ((thread = current_thread()) != NULL))
- return thread->proc->map;
- else
-#endif
- return kernel_map;
-}
diff --git a/sys/ddb/db_break.h b/sys/ddb/db_break.h
index 2159ffc1611..27f411b4859 100644
--- a/sys/ddb/db_break.h
+++ b/sys/ddb/db_break.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: db_break.h,v 1.8 2002/03/14 01:26:51 millert Exp $ */
+/* $OpenBSD: db_break.h,v 1.9 2010/11/27 19:59:11 miod Exp $ */
/* $NetBSD: db_break.h,v 1.8 1996/02/05 01:56:52 christos Exp $ */
/*
@@ -39,7 +39,6 @@
* Breakpoints.
*/
typedef struct db_breakpoint {
- struct vm_map *map; /* in this map */
db_addr_t address; /* set here */
int init_count; /* number of times to skip bkpt */
int count; /* current count */
@@ -52,10 +51,9 @@ typedef struct db_breakpoint {
db_breakpoint_t db_breakpoint_alloc(void);
void db_breakpoint_free(db_breakpoint_t);
-void db_set_breakpoint(struct vm_map *, db_addr_t, int);
-void db_delete_breakpoint(struct vm_map *, db_addr_t);
-db_breakpoint_t db_find_breakpoint(struct vm_map *, db_addr_t);
-db_breakpoint_t db_find_breakpoint_here(db_addr_t);
+void db_set_breakpoint(db_addr_t, int);
+void db_delete_breakpoint(db_addr_t);
+db_breakpoint_t db_find_breakpoint(db_addr_t);
void db_set_breakpoints(void);
void db_clear_breakpoints(void);
db_breakpoint_t db_set_temp_breakpoint(db_addr_t);
@@ -64,8 +62,5 @@ void db_list_breakpoints(void);
void db_delete_cmd(db_expr_t, int, db_expr_t, char *);
void db_breakpoint_cmd(db_expr_t, int, db_expr_t, char *);
void db_listbreak_cmd(db_expr_t, int, db_expr_t, char *);
-boolean_t db_map_equal(struct vm_map *, struct vm_map *);
-boolean_t db_map_current(struct vm_map *);
-struct vm_map *db_map_addr(vaddr_t);
#endif /* _DDB_DB_BREAK_H_ */
diff --git a/sys/ddb/db_run.c b/sys/ddb/db_run.c
index e85e84dff52..ec30a0b59a9 100644
--- a/sys/ddb/db_run.c
+++ b/sys/ddb/db_run.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: db_run.c,v 1.21 2010/11/27 19:57:23 miod Exp $ */
+/* $OpenBSD: db_run.c,v 1.22 2010/11/27 19:59:11 miod Exp $ */
/* $NetBSD: db_run.c,v 1.8 1996/02/05 01:57:12 christos Exp $ */
/*
@@ -96,7 +96,7 @@ db_stop_at_pc(db_regs_t *regs, boolean_t *is_breakpoint)
/*
* Now check for a breakpoint at this address.
*/
- bkpt = db_find_breakpoint_here(pc);
+ bkpt = db_find_breakpoint(pc);
if (bkpt) {
if (--bkpt->count == 0) {
db_clear_single_step(regs);
@@ -204,7 +204,7 @@ db_restart_at_pc(db_regs_t *regs, boolean_t watchpt)
}
if (db_run_mode == STEP_CONTINUE) {
- if (watchpt || db_find_breakpoint_here(pc)) {
+ if (watchpt || db_find_breakpoint(pc)) {
/*
* Step over breakpoint/watchpoint.
*/
diff --git a/sys/ddb/db_watch.c b/sys/ddb/db_watch.c
index 102b9d3ba1a..ca30469e679 100644
--- a/sys/ddb/db_watch.c
+++ b/sys/ddb/db_watch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: db_watch.c,v 1.9 2006/03/13 06:23:20 jsg Exp $ */
+/* $OpenBSD: db_watch.c,v 1.10 2010/11/27 19:59:11 miod Exp $ */
/* $NetBSD: db_watch.c,v 1.9 1996/03/30 22:30:12 christos Exp $ */
/*
@@ -84,36 +84,26 @@ db_watchpoint_free(db_watchpoint_t watch)
}
void
-db_set_watchpoint(struct vm_map *map, db_addr_t addr, vsize_t size)
+db_set_watchpoint(db_addr_t addr, vsize_t size)
{
db_watchpoint_t watch;
- if (map == NULL) {
- db_printf("No map.\n");
- return;
- }
-
/*
* Should we do anything fancy with overlapping regions?
*/
- for (watch = db_watchpoint_list;
- watch != 0;
- watch = watch->link)
- if (db_map_equal(watch->map, map) &&
- (watch->loaddr == addr) &&
- (watch->hiaddr == addr+size)) {
- db_printf("Already set.\n");
- return;
- }
+ for (watch = db_watchpoint_list; watch != 0; watch = watch->link)
+ if (watch->loaddr == addr && watch->hiaddr == addr + size) {
+ db_printf("Already set.\n");
+ return;
+ }
watch = db_watchpoint_alloc();
if (watch == 0) {
- db_printf("Too many watchpoints.\n");
- return;
+ db_printf("Too many watchpoints.\n");
+ return;
}
- watch->map = map;
watch->loaddr = addr;
watch->hiaddr = addr+size;
@@ -124,21 +114,18 @@ db_set_watchpoint(struct vm_map *map, db_addr_t addr, vsize_t size)
}
void
-db_delete_watchpoint(struct vm_map *map, db_addr_t addr)
+db_delete_watchpoint(db_addr_t addr)
{
db_watchpoint_t watch;
db_watchpoint_t *prev;
- for (prev = &db_watchpoint_list;
- (watch = *prev) != 0;
- prev = &watch->link)
- if (db_map_equal(watch->map, map) &&
- (watch->loaddr <= addr) &&
- (addr < watch->hiaddr)) {
- *prev = watch->link;
- db_watchpoint_free(watch);
- return;
- }
+ for (prev = &db_watchpoint_list; (watch = *prev) != 0;
+ prev = &watch->link)
+ if (watch->loaddr <= addr && addr < watch->hiaddr) {
+ *prev = watch->link;
+ db_watchpoint_free(watch);
+ return;
+ }
db_printf("Not set.\n");
}
@@ -153,14 +140,10 @@ db_list_watchpoints(void)
return;
}
- db_printf(" Map Address Size\n");
- for (watch = db_watchpoint_list;
- watch != 0;
- watch = watch->link)
- db_printf("%s%p %8lx %lx\n",
- db_map_current(watch->map) ? "*" : " ",
- watch->map, watch->loaddr,
- watch->hiaddr - watch->loaddr);
+ db_printf(" Address Size\n");
+ for (watch = db_watchpoint_list; watch != 0; watch = watch->link)
+ db_printf("%8lx %lx\n",
+ watch->loaddr, watch->hiaddr - watch->loaddr);
}
/* Delete watchpoint */
@@ -168,7 +151,7 @@ db_list_watchpoints(void)
void
db_deletewatch_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
{
- db_delete_watchpoint(db_map_addr(addr), addr);
+ db_delete_watchpoint(addr);
}
/* Set watchpoint */
@@ -185,7 +168,7 @@ db_watchpoint_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
size = 4;
db_skip_to_eol();
- db_set_watchpoint(db_map_addr(addr), addr, size);
+ db_set_watchpoint(addr, size);
}
/* list watchpoints */
@@ -202,15 +185,12 @@ db_set_watchpoints(void)
db_watchpoint_t watch;
if (!db_watchpoints_inserted && db_watchpoint_list != NULL) {
- for (watch = db_watchpoint_list;
- watch != 0;
- watch = watch->link)
- pmap_protect(watch->map->pmap,
- trunc_page(watch->loaddr),
- round_page(watch->hiaddr),
- VM_PROT_READ);
- pmap_update(watch->map->pmap);
- db_watchpoints_inserted = TRUE;
+ for (watch = db_watchpoint_list; watch != 0;
+ watch = watch->link)
+ pmap_protect(pmap_kernel(), trunc_page(watch->loaddr),
+ round_page(watch->hiaddr), VM_PROT_READ);
+ pmap_update(pmap_kernel());
+ db_watchpoints_inserted = TRUE;
}
}
@@ -219,35 +199,3 @@ db_clear_watchpoints(void)
{
db_watchpoints_inserted = FALSE;
}
-
-boolean_t
-db_find_watchpoint(struct vm_map *map, db_addr_t addr, db_regs_t *regs)
-{
- db_watchpoint_t watch;
- db_watchpoint_t found = 0;
-
- for (watch = db_watchpoint_list;
- watch != 0;
- watch = watch->link)
- if (db_map_equal(watch->map, map)) {
- if ((watch->loaddr <= addr) &&
- (addr < watch->hiaddr))
- return (TRUE);
- else if ((trunc_page(watch->loaddr) <= addr) &&
- (addr < round_page(watch->hiaddr)))
- found = watch;
- }
-
- /*
- * We didn't hit exactly on a watchpoint, but we are
- * in a protected region. We want to single-step
- * and then re-protect.
- */
-
- if (found) {
- db_watchpoints_inserted = FALSE;
- db_single_step(regs);
- }
-
- return (FALSE);
-}
diff --git a/sys/ddb/db_watch.h b/sys/ddb/db_watch.h
index ab20fe06509..1c14f78c431 100644
--- a/sys/ddb/db_watch.h
+++ b/sys/ddb/db_watch.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: db_watch.h,v 1.8 2002/03/14 01:26:51 millert Exp $ */
+/* $OpenBSD: db_watch.h,v 1.9 2010/11/27 19:59:11 miod Exp $ */
/* $NetBSD: db_watch.h,v 1.9 1996/02/05 01:57:24 christos Exp $ */
/*
@@ -37,7 +37,6 @@
* Watchpoint.
*/
typedef struct db_watchpoint {
- struct vm_map *map; /* in this map */
db_addr_t loaddr; /* from this address */
db_addr_t hiaddr; /* to this address */
struct db_watchpoint *link; /* link in in-use or free chain */
@@ -45,14 +44,13 @@ typedef struct db_watchpoint {
db_watchpoint_t db_watchpoint_alloc(void);
void db_watchpoint_free(db_watchpoint_t);
-void db_set_watchpoint(struct vm_map *, db_addr_t, vsize_t);
-void db_delete_watchpoint(struct vm_map *, db_addr_t);
+void db_set_watchpoint(db_addr_t, vsize_t);
+void db_delete_watchpoint(db_addr_t);
void db_list_watchpoints(void);
void db_deletewatch_cmd(db_expr_t, int, db_expr_t, char *);
void db_watchpoint_cmd(db_expr_t, int, db_expr_t, char *);
void db_listwatch_cmd(db_expr_t, int, db_expr_t, char *);
void db_set_watchpoints(void);
void db_clear_watchpoints(void);
-boolean_t db_find_watchpoint(struct vm_map *, db_addr_t, db_regs_t *);
#endif /* _DDB_DB_WATCH_ */