mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-02 03:32:04 +00:00
* Fix breakpoint management issues in r_bp
- Make r_bp_enable return bp_item - dbh: breakpoint handler plugins can now be listed and selected - Added 'dbe' and 'dbd' commands to enable and disable breakpoints
This commit is contained in:
parent
c19f08fdf0
commit
123e84b4ba
25
libr/bp/bp.c
25
libr/bp/bp.c
@ -10,9 +10,9 @@ R_API int r_bp_init(struct r_bp_t *bp)
|
||||
{
|
||||
int i;
|
||||
bp->nbps = 0;
|
||||
fprintf(stderr, "bp.init()\n");
|
||||
bp->cur = NULL;
|
||||
INIT_LIST_HEAD(&bp->bps);
|
||||
INIT_LIST_HEAD(&bp->plugins);
|
||||
for(i=0;bp_static_plugins[i];i++)
|
||||
r_bp_handle_add(bp, bp_static_plugins[i]);
|
||||
return R_TRUE;
|
||||
@ -45,14 +45,14 @@ R_API int r_bp_handle_add(struct r_bp_t *bp, struct r_bp_handle_t *foo)
|
||||
return R_FALSE;
|
||||
}
|
||||
bp->nbps++;
|
||||
list_add_tail(&(foo->list), &(bp->bps));
|
||||
list_add_tail(&(foo->list), &(bp->plugins));
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
R_API int r_bp_handle_set(struct r_bp_t *bp, const char *name)
|
||||
{
|
||||
struct list_head *pos;
|
||||
list_for_each_prev(pos, &bp->bps) {
|
||||
list_for_each_prev(pos, &bp->plugins) {
|
||||
struct r_bp_handle_t *h = list_entry(pos, struct r_bp_handle_t, list);
|
||||
if (!strcmp(h->name, name)) {
|
||||
bp->cur = h;
|
||||
@ -127,7 +127,7 @@ R_API int r_bp_in(struct r_bp_t *bp, u64 addr, int rwx)
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
R_API int r_bp_enable(struct r_bp_t *bp, u64 addr, int set)
|
||||
R_API struct r_bp_item_t *r_bp_enable(struct r_bp_t *bp, u64 addr, int set)
|
||||
{
|
||||
struct list_head *pos;
|
||||
struct r_bp_item_t *b;
|
||||
@ -135,10 +135,10 @@ R_API int r_bp_enable(struct r_bp_t *bp, u64 addr, int set)
|
||||
b = list_entry(pos, struct r_bp_item_t, list);
|
||||
if (addr >= b->addr && addr <= b->addr+b->size) {
|
||||
b->enabled = set;
|
||||
return R_TRUE;
|
||||
return b;
|
||||
}
|
||||
}
|
||||
return R_FALSE;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* TODO: detect overlapping of breakpoints */
|
||||
@ -187,6 +187,19 @@ R_API int r_bp_del(struct r_bp_t *bp, u64 addr)
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
R_API void r_bp_handle_list(struct r_bp_t *bp)
|
||||
{
|
||||
struct r_bp_handle_t *b;
|
||||
struct list_head *pos;
|
||||
list_for_each(pos, &bp->plugins) {
|
||||
b = list_entry(pos, struct r_bp_handle_t, list);
|
||||
if (bp->cur && !strcmp(bp->cur->name, b->name))
|
||||
printf(" * %s\n", b->name);
|
||||
else printf(" - %s\n", b->name);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
R_API int r_bp_list(struct r_bp_t *bp, int rad)
|
||||
{
|
||||
struct r_bp_item_t *b;
|
||||
|
@ -1517,12 +1517,28 @@ static int cmd_debug(void *data, const char *input)
|
||||
case '-':
|
||||
r_debug_bp_del(&core->dbg, r_num_math(&core->num, input+2));
|
||||
break;
|
||||
case 'e':
|
||||
r_debug_bp_enable(&core->dbg, r_num_math(&core->num, input+2), 1);
|
||||
break;
|
||||
case 'd':
|
||||
r_debug_bp_enable(&core->dbg, r_num_math(&core->num, input+2), 0);
|
||||
break;
|
||||
case 'h':
|
||||
if (input[2]==' ') {
|
||||
if (!r_bp_handle_set(&core->dbg.bp, input+3)) {
|
||||
eprintf("Invalid name: '%s'.\n", input+3);
|
||||
}
|
||||
} else r_bp_handle_list(&core->dbg.bp);
|
||||
break;
|
||||
case '?':
|
||||
r_cons_printf(
|
||||
"Usage: db [[-]addr] [len] [rwx] [condstring]\n"
|
||||
"db ; list breakpoints\n"
|
||||
"db 0x804800 ; add breakpoint\n"
|
||||
"db -0x804800 ; remove breakpoint\n"
|
||||
"db ; list breakpoint\n");
|
||||
"dbe 0x8048000 ; enable breakpoint\n"
|
||||
"dbd 0x8048000 ; disable breakpoint\n"
|
||||
"dbh x86 ; set/list breakpoint plugin handlers\n");
|
||||
break;
|
||||
default:
|
||||
r_debug_bp_add(&core->dbg, r_num_math(&core->num, input+1), 1);
|
||||
|
@ -72,7 +72,7 @@ static int __dbg_read(void *user, int pid, u64 addr, u8 *buf, int len)
|
||||
return r_core_read_at(core, addr, buf, len);
|
||||
}
|
||||
|
||||
static int __dbg_write(void *user, int pid, u64 addr, u8 *buf, int len)
|
||||
static int __dbg_write(void *user, int pid, u64 addr, const u8 *buf, int len)
|
||||
{
|
||||
struct r_core_t *core = (struct r_core_t *)user;
|
||||
// TODO: pid not used
|
||||
@ -123,7 +123,7 @@ R_API int r_core_init(struct r_core_t *core)
|
||||
r_core_cmd_init(core);
|
||||
r_flag_init(&core->flags);
|
||||
r_debug_init(&core->dbg);
|
||||
r_debug_set_io(&core->dbg,__dbg_read, __dbg_write, core);
|
||||
r_debug_set_io(&core->dbg, &__dbg_read, &__dbg_write, core);
|
||||
r_core_config_init(core);
|
||||
// XXX fix path here
|
||||
|
||||
|
@ -1,6 +1,17 @@
|
||||
/* radare - LGPL - Copyright 2009 pancake<nopcode.org> */
|
||||
|
||||
#include <r_debug.h>
|
||||
#include <r_bp.h>
|
||||
|
||||
R_API int r_debug_bp_enable(struct r_debug_t *dbg, u64 addr, int set)
|
||||
{
|
||||
struct r_bp_item_t *bp = r_bp_enable(&dbg->bp, addr, set);
|
||||
if (bp) {
|
||||
if (set) dbg->write(dbg->user, dbg->pid, addr, bp->bbytes, bp->size);
|
||||
else dbg->write(dbg->user, dbg->pid, addr, bp->obytes, bp->size);
|
||||
}
|
||||
return bp!=NULL;
|
||||
}
|
||||
|
||||
R_API int r_debug_bp_add(struct r_debug_t *dbg, u64 addr, int size)
|
||||
{
|
||||
@ -14,6 +25,8 @@ R_API int r_debug_bp_add(struct r_debug_t *dbg, u64 addr, int size)
|
||||
dbg->read(dbg->user, dbg->pid, addr, buf, size);
|
||||
/* register breakpoint in r_bp */
|
||||
bp = r_bp_add(&dbg->bp, buf, addr, size, 0, R_BP_EXEC);
|
||||
memcpy(buf, bp->bbytes, size);
|
||||
dbg->write(dbg->user, dbg->pid, addr, buf, size);
|
||||
/* if already set, r_bp should return false */
|
||||
free(buf);
|
||||
return bp!=NULL;
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
R_API int r_debug_pid_list(struct r_debug_t *dbg)
|
||||
{
|
||||
int count = 0;
|
||||
//int count = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,7 @@ struct r_bp_t {
|
||||
u64 trace_bp;
|
||||
int nbps;
|
||||
struct r_bp_handle_t *cur;
|
||||
struct list_head plugins;
|
||||
struct list_head bps;
|
||||
};
|
||||
|
||||
@ -57,12 +58,14 @@ R_API int r_bp_del(struct r_bp_t *bp, u64 addr);
|
||||
R_API int r_bp_handle_add(struct r_bp_t *bp, struct r_bp_handle_t *foo);
|
||||
R_API int r_bp_handle_set(struct r_bp_t *bp, const char *name);
|
||||
R_API int r_bp_handle_del(struct r_bp_t *bp, const char *name);
|
||||
R_API void r_bp_handle_list(struct r_bp_t *bp);
|
||||
|
||||
R_API int r_bp_in(struct r_bp_t *bp, u64 addr, int rwx);
|
||||
R_API int r_bp_list(struct r_bp_t *bp, int rad);
|
||||
R_API int r_bp_getbytes(struct r_bp_t *bp, u8 *buf, int len, int endian, int idx);
|
||||
R_API int r_bp_set_trace(struct r_bp_t *bp, u64 addr, int set);
|
||||
R_API int r_bp_set_trace_bp(struct r_bp_t *bp, u64 addr, int set);
|
||||
R_API struct r_bp_item_t *r_bp_enable(struct r_bp_t *bp, u64 addr, int set);
|
||||
|
||||
/* plugin pointers */
|
||||
extern struct r_bp_handle_t r_bp_plugin_x86;
|
||||
|
@ -99,7 +99,7 @@ int r_debug_handle_add(struct r_debug_t *dbg, struct r_debug_handle_t *foo);
|
||||
/* breakpoints */
|
||||
R_API int r_debug_bp_add(struct r_debug_t *dbg, u64 addr, int size);
|
||||
R_API int r_debug_bp_del(struct r_debug_t *dbg, u64 addr);
|
||||
R_API int r_debug_bp_enable(struct r_debug_t *dbg);
|
||||
R_API int r_debug_bp_enable(struct r_debug_t *dbg, u64 addr, int set);
|
||||
R_API int r_debug_bp_disable(struct r_debug_t *dbg);
|
||||
R_API int r_debug_bp_list(struct r_debug_t *dbg, int rad);
|
||||
#if 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user