- Prefix all plugins with 'io_' (like in the rest of libs) - Statify io_dbg and io_ptrace IO plugins * Added _free methods for r_io and r_debug. Oops * Initial dummy version of r_debug.vapi * More stuff in the debug/t/main.c (not yet working) * Better hg-miss missing file detection checks --HG-- rename : libr/io/p/dbg.c => libr/io/p/io_dbg.c rename : libr/io/p/ewf.c => libr/io/p/io_ewf.c rename : libr/io/p/malloc.c => libr/io/p/io_malloc.c rename : libr/io/p/ptrace.c => libr/io/p/io_ptrace.c rename : libr/io/p/shm.c => libr/io/p/io_shm.c
207 lines
4.2 KiB
C
207 lines
4.2 KiB
C
/* radare - LGPL - Copyright 2009 pancake<nopcode.org> */
|
|
|
|
#include <r_debug.h>
|
|
|
|
R_API int r_debug_init(struct r_debug_t *dbg)
|
|
{
|
|
dbg->pid = -1;
|
|
dbg->tid = -1;
|
|
dbg->swstep = 0; // software step
|
|
dbg->newstate = 0;
|
|
dbg->regs = dbg->oregs = NULL;
|
|
dbg->printf = printf;
|
|
dbg->h = NULL;
|
|
r_debug_handle_init(dbg);
|
|
r_bp_init(&dbg->bp);
|
|
return R_TRUE;
|
|
}
|
|
|
|
R_API int r_debug_set_io(struct r_debug_t *dbg, CB_READ, CB_WRITE, void *user)
|
|
{
|
|
dbg->read = _cb_read;
|
|
dbg->write = _cb_write;
|
|
dbg->user = user;
|
|
}
|
|
|
|
R_API struct r_debug_t *r_debug_new()
|
|
{
|
|
struct r_debug_t *dbg;
|
|
dbg = MALLOC_STRUCT(struct r_debug_t);
|
|
r_debug_init(dbg);
|
|
return dbg;
|
|
}
|
|
|
|
R_API struct r_debug_t *r_debug_free(struct r_debug_t *dbg)
|
|
{
|
|
// TODO: free it correctly
|
|
free(dbg);
|
|
return NULL;
|
|
}
|
|
|
|
R_API int r_debug_attach(struct r_debug_t *dbg, int pid)
|
|
{
|
|
int ret = R_FALSE;
|
|
if (dbg->h && dbg->h->attach) {
|
|
ret = dbg->h->attach(pid);
|
|
if (ret) {
|
|
dbg->pid = pid;
|
|
dbg->tid = pid;
|
|
} else fprintf(stderr, "Cannot attach to this pid\n");
|
|
} else fprintf(stderr, "dbg->attach = NULL\n");
|
|
return ret;
|
|
}
|
|
|
|
R_API int r_debug_startv(struct r_debug_t *dbg, int argc, char **argv)
|
|
{
|
|
return R_FALSE;
|
|
}
|
|
|
|
R_API int r_debug_start(struct r_debug_t *dbg, const char *cmd)
|
|
{
|
|
// TODO: parse cmd and generate argc and argv
|
|
return R_FALSE;
|
|
}
|
|
|
|
R_API int r_debug_detach(struct r_debug_t *dbg, int pid)
|
|
{
|
|
if (dbg->h && dbg->h->detach)
|
|
return dbg->h->detach(pid);
|
|
return R_FALSE;
|
|
}
|
|
|
|
R_API int r_debug_select(struct r_debug_t *dbg, int pid, int tid)
|
|
{
|
|
dbg->pid = pid;
|
|
dbg->tid = tid;
|
|
eprintf("PID: %d %d\n", pid, tid);
|
|
return R_TRUE;
|
|
}
|
|
|
|
R_API int r_debug_set_arch(struct r_debug_t *dbg, int arch)
|
|
{
|
|
/* XXX: use string identifiers here */
|
|
switch(arch) {
|
|
case R_DBG_ARCH_BF:
|
|
// TODO: set callbacks for brainfuck debugger here
|
|
break;
|
|
case R_DBG_ARCH_X86:
|
|
//r_reg_set(dbg->reg->nregs, R_DBG_ARCH_X86);
|
|
break;
|
|
}
|
|
return R_TRUE;
|
|
}
|
|
|
|
/*--*/
|
|
R_API int r_debug_stop_reason(struct r_debug_t *dbg)
|
|
{
|
|
// TODO: return reason to stop debugging
|
|
// - new process
|
|
// - trap instruction
|
|
// - illegal instruction
|
|
// - fpu exception
|
|
// ...
|
|
return R_TRUE;
|
|
}
|
|
|
|
R_API int r_debug_wait(struct r_debug_t *dbg)
|
|
{
|
|
int ret = R_FALSE;
|
|
if (dbg->h->wait) {
|
|
ret = dbg->h->wait(dbg->pid);
|
|
dbg->newstate = 1;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
// TODO: count number of steps done to check if no error??
|
|
R_API int r_debug_step(struct r_debug_t *dbg, int steps)
|
|
{
|
|
int i, ret = R_FALSE;
|
|
if (dbg->h && dbg->h->step) {
|
|
for(i=0;i<steps;i++) {
|
|
ret = dbg->h->step(dbg->pid);
|
|
if (ret == R_FALSE)
|
|
break;
|
|
r_debug_wait(dbg);
|
|
// TODO: create wrapper for dbg_wait
|
|
// TODO: check return value of wait and show error
|
|
dbg->steps++;
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
R_API int r_debug_syscall(struct r_debug_t *dbg, int num)
|
|
{
|
|
fprintf(stderr, "TODO\n");
|
|
return R_FALSE;
|
|
}
|
|
|
|
R_API int r_debug_step_over(struct r_debug_t *dbg, int steps)
|
|
{
|
|
// TODO: analyze opcode if it is stepoverable
|
|
fprintf(stderr, "TODO\n");
|
|
return r_debug_step(dbg, steps);
|
|
}
|
|
|
|
R_API int r_debug_continue(struct r_debug_t *dbg)
|
|
{
|
|
int ret = R_FALSE;
|
|
if (dbg->h){
|
|
if (dbg->h->cont) {
|
|
ret = dbg->h->cont(dbg->pid);
|
|
if (dbg->h->wait)
|
|
ret = dbg->h->wait(dbg->pid);
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
R_API int r_debug_continue_until(struct r_debug_t *dbg, ut64 addr)
|
|
{
|
|
//struct r_debug_bp_t *bp = r_debug_bp_add (dbg, addr);
|
|
//int ret = r_debug_continue(dbg);
|
|
/* TODO: check if the debugger stops at the right address */
|
|
//r_debug_bp_del(dbg, bp);
|
|
return -1;
|
|
}
|
|
|
|
R_API int r_debug_continue_syscall(struct r_debug_t *dbg, int sc)
|
|
{
|
|
int ret = R_FALSE;
|
|
if (dbg->h && dbg->h->contsc)
|
|
ret = dbg->h->contsc(dbg->pid, sc);
|
|
return ret;
|
|
}
|
|
|
|
// XXX wrong function name
|
|
R_API int r_debug_use_software_steps(struct r_debug_t *dbg, int value)
|
|
{
|
|
/* use software breakpoints and continues */
|
|
return -1;
|
|
}
|
|
|
|
|
|
// TODO: Move to pid.c ?
|
|
// TODO: Do we need an intermediate signal representation for portability?
|
|
// TODO: STOP, CONTINUE, KILL, ...
|
|
R_API int r_debug_kill(struct r_debug_t *dbg, int pid, int sig)
|
|
{
|
|
// XXX: use debugger handler backend here
|
|
#include <signal.h>
|
|
int ret = kill(pid, sig);
|
|
if (ret == -1)
|
|
return R_FALSE;
|
|
return R_TRUE;
|
|
}
|
|
|
|
/* mmu */
|
|
R_API int r_debug_mmu_alloc(struct r_debug_t *dbg, ut64 size, ut64 *addr)
|
|
{
|
|
return R_TRUE;
|
|
}
|
|
|
|
R_API int r_debug_mmu_free(struct r_debug_t *dbg, ut64 addr)
|
|
{
|
|
return R_TRUE;
|
|
}
|