fix hardcoded argv in memusage/skeleton
[rofl0r-debuglib.git] / debuglib.h
blob0cfee18bdd0aa04e90582bcde88579be51aecdf9
1 #ifndef DEBUGLIB_H
2 #define DEBUGLIB_H
4 #include <stddef.h>
5 #include <stdlib.h>
7 #include "process_maps.h"
9 #include "../lib/include/hashlist.h"
11 #define BP_INSTR_SIZE_MAX 16
12 typedef struct {
13 uintptr_t addr;
14 unsigned char map_perms;
15 unsigned char bp_instr_size;
16 char bp_backup[BP_INSTR_SIZE_MAX];
17 int active:1;
18 } breakpointinfo;
20 typedef struct {
21 pid_t pid;
22 hashlist* breakpoints;
23 sblist* processmaps;
24 int syscall_ret;
25 } pidinfo;
27 typedef struct {
28 sblist* pids;
29 } debugger_state;
31 typedef enum {
32 DE_NONE = 0,
33 DE_HIT_BP,
34 DE_EXIT, /* debugger notification when a process is about to exit. exitstatus can be queried with WEXITSTATUS(retval) */
35 DE_FORK,
36 DE_VFORK,
37 DE_CLONE,
38 DE_FORK_DONE,
39 DE_VFORK_DONE,
40 DE_CLONE_DONE,
41 DE_SYSCALL_ENTER,
42 DE_SYSCALL_RETURN,
43 DE_EXEC,
44 DE_SIGNAL,
45 DE_EXITED, /* custom notification when the process is done exiting. exitstatus is returned directly */
46 DE_MAX,
47 } debugger_event;
49 void dump_ram_line(void* offset, size_t length);
50 void dump_ram(void* offset, size_t length, size_t linesize);
52 void debugger_state_init(debugger_state*);
53 size_t debugger_get_pidcount(debugger_state* d);
54 pid_t debugger_pid_from_pidindex(debugger_state* d, size_t index);
55 ssize_t debugger_pidindex_from_pid(debugger_state* d, pid_t pid);
56 void debugger_add_pid(debugger_state* d, pid_t pid);
57 void debugger_remove_pid(debugger_state* d, pid_t pid);
58 //void debugger_set_pid(debugger_state *d, size_t pidindex, pid_t pid);
59 int debugger_set_breakpoint(debugger_state* state, pid_t pid, uintptr_t addr);
60 uintptr_t debugger_get_ip(debugger_state* d, pid_t pid);
61 int debugger_set_ip(debugger_state* d, pid_t pid, uintptr_t addr);
62 int debugger_attach(debugger_state *d, pid_t pid);
63 int debugger_detach(debugger_state *d, pid_t pid);
64 pid_t debugger_exec(debugger_state* d, const char* path, char *const args[], char *const env[]);
65 /* tells the debugger to signal on next syscall enter/return. does not actually wait. */
66 int debugger_wait_syscall(debugger_state* d, pid_t pid, int sig);
67 /* same, but tries the above in a loop until it succeeds */
68 int debugger_wait_syscall_retry(debugger_state* d, pid_t pid, int sig);
69 long debugger_get_syscall_number(debugger_state* state, pid_t pid);
70 long debugger_get_syscall_arg(debugger_state *d, pid_t pid, int argno);
71 void debugger_set_syscall_arg(debugger_state *d, pid_t pid, int argno, unsigned long nu);
72 void debugger_set_syscall_number(debugger_state * state, pid_t pid, long scnr);
73 int debugger_single_step(debugger_state* state, pid_t pid);
74 int debugger_continue(debugger_state *state, pid_t pid);
75 /* pid is an in-out pointer: when calling the function pass either -1 to get results from all
76 childs, or the pid of the process you wanna trace. on return, it will contain the pid
77 of the process that was queried (should be identical to the passed value, if it was not -1) */
78 debugger_event debugger_get_events(debugger_state* d, pid_t *pid, int* retval, int block);
79 const char* debugger_get_event_name(debugger_event de);
81 int read_process_memory_slow(pid_t pid, void* dest_addr, uintptr_t source_addr, size_t len);
82 int write_process_memory_slow(pid_t pid, uintptr_t dest_addr, void* source_addr, size_t len);
84 #pragma RcB2 DEP "debuglib.c"
86 #endif