1 #ifndef R2_DEBUG_H
2 #define R2_DEBUG_H
3
4 #include <r_types.h>
5 #include <r_anal.h>
6 #include <r_cons.h>
7 #include <r_hash.h>
8 #include <r_util.h>
9 #include <r_reg.h>
10 #include <r_egg.h>
11 #include <r_bp.h>
12 #include <r_io.h>
13 #include <r_syscall.h>
14
15 #include <r_config.h>
16 #include "r_bind.h"
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 R_LIB_VERSION_HEADER(r_debug);
22
23 /* hack to fix compilation of debugger on BSD systems */
24 /* This needs some testing (netbsd, freebsd, openbsd, kfreebsd) */
25 #if __BSD__
26 #include <machine/reg.h>
27
28 /* hakish hack to hack the openbsd/sparc64 hack */
29 #undef reg
30 #undef fpreg
31 #undef fpstate
32 #undef trapframe
33 #undef rwindow
34
35 #ifdef PTRACE_SYSCALL
36 /* on freebsd does not have the same meaning */
37 #undef PTRACE_SYSCALL
38 #endif
39
40 #define PTRACE_PEEKTEXT PT_READ_I
41 #define PTRACE_POKETEXT PT_WRITE_I
42 #define PTRACE_PEEKDATA PT_READ_D
43 #define PTRACE_POKEDATA PT_WRITE_D
44 #define PTRACE_ATTACH PT_ATTACH
45 #define PTRACE_DETACH PT_DETACH
46 #define PTRACE_SINGLESTEP PT_STEP
47 #define PTRACE_CONT PT_CONTINUE
48 #define PTRACE_GETREGS PT_GETREGS
49 #define PTRACE_SETREGS PT_SETREGS
50 #define PTRACE_SYSCALL PT_STEP
51 #endif
52
53 #define SNAP_PAGE_SIZE 4096
54 #define CHECK_POINT_LIMIT 0x100000 //TODO: take the benchmark
55 /*
56 * states that a process can be in
57 */
58 typedef enum {
59 R_DBG_PROC_STOP = 's',
60 R_DBG_PROC_RUN = 'r',
61 R_DBG_PROC_SLEEP = 'S',
62 R_DBG_PROC_ZOMBIE = 'z',
63 R_DBG_PROC_DEAD = 'd',
64 R_DBG_PROC_RAISED = 'R' // has produced a signal, breakpoint, etc..
65 } RDebugPidState;
66
67
68 // signal handling must support application and debugger level options
69 typedef enum {
70 R_DBG_SIGNAL_IGNORE = 0, // ignore signal handler
71 R_DBG_SIGNAL_CONT = 1, // pass signal to chlidren and continue execution
72 R_DBG_SIGNAL_SKIP = 2, //
73 //..
74 } RDebugSignalMode;
75
76
77 /*
78 * when a user wants to resume from a breakpoint, we need to know how they want
79 * to proceed. these values indicate their intention.
80 */
81 typedef enum {
82 R_DBG_RECOIL_NONE = 0,
83 R_DBG_RECOIL_STEP,
84 R_DBG_RECOIL_CONTINUE
85 } RDebugRecoilMode;
86
87 /*
88 * List of reasons that an inferior might have stopped
89 */
90 typedef enum {
91 R_DEBUG_REASON_DEAD = -1,
92 R_DEBUG_REASON_NONE = 0,
93 R_DEBUG_REASON_SIGNAL,
94 R_DEBUG_REASON_SEGFAULT,
95 R_DEBUG_REASON_BREAKPOINT,
96 R_DEBUG_REASON_TRACEPOINT,
97 R_DEBUG_REASON_COND,
98 R_DEBUG_REASON_READERR,
99 R_DEBUG_REASON_STEP,
100 R_DEBUG_REASON_ABORT,
101 R_DEBUG_REASON_WRITERR,
102 R_DEBUG_REASON_DIVBYZERO,
103 R_DEBUG_REASON_ILLEGAL,
104 R_DEBUG_REASON_UNKNOWN,
105 R_DEBUG_REASON_ERROR,
106 R_DEBUG_REASON_NEW_PID,
107 R_DEBUG_REASON_NEW_TID,
108 R_DEBUG_REASON_NEW_LIB,
109 R_DEBUG_REASON_EXIT_PID,
110 R_DEBUG_REASON_EXIT_TID,
111 R_DEBUG_REASON_EXIT_LIB,
112 R_DEBUG_REASON_TRAP,
113 R_DEBUG_REASON_SWI,
114 R_DEBUG_REASON_INT,
115 R_DEBUG_REASON_FPU,
116 R_DEBUG_REASON_USERSUSP,
117 } RDebugReasonType;
118
119
120 /* TODO: move to r_anal */
121 typedef struct r_debug_frame_t {
122 ut64 addr;
123 int size;
124 ut64 sp;
125 ut64 bp;
126 } RDebugFrame;
127
128 typedef struct r_debug_reason_t {
129 int /*RDebugReasonType*/ type;
130 int tid;
131 int signum;
132 ut64 bp_addr;
133 ut64 timestamp;
134 ut64 addr;
135 ut64 ptr;
136 } RDebugReason;
137
138 typedef struct r_debug_map_t {
139 char *name;
140 ut64 addr;
141 ut64 addr_end;
142 ut64 size;
143 ut64 offset;
144 char *file;
145 int perm;
146 int user;
147 bool shared;
148 } RDebugMap;
149
150 typedef struct r_debug_signal_t {
151 int type;
152 int num;
153 ut64 handler;
154 } RDebugSignal;
155
156 typedef struct r_debug_desc_t {
157 int fd;
158 char *path;
159 int perm;
160 int type;
161 ut64 off;
162 } RDebugDesc;
163
164 typedef struct r_debug_snap_t {
165 char *name;
166 ut64 addr;
167 ut64 addr_end;
168 ut32 size;
169 ut8 *data;
170 int perm;
171 int user;
172 bool shared;
173 } RDebugSnap;
174
175 typedef struct {
176 int cnum;
177 ut64 data;
178 } RDebugChangeReg;
179
180 typedef struct {
181 int cnum;
182 ut8 data;
183 } RDebugChangeMem;
184
185 typedef struct r_debug_checkpoint_t {
186 int cnum;
187 RRegArena *arena[R_REG_TYPE_LAST];
188 RList *snaps; // <RDebugSnap>
189 } RDebugCheckpoint;
190
191 typedef struct r_debug_session_t {
192 ut32 cnum;
193 ut32 maxcnum;
194 RDebugCheckpoint *cur_chkpt;
195 RVector *checkpoints; /* RVector<RDebugCheckpoint> */
196 HtUP *memory; /* RVector<RDebugChangeMem> */
197 HtUP *registers; /* RVector<RDebugChangeReg> */
198 int reasontype /*RDebugReasonType*/;
199 RBreakpointItem *bp;
200 } RDebugSession;
201
202 /* Session file format */
203 typedef struct r_session_header {
204 ut64 addr;
205 ut32 id;
206 ut32 difflist_len;
207 } RSessionHeader;
208
209 typedef struct r_diff_entry {
210 ut32 base_idx;
211 ut32 pages_len;
212 } RDiffEntry;
213
214 typedef struct r_snap_entry {
215 ut64 addr;
216 ut32 size;
217 ut64 timestamp;
218 int perm;
219 } RSnapEntry;
220
221 typedef struct r_debug_trace_t {
222 RList *traces;
223 int count;
224 int enabled;
225 //int changed;
226 int tag;
227 int dup;
228 char *addresses;
229 // TODO: add range here
230 HtPP *ht;
231 } RDebugTrace;
232
233 typedef struct r_debug_tracepoint_t {
234 ut64 addr;
235 ut64 tags; // XXX
236 int tag; // XXX
237 int size;
238 int count;
239 int times;
240 ut64 stamp;
241 } RDebugTracepoint;
242
243 typedef struct r_debug_t {
244 char *arch;
245 int bits; /// XXX: MUST SET ///
246 int hitinfo;
247
248 int main_pid;
249 int pid; /* selected process id */
250 int tid; /* selected thread id */
251 int forked_pid; /* last pid created by fork */
252 int n_threads;
253 RList *threads; /* NOTE: list contents are platform-specific */
254
255 char *malloc; /*choose malloc parser: 0 = glibc, 1 = jemalloc*/
256
257 /* dbg.* config options (see e?dbg)
258 * NOTE: some settings are checked inline instead of tracked here.
259 */
260 int bpsize; /* size of a breakpoint */
261 char *btalgo; /* select backtrace algorithm */
262 int btdepth; /* backtrace depth */
263 int regcols; /* display columns */
264 int swstep; /* steps with software traps */
265 int stop_all_threads; /* stop all threads at any stop */
266 int trace_forks; /* stop on new children */
267 int trace_execs; /* stop on new execs */
268 int trace_aftersyscall; /* stop after the syscall (before if disabled) */
269 int trace_clone; /* stop on new threads */
270 int follow_child; /* On fork, trace the child */
271 char *glob_libs; /* stop on lib load */
272 char *glob_unlibs; /* stop on lib unload */
273 bool consbreak; /* SIGINT handle for attached processes */
274 bool continue_all_threads;
275
276 /* tracking debugger state */
277 int steps; /* counter of steps done */
278 RDebugReason reason; /* stop reason */
279 RDebugRecoilMode recoil_mode; /* what did the user want to do? */
280 ut64 stopaddr; /* stop address */
281
282 /* tracing vars */
283 RDebugTrace *trace;
284 Sdb *tracenodes;
285 RTree *tree;
286 RList *call_frames;
287
288 RReg *reg;
289 RList *q_regs;
290 const char *creg; // current register value
291 RBreakpoint *bp;
292 void *user; // XXX(jjd): unused?? meant for caller's use??
293 char *snap_path;
294
295 /* io */
296 PrintfCallback cb_printf;
297 RIOBind iob;
298
299 struct r_debug_plugin_t *h;
300 RList *plugins;
301
302 bool pc_at_bp; /* after a breakpoint, is the pc at the bp? */
303 bool pc_at_bp_set; /* is the pc_at_bp variable set already? */
304
305 REvent *ev;
306
307 RAnal *anal;
308 RList *maps; // <RDebugMap>
309 RList *maps_user; // <RDebugMap>
310
311 bool trace_continue;
312 RAnalOp *cur_op;
313 RDebugSession *session;
314
315 Sdb *sgnls;
316 RCoreBind corebind;
317 PJ *pj;
318 // internal use only
319 int _mode;
320 RNum *num;
321 REgg *egg;
322 bool verbose;
323 bool main_arena_resolved; /* is the main_arena resolved already? */
324 int glibc_version;
325 } RDebug;
326
327 typedef struct r_debug_desc_plugin_t {
328 int (*open)(const char *path);
329 int (*close)(int fd);
330 int (*read)(int fd, ut64 addr, int len);
331 int (*write)(int fd, ut64 addr, int len);
332 int (*seek)(int fd, ut64 addr);
333 int (*dup)(int fd, int newfd);
334 RList* (*list)(int pid);
335 } RDebugDescPlugin;
336
337 typedef struct r_debug_info_t {
338 int pid;
339 int tid;
340 int uid;
341 int gid;
342 char *usr;
343 char *exe;
344 char *cmdline;
345 char *libname;
346 char *cwd;
347 int status; // zombie, running, sleeping, ...
348 int signum;
349 void * lib;
350 void * thread;
351 char *kernel_stack;
352 // retrieve mem/fd/core limits?
353 // list of threads ? hasthreads? counter?
354 // environment?
355 // /proc/pid/syscall ???
356 } RDebugInfo;
357
358 /* TODO: pass dbg and user data pointer everywhere */
359 typedef struct r_debug_plugin_t {
360 const char *name;
361 const char *license;
362 const char *author;
363 const char *version;
364 //const char **archs; // MUST BE DEPRECATED!!!!
365 ut32 bits;
366 const char *arch;
367 int canstep;
368 int keepio;
369 /* life */
370 RDebugInfo* (*info)(RDebug *dbg, const char *arg);
371 int (*startv)(int argc, char **argv);
372 int (*attach)(RDebug *dbg, int pid);
373 int (*detach)(RDebug *dbg, int pid);
374 int (*select)(RDebug *dbg, int pid, int tid);
375 RList *(*threads)(RDebug *dbg, int pid);
376 RList *(*pids)(RDebug *dbg, int pid);
377 RList *(*tids)(RDebug *dbg, int pid);
378 RFList (*backtrace)(RDebug *dbg, int count);
379 /* flow */
380 int (*stop)(RDebug *dbg);
381 int (*step)(RDebug *dbg);
382 int (*step_over)(RDebug *dbg);
383 int (*cont)(RDebug *dbg, int pid, int tid, int sig);
384 int (*wait)(RDebug *dbg, int pid);
385 bool (*gcore)(RDebug *dbg, RBuffer *dest);
386 bool (*kill)(RDebug *dbg, int pid, int tid, int sig);
387 RList* (*kill_list)(RDebug *dbg);
388 int (*contsc)(RDebug *dbg, int pid, int sc);
389 RList* (*frames)(RDebug *dbg, ut64 at);
390 RBreakpointCallback breakpoint;
391 // XXX: specify, pid, tid, or RDebug ?
392 int (*reg_read)(RDebug *dbg, int type, ut8 *buf, int size);
393 int (*reg_write)(RDebug *dbg, int type, const ut8 *buf, int size); //XXX struct r_regset_t regs);
394 char* (*reg_profile)(RDebug *dbg);
395 int (*set_reg_profile)(const char *str);
396 /* memory */
397 RList *(*map_get)(RDebug *dbg);
398 RList *(*modules_get)(RDebug *dbg);
399 RDebugMap* (*map_alloc)(RDebug *dbg, ut64 addr, int size, bool thp);
400 int (*map_dealloc)(RDebug *dbg, ut64 addr, int size);
401 int (*map_protect)(RDebug *dbg, ut64 addr, int size, int perms);
402 int (*init)(RDebug *dbg);
403 int (*drx)(RDebug *dbg, int n, ut64 addr, int size, int rwx, int g, int api_type);
404 RDebugDescPlugin desc;
405 // TODO: use RList here
406 } RDebugPlugin;
407
408 // TODO: rename to r_debug_process_t ? maybe a thread too ?
409 typedef struct r_debug_pid_t {
410 int pid;
411 int ppid;
412 char status; /* stopped, running, zombie, sleeping ,... */
413 int runnable; /* when using 'run', 'continue', .. this proc will be runnable */
414 bool signalled;
415 char *path;
416 int uid;
417 int gid;
418 ut64 pc;
419 } RDebugPid;
420
421 /*
422 * Radare's debugger has both an external and internal API.
423 *
424 * TODO(jjd): reconcile external API and extend it for better funcitonality
425 * when using R2 as a library.
426 */
427 #ifdef R_API
428 R_API RDebug *r_debug_new(int hard);
429 R_API RDebug *r_debug_free(RDebug *dbg);
430
431 R_API int r_debug_attach(RDebug *dbg, int pid);
432 R_API int r_debug_detach(RDebug *dbg, int pid);
433 R_API int r_debug_startv(RDebug *dbg, int argc, char **argv);
434 R_API int r_debug_start(RDebug *dbg, const char *cmd);
435
436 /* reason we stopped */
437 R_API RDebugReasonType r_debug_stop_reason(RDebug *dbg);
438 R_API const char *r_debug_reason_to_string(int type);
439
440 /* wait for another event */
441 R_API RDebugReasonType r_debug_wait(RDebug *dbg, RBreakpointItem **bp);
442
443 /* continuations */
444 R_API int r_debug_step(RDebug *dbg, int steps);
445 R_API int r_debug_step_over(RDebug *dbg, int steps);
446 R_API int r_debug_continue_until(RDebug *dbg, ut64 addr);
447 R_API int r_debug_continue_until_nonblock(RDebug *dbg, ut64 addr);
448 R_API int r_debug_continue_until_optype(RDebug *dbg, int type, int over);
449 R_API int r_debug_continue_until_nontraced(RDebug *dbg);
450 R_API int r_debug_continue_syscall(RDebug *dbg, int sc);
451 R_API int r_debug_continue_syscalls(RDebug *dbg, int *sc, int n_sc);
452 R_API int r_debug_continue(RDebug *dbg);
453 R_API int r_debug_continue_kill(RDebug *dbg, int signal);
454 #if __WINDOWS__
455 R_API int r_debug_continue_pass_exception(RDebug *dbg);
456 #endif
457
458 /* process/thread handling */
459 R_API bool r_debug_select(RDebug *dbg, int pid, int tid);
460 //R_API int r_debug_pid_add(RDebug *dbg);
461 //R_API int r_debug_pid_add_thread(RDebug *dbg);
462 //R_API int r_debug_pid_del(RDebug *dbg);
463 //R_API int r_debug_pid_del_thread(RDebug *dbg);
464 R_API int r_debug_pid_list(RDebug *dbg, int pid, char fmt);
465 R_API RDebugPid *r_debug_pid_new(const char *path, int pid, int uid, char status, ut64 pc);
466 R_API RDebugPid *r_debug_pid_free(RDebugPid *pid);
467 R_API RList *r_debug_pids(RDebug *dbg, int pid);
468
469 R_API bool r_debug_set_arch(RDebug *dbg, const char *arch, int bits);
470 R_API bool r_debug_use(RDebug *dbg, const char *str);
471
472 R_API RDebugInfo *r_debug_info(RDebug *dbg, const char *arg);
473 R_API void r_debug_info_free (RDebugInfo *rdi);
474
475 R_API ut64 r_debug_get_baddr(RDebug *dbg, const char *file);
476
477 /* send signals */
478 R_API void r_debug_signal_init(RDebug *dbg);
479 R_API int r_debug_signal_send(RDebug *dbg, int num);
480 R_API int r_debug_signal_what(RDebug *dbg, int num);
481 R_API int r_debug_signal_resolve(RDebug *dbg, const char *signame);
482 R_API const char *r_debug_signal_resolve_i(RDebug *dbg, int signum);
483 R_API void r_debug_signal_setup(RDebug *dbg, int num, int opt);
484 R_API int r_debug_signal_set(RDebug *dbg, int num, ut64 addr);
485 R_API void r_debug_signal_list(RDebug *dbg, int mode);
486 R_API int r_debug_kill(RDebug *dbg, int pid, int tid, int sig);
487 R_API RList *r_debug_kill_list(RDebug *dbg);
488 // XXX: must be uint64 action
489 R_API int r_debug_kill_setup(RDebug *dbg, int sig, int action);
490
491 /* handle.c */
492 R_API void r_debug_plugin_init(RDebug *dbg);
493 R_API int r_debug_plugin_set(RDebug *dbg, const char *str);
494 R_API bool r_debug_plugin_list(RDebug *dbg, int mode);
495 R_API bool r_debug_plugin_add(RDebug *dbg, RDebugPlugin *foo);
496 R_API bool r_debug_plugin_set_reg_profile(RDebug *dbg, const char *str);
497
498 /* memory */
499 R_API RList *r_debug_modules_list(RDebug*);
500 R_API RDebugMap *r_debug_map_alloc(RDebug *dbg, ut64 addr, int size, bool thp);
501 R_API int r_debug_map_dealloc(RDebug *dbg, RDebugMap *map);
502 R_API RList *r_debug_map_list_new(void);
503 R_API RDebugMap *r_debug_map_get(RDebug *dbg, ut64 addr);
504 R_API RDebugMap *r_debug_map_new(char *name, ut64 addr, ut64 addr_end, int perm, int user);
505 R_API void r_debug_map_free(RDebugMap *map);
506 R_API void r_debug_map_list(RDebug *dbg, ut64 addr, const char *input);
507 R_API void r_debug_map_list_visual(RDebug *dbg, ut64 addr, const char *input, int colors);
508
509 /* descriptors */
510 R_API RDebugDesc *r_debug_desc_new (int fd, char* path, int perm, int type, int off);
511 R_API void r_debug_desc_free (RDebugDesc *p);
512 R_API int r_debug_desc_open(RDebug *dbg, const char *path);
513 R_API int r_debug_desc_close(RDebug *dbg, int fd);
514 R_API int r_debug_desc_dup(RDebug *dbg, int fd, int newfd);
515 R_API int r_debug_desc_read(RDebug *dbg, int fd, ut64 addr, int len);
516 R_API int r_debug_desc_seek(RDebug *dbg, int fd, ut64 addr); // TODO: whence?
517 R_API int r_debug_desc_write(RDebug *dbg, int fd, ut64 addr, int len);
518 R_API int r_debug_desc_list(RDebug *dbg, int rad);
519
520 /* registers */
521 R_API int r_debug_reg_sync(RDebug *dbg, int type, int write);
522 R_API bool r_debug_reg_list(RDebug *dbg, int type, int size, PJ *pj, int rad, const char *use_color);
523 R_API int r_debug_reg_set(RDebug *dbg, const char *name, ut64 num);
524 R_API ut64 r_debug_reg_get(RDebug *dbg, const char *name);
525 R_API ut64 r_debug_reg_get_err(RDebug *dbg, const char *name, int *err, utX *value);
526
527 R_API ut64 r_debug_execute(RDebug *dbg, const ut8 *buf, int len, int restore);
528 R_API bool r_debug_map_sync(RDebug *dbg);
529
530 R_API int r_debug_stop(RDebug *dbg);
531
532 /* backtrace */
533 R_API RList *r_debug_frames(RDebug *dbg, ut64 at);
534
535 R_API bool r_debug_is_dead(RDebug *dbg);
536 R_API int r_debug_map_protect(RDebug *dbg, ut64 addr, int size, int perms);
537 /* args XXX: weird food */
538 R_API ut64 r_debug_arg_get(RDebug *dbg, const char *cc, int num);
539 R_API bool r_debug_arg_set(RDebug *dbg, const char *cc, int num, ut64 value);
540
541 /* breakpoints (most in r_bp, this calls those) */
542 R_API RBreakpointItem *r_debug_bp_add(RDebug *dbg, ut64 addr, int hw, bool watch, int rw, char *module, st64 m_delta);
543 R_API void r_debug_bp_rebase(RDebug *dbg, ut64 old_base, ut64 new_base);
544 R_API void r_debug_bp_update(RDebug *dbg);
545
546 /* pid */
547 R_API int r_debug_thread_list(RDebug *dbg, int pid, char fmt);
548
549 R_API void r_debug_tracenodes_reset(RDebug *dbg);
550
551 R_API void r_debug_trace_reset(RDebug *dbg);
552 R_API int r_debug_trace_pc(RDebug *dbg, ut64 pc);
553 R_API void r_debug_trace_op(RDebug *dbg, RAnalOp *op);
554 R_API void r_debug_trace_at(RDebug *dbg, const char *str);
555 R_API RDebugTracepoint *r_debug_trace_get(RDebug *dbg, ut64 addr);
556 R_API void r_debug_trace_list(RDebug *dbg, int mode, ut64 offset);
557 R_API RDebugTracepoint *r_debug_trace_add(RDebug *dbg, ut64 addr, int size);
558 R_API RDebugTrace *r_debug_trace_new(void);
559 R_API void r_debug_trace_free(RDebugTrace *dbg);
560 R_API int r_debug_trace_tag(RDebug *dbg, int tag);
561 R_API int r_debug_child_fork(RDebug *dbg);
562 R_API int r_debug_child_clone(RDebug *dbg);
563
564 R_API void r_debug_drx_list(RDebug *dbg);
565 R_API int r_debug_drx_set(RDebug *dbg, int idx, ut64 addr, int len, int rwx, int g);
566 R_API int r_debug_drx_unset(RDebug *dbg, int idx);
567
568 /* esil */
569 R_API ut64 r_debug_num_callback(RNum *userptr, const char *str, int *ok);
570 R_API int r_debug_esil_stepi(RDebug *dbg);
571 R_API ut64 r_debug_esil_step(RDebug *dbg, ut32 count);
572 R_API ut64 r_debug_esil_continue(RDebug *dbg);
573 R_API void r_debug_esil_watch(RDebug *dbg, int rwx, int dev, const char *expr);
574 R_API void r_debug_esil_watch_reset(RDebug *dbg);
575 R_API void r_debug_esil_watch_list(RDebug *dbg);
576 R_API int r_debug_esil_watch_empty(RDebug *dbg);
577 R_API void r_debug_esil_prestep (RDebug *d, int p);
578
579 /* record & replay */
580 // R_API ut8 r_debug_get_byte(RDebug *dbg, ut32 cnum, ut64 addr);
581 R_API bool r_debug_add_checkpoint(RDebug *dbg);
582 R_API bool r_debug_session_add_reg_change(RDebugSession *session, int arena, ut64 offset, ut64 data);
583 R_API bool r_debug_session_add_mem_change(RDebugSession *session, ut64 addr, ut8 data);
584 R_API void r_debug_session_restore_reg_mem(RDebug *dbg, ut32 cnum);
585 R_API void r_debug_session_list_memory(RDebug *dbg);
586 R_API void r_debug_session_serialize(RDebugSession *session, Sdb *db);
587 R_API void r_debug_session_deserialize(RDebugSession *session, Sdb *db);
588 R_API bool r_debug_session_save(RDebugSession *session, const char *file);
589 R_API bool r_debug_session_load(RDebug *dbg, const char *file);
590 R_API bool r_debug_trace_ins_before(RDebug *dbg);
591 R_API bool r_debug_trace_ins_after(RDebug *dbg);
592
593 R_API RDebugSession *r_debug_session_new(void);
594 R_API void r_debug_session_free(RDebugSession *session);
595
596 R_API RDebugSnap *r_debug_snap_map(RDebug *dbg, RDebugMap *map);
597 R_API bool r_debug_snap_contains(RDebugSnap *snap, ut64 addr);
598 R_API ut8 *r_debug_snap_get_hash(RDebugSnap *snap);
599 R_API bool r_debug_snap_is_equal(RDebugSnap *a, RDebugSnap *b);
600 R_API void r_debug_snap_free(RDebugSnap *snap);
601
602 R_API int r_debug_step_back(RDebug *dbg, int steps);
603 R_API bool r_debug_goto_cnum(RDebug *dbg, ut32 cnum);
604 R_API int r_debug_step_cnum(RDebug *dbg, int steps);
605 R_API bool r_debug_continue_back(RDebug *dbg);
606
607 /* ptrace */
608 #if HAVE_PTRACE
r_debug_ptrace(RDebug * dbg,r_ptrace_request_t request,pid_t pid,void * addr,r_ptrace_data_t data)609 static inline long r_debug_ptrace(RDebug *dbg, r_ptrace_request_t request, pid_t pid, void *addr, r_ptrace_data_t data) {
610 return dbg->iob.ptrace (dbg->iob.io, request, pid, addr, data);
611 }
612
r_debug_ptrace_func(RDebug * dbg,void * (* func)(void *),void * user)613 static inline void *r_debug_ptrace_func(RDebug *dbg, void *(*func)(void *), void *user) {
614 return dbg->iob.ptrace_func (dbg->iob.io, func, user);
615 }
616 #endif
617
618 /* plugin pointers */
619 extern RDebugPlugin r_debug_plugin_native;
620 extern RDebugPlugin r_debug_plugin_esil;
621 extern RDebugPlugin r_debug_plugin_rap;
622 extern RDebugPlugin r_debug_plugin_gdb;
623 extern RDebugPlugin r_debug_plugin_bf;
624 extern RDebugPlugin r_debug_plugin_io;
625 extern RDebugPlugin r_debug_plugin_winkd;
626 extern RDebugPlugin r_debug_plugin_windbg;
627 extern RDebugPlugin r_debug_plugin_bochs;
628 extern RDebugPlugin r_debug_plugin_qnx;
629 extern RDebugPlugin r_debug_plugin_null;
630 #endif
631
632 #ifdef __cplusplus
633 }
634 #endif
635
636 #endif
637
638 /* regset */
639 //R_API struct r_regset_t* r_regset_diff(struct r_regset_t *a, struct r_regset_t *b);
640 //R_API int r_regset_set(struct r_regset_t *r, int idx, const char *name, ut64 value);
641 //R_API struct r_regset_t *r_regset_new(int size);
642 //R_API void r_regset_free(struct r_regset_t *r);
643
644 #if 0
645 Missing callbacks
646 =================
647 - alloc
648 - dealloc
649 - list maps (memory regions)
650 - change memory protections
651 - touchtrace
652 - filedescriptor set/get/mod..
653 - get/set signals
654 - get regs, set regs
655
656 #endif
657