1 /* radare - LGPL - Copyright 2009-2018 pancake */
2
3 #include <r_bp.h>
4 #include <config.h>
5
r_bp_restore_one(RBreakpoint * bp,RBreakpointItem * b,bool set)6 R_API void r_bp_restore_one(RBreakpoint *bp, RBreakpointItem *b, bool set) {
7 if (set) {
8 //eprintf ("Setting bp at 0x%08"PFMT64x"\n", b->addr);
9 if (b->hw || !b->bbytes) {
10 eprintf ("hw breakpoints not yet supported\n");
11 } else {
12 bp->iob.write_at (bp->iob.io, b->addr, b->bbytes, b->size);
13 }
14 } else {
15 //eprintf ("Clearing bp at 0x%08"PFMT64x"\n", b->addr);
16 if (b->hw || !b->obytes) {
17 eprintf ("hw breakpoints not yet supported\n");
18 } else {
19 bp->iob.write_at (bp->iob.io, b->addr, b->obytes, b->size);
20 }
21 }
22 }
23
24 /**
25 * reflect all r_bp stuff in the process using dbg->bp_write or ->breakpoint
26 */
r_bp_restore(RBreakpoint * bp,bool set)27 R_API int r_bp_restore(RBreakpoint *bp, bool set) {
28 return r_bp_restore_except (bp, set, UT64_MAX);
29 }
30
31 /**
32 * reflect all r_bp stuff in the process using dbg->bp_write or ->breakpoint
33 *
34 * except the specified breakpoint...
35 */
r_bp_restore_except(RBreakpoint * bp,bool set,ut64 addr)36 R_API bool r_bp_restore_except(RBreakpoint *bp, bool set, ut64 addr) {
37 bool rc = true;
38 RListIter *iter;
39 RBreakpointItem *b;
40
41 if (set && bp->bpinmaps) {
42 bp->corebind.syncDebugMaps (bp->corebind.core);
43 }
44
45 r_list_foreach (bp->bps, iter, b) {
46 if (addr && b->addr == addr) {
47 continue;
48 }
49 // Avoid restoring disabled breakpoints
50 if (set && !b->enabled) {
51 continue;
52 }
53 // Check if the breakpoint is in a valid map
54 if (set && bp->bpinmaps && !r_bp_is_valid (bp, b)) {
55 continue;
56 }
57 if (bp->breakpoint && bp->breakpoint (bp, b, set)) {
58 continue;
59 }
60
61 /* write (o|b)bytes from every breakpoint in r_bp if not handled by plugin */
62 r_bp_restore_one (bp, b, set);
63 rc = true;
64 }
65 return rc;
66 }
67