Rizin
unix-like reverse engineering framework and cli tools
core.h File Reference
#include <rz_socket.h>
#include "../libgdbr.h"

Go to the source code of this file.

Typedefs

typedef int(* gdbr_server_cmd_cb) (libgdbr_t *, void *, const char *, char *, size_t)
 

Functions

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

Typedef Documentation

◆ gdbr_server_cmd_cb

typedef int(* gdbr_server_cmd_cb) (libgdbr_t *, void *, const char *, char *, size_t)

Definition at line 10 of file core.h.

Function Documentation

◆ 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 }
struct @667 g
int send_ack(libgdbr_t *g)
Functions sends a single ack ('+')
Definition: common.c:130
int read_packet(libgdbr_t *instance, bool vcont)
Definition: packet.c:143
int send_msg(libgdbr_t *g, const char *command)
Definition: common.c:146
#define eprintf(x, y...)
Definition: rlcc.c:7
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().