Implement proc_remove_breakpoint
diff --git a/breakpoints.c b/breakpoints.c
index 07430af..36f5e72 100644
--- a/breakpoints.c
+++ b/breakpoints.c
@@ -228,15 +228,13 @@
void
delete_breakpoint(Process *proc, void *addr)
{
- struct breakpoint *sbp;
-
debug(DEBUG_FUNCTION, "delete_breakpoint(pid=%d, addr=%p)", proc->pid, addr);
Process * leader = proc->leader;
assert(leader != NULL);
- sbp = dict_find_entry(leader->breakpoints, addr);
- assert(sbp); /* FIXME: remove after debugging has been done. */
+ struct breakpoint *sbp = dict_find_entry(leader->breakpoints, addr);
+ assert(sbp != NULL);
/* This should only happen on out-of-memory conditions. */
if (sbp == NULL)
return;
@@ -246,6 +244,11 @@
breakpoint_name(sbp), sbp->addr);
return;
}
+ if (sbp->enabled == 0) {
+ proc_remove_breakpoint(leader, sbp);
+ breakpoint_destroy(sbp);
+ free(sbp);
+ }
}
const char *
diff --git a/proc.c b/proc.c
index 898861b..fb02638 100644
--- a/proc.c
+++ b/proc.c
@@ -680,17 +680,22 @@
return NULL;
}
-int
-proc_add_breakpoint(struct Process *proc, struct breakpoint *bp)
+static void
+check_leader(struct Process *proc)
{
/* Only the group leader should be getting the breakpoints and
* thus have ->breakpoint initialized. */
assert(proc->leader != NULL);
assert(proc->leader == proc);
assert(proc->breakpoints != NULL);
+}
+int
+proc_add_breakpoint(struct Process *proc, struct breakpoint *bp)
+{
debug(DEBUG_FUNCTION, "proc_add_breakpoint(pid=%d, %s@%p)",
proc->pid, breakpoint_name(bp), bp->addr);
+ check_leader(proc);
/* XXX We might merge bp->libsym instead of the following
* assert, but that's not necessary right now. Read the
@@ -706,12 +711,14 @@
return 0;
}
-int
+void
proc_remove_breakpoint(struct Process *proc, struct breakpoint *bp)
{
- /* XXX We can't, really. We are missing dict_remove. */
- assert(!"Not yet implemented!");
- abort();
+ debug(DEBUG_FUNCTION, "proc_remove_breakpoint(pid=%d, %s@%p)",
+ proc->pid, breakpoint_name(bp), bp->addr);
+ check_leader(proc);
+ struct breakpoint *removed = dict_remove(proc->breakpoints, bp->addr);
+ assert(removed == bp);
}
/* Dict doesn't support iteration restarts, so here's this contraption
diff --git a/proc.h b/proc.h
index 9939c4e..ed2bb70 100644
--- a/proc.h
+++ b/proc.h
@@ -215,8 +215,9 @@
/* Insert BP into PROC. */
int proc_add_breakpoint(struct Process *proc, struct breakpoint *bp);
-/* Remove BP from PROC. */
-int proc_remove_breakpoint(struct Process *proc, struct breakpoint *bp);
+/* Remove BP from PROC. This has no reason to fail in runtime. If it
+ * does not find BP in PROC, it's hard error guarded by assertion. */
+void proc_remove_breakpoint(struct Process *proc, struct breakpoint *bp);
/* Iterate through the libraries of PROC. See each_process for
* detailed description of the iteration interface. */