* cleanup the TODO file

* Added cfg.debug config variable
* Fix the basic stuff for r.dbg.reg api integrated with core
* Failover into the plugin breakpoint implementation to support
  non memory breakpoints like API ones or hardware ones
* Added initial non-working version of the gdbwrap debug plugin
  - We need to design an IO plugin for gdbwrap too (or a way to
  change the IO based on the debug plugin)
This commit is contained in:
pancake 2009-04-17 11:42:45 +00:00
parent eb4b4b6f29
commit ff8a7ecd58
9 changed files with 113 additions and 32 deletions

7
TODO
View file

@ -8,7 +8,7 @@
<{include libr/TODO}>
* Implement rahash2
* 'Vc' cursor mode makes color toggle
* Finish and import the spp's getopt owns implementation in r_util
@ -34,8 +34,3 @@
scripting language, so we can for example prepare
a .c stub interface for python/perl/ruby/..
- Maybe having a preprocessor tool for this..
Debugger:
* arrows not working in visual
* add -i and -l to radare2
* make ruby do not ping with 'Load' message

View file

@ -165,6 +165,8 @@ R_API int r_core_config_init(struct r_core_t *core)
r_config_set(cfg, "cmd.bp", "");
r_config_set(cfg, "cfg.fortunes", "true");
r_config_set(cfg, "cfg.debug", "false");
#if 0
config_set_i("search.from", 0);
config_set_i("search.to", 0);

View file

@ -121,6 +121,7 @@ int main(int argc, char **argv)
fprintf (stderr, "Cannot open file '%s'\n", file);
return 1;
}
r_config_set(&r.config, "cfg.debug", "true");
} else
while (optind < argc) {
const char *file = argv[optind++];
@ -151,9 +152,9 @@ int main(int argc, char **argv)
r_core_cmdf (&r, "dp %d", r.file->fd);
r_core_cmd (&r, ".dr*", 0);
r_core_cmd (&r, "s eip", 0);
r_core_cmd (&r, "e cmd.prompt=.dr",0);
r_core_cmd (&r, "\"e cmd.vprompt=.dr\"",0);
r_core_cmd (&r, "\"e cmd.visual=.dr\"",0);
r_core_cmd (&r, "e cmd.prompt=.dr*",0);
r_core_cmd (&r, "\"e cmd.vprompt=.dr*\"",0);
r_core_cmd (&r, "\"e cmd.visual=.dr*\"",0);
}
if (seek)

View file

@ -4,10 +4,12 @@
#define NPF 6
static int printidx = 0;
//const char *printfmt[] = { "x", "pd", "p8", "pc", "ps", ".dr*&&s esp&&x 64&&dr&&s eip&&pd" };
const char *printfmt[] = { "x", "pd", "p8", "pc", "ps", "s esp&&x 64&&dr&&s eip&&pd" };
static int curset = 0, cursor = -1, ocursor=-1;
static int color = 1;
static int debug = 1;
static int flags = R_PRINT_FLAGS_ADDRMOD;
static int marks_init = 0;
@ -673,6 +675,7 @@ R_API int r_core_visual(struct r_core_t *core, const char *input)
}
color = r_config_get_i(&core->config, "scr.color");
debug = r_config_get_i(&core->config, "cfg.debug");
do {
scrseek = r_num_math(&core->num,
r_config_get(&core->config, "scr.seek"));
@ -680,6 +683,9 @@ R_API int r_core_visual(struct r_core_t *core, const char *input)
r_core_seek (core, scrseek, 1);
// TODO: read?
}
if (debug) {
r_core_cmd(core, ".dr*", 0);
}
cmdprompt = r_config_get (&core->config, "cmd.vprompt");
if (cmdprompt && cmdprompt[0])
r_core_cmd(core, cmdprompt, 0);

View file

@ -13,8 +13,9 @@ R_API int r_debug_bp_enable(struct r_debug_t *dbg, u64 addr, int set)
return bp!=NULL;
}
R_API int r_debug_bp_add(struct r_debug_t *dbg, u64 addr, int size)
R_API int r_debug_bp_add(struct r_debug_t *dbg, u64 addr, int size, int hw, int rwx)
{
int ret = R_FALSE;
struct r_bp_item_t *bp;
if (dbg->read == NULL) {
eprintf("No dbg->read callback defined\n");
@ -25,11 +26,14 @@ 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;
if (bp) {
if (dbg->h && (!dbg->h->bp_write || !dbg->h->bp_write(dbg->pid, addr, size, hw, rwx )))
dbg->write(dbg->user, dbg->pid, addr, bp->bbytes, size);
/* if already set, r_bp should return false */
free(buf);
ret = R_TRUE;
}
return ret;
}
R_API int r_debug_bp_del(struct r_debug_t *dbg, u64 addr)
@ -44,8 +48,10 @@ R_API int r_debug_bp_restore(struct r_debug_t *dbg, int set)
{
if (set) {
/* write bbytes from every breakpoint in r_bp */
// r_debug_bp_enable(dbg, addr, 1)
} else {
/* write obytes from every breakpoint */
// r_debug_bp_enable(dbg, addr, 0)
}
return R_TRUE;
}

View file

@ -19,7 +19,6 @@ int r_debug_handle_set(struct r_debug_t *dbg, const char *str)
return R_TRUE;
}
}
return R_FALSE;
}
@ -32,7 +31,6 @@ int r_debug_handle_list(struct r_debug_t *dbg, const char *str)
printf("%d %s %s\n", count, h->name, ((h==dbg->h)?"*":""));
count++;
}
return R_FALSE;
}

67
libr/debug/p/dbg_gdb.c Normal file
View file

@ -0,0 +1,67 @@
/* radare - LGPL - Copyright 2009 pancake<nopcode.org> */
#include <r_debug.h>
#include <r_lib.h>
#include "libgdbwrap/include/gdbwrapper.h"
/* TODO: The IO stuff must be communicated with the r_dbg */
/* a transplant sometimes requires to change the IO */
/* so, for here, we need r_io_plugin_gdb */
/* TODO: rename to gdbwrap? */
static int r_debug_gdb_step(int pid)
{
gdbwrap_stepi(desc);
}
struct r_debug_regset_t * r_debug_gdb_reg_read(int pid)
{
struct r_debug_regset *r = NULL;
/* only for x86-32 */
gdbwrap_gdbreg32 *reg = gdbwrap_readgenreg(desc);
r = r_debug_regset_new(9);
r_debug_regset_set(r, 0, "eax", reg->eax);
r_debug_regset_set(r, 1, "ebx", reg->ebx);
r_debug_regset_set(r, 2, "ecx", reg->ecx);
r_debug_regset_set(r, 3, "edx", reg->edx);
r_debug_regset_set(r, 4, "esi", reg->esi);
r_debug_regset_set(r, 5, "edi", reg->edi);
r_debug_regset_set(r, 6, "esp", reg->esp);
r_debug_regset_set(r, 7, "ebp", reg->ebp);
r_debug_regset_set(r, 8, "eip", reg->eip);
return r;
}
static int r_debug_gdb_reg_write(int pid, struct r_debug_regset_t *regs)
{
/* TODO */
}
static int r_debug_ptrace_continue(int pid)
{
gdbwrap_continue(desc);
}
static int r_debug_ptrace_wait(int pid)
{
/* do nothing */
}
static struct r_debug_handle_t r_dbg_plugin_gdb = {
.name = "gdb",
.archs = { "x86", 0 }, //"x86-64", "arm", "powerpc", 0 },
.step = &r_debug_gdb_step,
.cont = &r_debug_gdb_continue,
//.attach = &r_debug_gdb_attach,
//.detach = &r_debug_gdb_detach,
.wait = &r_debug_gdb_wait,
.reg_read = &r_debug_gdb_reg_read,
.reg_write = &r_debug_gdb_reg_write,
//.bp_write = &r_debug_gdb_bp_write,
//.bp_read = &r_debug_gdb_bp_read,
};
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_DBG,
.data = &r_dbg_plugin_gdb
};

View file

@ -79,31 +79,36 @@ struct r_debug_regset_t * r_debug_ptrace_reg_read(int pid)
/* TODO: use enum for 0, 1, 2... ? */
/* TODO: missing eflags here */
r = r_debug_regset_new(9);
r_debug_regset_set(r, 0, "eax", regs.eax);
r_debug_regset_set(r, 1, "ebx", regs.ebx);
r_debug_regset_set(r, 2, "ecx", regs.ecx);
r_debug_regset_set(r, 3, "edx", regs.edx);
r_debug_regset_set(r, 4, "esi", regs.esi);
r_debug_regset_set(r, 5, "edi", regs.edi);
r_debug_regset_set(r, 6, "esp", regs.esp);
r_debug_regset_set(r, 7, "ebp", regs.ebp);
r_debug_regset_set(r, 8, "eip", regs.eip);
r_debug_regset_set(r, 0, "eax", (u64)(u32)regs.eax);
r_debug_regset_set(r, 1, "ebx", (u64)(u32)regs.ebx);
r_debug_regset_set(r, 2, "ecx", (u64)(u32)regs.ecx);
r_debug_regset_set(r, 3, "edx", (u64)(u32)regs.edx);
r_debug_regset_set(r, 4, "esi", (u64)(u32)regs.esi);
r_debug_regset_set(r, 5, "edi", (u64)(u32)regs.edi);
r_debug_regset_set(r, 6, "esp", (u64)(u32)regs.esp);
r_debug_regset_set(r, 7, "ebp", (u64)(u32)regs.ebp);
r_debug_regset_set(r, 8, "eip", (u64)(u32)regs.eip);
#endif
#endif /* linux */
return r;
}
int r_debug_ptrace_reg_write(int pid, struct r_debug_regset_t *regs)
static int r_debug_ptrace_reg_write(int pid, struct r_debug_regset_t *regs)
{
/* TODO */
}
static int r_debug_ptrace_bp_write(int pid, u64 addr, int hw, int type)
static int r_debug_ptrace_bp_write(int pid, u64 addr, int size, int hw, int rwx)
{
return R_TRUE;
if (hw) {
/* implement DRx register handling here */
return R_TRUE;
}
return R_FALSE;
}
static int r_debug_ptrace_bp_read(int pid, u64 addr, int hw, int type)
/* TODO: rethink */
static int r_debug_ptrace_bp_read(int pid, u64 addr, int hw, int rwx)
{
return R_TRUE;
}

View file

@ -48,7 +48,8 @@ struct r_debug_handle_t {
int (*cont)(int pid);
int (*wait)(int pid);
int (*contsc)(int pid, int sc);
int (*bp_write)(int pid, u64 addr, int hw, int type);
//int (*bp_write)(int pid, u64 addr, int hw, int type);
int (*bp_write)(int pid, u64 addr, int size, int hw, int rwx);
struct r_debug_regset_t * (*reg_read)(int pid);
int (*reg_write)(int pid, struct r_debug_regset_t *regs);
// XXX bad signature int (*bp_read)(int pid, u64 addr, int hw, int type);
@ -118,7 +119,7 @@ R_API int r_debug_handle_list(struct r_debug_t *dbg, const char *str);
R_API 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_add(struct r_debug_t *dbg, u64 addr, int size, int hw, int rwx);
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, u64 addr, int set);
R_API int r_debug_bp_disable(struct r_debug_t *dbg);