* Added support for LUA bindings
- Simple test program for r_bp * Fix debugger build on arm/mips/powerpc
This commit is contained in:
parent
05df350346
commit
c50ea5b5a9
48
libr/bp/bp.c
48
libr/bp/bp.c
|
@ -6,8 +6,7 @@
|
|||
static struct r_bp_handle_t *bp_static_plugins[] =
|
||||
{ R_BP_STATIC_PLUGINS };
|
||||
|
||||
R_API struct r_bp_t *r_bp_init(struct r_bp_t *bp)
|
||||
{
|
||||
R_API struct r_bp_t *r_bp_init(struct r_bp_t *bp) {
|
||||
int i;
|
||||
if (bp) {
|
||||
bp->cur = NULL;
|
||||
|
@ -28,15 +27,13 @@ R_API struct r_bp_t *r_bp_new() {
|
|||
return r_bp_init (MALLOC_STRUCT (struct r_bp_t));
|
||||
}
|
||||
|
||||
R_API struct r_bp_t *r_bp_free(struct r_bp_t *bp)
|
||||
{
|
||||
R_API struct r_bp_t *r_bp_free(struct r_bp_t *bp) {
|
||||
/* XXX : properly destroy bp list */
|
||||
free (bp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
R_API int r_bp_get_bytes(struct r_bp_t *bp, ut8 *buf, int len, int endian, int idx)
|
||||
{
|
||||
R_API int r_bp_get_bytes(struct r_bp_t *bp, ut8 *buf, int len, int endian, int idx) {
|
||||
int i;
|
||||
struct r_bp_arch_t *b;
|
||||
if (bp->cur) {
|
||||
|
@ -55,23 +52,20 @@ R_API int r_bp_get_bytes(struct r_bp_t *bp, ut8 *buf, int len, int endian, int i
|
|||
return 0;
|
||||
}
|
||||
|
||||
R_API RBreakpointItem *r_bp_at_addr(RBreakpoint *bp, ut64 addr, int rwx)
|
||||
{
|
||||
R_API RBreakpointItem *r_bp_at_addr(RBreakpoint *bp, ut64 addr, int rwx) {
|
||||
struct list_head *pos;
|
||||
RBreakpointItem *b;
|
||||
|
||||
eprintf ("===ataddr=== 0x%08llx\n", addr);
|
||||
list_for_each(pos, &bp->bps) {
|
||||
b = list_entry(pos, struct r_bp_item_t, list);
|
||||
eprintf ("---ataddr--- 0x%08llx %d %d\n", b->addr, b->size, b->recoil);
|
||||
// eprintf ("---ataddr--- 0x%08llx %d %d\n", b->addr, b->size, b->recoil);
|
||||
if (addr >= b->addr && addr <= b->addr+b->size && rwx&b->rwx)
|
||||
return b;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
R_API struct r_bp_item_t *r_bp_enable(struct r_bp_t *bp, ut64 addr, int set)
|
||||
{
|
||||
R_API struct r_bp_item_t *r_bp_enable(struct r_bp_t *bp, ut64 addr, int set) {
|
||||
struct list_head *pos;
|
||||
struct r_bp_item_t *b;
|
||||
list_for_each(pos, &bp->bps) {
|
||||
|
@ -84,29 +78,25 @@ R_API struct r_bp_item_t *r_bp_enable(struct r_bp_t *bp, ut64 addr, int set)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
R_API int r_bp_stepy_continuation(struct r_bp_t *bp)
|
||||
{
|
||||
R_API int r_bp_stepy_continuation(struct r_bp_t *bp) {
|
||||
// TODO: implement
|
||||
return bp->stepcont;
|
||||
}
|
||||
|
||||
R_API int r_bp_add_cond(struct r_bp_t *bp, const char *cond)
|
||||
{
|
||||
R_API int r_bp_add_cond(struct r_bp_t *bp, const char *cond) {
|
||||
// TODO: implement contitional breakpoints
|
||||
bp->stepcont = R_TRUE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
R_API int r_bp_del_cond(struct r_bp_t *bp, int idx)
|
||||
{
|
||||
R_API int r_bp_del_cond(struct r_bp_t *bp, int idx) {
|
||||
// add contitional
|
||||
bp->stepcont = R_FALSE;
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
/* TODO: detect overlapping of breakpoints */
|
||||
static struct r_bp_item_t *r_bp_add(struct r_bp_t *bp, const ut8 *obytes, ut64 addr, int size, int hw, int rwx)
|
||||
{
|
||||
static struct r_bp_item_t *r_bp_add(struct r_bp_t *bp, const ut8 *obytes, ut64 addr, int size, int hw, int rwx) {
|
||||
int ret;
|
||||
struct r_bp_item_t *b;
|
||||
if (r_bp_at_addr (bp, addr, rwx)) {
|
||||
|
@ -149,14 +139,12 @@ static struct r_bp_item_t *r_bp_add(struct r_bp_t *bp, const ut8 *obytes, ut64 a
|
|||
return b;
|
||||
}
|
||||
|
||||
R_API int r_bp_add_fault(struct r_bp_t *bp, ut64 addr, int size, int rwx)
|
||||
{
|
||||
R_API int r_bp_add_fault(struct r_bp_t *bp, ut64 addr, int size, int rwx) {
|
||||
// TODO
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
R_API struct r_bp_item_t *r_bp_add_sw(struct r_bp_t *bp, ut64 addr, int size, int rwx)
|
||||
{
|
||||
R_API struct r_bp_item_t *r_bp_add_sw(struct r_bp_t *bp, ut64 addr, int size, int rwx) {
|
||||
struct r_bp_item_t *item;
|
||||
ut8 *bytes;
|
||||
if (size<1)
|
||||
|
@ -172,13 +160,11 @@ R_API struct r_bp_item_t *r_bp_add_sw(struct r_bp_t *bp, ut64 addr, int size, in
|
|||
return item;
|
||||
}
|
||||
|
||||
R_API struct r_bp_item_t *r_bp_add_hw(struct r_bp_t *bp, ut64 addr, int size, int rwx)
|
||||
{
|
||||
R_API struct r_bp_item_t *r_bp_add_hw(struct r_bp_t *bp, ut64 addr, int size, int rwx) {
|
||||
return r_bp_add (bp, NULL, addr, size, R_BP_TYPE_HW, rwx);
|
||||
}
|
||||
|
||||
R_API int r_bp_del(struct r_bp_t *bp, ut64 addr)
|
||||
{
|
||||
R_API int r_bp_del(struct r_bp_t *bp, ut64 addr) {
|
||||
struct list_head *pos;
|
||||
struct r_bp_item_t *b;
|
||||
list_for_each(pos, &bp->bps) {
|
||||
|
@ -194,8 +180,7 @@ R_API int r_bp_del(struct r_bp_t *bp, ut64 addr)
|
|||
// TODO: rename or drop?
|
||||
// TODO: use a r_bp_item instead of address
|
||||
// TODO: we can just drop it.. its just b->trace = R_TRUE or so..
|
||||
R_API int r_bp_set_trace(struct r_bp_t *bp, ut64 addr, int set)
|
||||
{
|
||||
R_API int r_bp_set_trace(struct r_bp_t *bp, ut64 addr, int set) {
|
||||
struct list_head *pos;
|
||||
struct r_bp_item_t *b;
|
||||
list_for_each(pos, &bp->bps) {
|
||||
|
@ -219,8 +204,7 @@ R_API int r_bp_set_trace_bp(struct r_bp_t *bp, ut64 addr, int set)
|
|||
#endif
|
||||
|
||||
// TODO: deprecate
|
||||
R_API int r_bp_list(struct r_bp_t *bp, int rad)
|
||||
{
|
||||
R_API int r_bp_list(struct r_bp_t *bp, int rad) {
|
||||
int n = 0;
|
||||
struct r_bp_item_t *b;
|
||||
struct list_head *pos;
|
||||
|
|
|
@ -16,22 +16,22 @@ R_API int r_bp_handle_add(struct r_bp_t *bp, struct r_bp_handle_t *foo)
|
|||
return R_FALSE;
|
||||
}
|
||||
/* avoid dupped plugins */
|
||||
list_for_each_prev(pos, &bp->bps) {
|
||||
struct r_bp_handle_t *h = list_entry(pos, struct r_bp_handle_t, list);
|
||||
if (!strcmp(h->name, foo->name))
|
||||
list_for_each_prev (pos, &bp->bps) {
|
||||
struct r_bp_handle_t *h = list_entry (pos, struct r_bp_handle_t, list);
|
||||
if (!strcmp (h->name, foo->name))
|
||||
return R_FALSE;
|
||||
}
|
||||
bp->nbps++;
|
||||
list_add_tail(&(foo->list), &(bp->plugins));
|
||||
list_add_tail (&(foo->list), &(bp->plugins));
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
R_API int r_bp_use(struct r_bp_t *bp, const char *name)
|
||||
{
|
||||
struct list_head *pos;
|
||||
list_for_each_prev(pos, &bp->plugins) {
|
||||
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)) {
|
||||
if (!strcmp (h->name, name)) {
|
||||
bp->cur = h;
|
||||
return R_TRUE;
|
||||
}
|
||||
|
@ -40,14 +40,13 @@ R_API int r_bp_use(struct r_bp_t *bp, const char *name)
|
|||
}
|
||||
|
||||
// TODO: deprecate
|
||||
R_API void r_bp_handle_list(struct r_bp_t *bp)
|
||||
{
|
||||
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) {
|
||||
list_for_each (pos, &bp->plugins) {
|
||||
b = list_entry(pos, struct r_bp_handle_t, list);
|
||||
printf("bp %c %s\n",
|
||||
(bp->cur && !strcmp(bp->cur->name, b->name))?'*':'-',
|
||||
printf ("bp %c %s\n",
|
||||
(bp->cur && !strcmp (bp->cur->name, b->name))?'*':'-',
|
||||
b->name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,24 +2,20 @@
|
|||
#include <r_bp.h>
|
||||
|
||||
// TRAPTRACE
|
||||
R_API int r_bp_add_traptrace(struct r_bp_t *bp, ut64 from, ut64 to)
|
||||
{
|
||||
R_API int r_bp_add_traptrace(struct r_bp_t *bp, ut64 from, ut64 to) {
|
||||
// read a memory, overwrite it as breakpointing area
|
||||
// everytime it is hitted, instruction is restored
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
R_API int r_bp_del_traptrace(struct r_bp_t *bp, ut64 from, ut64 to)
|
||||
{
|
||||
R_API int r_bp_del_traptrace(struct r_bp_t *bp, ut64 from, ut64 to) {
|
||||
// read a memory, overwrite it as breakpointing area
|
||||
// everytime it is hitted, instruction is restored
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
R_API int r_bp_restore_traptrace(struct r_bp_t *bp, ut64 from, ut64 to)
|
||||
{
|
||||
R_API int r_bp_restore_traptrace(struct r_bp_t *bp, ut64 from, ut64 to) {
|
||||
// read a memory, overwrite it as breakpointing area
|
||||
// everytime it is hitted, instruction is restored
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -186,8 +186,8 @@ static int r_debug_native_continue(int pid, int sig) {
|
|||
//ptrace(PT_CONTINUE, pid, 0, 0);
|
||||
ptrace (PT_DETACH, pid, 0, 0);
|
||||
#if 0
|
||||
task_resume(inferior_task); // ???
|
||||
thread_resume(inferior_threads[0]);
|
||||
task_resume(inferior_task); // ???
|
||||
thread_resume(inferior_threads[0]);
|
||||
#endif
|
||||
return 0;
|
||||
#else
|
||||
|
@ -670,11 +670,11 @@ const char *archlist[3] = { "x86", "x86-32", 0 };
|
|||
#elif __x86_64__
|
||||
const char *archlist[4] = { "x86", "x86-32", "x86-64", 0 };
|
||||
#elif __powerpc__ || __POWERPC__
|
||||
const char *archlist[3] = { "powerpc", 0 };
|
||||
const char *archlist[2] = { "powerpc", 0 };
|
||||
#elif __mips__
|
||||
const char *archlist[3] = { "mips", 0 };
|
||||
const char *archlist[2] = { "mips", 0 };
|
||||
#elif __arm__
|
||||
const char *archlist[3] = { "arm", 0 };
|
||||
const char *archlist[2] = { "arm", 0 };
|
||||
#endif
|
||||
|
||||
static int r_debug_native_kill(struct r_debug_t *dbg, int sig) {
|
||||
|
@ -689,7 +689,6 @@ static int r_debug_native_kill(struct r_debug_t *dbg, int sig) {
|
|||
#endif
|
||||
}
|
||||
|
||||
// TODO: think on a way to define the program counter register name
|
||||
struct r_debug_handle_t r_debug_plugin_native = {
|
||||
.name = "native",
|
||||
.archs = (const char **)archlist,
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
LANG=lua
|
||||
LANG_EXT=lua
|
||||
LIBS_PFX=
|
||||
|
||||
include ../rules.mk
|
||||
|
||||
tri:
|
||||
valaswig -o r_debug.i -m r_debug --vapidir ../../libr/vapi/ r_debug
|
||||
swig -lua -I/usr/include/libr r_debug.i
|
||||
gcc r_debug_wrap.c -shared -fPIC -I /usr/include/libr -I /usr/include/lua5.1/ -o _r_debug.so -lr_debug -lr_bp -lr_reg -lr_util
|
||||
|
||||
bis:
|
||||
valaswig-cc lua r_io -I../../libr/include r_io `pkg-config --libs r_io`
|
|
@ -0,0 +1,12 @@
|
|||
-- RBreakpoint --
|
||||
require "r_bp"
|
||||
|
||||
print ("Type_SW: "..r_bp.Type_SW)
|
||||
print ("Type_HW: "..r_bp.Type_HW)
|
||||
print "-->"
|
||||
a = r_bp.RBreakpoint()
|
||||
a:use ('x86')
|
||||
a:add_hw (0x8048000, 10, 0)
|
||||
a:add_sw (0x9540000, 16, 0)
|
||||
a:list (true)
|
||||
print "--"
|
|
@ -6,8 +6,6 @@ LIBS+=r_debug.so r_config.so r_io.so r_syscall.so r_search.so r_lib.so libr.so
|
|||
all: ${LIBS}
|
||||
|
||||
%.so:
|
||||
@echo ignore $@
|
||||
#@if test ../../libr/vapi/`echo $@|sed -e s,.so,.vapi,` -nt ${LIBS_PFX}$@ ; then
|
||||
@-test ../../libr/vapi/`echo $@|sed -e s,.so,.vapi,` -nt ${LIBS_PFX}$@ ; \
|
||||
if [ ! $$? = 0 ]; then \
|
||||
if [ ! -e ${LIBS_PFX}$@ ]; then \
|
||||
|
|
Loading…
Reference in New Issue