2009-02-05 22:08:46 +01:00
|
|
|
#ifndef _INCLUDE_R_DEBUG_H_
|
|
|
|
#define _INCLUDE_R_DEBUG_H_
|
|
|
|
|
|
|
|
#include <r_types.h>
|
2010-02-04 13:23:53 +01:00
|
|
|
#include <r_anal.h>
|
2009-02-05 22:08:46 +01:00
|
|
|
#include <r_util.h>
|
|
|
|
#include <r_reg.h>
|
2009-04-11 21:22:20 +00:00
|
|
|
#include <r_bp.h>
|
2009-09-10 20:51:34 +00:00
|
|
|
#include <r_io.h>
|
2009-02-05 22:08:46 +01:00
|
|
|
#include <r_syscall.h>
|
|
|
|
#include "list.h"
|
|
|
|
|
2009-12-24 03:17:53 +01:00
|
|
|
enum {
|
|
|
|
R_DBG_PROC_STOP,
|
|
|
|
R_DBG_PROC_RUN,
|
|
|
|
R_DBG_PROC_SLEEP,
|
|
|
|
R_DBG_PROC_ZOMBIE,
|
|
|
|
};
|
|
|
|
|
2010-02-02 11:09:52 +01:00
|
|
|
// signal handling must support application and debugger level options
|
|
|
|
enum {
|
|
|
|
R_DBG_SIGNAL_IGNORE, // ignore signal handler
|
|
|
|
R_DBG_SIGNAL_BYPASS,
|
|
|
|
R_DBG_SIGNAL_HANDLE, //
|
|
|
|
R_DBG_SIGNAL_SETUP,
|
|
|
|
//..
|
|
|
|
};
|
|
|
|
|
2010-03-01 10:49:04 +01:00
|
|
|
/* TODO: move to r_anal */
|
|
|
|
typedef struct r_debug_frame_t {
|
|
|
|
ut64 addr;
|
|
|
|
int size;
|
|
|
|
} RDebugFrame;
|
|
|
|
|
2010-02-04 13:23:53 +01:00
|
|
|
typedef struct r_debug_map_t {
|
|
|
|
char *name;
|
|
|
|
ut64 addr;
|
|
|
|
ut64 addr_end;
|
|
|
|
ut64 size;
|
|
|
|
char *file;
|
|
|
|
int perm;
|
|
|
|
int user;
|
|
|
|
} RDebugMap;
|
|
|
|
|
2009-12-24 03:17:53 +01:00
|
|
|
typedef struct r_debug_t {
|
2009-09-20 02:16:14 +02:00
|
|
|
int pid; /* selected process id */
|
|
|
|
int tid; /* selected thread id */
|
|
|
|
int swstep; /* steps with software traps */
|
|
|
|
int steps; /* counter of steps done */
|
|
|
|
int newstate;
|
2010-01-19 11:25:17 +01:00
|
|
|
char *reg_profile;
|
2009-09-20 02:16:14 +02:00
|
|
|
struct r_reg_t *reg;
|
|
|
|
struct r_bp_t *bp;
|
|
|
|
void *user;
|
|
|
|
/* io */
|
|
|
|
void (*printf)(const char *str, ...);
|
|
|
|
struct r_debug_handle_t *h;
|
|
|
|
struct list_head handlers;
|
2010-02-05 12:21:37 +01:00
|
|
|
RIOBind iob;
|
2010-02-04 13:23:53 +01:00
|
|
|
RList *maps; // <RDebugMap>
|
|
|
|
RList *maps_user; // <RDebugMap>
|
2009-09-20 02:16:14 +02:00
|
|
|
/* TODO
|
|
|
|
- list of processes and their threads
|
|
|
|
- list of mapped memory (from /proc/XX/maps)
|
|
|
|
- list of managed memory (allocated in child...)
|
|
|
|
*/
|
2010-01-26 01:28:33 +01:00
|
|
|
} RDebug;
|
2009-09-20 02:16:14 +02:00
|
|
|
|
2009-02-05 22:08:46 +01:00
|
|
|
/* TODO: pass dbg and user data pointer everywhere */
|
2009-12-24 03:17:53 +01:00
|
|
|
typedef struct r_debug_handle_t {
|
2009-02-05 22:08:46 +01:00
|
|
|
const char *name;
|
2010-03-03 14:48:17 +01:00
|
|
|
const char **archs; // MUST BE DEPREACTED!!!!
|
|
|
|
ut32 bits;
|
|
|
|
ut32 arch;
|
2009-09-15 13:24:28 +02:00
|
|
|
/* life */
|
2009-08-22 01:54:24 +00:00
|
|
|
int (*startv)(int argc, char **argv);
|
2009-02-05 22:08:46 +01:00
|
|
|
int (*attach)(int pid);
|
|
|
|
int (*detach)(int pid);
|
2010-02-02 11:09:52 +01:00
|
|
|
int (*select)(int pid, int tid);
|
2010-02-12 11:45:22 +01:00
|
|
|
RFList (*backtrace)(int count);
|
2009-09-15 13:24:28 +02:00
|
|
|
/* flow */
|
2009-02-16 11:24:45 +01:00
|
|
|
int (*step)(int pid); // if step() is NULL; reimplement it with traps
|
2010-01-19 11:25:17 +01:00
|
|
|
int (*cont)(int pid, int sig);
|
2009-02-18 01:43:57 +01:00
|
|
|
int (*wait)(int pid);
|
2010-02-28 22:58:21 +01:00
|
|
|
int (*kill)(RDebug *dbg, int sig);
|
2009-02-05 22:08:46 +01:00
|
|
|
int (*contsc)(int pid, int sc);
|
2010-03-02 11:18:49 +01:00
|
|
|
RList* (*frames)(RDebug *dbg);
|
2009-09-15 13:24:28 +02:00
|
|
|
/* registers */
|
2010-01-26 01:28:33 +01:00
|
|
|
RBreakpointCallback breakpoint;
|
2009-09-20 02:16:14 +02:00
|
|
|
int (*reg_read)(struct r_debug_t *dbg, int type, ut8 *buf, int size);
|
|
|
|
char* (*reg_profile)();
|
2010-01-19 11:25:17 +01:00
|
|
|
int (*reg_write)(int pid, int type, const ut8 *buf, int size); //XXX struct r_regset_t regs);
|
2009-09-15 13:24:28 +02:00
|
|
|
/* memory */
|
2010-02-04 13:23:53 +01:00
|
|
|
RList *(*map_get)(RDebug *dbg);
|
|
|
|
ut64 (*map_alloc)(RDebug *dbg, RDebugMap *map);
|
|
|
|
int (*map_dealloc)(RDebug *dbg, ut64 addr);
|
2009-02-05 22:08:46 +01:00
|
|
|
struct list_head list;
|
2010-01-26 01:28:33 +01:00
|
|
|
} RDebugHandle;
|
2009-02-05 22:08:46 +01:00
|
|
|
|
2009-12-24 03:17:53 +01:00
|
|
|
// TODO: rename to r_debug_process_t ? maybe a thread too ?
|
|
|
|
typedef struct r_debug_pid_t {
|
2009-04-01 22:44:43 +00:00
|
|
|
int pid;
|
|
|
|
int status; /* stopped, running, zombie, sleeping ,... */
|
|
|
|
int runnable; /* when using 'run', 'continue', .. this proc will be runnable */
|
2010-02-21 20:24:28 +01:00
|
|
|
const char *path;
|
|
|
|
//struct list_head threads;
|
|
|
|
//struct list_head childs;
|
|
|
|
//struct r_debug_pid_t *parent;
|
|
|
|
//struct list_head list;
|
2010-01-26 01:28:33 +01:00
|
|
|
} RDebugPid;
|
2009-02-05 22:08:46 +01:00
|
|
|
|
2009-12-24 03:17:53 +01:00
|
|
|
#ifdef R_API
|
2010-02-12 00:43:11 +01:00
|
|
|
R_API int r_debug_attach(struct r_debug_t *dbg, int pid);
|
|
|
|
R_API int r_debug_detach(struct r_debug_t *dbg, int pid);
|
|
|
|
R_API int r_debug_startv(struct r_debug_t *dbg, int argc, char **argv);
|
|
|
|
R_API int r_debug_start(struct r_debug_t *dbg, const char *cmd);
|
|
|
|
R_API int r_debug_stop_reason(struct r_debug_t *dbg);
|
|
|
|
R_API int r_debug_wait(struct r_debug_t *dbg);
|
|
|
|
R_API int r_debug_step_over(struct r_debug_t *dbg, int steps);
|
|
|
|
R_API int r_debug_continue_until(struct r_debug_t *dbg, ut64 addr);
|
|
|
|
R_API int r_debug_continue_syscall(struct r_debug_t *dbg, int sc);
|
|
|
|
R_API int r_debug_pid_add(struct r_debug_t *dbg);
|
|
|
|
R_API int r_debug_pid_add_thread(struct r_debug_t *dbg);
|
|
|
|
R_API int r_debug_pid_del(struct r_debug_t *dbg);
|
|
|
|
R_API int r_debug_pid_del_thread(struct r_debug_t *dbg);
|
|
|
|
|
2009-09-20 02:16:14 +02:00
|
|
|
R_API int r_debug_use(struct r_debug_t *dbg, const char *str);
|
2009-04-16 20:49:18 +00:00
|
|
|
R_API int r_debug_handle_add(struct r_debug_t *dbg, struct r_debug_handle_t *foo);
|
|
|
|
R_API int r_debug_handle_init(struct r_debug_t *dbg);
|
2009-09-22 13:27:33 +02:00
|
|
|
R_API int r_debug_handle_list(struct r_debug_t *dbg);
|
2009-09-20 02:16:14 +02:00
|
|
|
|
2010-01-19 11:25:17 +01:00
|
|
|
R_API struct r_debug_t *r_debug_init(struct r_debug_t *dbg, int hard);
|
2009-08-22 03:11:33 +00:00
|
|
|
R_API struct r_debug_t *r_debug_new();
|
|
|
|
R_API struct r_debug_t *r_debug_free(struct r_debug_t *dbg);
|
2009-02-05 22:08:46 +01:00
|
|
|
|
2009-04-01 22:44:43 +00:00
|
|
|
/* send signals */
|
2010-02-02 11:09:52 +01:00
|
|
|
R_API int r_debug_kill(struct r_debug_t *dbg, int sig);
|
|
|
|
R_API int r_debug_kill_setup(struct r_debug_t *dbg, int sig, int action);
|
2009-04-16 20:49:18 +00:00
|
|
|
R_API int r_debug_step(struct r_debug_t *dbg, int steps);
|
|
|
|
R_API int r_debug_continue(struct r_debug_t *dbg);
|
2010-01-19 11:25:17 +01:00
|
|
|
R_API int r_debug_continue_kill(struct r_debug_t *dbg, int signal);
|
2009-04-16 20:49:18 +00:00
|
|
|
R_API int r_debug_select(struct r_debug_t *dbg, int pid, int tid);
|
2009-08-14 00:37:18 +00:00
|
|
|
|
2009-03-06 00:00:41 +00:00
|
|
|
/* handle.c */
|
2009-04-16 20:49:18 +00:00
|
|
|
R_API int r_debug_handle_init(struct r_debug_t *dbg);
|
|
|
|
R_API int r_debug_handle_set(struct r_debug_t *dbg, const char *str);
|
2009-08-22 01:54:24 +00:00
|
|
|
R_API int r_debug_handle_list(struct r_debug_t *dbg);
|
2009-04-16 20:49:18 +00:00
|
|
|
R_API int r_debug_handle_add(struct r_debug_t *dbg, struct r_debug_handle_t *foo);
|
2009-02-05 22:08:46 +01:00
|
|
|
|
2009-09-17 11:48:36 +02:00
|
|
|
/* memory */
|
2010-02-04 13:23:53 +01:00
|
|
|
R_API int r_debug_map_alloc(RDebug *dbg, RDebugMap *map);
|
|
|
|
R_API int r_debug_map_dealloc(RDebug *dbg, RDebugMap *map);
|
|
|
|
R_API RList *r_debug_map_list_new();
|
|
|
|
R_API void r_debug_map_list_free(RList *maps);
|
|
|
|
R_API RDebugMap *r_debug_map_get(RDebug *dbg, ut64 addr);
|
|
|
|
R_API RDebugMap *r_debug_map_new (char *name, ut64 addr, ut64 addr_end, int perm, int user);
|
|
|
|
R_API void r_debug_map_free(RDebugMap *map);
|
|
|
|
R_API int r_debug_map_dealloc(RDebug *dbg, RDebugMap *map);
|
2010-02-05 12:21:37 +01:00
|
|
|
R_API void r_debug_map_list(RDebug *dbg, ut64 addr);
|
2009-04-16 20:49:18 +00:00
|
|
|
|
|
|
|
/* registers */
|
2009-09-20 02:16:14 +02:00
|
|
|
R_API int r_debug_reg_sync(struct r_debug_t *dbg, int type, int write);
|
|
|
|
R_API int r_debug_reg_list(struct r_debug_t *dbg, int type, int size, int rad);
|
2010-02-28 22:58:21 +01:00
|
|
|
R_API int r_debug_reg_set(struct r_debug_t *dbg, const char *name, ut64 num);
|
|
|
|
R_API ut64 r_debug_reg_get(struct r_debug_t *dbg, const char *name);
|
2010-02-05 12:21:37 +01:00
|
|
|
|
|
|
|
R_API void r_debug_io_bind(RDebug *dbg, RIO *io);
|
|
|
|
R_API ut64 r_debug_execute(struct r_debug_t *dbg, ut8 *buf, int len);
|
|
|
|
R_API int r_debug_map_sync(RDebug *dbg);
|
2010-03-02 11:18:49 +01:00
|
|
|
|
|
|
|
/* backtrace */
|
|
|
|
R_API RList *r_debug_frames (RDebug *dbg);
|
2010-03-04 01:46:25 +01:00
|
|
|
|
|
|
|
/* args */
|
|
|
|
R_API ut64 r_debug_arg_get (RDebug *dbg, int fast, int num);
|
|
|
|
R_API int r_debug_arg_set (RDebug *dbg, int fast, int num, ut64 value);
|
2009-09-22 13:27:33 +02:00
|
|
|
#endif
|
2009-12-24 03:17:53 +01:00
|
|
|
#endif
|
2009-04-16 20:49:18 +00:00
|
|
|
|
|
|
|
/* regset */
|
2009-09-22 13:27:33 +02:00
|
|
|
//R_API struct r_regset_t* r_regset_diff(struct r_regset_t *a, struct r_regset_t *b);
|
|
|
|
//R_API int r_regset_set(struct r_regset_t *r, int idx, const char *name, ut64 value);
|
|
|
|
//R_API struct r_regset_t *r_regset_new(int size);
|
|
|
|
//R_API void r_regset_free(struct r_regset_t *r);
|
2009-08-14 00:37:18 +00:00
|
|
|
|
2009-02-05 22:08:46 +01:00
|
|
|
#if 0
|
|
|
|
Missing callbacks
|
|
|
|
=================
|
|
|
|
- alloc
|
|
|
|
- dealloc
|
2010-02-02 11:09:52 +01:00
|
|
|
- list maps (memory regions)
|
2009-02-05 22:08:46 +01:00
|
|
|
- change memory protections
|
|
|
|
- touchtrace
|
|
|
|
- filedescriptor set/get/mod..
|
|
|
|
- get/set signals
|
|
|
|
- get regs, set regs
|
|
|
|
|
|
|
|
#endif
|