Skip to content

Commit

Permalink
* Added r_reg pkgconfig file
Browse files Browse the repository at this point in the history
* Some fixes in the r_reg VAPI
  - Added vala test program
* r_debug is now broken because the new r_reg
* Add r_free_internal to reduce leaks in r_reg
  • Loading branch information
radare committed Sep 19, 2009
1 parent b881d4b commit 85dfbe5
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 15 deletions.
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ for A in ${ENVWORDS} ; do
SEDFLAGS="${SEDFLAGS}s,@${A}@,${VAR},g;"
done
SEDFLAGS="${SEDFLAGS}'"
for A in ./config-user.mk libr/include/r_userconf.h pkgcfg/libr.pc pkgcfg/r_io.pc pkgcfg/r_asm.pc pkgcfg/r_bin.pc pkgcfg/r_cons.pc pkgcfg/r_diff.pc pkgcfg/r_core.pc pkgcfg/r_socket.pc pkgcfg/r_line.pc pkgcfg/r_syscall.pc pkgcfg/r_macro.pc pkgcfg/r_util.pc pkgcfg/r_search.pc pkgcfg/r_vm.pc pkgcfg/r_th.pc pkgcfg/r_bp.pc pkgcfg/r_db.pc ; do # SUBDIRS
for A in ./config-user.mk libr/include/r_userconf.h pkgcfg/libr.pc pkgcfg/r_io.pc pkgcfg/r_asm.pc pkgcfg/r_bin.pc pkgcfg/r_cons.pc pkgcfg/r_diff.pc pkgcfg/r_core.pc pkgcfg/r_socket.pc pkgcfg/r_debug.pc pkgcfg/r_reg.pc pkgcfg/r_line.pc pkgcfg/r_syscall.pc pkgcfg/r_macro.pc pkgcfg/r_util.pc pkgcfg/r_search.pc pkgcfg/r_vm.pc pkgcfg/r_th.pc pkgcfg/r_bp.pc pkgcfg/r_db.pc ; do # SUBDIRS
if [ -f "${VPATH}/${A}.acr" ]; then
SD_TARGET=${A}
else
Expand Down
2 changes: 2 additions & 0 deletions configure.acr
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ SUBDIRS ./config-user.mk libr/include/r_userconf.h
pkgcfg/r_diff.pc
pkgcfg/r_core.pc
pkgcfg/r_socket.pc
pkgcfg/r_debug.pc
pkgcfg/r_reg.pc
pkgcfg/r_line.pc
pkgcfg/r_syscall.pc
pkgcfg/r_macro.pc
Expand Down
2 changes: 2 additions & 0 deletions libr/debug/p/dbg_gdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ static int r_debug_gdb_step(int pid)

struct r_debug_regset_t * r_debug_gdb_reg_read(int pid)
{
#if 0
struct r_debug_regset *r = NULL;
/* only for x86-32 */
gdbwrap_gdbreg32 *reg = gdbwrap_readgenreg(desc);
Expand All @@ -32,6 +33,7 @@ struct r_debug_regset_t * r_debug_gdb_reg_read(int pid)
r_debug_regset_set(r, 7, "ebp", reg->ebp);
r_debug_regset_set(r, 8, "eip", reg->eip);
return r;
#endif
}

static int r_debug_gdb_reg_write(int pid, struct r_debug_regset_t *regs)
Expand Down
4 changes: 3 additions & 1 deletion libr/debug/p/dbg_ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ struct r_regset_t* r_debug_ptrace_reg_read(int pid)
struct user_regs_struct regs;
memset(&regs,0, sizeof(regs));
ptrace(PTRACE_GETREGS, pid, 0, &regs);
#if 0
#if __WORDSIZE == 64
r = r_regset_new(17);
r_regset_set(r, 0, "rax", regs.rax);
Expand Down Expand Up @@ -99,6 +100,7 @@ struct r_regset_t* r_debug_ptrace_reg_read(int pid)
r_regset_set(r, 8, "eip", (ut64)(ut32)regs.eip);
#endif
#endif /* linux */
#endif
return r;
}

Expand Down Expand Up @@ -158,7 +160,7 @@ struct r_debug_handle_t r_debug_plugin_ptrace = {
.detach = &r_debug_ptrace_detach,
.wait = &r_debug_ptrace_wait,
.get_arch = &r_debug_get_arch,
.bp_write = &r_debug_ptrace_bp_write,
//.bp_write = &r_debug_ptrace_bp_write,
.reg_read = &r_debug_ptrace_reg_read,
.reg_write = &r_debug_ptrace_reg_write,
//.bp_read = &r_debug_ptrace_bp_read,
Expand Down
2 changes: 2 additions & 0 deletions libr/debug/reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ R_API int r_debug_reg_sync(struct r_debug_t *dbg, int write)
}
return (dbg->regs != NULL);
}
#if 0

R_API struct r_regset_t *r_debug_reg_diff(struct r_debug_t *dbg)
{
Expand Down Expand Up @@ -66,3 +67,4 @@ R_API int r_debug_reg_list(struct r_debug_t *dbg, struct r_regset_t *rs, int rad
}
return R_TRUE;
}
#endif
1 change: 1 addition & 0 deletions libr/include/r_reg.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define _INCLUDE_R_REG_H_

#include <r_types.h>
#include <r_util.h>
#include <list.h>

enum {
Expand Down
2 changes: 1 addition & 1 deletion libr/libr.pc.acr
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ Name: libr
Description: radare framework libraries
Version: 0.1
Requires:
Libs: -L${libdir} -lr_core -lr_lang -lr_search -lr_cmd -lr_meta -lr_asm -lr_util
Libs: -L${libdir} -lr_core -lr_lang -lr_search -lr_cmd -lr_meta -lr_asm -lr_util -lr_reg
Cflags: -I${includedir}/libr
11 changes: 11 additions & 0 deletions libr/reg/reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@

static void r_reg_free_internal(struct r_reg_t *reg)
{
struct list_head *pos, *n;
struct r_reg_item_t *r;
int i;

for(i=0;i<R_REG_TYPE_LAST;i++) {
list_for_each_safe(pos, n, &reg->regset[i].regs) {
r = list_entry(pos, struct r_reg_item_t, list);
list_del(&r->list);
free(r);
}
}
}

R_API struct r_reg_t *r_reg_free(struct r_reg_t *reg)
Expand Down
20 changes: 10 additions & 10 deletions libr/vapi/r_reg.vapi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Radare {
[Compact]
[CCode (cname="struct r_reg_t", free_function="r_reg_free", cprefix="r_reg_")]
public class Register {
[CCode (cprefix="R_REG_TYPE")]
[CCode (cprefix="R_REG_TYPE_")]
public enum Type {
GPR,
DRX,
Expand All @@ -17,8 +17,8 @@ namespace Radare {
}

[Compact]
[CCode (cname="struct r_reg_item_t", destroy_function="" )]
public struct Item {
[CCode (cname="struct r_reg_item_t", destroy_function="", free_function="" )]
public class Item {
public string name;
public int size;
public int offset;
Expand All @@ -27,25 +27,25 @@ namespace Radare {
}

[Compact]
[CCode (cname="struct r_reg_arena_t", destroy_function="" )]
public struct Arena {
[CCode (cname="struct r_reg_arena_t", destroy_function="", free_function="" )]
public class Arena {
public uint8* bytes;
public int size;
}

[Compact]
[CCode (cname="struct r_reg_set_t", destroy_function="" )]
public struct Set {
[CCode (cname="struct r_reg_set_t", destroy_function="", free_function="" )]
public class Set {
public Register.Arena arena;
public Radare.List<Register.Arena> arenas;
public Radare.List<Register.Item> regs;
public Radare.List<Register.Arena*> arenas;
public Radare.List<Register.Item*> regs;
}

public Register();
public bool set_profile(string file);
public bool set_profile_string(string profile);
public Register.Item get(string name);
public Radare.List<Register.Item> get_list(string profile);
public Radare.List<Register.Item*> get_list(Register.Type type);

public uint64 get_value(Register.Item item);
public bool set_value(Register.Item item, uint64 val);
Expand Down
5 changes: 4 additions & 1 deletion libr/vapi/t/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
all: core hash sc socket asm search iter bin db io list
all: core regs hash sc socket asm search iter bin db io list
@true

regs:
valac --pkg r_reg regs.vala --pkg r_util

# XXX
list:
valac -o list list_c.c list.vala --pkg r_util --vapidir=${PWD}/.. -X -I.
Expand Down
22 changes: 22 additions & 0 deletions libr/vapi/t/regs.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Radare;

void main() {

Register reg = new Register();

reg.set_profile_string("""
gpr eip .32 0 0
gpr eax .32 4 0
"""
);
reg.set_value(reg.get("eax"), 666);

Radare.List<Register.Item*> head =
reg.get_list(Register.Type.GPR);

foreach(Register.Item* item in head) {
stdout.printf(" - %s (%d) = 0x%08llx\n",
item->name, item->size,
reg.get_value(item));
}
}
2 changes: 1 addition & 1 deletion pkgcfg/r_debug.pc.acr
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ Name: r_debug
Description: radare foundation libraries
Version: 0.2
Requires:
Libs: -L${libdir} -lr_debug
Libs: -L${libdir} -lr_debug -lr_reg -lr_bp
Cflags: -I${includedir}/libr

0 comments on commit 85dfbe5

Please sign in to comment.