]> git.feebdaed.xyz Git - 0xmirror/radare2.git/commitdiff
Address some TODOs in the breakpoint apis
authorpancake <pancake@nowsecure.com>
Wed, 10 Dec 2025 08:44:28 +0000 (09:44 +0100)
committerGitHub <noreply@github.com>
Wed, 10 Dec 2025 08:44:28 +0000 (09:44 +0100)
.github/workflows/build.yml
libr/bp/bp.c
libr/bp/bp_plugin.c
libr/bp/bp_traptrace.c
libr/bp/bp_watch.c
libr/include/r_bp.h

index 8fe271d321d0742c59ea520538274409921806c7..a73a0f4972d1c23d3908dc3b861cd2a76eca69c6 100644 (file)
@@ -264,7 +264,7 @@ jobs:
     - if: ${{ matrix.sdk }}
       name: Create iOS SDK
       run: |
-        ./sys/ios-sdk.sh
+        ./sys/sdk-ios.sh
         pushd /tmp/r2ios
         zip -r /tmp/r2ios-sdk.zip *
         popd
index 912f41b220e57fab4874ff403171483be04d3d8a..3373fad8d8fd088eed001ef1b07301b5ed7fde43 100644 (file)
@@ -30,7 +30,6 @@ R_API RBreakpoint *r_bp_new(void) {
        bp->traces = r_bp_traptrace_new ();
        bp->bps = r_list_newf ((RListFree)r_bp_item_free);
        bp->plugins = r_list_newf ((RListFree)free);
-       bp->nhwbps = 0;
        for (i = 0; bp_static_plugins[i]; i++) {
                static_plugin = R_NEW (RBreakpointPlugin);
                memcpy (static_plugin, bp_static_plugins[i],
@@ -41,7 +40,8 @@ R_API RBreakpoint *r_bp_new(void) {
        return bp;
 }
 
-R_API RBreakpoint *r_bp_free(RBreakpoint *bp) {
+// AIRPDO return void
+R_API void r_bp_free(RBreakpoint *bp) {
        if (bp) {
                r_list_free (bp->bps);
                r_list_free (bp->plugins);
@@ -49,7 +49,6 @@ R_API RBreakpoint *r_bp_free(RBreakpoint *bp) {
                free (bp->bps_idx);
                free (bp);
        }
-       return NULL;
 }
 
 R_API int r_bp_get_bytes(RBreakpoint *bp, ut8 *buf, int len, int endian, int idx) {
@@ -204,13 +203,14 @@ static RBreakpointItem *r_bp_add(RBreakpoint *bp, const ut8 * R_NULLABLE obytes,
                        R_LOG_WARN ("Cannot get breakpoint bytes. No architecture selected?");
                }
        }
-       bp->nbps++;
        r_list_append (bp->bps, b);
        return b;
 }
 
 R_API void r_bp_add_fault(RBreakpoint *bp, ut64 addr, int size, int perm) {
-       // TODO
+       R_RETURN_IF_FAIL (bp);
+       /* Add a fault-type breakpoint (no original bytes to preserve) */
+       r_bp_add (bp, NULL, addr, size, R_BP_TYPE_FAULT, perm);
 }
 
 R_API RBreakpointItem* r_bp_add_sw(RBreakpoint *bp, ut64 addr, int size, int perm) {
@@ -401,6 +401,7 @@ R_API int r_bp_size(RBreakpoint *bp) {
 
 // Check if the breakpoint is in a valid map
 R_API bool r_bp_is_valid(RBreakpoint *bp, RBreakpointItem *b) {
+       R_RETURN_VAL_IF_FAIL (bp && b, false);
        if (bp->bpinmaps) {
                return bp->coreb.isMapped (bp->coreb.core, b->addr, b->perm);
        }
index 5512dc5a20fbff46c7e6a2ffa1e45ba6f676bd8d..984ac17c468905a70798ccc849699194137bebcf 100644 (file)
@@ -2,48 +2,42 @@
 
 #include <r_bp.h>
 
-R_API int r_bp_plugin_del(RBreakpoint *bp, const char *name) {
+R_API bool r_bp_plugin_del(RBreakpoint *bp, const char *name) {
+       R_RETURN_VAL_IF_FAIL (bp && name, false);
        RListIter *iter;
        RBreakpointPlugin *h;
-       if (name && *name) {
-               r_list_foreach (bp->plugins, iter, h) {
-                       if (!strcmp (h->meta.name, name)) {
-                               if (bp->cur == h) {
-                                       bp->cur = NULL;
-                               }
-                               r_list_delete (bp->plugins, iter);
-                               bp->nbps--;
-                               return true;
+       r_list_foreach (bp->plugins, iter, h) {
+               if (!strcmp (h->meta.name, name)) {
+                       if (bp->cur == h) {
+                               bp->cur = NULL;
                        }
+                       r_list_delete (bp->plugins, iter);
+                       return true;
                }
        }
        return false;
 }
 
-R_API int r_bp_plugin_add(RBreakpoint *bp, RBreakpointPlugin *foo) {
+R_API bool r_bp_plugin_add(RBreakpoint *bp, RBreakpointPlugin *foo) {
+       R_RETURN_VAL_IF_FAIL (bp && foo, false);
        RListIter *iter;
        RBreakpointPlugin *h;
-       if (!bp) {
-               R_LOG_ERROR ("Cannot add plugin because dbg->bp is null and/or plugin is null");
-               return false;
-       }
-       /* avoid dupped plugins */
-       r_list_foreach (bp->bps, iter, h) {
+       r_list_foreach (bp->plugins, iter, h) {
                if (!strcmp (h->meta.name, foo->meta.name)) {
                        return false;
                }
        }
-       bp->nbps++;
        r_list_append (bp->plugins, foo);
        return true;
 }
 
-R_API int r_bp_plugin_remove(RBreakpoint *bp, RBreakpointPlugin *plugin) {
-       // R2_590 TODO
-       return true;
+R_API bool r_bp_plugin_remove(RBreakpoint *bp, RBreakpointPlugin *plugin) {
+       R_RETURN_VAL_IF_FAIL (bp && plugin, false);
+       return r_bp_plugin_del (bp, plugin->meta.name);
 }
 
-R_API int r_bp_use(RBreakpoint *bp, const char *name, int bits) {
+R_API bool r_bp_use(RBreakpoint *bp, const char *name, int bits) {
+       R_RETURN_VAL_IF_FAIL (bp && name, false);
        RListIter *iter;
        bp->bits = bits;
        RBreakpointPlugin *h;
@@ -57,6 +51,7 @@ R_API int r_bp_use(RBreakpoint *bp, const char *name, int bits) {
 }
 
 R_API char *r_bp_plugin_list(RBreakpoint *bp) {
+       R_RETURN_VAL_IF_FAIL (bp, NULL);
        RListIter *iter;
        RBreakpointPlugin *b;
        RStrBuf *sb = r_strbuf_new ("");
index 6756a309c1feeb1bb747d9eca9420750a9e4df20..cecb965e77a4d5ffffd7c46a7c62d8a09a53049e 100644 (file)
@@ -100,9 +100,15 @@ R_API int r_bp_traptrace_add(RBreakpoint *bp, ut64 from, ut64 to) {
                return false;
        }
        // TODO: check return value
-       bp->iob.read_at (bp->iob.io, from, buf, len);
+       int rd = bp->iob.read_at (bp->iob.io, from, buf, (int)len);
+       if (rd != (int)len) {
+               free (buf);
+               free (trap);
+               free (bits);
+               return false;
+       }
        memset (bits, 0x00, bitlen);
-       r_bp_get_bytes (bp, trap, len, bp->endian, 0);
+       r_bp_get_bytes (bp, trap, (int)len, bp->endian, 0);
 
        trace = R_NEW (RBreakpointTrace);
        if (!trace) {
index ca126d2b5f81654147bb201142e5852c7a5deacd..51f68b95a254aa279c1c30acf47322ae1d581016 100644 (file)
@@ -9,15 +9,15 @@ static void r_bp_watch_add_hw(RBreakpoint *bp, RBreakpointItem *b) {
 }
 
 R_API RBreakpointItem* r_bp_watch_add(RBreakpoint *bp, ut64 addr, int size, int hw, int perm) {
-       RBreakpointItem *b;
+       // use R_RETURN precondition checks in all R_API functions
        if (addr == UT64_MAX || size < 1) {
                return NULL;
        }
        if (r_bp_get_in (bp, addr, perm)) {
-               eprintf ("Breakpoint already set at this address.\n");
+               R_LOG_WARN ("Breakpoint already set at this address");
                return NULL;
        }
-       b = r_bp_item_new (bp);
+       RBreakpointItem *b = r_bp_item_new (bp);
        b->addr = addr + bp->delta;
        b->size = size;
        b->enabled = true;
@@ -26,13 +26,13 @@ R_API RBreakpointItem* r_bp_watch_add(RBreakpoint *bp, ut64 addr, int size, int
        if (hw) {
                r_bp_watch_add_hw (bp, b);
        } else {
-               eprintf ("[TODO]: Software watchpoint is not implemented yet (use ESIL)\n");
+               R_LOG_TODO ("Software watchpoint is not implemented yet (use ESIL)");
                /* TODO */
        }
-       bp->nbps++;
        r_list_append (bp->bps, b);
        return b;
 }
 
 R_API void r_bp_watch_del(void) {
+       R_LOG_TODO ("r_bp_watch_del not implemented");
 }
index 93918e7f7a59c6e6b924a9ed7ccf08442ce43043..a5a9057acde7c9162eb2338cf8d73060b8f62392 100644 (file)
@@ -77,13 +77,12 @@ typedef struct r_bp_t {
        RList *plugins;
        RBreakpointCallback breakpoint;
        /* storage of breakpoints */
-       int nbps;
-       int nhwbps;
        RList *bps; // list of breakpoints
        RBreakpointItem **bps_idx;
        int bps_idx_count;
        st64 delta;
        ut64 baddr;
+       int nhwbps;
 } RBreakpoint;
 
 // DEPRECATED: USE R_PERM
@@ -106,15 +105,15 @@ typedef struct r_bp_trace_t {
 
 #ifdef R_API
 R_API RBreakpoint *r_bp_new(void);
-R_API RBreakpoint *r_bp_free(RBreakpoint *bp);
+R_API void r_bp_free(RBreakpoint *bp);
 
 R_API bool r_bp_del(RBreakpoint *bp, ut64 addr);
 R_API bool r_bp_del_all(RBreakpoint *bp);
 
-R_API int r_bp_plugin_add(RBreakpoint *bp, RBreakpointPlugin *plugin);
-R_API int r_bp_plugin_remove(RBreakpoint *bp, RBreakpointPlugin *plugin);
-R_API int r_bp_use(RBreakpoint *bp, const char *name, int bits);
-R_API int r_bp_plugin_del(RBreakpoint *bp, const char *name);
+R_API bool r_bp_plugin_add(RBreakpoint *bp, RBreakpointPlugin *plugin);
+R_API bool r_bp_use(RBreakpoint *bp, const char *name, int bits);
+R_API bool r_bp_plugin_remove(RBreakpoint *bp, RBreakpointPlugin *plugin);
+R_API bool r_bp_plugin_del(RBreakpoint *bp, const char *name);
 R_API char *r_bp_plugin_list(RBreakpoint *bp);
 
 R_API int r_bp_in(RBreakpoint *bp, ut64 addr, int perm);
@@ -127,6 +126,7 @@ R_API bool r_bp_set_trace(RBreakpoint *bp, ut64 addr, int set);
 R_API void r_bp_set_trace_all(RBreakpoint *bp, int set);
 R_API RBreakpointItem *r_bp_enable(RBreakpoint *bp, ut64 addr, int set, int count);
 R_API void r_bp_enable_all(RBreakpoint *bp, int set);
+R_API int r_bp_stepy_continuation(RBreakpoint *bp);
 
 /* index api */
 R_API RBreakpointItem *r_bp_get_index(RBreakpoint *bp, int idx);
@@ -159,7 +159,6 @@ R_API int r_bp_traptrace_free_at(RBreakpoint *bp, ut64 from);
 R_API void r_bp_traptrace_list(RBreakpoint *bp);
 R_API bool r_bp_traptrace_at(RBreakpoint *bp, ut64 from, int len);
 R_API RList *r_bp_traptrace_new(void);
-R_API void r_bp_traptrace_enable(RBreakpoint *bp, int enable);
 
 /* watchpoint */
 R_API RBreakpointItem *r_bp_watch_add(RBreakpoint *bp, ut64 addr, int size, int hw, int rw);