2009-02-05 21:08:46 +00:00
|
|
|
#ifndef _INCLUDE_R_DEBUG_H_
|
|
|
|
#define _INCLUDE_R_DEBUG_H_
|
|
|
|
|
|
|
|
#include <r_types.h>
|
|
|
|
#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 21:08:46 +00:00
|
|
|
#include <r_syscall.h>
|
|
|
|
#include "list.h"
|
|
|
|
|
|
|
|
/* TODO: pass dbg and user data pointer everywhere */
|
|
|
|
struct r_debug_handle_t {
|
|
|
|
const char *name;
|
2009-04-15 11:09:36 +00:00
|
|
|
const char **archs;
|
2009-08-22 01:54:24 +00:00
|
|
|
int (*startv)(int argc, char **argv);
|
2009-02-05 21:08:46 +00:00
|
|
|
int (*attach)(int pid);
|
|
|
|
int (*detach)(int pid);
|
2009-02-16 10:24:45 +00:00
|
|
|
int (*step)(int pid); // if step() is NULL; reimplement it with traps
|
2009-02-05 21:08:46 +00:00
|
|
|
int (*cont)(int pid);
|
2009-02-18 00:43:57 +00:00
|
|
|
int (*wait)(int pid);
|
2009-09-13 22:37:28 +00:00
|
|
|
int (*get_arch)();
|
2009-02-05 21:08:46 +00:00
|
|
|
int (*contsc)(int pid, int sc);
|
2009-07-08 11:49:55 +00:00
|
|
|
//int (*bp_write)(int pid, ut64 addr, int hw, int type);
|
|
|
|
int (*bp_write)(int pid, ut64 addr, int size, int hw, int rwx);
|
2009-09-13 22:37:28 +00:00
|
|
|
struct r_regset_t * (*reg_read)(int pid);
|
|
|
|
int (*reg_write)(int pid, struct r_regset_t *regs);
|
2009-07-08 11:49:55 +00:00
|
|
|
// XXX bad signature int (*bp_read)(int pid, ut64 addr, int hw, int type);
|
2009-02-05 21:08:46 +00:00
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct r_debug_t {
|
|
|
|
int pid; /* selected process id */
|
|
|
|
int tid; /* selected thread id */
|
|
|
|
int swstep; /* steps with software traps */
|
|
|
|
int steps; /* counter of steps done */
|
2009-04-15 11:09:36 +00:00
|
|
|
int newstate;
|
2009-09-13 22:37:28 +00:00
|
|
|
struct r_regset_t *oregs;
|
|
|
|
struct r_regset_t *regs;
|
|
|
|
struct r_bp_t *bp;
|
2009-04-12 23:10:22 +00:00
|
|
|
void *user;
|
2009-02-05 21:08:46 +00:00
|
|
|
/* io */
|
2009-04-16 20:49:18 +00:00
|
|
|
void (*printf)(const char *str, ...);
|
2009-02-05 21:08:46 +00:00
|
|
|
struct r_debug_handle_t *h;
|
|
|
|
struct list_head handlers;
|
2009-04-01 22:44:43 +00:00
|
|
|
/* TODO
|
|
|
|
- list of processes and their threads
|
|
|
|
- list of mapped memory (from /proc/XX/maps)
|
|
|
|
- list of managed memory (allocated in child...)
|
|
|
|
*/
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
R_DBG_PROC_STOP,
|
|
|
|
R_DBG_PROC_RUN,
|
|
|
|
R_DBG_PROC_SLEEP,
|
|
|
|
R_DBG_PROC_ZOMBIE,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct r_debug_pid_t {
|
|
|
|
int pid;
|
|
|
|
int status; /* stopped, running, zombie, sleeping ,... */
|
|
|
|
int runnable; /* when using 'run', 'continue', .. this proc will be runnable */
|
|
|
|
struct list_head threads;
|
|
|
|
struct list_head childs;
|
|
|
|
struct r_debug_pid_t *parent;
|
|
|
|
struct list_head list;
|
2009-02-05 21:08:46 +00:00
|
|
|
};
|
|
|
|
|
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_set(struct r_debug_t *dbg, const char *str);
|
|
|
|
R_API int r_debug_handle_init(struct r_debug_t *dbg);
|
|
|
|
R_API int r_debug_init(struct r_debug_t *dbg);
|
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 21:08:46 +00:00
|
|
|
|
2009-09-10 20:51:34 +00:00
|
|
|
#if 0
|
2009-08-22 03:11:33 +00:00
|
|
|
#define CB_READ int (*_cb_read)(void *user, int pid, ut64 addr, ut8 *buf, int len)
|
|
|
|
#define CB_WRITE int (*_cb_write)(void *user, int pid, ut64 addr, const ut8 *buf, int len)
|
|
|
|
|
|
|
|
R_API int r_debug_set_io(struct r_debug_t *dbg, CB_READ, CB_WRITE, void *user);
|
2009-09-10 20:51:34 +00:00
|
|
|
#endif
|
2009-04-12 23:10:22 +00:00
|
|
|
|
2009-04-01 22:44:43 +00:00
|
|
|
/* send signals */
|
2009-04-16 20:49:18 +00:00
|
|
|
R_API int r_debug_kill(struct r_debug_t *dbg, int pid, int sig);
|
|
|
|
R_API int r_debug_step(struct r_debug_t *dbg, int steps);
|
|
|
|
R_API int r_debug_continue(struct r_debug_t *dbg);
|
|
|
|
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 21:08:46 +00:00
|
|
|
|
2009-04-12 22:46:44 +00:00
|
|
|
/* breakpoints */
|
2009-07-08 11:49:55 +00:00
|
|
|
R_API int r_debug_bp_add(struct r_debug_t *dbg, ut64 addr, int size, int hw, int rwx);
|
|
|
|
R_API int r_debug_bp_del(struct r_debug_t *dbg, ut64 addr);
|
|
|
|
R_API int r_debug_bp_enable(struct r_debug_t *dbg, ut64 addr, int set);
|
2009-04-12 22:46:44 +00:00
|
|
|
R_API int r_debug_bp_disable(struct r_debug_t *dbg);
|
|
|
|
R_API int r_debug_bp_list(struct r_debug_t *dbg, int rad);
|
2009-04-16 20:49:18 +00:00
|
|
|
|
|
|
|
/* registers */
|
|
|
|
R_API int r_debug_reg_sync(struct r_debug_t *dbg, int write);
|
2009-07-08 11:49:55 +00:00
|
|
|
R_API ut64 r_debug_reg_get(struct r_debug_t *dbg, const char *name);
|
|
|
|
R_API int r_debug_reg_set(struct r_debug_t *dbg, const char *name, ut64 value);
|
2009-09-13 22:37:28 +00:00
|
|
|
R_API struct r_regset_t *r_debug_reg_diff(struct r_debug_t *dbg);
|
|
|
|
R_API int r_debug_reg_list(struct r_debug_t *dbg, struct r_regset_t *rs, int rad);
|
2009-04-16 20:49:18 +00:00
|
|
|
|
|
|
|
/* regset */
|
2009-09-13 22:37:28 +00: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 21:08:46 +00:00
|
|
|
#if 0
|
|
|
|
Missing callbacks
|
|
|
|
=================
|
|
|
|
- alloc
|
|
|
|
- dealloc
|
|
|
|
- list maps
|
|
|
|
- change memory protections
|
|
|
|
- touchtrace
|
|
|
|
- filedescriptor set/get/mod..
|
|
|
|
- get/set signals
|
|
|
|
- get regs, set regs
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2009-08-22 01:54:24 +00:00
|
|
|
/* plugin pointers */
|
|
|
|
extern struct r_debug_handle_t r_debug_plugin_ptrace;
|
|
|
|
extern struct r_debug_handle_t r_debug_plugin_gdb;
|
|
|
|
|
2009-02-05 21:08:46 +00:00
|
|
|
#endif
|