Rizin
unix-like reverse engineering framework and cli tools
libgdbr.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2014 defragger <rlaemmert@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
5 #ifndef LIBGDBR_H
6 #define LIBGDBR_H
7 
8 #include <stdint.h>
9 
10 #include "arch.h"
11 #include "rz_types_base.h"
12 #include "rz_socket.h"
13 #include "rz_th.h"
14 
15 #define MSG_OK 0
16 #define MSG_NOT_SUPPORTED -1
17 #define MSG_ERROR_1 -2
18 
19 #define GDB_REMOTE_TYPE_GDB 0
20 #define GDB_REMOTE_TYPE_LLDB 1
21 #define GDB_MAX_PKTSZ 4
22 
26 typedef struct libgdbr_message_t {
28  char *msg;
31 
36 typedef struct libgdbr_stub_features_t {
37  ut32 pkt_sz; /* Max packet size */
58  bool Qbtrace_pt;
61  bool QNonStop;
65  bool QAgent;
66  bool QAllow;
76  bool swbreak;
77  bool hwbreak;
82  bool no_resumed;
87  bool tracenz;
89  // lldb-specific features
90  struct {
91  bool g;
94  bool qEcho;
95  } lldb;
96  // Cannot be determined with qSupported, found out on query
97  bool qC;
99  struct {
100  bool c, C, s, S, t, r;
101  } vcont;
102  bool P;
104 
109  typedef struct libgdbr_fstat_t {
110  unsigned dev;
111  unsigned ino;
112  unsigned mode;
113  unsigned numlinks;
114  unsigned uid;
115  unsigned gid;
116  unsigned rdev;
117  uint64_t size;
118  uint64_t blksize;
120  unsigned atime;
121  unsigned mtime;
122  unsigned ctime;
123  })
124 libgdbr_fstat_t;
125 
129 typedef struct libgdbr_stop_reason {
130  unsigned signum;
131  int core;
132  int reason;
133  bool syscall;
134  bool library;
135  bool swbreak;
136  bool hwbreak;
137  bool create;
138  bool vforkdone;
139  bool is_valid;
140  struct {
141  bool present;
144  struct {
145  bool present;
146  char *path;
147  } exec;
148  struct {
149  bool present;
150  int pid;
151  int tid;
154 
159 typedef struct libgdbr_t {
160  char *send_buff; // defines a buffer for reading and sending stuff
162  ssize_t send_max; // defines the maximal len for the given buffer
163  char *read_buff;
164  ssize_t read_max; // defines the maximal len for the given buffer
165  ssize_t read_len; // len of read_buff (if read_buff not fully consumed)
166 
167  // is already handled (i.e. already send or ...)
170  int acks;
171  char *data;
176  int pid; // little endian
177  int tid; // little endian
178  int page_size; // page size for target (useful for qemu)
179  bool attached; // Remote server attached to process or created
181 
182  int remote_file_fd; // For remote file I/O
183  int num_retries; // number of retries for packet reading
184 
186  bool no_ack;
187  bool is_server;
189  bool get_baddr;
191 
193  int gdbr_lock_depth; // current depth inside the recursive lock
194 
195  // parsed from target
196  struct {
197  char *regprofile;
198  int arch, bits;
199  bool valid;
201 
202  bool isbreaked;
204 
209 int gdbr_init(libgdbr_t *g, bool is_server);
210 
216 bool gdbr_set_architecture(libgdbr_t *g, int arch, int bits);
217 
223 char *gdbr_get_reg_profile(int arch, int bits);
224 
230 int gdbr_set_reg_profile(libgdbr_t *g, const char *str);
231 
236 int gdbr_cleanup(libgdbr_t *g);
237 
238 #endif
int bits(struct state *s, int need)
Definition: blast.c:72
cs_arch arch
Definition: cstool.c:13
uint32_t ut32
struct @667 g
voidpf void uLong size
Definition: ioapi.h:138
const char int mode
Definition: ioapi.h:137
struct libgdbr_t libgdbr_t
struct libgdbr_stub_features_t libgdbr_stub_features_t
struct libgdbr_stop_reason libgdbr_stop_reason_t
struct libgdbr_message_t libgdbr_message_t
int gdbr_set_reg_profile(libgdbr_t *g, const char *str)
Function set the gdbr internal registers profile.
Definition: libgdbr.c:125
bool gdbr_set_architecture(libgdbr_t *g, int arch, int bits)
Function initializes the architecture of the gdbsession.
Definition: libgdbr.c:52
char * gdbr_get_reg_profile(int arch, int bits)
Function get gdb registers profile based on arch and bits.
Definition: libgdbr.c:76
RZ_PACKED(typedef struct libgdbr_fstat_t { unsigned dev;unsigned ino;unsigned mode;unsigned numlinks;unsigned uid;unsigned gid;unsigned rdev;uint64_t size;uint64_t blksize;uint64_t blocks;unsigned atime;unsigned mtime;unsigned ctime;}) libgdbr_fstat_t
int gdbr_cleanup(libgdbr_t *g)
frees all buffers and cleans the libgdbr instance stuff
Definition: libgdbr.c:146
int gdbr_init(libgdbr_t *g, bool is_server)
Function initializes the libgdbr lib.
Definition: libgdbr.c:9
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask dev
Definition: sflib.h:88
unsigned long uint64_t
Definition: sftypes.h:28
unsigned char uint8_t
Definition: sftypes.h:31
int ssize_t
Definition: sftypes.h:39
Definition: arch.h:13
uint8_t chk
Definition: libgdbr.h:29
ssize_t len
Definition: libgdbr.h:27
struct libgdbr_stop_reason::@441 thread
struct libgdbr_stop_reason::@440 exec
struct libgdbr_stop_reason::@439 watchpoint
unsigned signum
Definition: libgdbr.h:130
struct libgdbr_stop_reason::@441 fork
struct libgdbr_stop_reason::@441 vfork
bool qXfer_libraries_svr4_read
Definition: libgdbr.h:43
bool qXfer_traceframe_info_read
Definition: libgdbr.h:52
bool augmented_libraries_svr4_read
Definition: libgdbr.h:83
struct libgdbr_stub_features_t::@437 lldb
bool EnableDisableTracepoints
Definition: libgdbr.h:86
struct libgdbr_stub_features_t::@438 vcont
bool QListThreadsInStopReply
Definition: libgdbr.h:93
bool is_server
Definition: libgdbr.h:187
bool isbreaked
Definition: libgdbr.h:202
char * read_buff
Definition: libgdbr.h:163
bool attached
Definition: libgdbr.h:179
bool get_baddr
Definition: libgdbr.h:189
ssize_t read_len
Definition: libgdbr.h:165
char * data
Definition: libgdbr.h:171
int page_size
Definition: libgdbr.h:178
int last_code
Definition: libgdbr.h:175
bool no_ack
Definition: libgdbr.h:186
int connected
Definition: libgdbr.h:169
bool server_debug
Definition: libgdbr.h:188
bool valid
Definition: libgdbr.h:199
int bits
Definition: libgdbr.h:198
gdb_reg_t * registers
Definition: libgdbr.h:174
int acks
Definition: libgdbr.h:170
int pid
Definition: libgdbr.h:176
ssize_t data_len
Definition: libgdbr.h:172
struct libgdbr_t::@442 target
RzThreadLock * gdbr_lock
Definition: libgdbr.h:192
libgdbr_stop_reason_t stop_reason
Definition: libgdbr.h:190
ssize_t send_len
Definition: libgdbr.h:161
ssize_t data_max
Definition: libgdbr.h:173
int gdbr_lock_depth
Definition: libgdbr.h:193
int remote_type
Definition: libgdbr.h:185
int arch
Definition: libgdbr.h:198
libgdbr_stub_features_t stub_features
Definition: libgdbr.h:180
int tid
Definition: libgdbr.h:177
RzSocket * sock
Definition: libgdbr.h:168
ssize_t send_max
Definition: libgdbr.h:162
char * regprofile
Definition: libgdbr.h:197
char * send_buff
Definition: libgdbr.h:160
ssize_t read_max
Definition: libgdbr.h:164
int remote_file_fd
Definition: libgdbr.h:182
int num_retries
Definition: libgdbr.h:183
uint64_t blocks
Definition: list.c:104
ut64(WINAPI *w32_GetEnabledXStateFeatures)()