Rizin
unix-like reverse engineering framework and cli tools
rz_bp.h
Go to the documentation of this file.
1 #ifndef RZ_BP_H
2 #define RZ_BP_H
3 
4 #include <rz_types.h>
5 #include <rz_lib.h>
6 #include <rz_io.h>
7 #include <rz_list.h>
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
14 
15 #define RZ_BP_MAXPIDS 10
16 #define RZ_BP_CONT_NORMAL 0
17 
18 typedef struct rz_bp_arch_t {
19  int bits;
20  int length;
21  int endian;
22  const ut8 *bytes;
24 
25 enum {
31 };
32 
33 typedef struct rz_bp_plugin_t {
34  char *name;
35  char *arch;
36  int type; // RZ_BP_TYPE_SW
37  int nbps;
40 
41 typedef struct rz_bp_item_t {
42  char *name;
43  char *module_name; /*module where you get the base address*/
44  st64 module_delta; /*delta to apply to module */
47  int size; /* size of breakpoint area */
48  bool swstep; /* is this breakpoint from a swstep? */
49  int perm;
50  int hw;
51  int trace;
52  int internal; /* used for internal purposes */
53  int enabled;
54  int togglehits; /* counter that toggles breakpoint on reaching 0 */
55  int hits;
56  ut8 *obytes; /* original bytes */
57  ut8 *bbytes; /* breakpoint bytes */
59  char *data;
60  char *cond; /* used for conditional breakpoints */
61  char *expr; /* to be used for named breakpoints (see rz_debug_bp_update) */
63 
64 struct rz_bp_t;
65 typedef int (*RzBreakpointCallback)(struct rz_bp_t *bp, RzBreakpointItem *b, bool set);
66 
71 typedef struct rz_bp_context_t {
72  void *user;
73  bool (*is_mapped)(ut64 addr, int perm, void *user);
74  void (*maps_sync)(void *user);
75  int (*bits_at)(ut64 addr, void *user);
77 
78 typedef struct rz_bp_t {
79  void *user;
81  int stepcont;
82  int endian;
83  bool bpinmaps; /* Only enable breakpoints inside a valid map */
84  RzIOBind iob; // compile time dependency
86  RzList *traces; // XXX
90  /* storage of breakpoints */
91  int nbps;
92  int nhwbps;
93  RzList *bps; // list of breakpoints
98 
99 typedef struct rz_bp_trace_t {
105  int length;
106  int bitlen;
108 
109 #ifdef RZ_API
112 
115 
117 RZ_API int rz_bp_use(RZ_NONNULL RzBreakpoint *bp, RZ_NONNULL const char *name);
118 RZ_API int rz_bp_plugin_del(RzBreakpoint *bp, const char *name);
120 
123 
124 /* bp item attribs setters */
126 RZ_API int rz_bp_set_trace(RzBreakpoint *bp, ut64 addr, int set);
127 RZ_API int rz_bp_set_trace_all(RzBreakpoint *bp, int set);
129 RZ_API bool rz_bp_enable_all(RzBreakpoint *bp, int set);
130 
131 /* index api */
132 RZ_API int rz_bp_del_index(RzBreakpoint *bp, int idx);
135 
139 
145 
146 RZ_API int rz_bp_add_fault(RzBreakpoint *bp, ut64 addr, int size, int perm);
147 
151 RZ_API int rz_bp_restore(RzBreakpoint *bp, bool set);
152 RZ_API bool rz_bp_restore_except(RzBreakpoint *bp, bool set, ut64 addr);
153 
154 /* traptrace */
155 RZ_API void rz_bp_traptrace_free(void *ptr);
156 RZ_API void rz_bp_traptrace_enable(RzBreakpoint *bp, int enable);
157 RZ_API void rz_bp_traptrace_reset(RzBreakpoint *bp, int hard);
164 
165 /* watchpoint */
167 
168 /* serialize */
169 typedef void *RzSerializeBpParser;
171 RZ_API RzSerializeBpParser rz_serialize_bp_parser_new(void);
173 
174 /* plugin pointers */
181 #endif
182 #ifdef __cplusplus
183 }
184 #endif
185 
186 #endif
size_t len
Definition: 6502dis.c:15
int bits(struct state *s, int need)
Definition: blast.c:72
RZ_API RZ_BORROW RzBreakpointItem * rz_bp_get_ending_at(RZ_NONNULL RzBreakpoint *bp, ut64 addr)
Get the breakpoint b that fulfills b->addr + b-> size == addr After hitting a (usually software) brea...
Definition: bp.c:119
RZ_API int rz_bp_set_trace_all(RzBreakpoint *bp, int set)
Definition: bp.c:338
RZ_API bool rz_bp_is_valid(RzBreakpoint *bp, RzBreakpointItem *b)
Definition: bp.c:406
RZ_API int rz_bp_del_index(RzBreakpoint *bp, int idx)
Definition: bp.c:364
RZ_API RzBreakpointItem * rz_bp_get_in(RzBreakpoint *bp, ut64 addr, int perm)
Definition: bp.c:139
RZ_API RzBreakpointItem * rz_bp_get_index(RzBreakpoint *bp, int idx)
Definition: bp.c:347
RZ_API int rz_bp_get_index_at(RzBreakpoint *bp, ut64 addr)
Definition: bp.c:354
RZ_API RzBreakpoint * rz_bp_new(RZ_BORROW RZ_NONNULL RzBreakpointContext *ctx)
Definition: bp.c:26
RZ_API int rz_bp_set_trace(RzBreakpoint *bp, ut64 addr, int set)
Definition: bp.c:329
RZ_API bool rz_bp_item_set_data(RZ_NONNULL RzBreakpointItem *item, RZ_NULLABLE const char *data)
set the data for a RzBreakpointItem
Definition: bp.c:445
RZ_API RZ_BORROW RzBreakpointItem * rz_bp_get_at(RZ_NONNULL RzBreakpoint *bp, ut64 addr)
Get the breakpoint at exactly addr.
Definition: bp.c:102
RZ_API int rz_bp_size(RZ_NONNULL RzBreakpoint *bp, int bits)
Predict the software breakpoint size to use for the given arch-bitness.
Definition: bp.c:377
RZ_API RzBreakpoint * rz_bp_free(RzBreakpoint *bp)
Definition: bp.c:48
RZ_API bool rz_bp_del(RzBreakpoint *bp, ut64 addr)
Definition: bp.c:315
RZ_API bool rz_bp_del_all(RzBreakpoint *bp)
Definition: bp.c:303
RZ_API RzBreakpointItem * rz_bp_add_hw(RzBreakpoint *bp, ut64 addr, int size, int perm)
Definition: bp.c:299
RZ_API RzBreakpointItem * rz_bp_enable(RzBreakpoint *bp, ut64 addr, int set, int count)
Definition: bp.c:152
RZ_API bool rz_bp_item_set_cond(RZ_NONNULL RzBreakpointItem *item, RZ_NULLABLE const char *cond)
set the condition for a RzBreakpointItem
Definition: bp.c:423
RZ_API int rz_bp_add_fault(RzBreakpoint *bp, ut64 addr, int size, int perm)
Definition: bp.c:271
RZ_API int rz_bp_get_bytes(RZ_NONNULL RzBreakpoint *bp, ut64 addr, RZ_NONNULL ut8 *buf, int len)
Definition: bp.c:61
RZ_API bool rz_bp_enable_all(RzBreakpoint *bp, int set)
Definition: bp.c:162
RZ_API bool rz_bp_item_set_name(RZ_NONNULL RzBreakpointItem *item, RZ_NULLABLE const char *name)
set the name for a RzBreakpointItem
Definition: bp.c:489
RZ_API bool rz_bp_item_set_expr(RZ_NONNULL RzBreakpointItem *item, RZ_NULLABLE const char *expr)
set the expr for a RzBreakpointItem
Definition: bp.c:467
RZ_API RZ_BORROW RzBreakpointItem * rz_bp_add_sw(RZ_NONNULL RzBreakpoint *bp, ut64 addr, int size, int perm)
Add a software breakpoint size preferred size of the breakpoint, or 0 to determine automatically.
Definition: bp.c:280
RZ_API int rz_bp_size_at(RZ_NONNULL RzBreakpoint *bp, ut64 addr)
Predict the software breakpoint size to use when placing a breakpoint at addr.
Definition: bp.c:399
struct rz_bp_plugin_t rz_bp_plugin_arm
Definition: bp_arm.c:34
struct rz_bp_plugin_t rz_bp_plugin_bf
Definition: bp_bf.c:13
RZ_API void rz_bp_restore_one(RzBreakpoint *bp, RzBreakpointItem *b, bool set)
Definition: bp_io.c:7
RZ_API int rz_bp_restore(RzBreakpoint *bp, bool set)
Definition: bp_io.c:28
RZ_API bool rz_bp_restore_except(RzBreakpoint *bp, bool set, ut64 addr)
Definition: bp_io.c:37
struct rz_bp_plugin_t rz_bp_plugin_mips
Definition: bp_mips.c:15
RZ_API void rz_bp_plugin_list(RzBreakpoint *bp)
Definition: bp_plugin.c:61
RZ_API int rz_bp_use(RZ_NONNULL RzBreakpoint *bp, RZ_NONNULL const char *name)
Definition: bp_plugin.c:47
RZ_API bool rz_bp_plugin_add(RzBreakpoint *bp, RZ_BORROW RZ_NONNULL RzBreakpointPlugin *plugin)
Definition: bp_plugin.c:24
RZ_API int rz_bp_plugin_del(RzBreakpoint *bp, const char *name)
Definition: bp_plugin.c:6
struct rz_bp_plugin_t rz_bp_plugin_ppc
Definition: bp_ppc.c:14
struct rz_bp_plugin_t rz_bp_plugin_sh
Definition: bp_sh.c:13
RZ_API int rz_bp_traptrace_at(RzBreakpoint *bp, ut64 from, int len)
Definition: bp_traptrace.c:161
RZ_API void rz_bp_traptrace_list(RzBreakpoint *bp)
Definition: bp_traptrace.c:148
RZ_API void rz_bp_traptrace_enable(RzBreakpoint *bp, int enable)
Definition: bp_traptrace.c:25
RZ_API ut64 rz_bp_traptrace_next(RzBreakpoint *bp, ut64 addr)
Definition: bp_traptrace.c:54
RZ_API int rz_bp_traptrace_add(RzBreakpoint *bp, ut64 from, ut64 to)
Definition: bp_traptrace.c:71
RZ_API void rz_bp_traptrace_free(void *ptr)
Definition: bp_traptrace.c:8
RZ_API void rz_bp_traptrace_reset(RzBreakpoint *bp, int hard)
Definition: bp_traptrace.c:34
RZ_API RzList * rz_bp_traptrace_new(void)
Definition: bp_traptrace.c:16
RZ_API int rz_bp_traptrace_free_at(RzBreakpoint *bp, ut64 from)
Definition: bp_traptrace.c:132
RZ_API RZ_BORROW RzBreakpointItem * rz_bp_watch_add(RZ_NONNULL RzBreakpoint *bp, ut64 addr, int size, int hw, int perm)
Definition: bp_watch.c:15
struct rz_bp_plugin_t rz_bp_plugin_x86
Definition: bp_x86.c:13
static RzNumCalcValue expr(RzNum *, RzNumCalc *, int)
Definition: calc.c:167
#define RZ_API
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
int idx
Definition: setup.py:197
@ RZ_BP_TYPE_HW
Definition: rz_bp.h:27
@ RZ_BP_TYPE_SW
Definition: rz_bp.h:26
@ RZ_BP_TYPE_DELETE
Definition: rz_bp.h:30
@ RZ_BP_TYPE_COND
Definition: rz_bp.h:28
@ RZ_BP_TYPE_FAULT
Definition: rz_bp.h:29
struct rz_bp_arch_t RzBreakpointArch
struct rz_bp_plugin_t RzBreakpointPlugin
int(* RzBreakpointCallback)(struct rz_bp_t *bp, RzBreakpointItem *b, bool set)
Definition: rz_bp.h:65
#define RZ_BP_MAXPIDS
Definition: rz_bp.h:15
struct rz_bp_trace_t RzBreakpointTrace
RZ_LIB_VERSION_HEADER(rz_bp)
struct rz_bp_t RzBreakpoint
struct rz_bp_item_t RzBreakpointItem
struct rz_bp_context_t RzBreakpointContext
Outer context of mappings/etc. in which the RzBreakpoint instance will operate in....
#define RZ_NULLABLE
Definition: rz_types.h:65
#define RZ_NONNULL
Definition: rz_types.h:64
int(* PrintfCallback)(const char *str,...) RZ_PRINTF_CHECK(1
Definition: rz_types.h:233
#define RZ_BORROW
Definition: rz_types.h:63
#define st64
Definition: rz_types_base.h:10
RZ_API bool rz_serialize_bp_load(RZ_NONNULL Sdb *db, RZ_NONNULL RzBreakpoint *bp, RZ_NULLABLE RzSerializeResultInfo *res)
Load a serialized breakpoints to a RzBreakpoint instance.
Definition: serialize_bp.c:302
RZ_API void rz_serialize_bp_save(RZ_NONNULL Sdb *db, RZ_NONNULL RzBreakpoint *bp)
serialize and save the breakpoints in a sdb
Definition: serialize_bp.c:13
RZ_API RzSerializeBpParser rz_serialize_bp_parser_new(void)
Create a new RzSerializeBpParser instance.
Definition: serialize_bp.c:90
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
Definition: sfsocketcall.h:123
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr socklen_t static fromlen const void const struct sockaddr to
Definition: sfsocketcall.h:125
static int
Definition: sfsocketcall.h:114
#define b(i)
Definition: sha256.c:42
#define cond(bop, top, mask, flags)
Definition: z80asm.h:102
int endian
Definition: rz_bp.h:21
int bits
Definition: rz_bp.h:19
const ut8 * bytes
Definition: rz_bp.h:22
int length
Definition: rz_bp.h:20
Outer context of mappings/etc. in which the RzBreakpoint instance will operate in....
Definition: rz_bp.h:71
int(* bits_at)(ut64 addr, void *user)
get the arch-bitness to use at the given address (e.g. thumb or 32)
Definition: rz_bp.h:75
bool(* is_mapped)(ut64 addr, int perm, void *user)
check if the address is mapped and has the given permissions
Definition: rz_bp.h:73
void * user
Definition: rz_bp.h:72
void(* maps_sync)(void *user)
synchronize any maps from the debugee
Definition: rz_bp.h:74
ut8 * bbytes
Definition: rz_bp.h:57
char * expr
Definition: rz_bp.h:61
int hw
Definition: rz_bp.h:50
st64 module_delta
Definition: rz_bp.h:44
char * data
Definition: rz_bp.h:59
ut8 * obytes
Definition: rz_bp.h:56
char * module_name
Definition: rz_bp.h:43
int size
Definition: rz_bp.h:47
int perm
Definition: rz_bp.h:49
char * name
Definition: rz_bp.h:42
bool swstep
Definition: rz_bp.h:48
int pids[RZ_BP_MAXPIDS]
Definition: rz_bp.h:58
ut64 addr
Definition: rz_bp.h:45
int togglehits
Definition: rz_bp.h:54
int hits
Definition: rz_bp.h:55
int enabled
Definition: rz_bp.h:53
int trace
Definition: rz_bp.h:51
char * cond
Definition: rz_bp.h:60
ut64 delta
Definition: rz_bp.h:46
char * name
Definition: rz_bp.h:34
int type
Definition: rz_bp.h:36
int nbps
Definition: rz_bp.h:37
char * arch
Definition: rz_bp.h:35
RzBreakpointArch * bps
Definition: rz_bp.h:38
Definition: rz_bp.h:78
int nhwbps
Definition: rz_bp.h:92
int stepcont
Definition: rz_bp.h:81
PrintfCallback cb_printf
Definition: rz_bp.h:88
int nbps
Definition: rz_bp.h:91
RzBreakpointItem ** bps_idx
Definition: rz_bp.h:94
RzBreakpointCallback breakpoint
Definition: rz_bp.h:89
RzList * plugins
Definition: rz_bp.h:87
bool bpinmaps
Definition: rz_bp.h:83
RzList * traces
Definition: rz_bp.h:86
RzBreakpointContext ctx
Definition: rz_bp.h:80
RzIOBind iob
Definition: rz_bp.h:84
int bps_idx_count
Definition: rz_bp.h:95
RzBreakpointPlugin * cur
Definition: rz_bp.h:85
int endian
Definition: rz_bp.h:82
RzList * bps
Definition: rz_bp.h:93
void * user
Definition: rz_bp.h:79
ut64 baddr
Definition: rz_bp.h:96
ut8 * bits
Definition: rz_bp.h:104
int bitlen
Definition: rz_bp.h:106
ut8 * traps
Definition: rz_bp.h:102
int length
Definition: rz_bp.h:105
ut64 addr_end
Definition: rz_bp.h:101
ut64 addr
Definition: rz_bp.h:100
ut8 * buffer
Definition: rz_bp.h:103
Definition: sdb.h:63
#define bool
Definition: sysdefs.h:146
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int addr
Definition: z80asm.c:58