Rizin
unix-like reverse engineering framework and cli tools
core.c File Reference
#include "gdbserver/core.h"
#include "gdbr_common.h"
#include "libgdbr.h"
#include "packet.h"
#include "utils.h"
#include "rz_util/rz_str.h"

Go to the source code of this file.

Functions

static int _server_handle_qSupported (libgdbr_t *g)
 
static int _server_handle_qTStatus (libgdbr_t *g)
 
static int _server_handle_qOffsets (libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
 
static int _server_handle_exec_file_read (libgdbr_t *g, gdbr_server_cmd_cb cb, void *core_ptr)
 
static int _server_handle_M (libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
 
static int _server_handle_s (libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
 
static int _server_handle_c (libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
 
static int _server_handle_ques (libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
 
static int _server_handle_qC (libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
 
static int _server_handle_k (libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
 
static int _server_handle_vKill (libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
 
static int _server_handle_z (libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
 
static int _server_handle_vCont (libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
 
static int _server_handle_qAttached (libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
 
static int _server_handle_Hg (libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
 
static int _server_handle_Hc (libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
 
static int _server_handle_qfThreadInfo (libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
 
static int _server_handle_qsThreadInfo (libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
 
static int _server_handle_g (libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
 
static int _server_handle_m (libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
 
static int _server_handle_p (libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
 
static int _server_handle_P (libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
 
static int _server_handle_vMustReplyEmpty (libgdbr_t *g)
 
static int _server_handle_qTfV (libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
 
int gdbr_server_serve (libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
 

Function Documentation

◆ _server_handle_c()

static int _server_handle_c ( libgdbr_t g,
gdbr_server_cmd_cb  cmd_cb,
void *  core_ptr 
)
static

Definition at line 140 of file core.c.

140  {
141  char message[64];
142  if (send_ack(g) < 0) {
143  return -1;
144  }
145  if (g->data_len > 1) {
146  // We don't handle s[addr] packet
147  return send_msg(g, "E01");
148  }
149  if (cmd_cb(g, core_ptr, "dc", NULL, 0) < 0) {
150  send_msg(g, "E01");
151  return -1;
152  }
153  if (cmd_cb(g, core_ptr, "?", message, sizeof(message)) < 0) {
154  send_msg(g, "");
155  return -1;
156  }
157  return send_msg(g, message);
158 }
#define NULL
Definition: cris-opc.c:27
struct @667 g
int send_ack(libgdbr_t *g)
Functions sends a single ack ('+')
Definition: common.c:130
int send_msg(libgdbr_t *g, const char *command)
Definition: common.c:146
char * message
Definition: main.c:12

References g, message, NULL, send_ack(), and send_msg().

Referenced by gdbr_server_serve().

◆ _server_handle_exec_file_read()

static int _server_handle_exec_file_read ( libgdbr_t g,
gdbr_server_cmd_cb  cb,
void *  core_ptr 
)
static

Definition at line 56 of file core.c.

57  {
58  char *buf, *ptr, cmd[64] = { 0 };
59  size_t buflen = 512;
60  int ret;
61  if (send_ack(g) < 0) {
62  return -1;
63  }
64  ptr = g->data + strlen("qXfer:exec-file:read:");
65  if (*ptr != ':') {
66  int pid;
67  if ((pid = (int)strtol(ptr, NULL, 16)) <= 0 || pid != g->pid) {
68  return send_msg(g, "E00");
69  }
70  }
71  if (!(ptr = strchr(ptr, ':'))) {
72  return send_msg(g, "E00");
73  }
74  ptr++;
75  snprintf(cmd, sizeof(cmd) - 1, "if%s", ptr);
76  if (!(buf = malloc(buflen))) {
77  send_msg(g, "E01");
78  return -1;
79  }
80  if (cb(g, core_ptr, cmd, buf, buflen) < 0) {
81  free(buf);
82  return send_msg(g, "E01");
83  }
84  ret = send_msg(g, buf);
85  free(buf);
86  return ret;
87 }
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 cmd
Definition: sflib.h:79
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void * buf
Definition: ioapi.h:138
snprintf
Definition: kernel.h:364
void * malloc(size_t size)
Definition: malloc.c:123
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 pid
Definition: sflib.h:64
ut8 * buf
Definition: core.c:75
ut64 buflen
Definition: core.c:76
static const char * cb[]
Definition: z80_tab.h:176

References buf, buflen, cb, cmd, free(), g, malloc(), NULL, pid, send_ack(), send_msg(), and snprintf.

Referenced by gdbr_server_serve().

◆ _server_handle_g()

static int _server_handle_g ( libgdbr_t g,
gdbr_server_cmd_cb  cmd_cb,
void *  core_ptr 
)
static

Definition at line 364 of file core.c.

364  {
365  char *buf;
366  // To be very safe
367  int buf_len = 4096;
368  int ret;
369  if (send_ack(g) < 0) {
370  return -1;
371  }
372  if (!(buf = malloc(buf_len))) {
373  send_msg(g, "E01");
374  return -1;
375  }
376  memset(buf, 0, buf_len);
377  if (cmd_cb(g, core_ptr, "dr", buf, buf_len) < 0) {
378  free(buf);
379  send_msg(g, "E01");
380  return -1;
381  }
382  ret = send_msg(g, buf);
383  free(buf);
384  return ret;
385 }
static int buf_len
Definition: asm_arc.c:22
return memset(p, 0, total)

References buf, buf_len, free(), g, malloc(), memset(), send_ack(), and send_msg().

Referenced by gdbr_server_serve().

◆ _server_handle_Hc()

static int _server_handle_Hc ( libgdbr_t g,
gdbr_server_cmd_cb  cmd_cb,
void *  core_ptr 
)
static

Definition at line 313 of file core.c.

313  {
314  // Usually this is only sent with Hc-1. Still. Set the threads for next operations
315  char cmd[32];
316  int tid;
317  if (send_ack(g) < 0) {
318  return -1;
319  }
320  if (g->data_len <= 2 || isalpha(g->data[2])) {
321  return send_msg(g, "E01");
322  }
323  // Hc-1 = "all threads", Hc0 = "pick any thread"
324  if (g->data[2] == '0' || !strncmp(g->data + 2, "-1", 2)) {
325  return send_msg(g, "OK");
326  }
327  sscanf(g->data + 2, "%x", &tid);
328  snprintf(cmd, sizeof(cmd) - 1, "dpt=%d", tid);
329  // Set thread for future operations
330  if (cmd_cb(g, core_ptr, cmd, NULL, 0) < 0) {
331  send_msg(g, "E01");
332  return -1;
333  }
334  return send_msg(g, "OK");
335 }
#define isalpha(c)
Definition: safe-ctype.h:125

References cmd, g, isalpha, NULL, send_ack(), send_msg(), and snprintf.

Referenced by gdbr_server_serve().

◆ _server_handle_Hg()

static int _server_handle_Hg ( libgdbr_t g,
gdbr_server_cmd_cb  cmd_cb,
void *  core_ptr 
)
static

Definition at line 287 of file core.c.

287  {
288  // We don't yet support multiprocess. Client is not supposed to send Hgp. If we receive it anyway,
289  // send error
290  char cmd[32];
291  int tid;
292  if (send_ack(g) < 0) {
293  return -1;
294  }
295  if (g->data_len <= 2 || isalpha(g->data[2])) {
296  return send_msg(g, "E01");
297  }
298  // Hg-1 = "all threads", Hg0 = "pick any thread"
299  if (g->data[2] == '0' || !strncmp(g->data + 2, "-1", 2)) {
300  return send_msg(g, "OK");
301  }
302  sscanf(g->data + 2, "%x", &tid);
303  snprintf(cmd, sizeof(cmd) - 1, "dpt=%d", tid);
304  // Set thread for future operations
305  if (cmd_cb(g, core_ptr, cmd, NULL, 0) < 0) {
306  send_msg(g, "E01");
307  return -1;
308  }
309  return send_msg(g, "OK");
310 }

References cmd, g, isalpha, NULL, send_ack(), send_msg(), and snprintf.

Referenced by gdbr_server_serve().

◆ _server_handle_k()

static int _server_handle_k ( libgdbr_t g,
gdbr_server_cmd_cb  cmd_cb,
void *  core_ptr 
)
static

Definition at line 191 of file core.c.

191  {
192  send_ack(g);
193  return -1;
194 }

References g, and send_ack().

Referenced by gdbr_server_serve().

◆ _server_handle_M()

static int _server_handle_M ( libgdbr_t g,
gdbr_server_cmd_cb  cmd_cb,
void *  core_ptr 
)
static

Definition at line 89 of file core.c.

89  {
90  if (send_ack(g) < 0) {
91  return -1;
92  }
93  char *memstr, *buf;
94  ut64 memlen, memlen2, addr;
95  g->data[g->data_len] = '\0';
96  if (sscanf(g->data + 1, "%" PFMT64x ",%" PFMT64x, &addr, &memlen) != 2) {
97  return send_msg(g, "E01");
98  }
99  memlen2 = memlen * 2;
100  if (!(memstr = strchr(g->data, ':')) || !*(++memstr)) {
101  return send_msg(g, "E01");
102  }
103  if (memlen2 != strlen(memstr)) {
104  return send_msg(g, "E01");
105  }
106  if (!(buf = malloc(memlen2 + 64))) {
107  return send_msg(g, "E01");
108  }
109  snprintf(buf, memlen2 + 63, "wx 0x%s @ 0x%" PFMT64x, memstr, addr);
110  buf[memlen2 + 63] = '\0';
111  eprintf("buf: %s\n", buf);
112  if (cmd_cb(g, core_ptr, buf, NULL, 0) < 0) {
113  free(buf);
114  return send_msg(g, "E01");
115  }
116  free(buf);
117  return send_msg(g, "OK");
118 }
#define eprintf(x, y...)
Definition: rlcc.c:7
#define PFMT64x
Definition: rz_types.h:393
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int addr
Definition: z80asm.c:58

References addr, buf, eprintf, free(), g, malloc(), NULL, PFMT64x, send_ack(), send_msg(), snprintf, and ut64().

Referenced by gdbr_server_serve().

◆ _server_handle_m()

static int _server_handle_m ( libgdbr_t g,
gdbr_server_cmd_cb  cmd_cb,
void *  core_ptr 
)
static

Definition at line 387 of file core.c.

387  {
388  ut64 addr;
389  int length;
390  char *cmd, *buf;
391  if (send_ack(g) < 0) {
392  return -1;
393  }
394  g->data[g->data_len] = 0;
395  sscanf(g->data, "m%" PFMT64x, &addr);
396  if (!(cmd = strdup(g->data))) {
397  send_msg(g, "E01");
398  return -1;
399  }
400  if (!(buf = malloc(g->data_max / 2))) {
401  free(cmd);
402  send_msg(g, "E01");
403  return -1;
404  }
405  if ((length = cmd_cb(g, core_ptr, cmd, buf, (g->data_max / 2) - 1)) < 0 || length >= g->data_max / 2) {
406  free(cmd);
407  free(buf);
408  return send_msg(g, "E01");
409  }
410  pack_hex(buf, length, g->data);
411  free(cmd);
412  free(buf);
413  g->data[length * 2] = '\0';
414  return send_msg(g, g->data);
415 }
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 static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
int pack_hex(const char *src, ut64 len, char *dst)
Definition: utils.c:111

References addr, buf, cmd, free(), g, length, malloc(), pack_hex(), PFMT64x, send_ack(), send_msg(), strdup(), and ut64().

Referenced by gdbr_server_serve().

◆ _server_handle_p()

static int _server_handle_p ( libgdbr_t g,
gdbr_server_cmd_cb  cmd_cb,
void *  core_ptr 
)
static

Definition at line 418 of file core.c.

418  {
419  char message[128] = { 0 }, cmd[128] = { 0 };
420  int regnum, i;
421  if (send_ack(g) < 0) {
422  return -1;
423  }
424  if (!isxdigit(g->data[1])) {
425  return send_msg(g, "E01");
426  }
427  regnum = strtol(g->data + 1, NULL, 16);
428  // We need to do this because length of register set is not known
429  for (i = 0; i < regnum; i++) {
430  if (!*g->registers[i].name) {
431  return send_msg(g, "E01");
432  }
433  }
434  if (snprintf(cmd, sizeof(cmd) - 1, "dr %s", g->registers[regnum].name) < 0) {
435  send_msg(g, "E01");
436  return -1;
437  }
438  if (cmd_cb(g, core_ptr, cmd, message, sizeof(message)) < 0) {
439  send_msg(g, "E01");
440  return -1;
441  }
442  return send_msg(g, message);
443 }
lzma_index ** i
Definition: index.h:629
#define isxdigit(c)
Definition: safe-ctype.h:145

References cmd, g, i, isxdigit, message, NULL, send_ack(), send_msg(), and snprintf.

Referenced by gdbr_server_serve().

◆ _server_handle_P()

static int _server_handle_P ( libgdbr_t g,
gdbr_server_cmd_cb  cmd_cb,
void *  core_ptr 
)
static

Definition at line 446 of file core.c.

446  {
447  char *ptr, *cmd;
448  int regnum, len, i;
449  if (send_ack(g) < 0) {
450  return -1;
451  }
452  if (!isxdigit(g->data[1]) || !(ptr = strchr(g->data, '='))) {
453  return send_msg(g, "E01");
454  }
455  ptr++;
456  if (!isxdigit(*ptr)) {
457  return send_msg(g, "E01");
458  }
459  regnum = strtol(g->data + 1, NULL, 16);
460  // We need to do this because length of register set is not known
461  for (i = 0; i < regnum; i++) {
462  if (!*g->registers[i].name) {
463  return send_msg(g, "E01");
464  }
465  }
466  len = strlen(g->registers[regnum].name) + strlen(ptr) + 10;
467  if (!(cmd = calloc(len, sizeof(char)))) {
468  return send_msg(g, "E01");
469  }
470  snprintf(cmd, len - 1, "dr %s=0x%s", g->registers[regnum].name, ptr);
471  if (cmd_cb(g, core_ptr, cmd, NULL, 0) < 0) {
472  free(cmd);
473  send_msg(g, "E01");
474  return -1;
475  }
476  free(cmd);
477  return send_msg(g, "OK");
478 }
size_t len
Definition: 6502dis.c:15
void * calloc(size_t number, size_t size)
Definition: malloc.c:102

References calloc(), cmd, free(), g, i, isxdigit, len, NULL, send_ack(), send_msg(), and snprintf.

Referenced by gdbr_server_serve().

◆ _server_handle_qAttached()

static int _server_handle_qAttached ( libgdbr_t g,
gdbr_server_cmd_cb  cmd_cb,
void *  core_ptr 
)
static

Definition at line 275 of file core.c.

275  {
276  if (send_ack(g) < 0) {
277  return -1;
278  }
279  // TODO check if process was attached or created
280  // Right now, says that process was created
281  return send_msg(g, "0");
282 }

References g, send_ack(), and send_msg().

Referenced by gdbr_server_serve().

◆ _server_handle_qC()

static int _server_handle_qC ( libgdbr_t g,
gdbr_server_cmd_cb  cmd_cb,
void *  core_ptr 
)
static

Definition at line 172 of file core.c.

172  {
173  char *buf;
174  int ret;
175  size_t buf_len = 80;
176  if (send_ack(g) < 0) {
177  return -1;
178  }
179  if (!(buf = malloc(buf_len))) {
180  return -1;
181  }
182  if (cmd_cb(g, core_ptr, "dp", buf, buf_len) < 0) {
183  free(buf);
184  return -1;
185  }
186  ret = send_msg(g, buf);
187  free(buf);
188  return ret;
189 }

References buf, buf_len, free(), g, malloc(), send_ack(), and send_msg().

Referenced by gdbr_server_serve().

◆ _server_handle_qfThreadInfo()

static int _server_handle_qfThreadInfo ( libgdbr_t g,
gdbr_server_cmd_cb  cmd_cb,
void *  core_ptr 
)
static

Definition at line 337 of file core.c.

337  {
338  char *buf;
339  int ret;
340  size_t buf_len = g->stub_features.pkt_sz;
341  if (send_ack(g) < 0) {
342  return -1;
343  }
344  if (!(buf = malloc(buf_len))) {
345  return -1;
346  }
347  if (cmd_cb(g, core_ptr, "dpt", buf, buf_len) < 0) {
348  free(buf);
349  return -1;
350  }
351  ret = send_msg(g, buf);
352  free(buf);
353  return ret;
354 }

References buf, buf_len, free(), g, malloc(), send_ack(), and send_msg().

Referenced by gdbr_server_serve().

◆ _server_handle_qOffsets()

static int _server_handle_qOffsets ( libgdbr_t g,
gdbr_server_cmd_cb  cmd_cb,
void *  core_ptr 
)
static

Definition at line 43 of file core.c.

43  {
44  char buf[64], *ptr;
45  ptr = buf + sprintf(buf, "TextSeg=");
46  if (send_ack(g) < 0) {
47  return -1;
48  }
49  if (cmd_cb(g, core_ptr, "dm", ptr, sizeof(buf) - (ptr - buf) - 1) < 0) {
50  send_msg(g, "");
51  return -1;
52  }
53  return send_msg(g, buf);
54 }
sprintf
Definition: kernel.h:365

References g, send_ack(), send_msg(), and sprintf.

Referenced by gdbr_server_serve().

◆ _server_handle_qsThreadInfo()

static int _server_handle_qsThreadInfo ( libgdbr_t g,
gdbr_server_cmd_cb  cmd_cb,
void *  core_ptr 
)
static

Definition at line 356 of file core.c.

356  {
357  // TODO handle overflow from qfThreadInfo. Otherwise this won't work with programs with many threads
358  if (send_ack(g) < 0 || send_msg(g, "l") < 0) {
359  return -1;
360  }
361  return 0;
362 }

References g, send_ack(), and send_msg().

Referenced by gdbr_server_serve().

◆ _server_handle_qSupported()

static int _server_handle_qSupported ( libgdbr_t g)
static

Definition at line 17 of file core.c.

17  {
18  int ret;
19  char *buf;
20  if (!(buf = malloc(128))) {
21  return -1;
22  }
23  snprintf(buf, 127, "PacketSize=%x;QStartNoAckMode+;qXfer:exec-file:read+",
24  (ut32)(g->read_max - 1));
25  if (handle_qSupported(g) < 0) {
26  free(buf);
27  return -1;
28  }
29  ret = send_msg(g, buf);
30  free(buf);
31  return ret;
32 }
uint32_t ut32
int handle_qSupported(libgdbr_t *g)
Definition: common.c:12

References buf, free(), g, handle_qSupported(), malloc(), send_msg(), and snprintf.

Referenced by gdbr_server_serve().

◆ _server_handle_qTfV()

static int _server_handle_qTfV ( libgdbr_t g,
gdbr_server_cmd_cb  cmd_cb,
void *  core_ptr 
)
static

Definition at line 487 of file core.c.

487  {
488  // TODO
489  if (send_ack(g) < 0) {
490  return -1;
491  }
492  return send_msg(g, "");
493 }

References g, send_ack(), and send_msg().

Referenced by gdbr_server_serve().

◆ _server_handle_qTStatus()

static int _server_handle_qTStatus ( libgdbr_t g)
static

Definition at line 34 of file core.c.

34  {
35  // TODO Handle proper reporting of trace status
36  const char *message = "";
37  if (send_ack(g) < 0) {
38  return -1;
39  }
40  return send_msg(g, message);
41 }

References g, message, send_ack(), and send_msg().

Referenced by gdbr_server_serve().

◆ _server_handle_ques()

static int _server_handle_ques ( libgdbr_t g,
gdbr_server_cmd_cb  cmd_cb,
void *  core_ptr 
)
static

Definition at line 160 of file core.c.

160  {
161  char message[64] = { 0 };
162  if (send_ack(g) < 0) {
163  return -1;
164  }
165  if (cmd_cb(g, core_ptr, "?", message, sizeof(message)) < 0) {
166  send_msg(g, "");
167  return -1;
168  }
169  return send_msg(g, message);
170 }

References g, message, send_ack(), and send_msg().

Referenced by gdbr_server_serve().

◆ _server_handle_s()

static int _server_handle_s ( libgdbr_t g,
gdbr_server_cmd_cb  cmd_cb,
void *  core_ptr 
)
static

Definition at line 120 of file core.c.

120  {
121  char message[64];
122  if (send_ack(g) < 0) {
123  return -1;
124  }
125  if (g->data_len > 1) {
126  // We don't handle s[addr] packet
127  return send_msg(g, "E01");
128  }
129  if (cmd_cb(g, core_ptr, "ds", NULL, 0) < 0) {
130  send_msg(g, "E01");
131  return -1;
132  }
133  if (cmd_cb(g, core_ptr, "?", message, sizeof(message)) < 0) {
134  send_msg(g, "");
135  return -1;
136  }
137  return send_msg(g, message);
138 }

References g, message, NULL, send_ack(), and send_msg().

Referenced by gdbr_server_serve().

◆ _server_handle_vCont()

static int _server_handle_vCont ( libgdbr_t g,
gdbr_server_cmd_cb  cmd_cb,
void *  core_ptr 
)
static

Definition at line 237 of file core.c.

237  {
238  char *action = NULL;
239  if (send_ack(g) < 0) {
240  return -1;
241  }
242  g->data[g->data_len] = '\0';
243  if (g->data[5] == '?') {
244  // Query about everything we support
245  return send_msg(g, "vCont;c;s");
246  }
247  if (!strtok(g->data, ";")) {
248  return send_msg(g, "E01");
249  }
250  while ((action = strtok(NULL, ";"))) {
251  eprintf("action: %s\n", action);
252  switch (action[0]) {
253  case 's':
254  // TODO handle thread selections
255  if (cmd_cb(g, core_ptr, "ds", NULL, 0) < 0) {
256  send_msg(g, "E01");
257  return -1;
258  }
259  return send_msg(g, "OK");
260  case 'c':
261  // TODO handle thread selections
262  if (cmd_cb(g, core_ptr, "dc", NULL, 0) < 0) {
263  send_msg(g, "E01");
264  return -1;
265  }
266  return send_msg(g, "OK");
267  default:
268  // TODO support others
269  return send_msg(g, "E01");
270  }
271  }
272  return -1;
273 }

References test-lz4-speed::action, eprintf, g, NULL, send_ack(), and send_msg().

Referenced by gdbr_server_serve().

◆ _server_handle_vKill()

static int _server_handle_vKill ( libgdbr_t g,
gdbr_server_cmd_cb  cmd_cb,
void *  core_ptr 
)
static

Definition at line 196 of file core.c.

196  {
197  if (send_ack(g) < 0) {
198  return -1;
199  }
200  // TODO handle killing of pid
201  send_msg(g, "OK");
202  return -1;
203 }

References g, send_ack(), and send_msg().

Referenced by gdbr_server_serve().

◆ _server_handle_vMustReplyEmpty()

static int _server_handle_vMustReplyEmpty ( libgdbr_t g)
static

Definition at line 480 of file core.c.

480  {
481  if (send_ack(g) < 0) {
482  return -1;
483  }
484  return send_msg(g, "");
485 }

References g, send_ack(), and send_msg().

Referenced by gdbr_server_serve().

◆ _server_handle_z()

static int _server_handle_z ( libgdbr_t g,
gdbr_server_cmd_cb  cmd_cb,
void *  core_ptr 
)
static

Definition at line 205 of file core.c.

205  {
206  if (send_ack(g) < 0) {
207  return -1;
208  }
209  char set; // Z = set, z = remove
210  int type;
211  ut64 addr;
212  char cmd[64];
213  sscanf(g->data, "%c%d,%" PFMT64x, &set, &type, &addr);
214  if (type != 0) {
215  // TODO handle hw breakpoints and watchpoints
216  return send_msg(g, "E01");
217  }
218  switch (set) {
219  case 'Z':
220  // Set
221  snprintf(cmd, sizeof(cmd) - 1, "db @ 0x%" PFMT64x, addr);
222  break;
223  case 'z':
224  // Remove
225  snprintf(cmd, sizeof(cmd) - 1, "db- @ 0x%" PFMT64x, addr);
226  break;
227  default:
228  return send_msg(g, "E01");
229  }
230  if (cmd_cb(g, core_ptr, cmd, NULL, 0) < 0) {
231  send_msg(g, "E01");
232  return -1;
233  }
234  return send_msg(g, "OK");
235 }
int type
Definition: mipsasm.c:17

References addr, cmd, g, NULL, PFMT64x, send_ack(), send_msg(), snprintf, type, and ut64().

Referenced by gdbr_server_serve().

◆ gdbr_server_serve()

int gdbr_server_serve ( libgdbr_t g,
gdbr_server_cmd_cb  cmd_cb,
void *  core_ptr 
)

Definition at line 495 of file core.c.

495  {
496  int ret;
497  if (!g) {
498  return -1;
499  }
500  while (1) {
501  if (read_packet(g, false) < 0) {
502  continue;
503  }
504  if (g->data_len == 0) {
505  continue;
506  }
507  if (rz_str_startswith(g->data, "k")) {
508  return _server_handle_k(g, cmd_cb, core_ptr);
509  }
510  if (rz_str_startswith(g->data, "vKill")) {
511  return _server_handle_vKill(g, cmd_cb, core_ptr);
512  }
513  if (rz_str_startswith(g->data, "qSupported")) {
514  if ((ret = _server_handle_qSupported(g)) < 0) {
515  return ret;
516  }
517  continue;
518  }
519  if (rz_str_startswith(g->data, "qTStatus")) {
520  if ((ret = _server_handle_qTStatus(g)) < 0) {
521  return ret;
522  }
523  continue;
524  }
525  if (rz_str_startswith(g->data, "qC") && g->data_len == 2) {
526  if ((ret = _server_handle_qC(g, cmd_cb, core_ptr)) < 0) {
527  return ret;
528  }
529  continue;
530  }
531  if (rz_str_startswith(g->data, "qAttached")) {
532  if ((ret = _server_handle_qAttached(g, cmd_cb, core_ptr)) < 0) {
533  return ret;
534  }
535  continue;
536  }
537  if (rz_str_startswith(g->data, "vMustReplyEmpty")) {
538  if ((ret = _server_handle_vMustReplyEmpty(g)) < 0) {
539  return ret;
540  }
541  continue;
542  }
543  if (rz_str_startswith(g->data, "qTfV")) {
544  if ((ret = _server_handle_qTfV(g, cmd_cb, core_ptr)) < 0) {
545  return ret;
546  }
547  continue;
548  }
549  if (rz_str_startswith(g->data, "qfThreadInfo")) {
550  if ((ret = _server_handle_qfThreadInfo(g, cmd_cb, core_ptr)) < 0) {
551  return ret;
552  }
553  continue;
554  }
555  if (rz_str_startswith(g->data, "qsThreadInfo")) {
556  if ((ret = _server_handle_qsThreadInfo(g, cmd_cb, core_ptr)) < 0) {
557  return ret;
558  }
559  continue;
560  }
561  if (rz_str_startswith(g->data, "Hg")) {
562  if ((ret = _server_handle_Hg(g, cmd_cb, core_ptr)) < 0) {
563  return ret;
564  }
565  continue;
566  }
567  if (rz_str_startswith(g->data, "Hc")) {
568  if ((ret = _server_handle_Hc(g, cmd_cb, core_ptr)) < 0) {
569  return ret;
570  }
571  continue;
572  }
573  if (rz_str_startswith(g->data, "?")) {
574  if ((ret = _server_handle_ques(g, cmd_cb, core_ptr)) < 0) {
575  return ret;
576  }
577  continue;
578  }
579  if (rz_str_startswith(g->data, "g") && g->data_len == 1) {
580  if ((ret = _server_handle_g(g, cmd_cb, core_ptr)) < 0) {
581  return ret;
582  }
583  continue;
584  }
585  if (rz_str_startswith(g->data, "vCont")) {
586  if ((ret = _server_handle_vCont(g, cmd_cb, core_ptr)) < 0) {
587  return ret;
588  }
589  continue;
590  }
591  if (rz_str_startswith(g->data, "qOffsets")) {
592  if ((ret = _server_handle_qOffsets(g, cmd_cb, core_ptr)) < 0) {
593  return ret;
594  }
595  continue;
596  }
597  if (g->data[0] == 'z' || g->data[0] == 'Z') {
598  if ((ret = _server_handle_z(g, cmd_cb, core_ptr)) < 0) {
599  return ret;
600  }
601  continue;
602  }
603  if (g->data[0] == 's') {
604  if ((ret = _server_handle_s(g, cmd_cb, core_ptr)) < 0) {
605  return ret;
606  }
607  continue;
608  }
609  if (g->data[0] == 'c') {
610  if ((ret = _server_handle_c(g, cmd_cb, core_ptr)) < 0) {
611  return ret;
612  }
613  continue;
614  }
615  if (rz_str_startswith(g->data, "m")) {
616  if ((ret = _server_handle_m(g, cmd_cb, core_ptr)) < 0) {
617  return ret;
618  }
619  continue;
620  }
621  if (rz_str_startswith(g->data, "M")) {
622  if ((ret = _server_handle_M(g, cmd_cb, core_ptr)) < 0) {
623  return ret;
624  }
625  continue;
626  }
627  if (rz_str_startswith(g->data, "P")) {
628  if ((ret = _server_handle_P(g, cmd_cb, core_ptr)) < 0) {
629  return ret;
630  }
631  continue;
632  }
633  if (rz_str_startswith(g->data, "p")) {
634  if ((ret = _server_handle_p(g, cmd_cb, core_ptr)) < 0) {
635  return ret;
636  }
637  continue;
638  }
639  if (rz_str_startswith(g->data, "qXfer:exec-file:read:")) {
640  if ((ret = _server_handle_exec_file_read(g, cmd_cb, core_ptr)) < 0) {
641  return ret;
642  }
643  continue;
644  }
645  if (rz_str_startswith(g->data, "QStartNoAckMode")) {
646  if (send_ack(g) < 0) {
647  return -1;
648  }
649  g->no_ack = true;
650  if (g->server_debug) {
651  eprintf("[noack mode enabled]\n");
652  }
653  if (send_msg(g, "OK") < 0) {
654  return -1;
655  }
656  continue;
657  }
658  // Unrecognized packet
659  if (send_ack(g) < 0 || send_msg(g, "") < 0) {
660  g->data[g->data_len] = '\0';
661  eprintf("Unknown packet: %s\n", g->data);
662  return -1;
663  }
664  };
665  return ret;
666 }
int read_packet(libgdbr_t *instance, bool vcont)
Definition: packet.c:143
RZ_API bool rz_str_startswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string starts with a specifc sequence of characters (case sensitive)
Definition: str.c:3286
static int _server_handle_vMustReplyEmpty(libgdbr_t *g)
Definition: core.c:480
static int _server_handle_Hg(libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
Definition: core.c:287
static int _server_handle_g(libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
Definition: core.c:364
static int _server_handle_p(libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
Definition: core.c:418
static int _server_handle_qTStatus(libgdbr_t *g)
Definition: core.c:34
static int _server_handle_k(libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
Definition: core.c:191
static int _server_handle_m(libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
Definition: core.c:387
static int _server_handle_M(libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
Definition: core.c:89
static int _server_handle_qSupported(libgdbr_t *g)
Definition: core.c:17
static int _server_handle_vKill(libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
Definition: core.c:196
static int _server_handle_ques(libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
Definition: core.c:160
static int _server_handle_vCont(libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
Definition: core.c:237
static int _server_handle_exec_file_read(libgdbr_t *g, gdbr_server_cmd_cb cb, void *core_ptr)
Definition: core.c:56
static int _server_handle_z(libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
Definition: core.c:205
static int _server_handle_c(libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
Definition: core.c:140
static int _server_handle_P(libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
Definition: core.c:446
static int _server_handle_qOffsets(libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
Definition: core.c:43
static int _server_handle_qC(libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
Definition: core.c:172
static int _server_handle_s(libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
Definition: core.c:120
static int _server_handle_qTfV(libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
Definition: core.c:487
static int _server_handle_Hc(libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
Definition: core.c:313
static int _server_handle_qfThreadInfo(libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
Definition: core.c:337
static int _server_handle_qsThreadInfo(libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
Definition: core.c:356
static int _server_handle_qAttached(libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr)
Definition: core.c:275

References _server_handle_c(), _server_handle_exec_file_read(), _server_handle_g(), _server_handle_Hc(), _server_handle_Hg(), _server_handle_k(), _server_handle_M(), _server_handle_m(), _server_handle_p(), _server_handle_P(), _server_handle_qAttached(), _server_handle_qC(), _server_handle_qfThreadInfo(), _server_handle_qOffsets(), _server_handle_qsThreadInfo(), _server_handle_qSupported(), _server_handle_qTfV(), _server_handle_qTStatus(), _server_handle_ques(), _server_handle_s(), _server_handle_vCont(), _server_handle_vKill(), _server_handle_vMustReplyEmpty(), _server_handle_z(), eprintf, g, read_packet(), rz_str_startswith(), send_ack(), and send_msg().

Referenced by rz_core_rtr_gdb_run().