Rizin
unix-like reverse engineering framework and cli tools
cdebug.c File Reference
#include <rz_core.h>
#include <rz_debug.h>
#include "core_private.h"

Go to the source code of this file.

Macros

#define SIGKILL   9
 

Functions

RZ_API bool rz_core_is_debug (RzCore *core)
 Check whether the core is in debug mode (equivalent to cfg.debug) More...
 
static bool is_x86_call (RzDebug *dbg, ut64 addr)
 
static bool is_x86_ret (RzDebug *dbg, ut64 addr)
 
RZ_API bool rz_core_debug_step_one (RzCore *core, int times)
 
RZ_IPI void rz_core_debug_continue (RzCore *core)
 
RZ_API bool rz_core_debug_continue_until (RzCore *core, ut64 addr, ut64 to)
 
RZ_IPI void rz_core_debug_sync_bits (RzCore *core)
 
RZ_IPI void rz_core_debug_single_step_in (RzCore *core)
 
RZ_IPI void rz_core_debug_single_step_over (RzCore *core)
 
RZ_API void rz_core_debug_breakpoint_toggle (RZ_NONNULL RzCore *core, ut64 addr)
 Toggle breakpoint. More...
 
RZ_API void rz_core_debug_bp_add_noreturn_func (RzCore *core)
 Put a breakpoint into every no-return function. More...
 
RZ_IPI void rz_core_debug_attach (RzCore *core, int pid)
 
RZ_API RzCmdStatus rz_core_debug_plugin_print (RzDebug *dbg, RzDebugPlugin *plugin, RzCmdStateOutput *state, int count, char *spaces)
 
RZ_API RzCmdStatus rz_core_debug_plugins_print (RzCore *core, RzCmdStateOutput *state)
 
RZ_IPI void rz_core_debug_print_status (RzCore *core)
 
static void print_debug_map_json (RzDebugMap *map, PJ *pj)
 
static void print_debug_map_line (RzDebug *dbg, RzDebugMap *map, ut64 addr, RzOutputMode mode)
 
static void apply_maps_as_flags (RzCore *core, RzList *maps, bool print_only)
 
RZ_API void rz_core_debug_map_update_flags (RzCore *core)
 
RZ_API void rz_core_debug_map_print (RzCore *core, ut64 addr, RzCmdStateOutput *state)
 
static int cmp (const void *a, const void *b)
 
static int findMinMax (RzList *maps, ut64 *min, ut64 *max, int skip, int width)
 Find the min and max addresses in an RzList of maps. More...
 
static void print_debug_maps_ascii_art (RzDebug *dbg, RzList *maps, ut64 addr, int colors)
 
RZ_API void rz_debug_map_list_visual (RzDebug *dbg, ut64 addr, const char *input, int colors)
 
RZ_API void rz_debug_trace_print (RzDebug *dbg, RzCmdStateOutput *state, ut64 offset)
 
RZ_API void rz_debug_traces_ascii (RzDebug *dbg, ut64 offset)
 
RZ_API bool rz_core_debug_process_close (RzCore *core)
 Close debug process (Kill debugee and all child processes) More...
 
RZ_API bool rz_core_debug_step_until_frame (RzCore *core)
 Step until end of frame. More...
 
RZ_API bool rz_core_debug_step_back (RzCore *core, int steps)
 Step back. More...
 
RZ_API bool rz_core_debug_step_over (RzCore *core, int steps)
 Step over. More...
 
RZ_API bool rz_core_debug_step_skip (RzCore *core, int times)
 Skip operations. More...
 
RZ_API void rz_backtrace_free (RZ_NULLABLE RzBacktrace *bt)
 
static void get_backtrace_info (RzCore *core, RzDebugFrame *frame, ut64 addr, char **flagdesc, char **flagdesc2, char **pcstr, char **spstr)
 
RZ_API RZ_OWN RzListrz_core_debug_backtraces (RzCore *core)
 Get backtraces based on dbg.btdepth and dbg.btalgo. More...
 

Macro Definition Documentation

◆ SIGKILL

#define SIGKILL   9

Function Documentation

◆ apply_maps_as_flags()

static void apply_maps_as_flags ( RzCore core,
RzList maps,
bool  print_only 
)
static

Definition at line 437 of file cdebug.c.

437  {
438  RzListIter *iter;
439  RzDebugMap *map;
440  rz_list_foreach (maps, iter, map) {
441  char *name = (map->name && *map->name)
442  ? rz_str_newf("%s.%s", map->name, rz_str_rwx_i(map->perm))
443  : rz_str_newf("%08" PFMT64x ".%s", map->addr, rz_str_rwx_i(map->perm));
444  if (!name) {
445  continue;
446  }
447  rz_name_filter(name, 0, true);
448  ut64 size = map->addr_end - map->addr;
449  if (print_only) {
450  rz_cons_printf("f+ map.%s 0x%08" PFMT64x " @ 0x%08" PFMT64x "\n",
451  name, size, map->addr);
452  } else {
453  rz_flag_set_next(core->flags, name, map->addr, size);
454  }
455  free(name);
456  }
457 }
static RzList * maps(RzBinFile *bf)
Definition: bin_bf.c:116
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
size_t map(int syms, int left, int len)
Definition: enough.c:237
RZ_API RzFlagItem * rz_flag_set_next(RzFlag *f, const char *name, ut64 off, ut32 size)
Definition: flag.c:494
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void uLong size
Definition: ioapi.h:138
RZ_API bool rz_name_filter(char *name, int len, bool strict)
Definition: name.c:43
RZ_API const char * rz_str_rwx_i(int rwx)
Definition: str.c:332
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
#define PFMT64x
Definition: rz_types.h:393
Definition: z80asm.h:102
RzFlag * flags
Definition: rz_core.h:330
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References rz_core_t::flags, free(), map(), maps(), PFMT64x, rz_cons_printf(), rz_flag_set_next(), rz_name_filter(), rz_str_newf(), rz_str_rwx_i(), and ut64().

Referenced by rz_core_debug_map_print(), and rz_core_debug_map_update_flags().

◆ cmp()

static int cmp ( const void *  a,
const void *  b 
)
static

Definition at line 530 of file cdebug.c.

530  {
531  RzDebugMap *ma = (RzDebugMap *)a;
532  RzDebugMap *mb = (RzDebugMap *)b;
533  return ma->addr - mb->addr;
534 }
#define b(i)
Definition: sha256.c:42
#define a(i)
Definition: sha256.c:41

References a, rz_debug_map_t::addr, and b.

Referenced by print_debug_maps_ascii_art().

◆ findMinMax()

static int findMinMax ( RzList maps,
ut64 min,
ut64 max,
int  skip,
int  width 
)
static

Find the min and max addresses in an RzList of maps.

Parameters
mapsRzList of maps that will be searched through
minPointer to a ut64 that the min will be stored in
maxPointer to a ut64 that the max will be stored in
skipHow many maps to skip at the start of iteration
widthDivisor for the return value
Returns
(max-min)/width

Used to determine the min & max addresses of maps and scale the ascii bar to the width of the terminal

Definition at line 548 of file cdebug.c.

548  {
549  RzDebugMap *map;
550  RzListIter *iter;
551  *min = UT64_MAX;
552  *max = 0;
553  rz_list_foreach (maps, iter, map) {
554  if (skip > 0) {
555  skip--;
556  continue;
557  }
558  if (map->addr < *min) {
559  *min = map->addr;
560  }
561  if (map->addr_end > *max) {
562  *max = map->addr_end;
563  }
564  }
565  return (int)(*max - *min) / width;
566 }
int max
Definition: enough.c:225
void skip(file *in, unsigned n)
Definition: gzappend.c:202
#define min(a, b)
Definition: qsort.h:83
#define UT64_MAX
Definition: rz_types_base.h:86
int width
Definition: main.c:10

References map(), maps(), max, min, skip(), UT64_MAX, and width.

Referenced by print_debug_maps_ascii_art().

◆ get_backtrace_info()

static void get_backtrace_info ( RzCore core,
RzDebugFrame frame,
ut64  addr,
char **  flagdesc,
char **  flagdesc2,
char **  pcstr,
char **  spstr 
)
static

Definition at line 866 of file cdebug.c.

867  {
868  RzFlagItem *f = rz_flag_get_at(core->flags, frame->addr, true);
869  *flagdesc = NULL;
870  *flagdesc2 = NULL;
871  if (f) {
872  if (f->offset != addr) {
873  int delta = (int)(frame->addr - f->offset);
874  if (delta > 0) {
875  *flagdesc = rz_str_newf("%s+%d", f->name, delta);
876  } else if (delta < 0) {
877  *flagdesc = rz_str_newf("%s%d", f->name, delta);
878  } else {
879  *flagdesc = rz_str_newf("%s", f->name);
880  }
881  } else {
882  *flagdesc = rz_str_newf("%s", f->name);
883  }
884  if (!strchr(f->name, '.')) {
885  f = rz_flag_get_at(core->flags, frame->addr - 1, true);
886  }
887  if (f) {
888  if (f->offset != addr) {
889  int delta = (int)(frame->addr - 1 - f->offset);
890  if (delta > 0) {
891  *flagdesc2 = rz_str_newf("%s+%d", f->name, delta + 1);
892  } else if (delta < 0) {
893  *flagdesc2 = rz_str_newf("%s%d", f->name, delta + 1);
894  } else {
895  *flagdesc2 = rz_str_newf("%s+1", f->name);
896  }
897  } else {
898  *flagdesc2 = rz_str_newf("%s", f->name);
899  }
900  }
901  }
902  if (!rz_str_cmp(*flagdesc, *flagdesc2, -1)) {
903  free(*flagdesc2);
904  *flagdesc2 = NULL;
905  }
906  if (!(pcstr && spstr)) {
907  return;
908  }
909  if (core->dbg->bits & RZ_SYS_BITS_64) {
910  *pcstr = rz_str_newf("0x%-16" PFMT64x, frame->addr);
911  *spstr = rz_str_newf("0x%-16" PFMT64x, frame->sp);
912  } else if (core->dbg->bits & RZ_SYS_BITS_32) {
913  *pcstr = rz_str_newf("0x%-8" PFMT64x, frame->addr);
914  *spstr = rz_str_newf("0x%-8" PFMT64x, frame->sp);
915  } else {
916  *pcstr = rz_str_newf("0x%" PFMT64x, frame->addr);
917  *spstr = rz_str_newf("0x%" PFMT64x, frame->sp);
918  }
919 }
#define NULL
Definition: cris-opc.c:27
RZ_API RzFlagItem * rz_flag_get_at(RzFlag *f, ut64 off, bool closest)
Definition: flag.c:404
RZ_API int rz_str_cmp(const char *dst, const char *orig, int len)
Definition: str.c:974
@ RZ_SYS_BITS_32
Definition: rz_sys.h:20
@ RZ_SYS_BITS_64
Definition: rz_sys.h:21
static int
Definition: sfsocketcall.h:114
#define f(i)
Definition: sha256.c:46
RzDebug * dbg
Definition: rz_core.h:329
int bits
Definition: rz_debug.h:243
static st64 delta
Definition: vmenus.c:2425
static int addr
Definition: z80asm.c:58

References addr, rz_debug_frame_t::addr, rz_debug_t::bits, rz_core_t::dbg, delta, f, rz_core_t::flags, free(), int, NULL, PFMT64x, rz_flag_get_at(), rz_str_cmp(), rz_str_newf(), RZ_SYS_BITS_32, RZ_SYS_BITS_64, and rz_debug_frame_t::sp.

Referenced by rz_core_debug_backtraces().

◆ is_x86_call()

static bool is_x86_call ( RzDebug dbg,
ut64  addr 
)
static

Definition at line 17 of file cdebug.c.

17  {
18  ut8 buf[3];
19  ut8 *op = buf;
21  switch (buf[0]) { /* Segment override prefixes */
22  case 0x65:
23  case 0x64:
24  case 0x26:
25  case 0x3e:
26  case 0x36:
27  case 0x2e:
28  op++;
29  }
30  if (op[0] == 0xe8) {
31  return true;
32  }
33  if (op[0] == 0xff /* bits 4-5 (from right) of next byte must be 01 */
34  && (op[1] & 0x30) == 0x10) {
35  return true;
36  }
37  /* ... */
38  return false;
39 }
RzDebug * dbg
Definition: desil.c:30
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
#define RZ_ARRAY_SIZE(x)
Definition: rz_types.h:300
RzIOBind iob
Definition: rz_debug.h:293
RzIOReadAt read_at
Definition: rz_io.h:240
RzIO * io
Definition: rz_io.h:232
Definition: dis.c:32

References addr, dbg, rz_io_bind_t::io, rz_debug_t::iob, rz_io_bind_t::read_at, and RZ_ARRAY_SIZE.

Referenced by rz_core_debug_continue_until().

◆ is_x86_ret()

static bool is_x86_ret ( RzDebug dbg,
ut64  addr 
)
static

Definition at line 41 of file cdebug.c.

41  {
42  ut8 buf[1];
44  switch (buf[0]) {
45  case 0xc3:
46  case 0xcb:
47  case 0xc2:
48  case 0xca:
49  return true;
50  default:
51  return false;
52  }
53  /* Possibly incomplete with regard to instruction prefixes */
54 }

References addr, dbg, rz_io_bind_t::io, rz_debug_t::iob, rz_io_bind_t::read_at, and RZ_ARRAY_SIZE.

Referenced by rz_core_debug_continue_until().

◆ print_debug_map_json()

static void print_debug_map_json ( RzDebugMap map,
PJ pj 
)
static

Definition at line 371 of file cdebug.c.

371  {
372  pj_o(pj);
373  if (map->name && *map->name) {
374  pj_ks(pj, "name", map->name);
375  }
376  if (map->file && *map->file) {
377  pj_ks(pj, "file", map->file);
378  }
379  pj_kn(pj, "addr", map->addr);
380  pj_kn(pj, "addr_end", map->addr_end);
381  pj_ks(pj, "type", map->user ? "u" : "s");
382  pj_ks(pj, "perm", rz_str_rwx_i(map->perm));
383  pj_end(pj);
384 }
RZ_API PJ * pj_end(PJ *j)
Definition: pj.c:87
RZ_API PJ * pj_o(PJ *j)
Definition: pj.c:75
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
Definition: pj.c:170
RZ_API PJ * pj_kn(PJ *j, const char *k, ut64 n)
Definition: pj.c:121

References map(), pj_end(), pj_kn(), pj_ks(), pj_o(), and rz_str_rwx_i().

Referenced by rz_core_debug_map_print().

◆ print_debug_map_line()

static void print_debug_map_line ( RzDebug dbg,
RzDebugMap map,
ut64  addr,
RzOutputMode  mode 
)
static

Definition at line 387 of file cdebug.c.

387  {
388  char humansz[8];
389  if (mode == RZ_OUTPUT_MODE_QUIET) { // "dmq"
390  char *name = (map->name && *map->name)
391  ? rz_str_newf("%s.%s", map->name, rz_str_rwx_i(map->perm))
392  : rz_str_newf("%08" PFMT64x ".%s", map->addr, rz_str_rwx_i(map->perm));
393  rz_name_filter(name, 0, true);
394  rz_num_units(humansz, sizeof(humansz), map->addr_end - map->addr);
395  rz_cons_printf("0x%016" PFMT64x " - 0x%016" PFMT64x " %6s %5s %s\n",
396  map->addr,
397  map->addr_end,
398  humansz,
399  rz_str_rwx_i(map->perm),
400  name);
401  free(name);
402  } else {
403  const char *fmtstr = dbg->bits & RZ_SYS_BITS_64
404  ? "0x%016" PFMT64x " - 0x%016" PFMT64x " %c %s %6s %c %s %s %s%s%s\n"
405  : "0x%08" PFMT64x " - 0x%08" PFMT64x " %c %s %6s %c %s %s %s%s%s\n";
406  const char *type = map->shared ? "sys" : "usr";
407  const char *flagname = dbg->corebind.getName
408  ? dbg->corebind.getName(dbg->corebind.core, map->addr)
409  : NULL;
410  if (!flagname) {
411  flagname = "";
412  } else if (map->name) {
413  char *filtered_name = strdup(map->name);
414  rz_name_filter(filtered_name, 0, true);
415  if (!strncmp(flagname, "map.", 4) &&
416  !strcmp(flagname + 4, filtered_name)) {
417  flagname = "";
418  }
419  free(filtered_name);
420  }
421  rz_num_units(humansz, sizeof(humansz), map->size);
422  rz_cons_printf(fmtstr,
423  map->addr,
424  map->addr_end,
425  (addr >= map->addr && addr < map->addr_end) ? '*' : '-',
426  type,
427  humansz,
428  map->user ? 'u' : 's',
429  rz_str_rwx_i(map->perm),
430  map->name ? map->name : "?",
431  map->file ? map->file : "?",
432  *flagname ? " ; " : "",
433  flagname);
434  }
435 }
const char int mode
Definition: ioapi.h:137
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 type
Definition: mipsasm.c:17
RZ_API char * rz_num_units(char *buf, size_t len, ut64 number)
Definition: unum.c:108
@ RZ_OUTPUT_MODE_QUIET
Definition: rz_types.h:42
void * core
Definition: rz_bind.h:31
RzCoreGetName getName
Definition: rz_bind.h:40
RzCoreBind corebind
Definition: rz_debug.h:314

References addr, rz_debug_t::bits, rz_core_bind_t::core, rz_debug_t::corebind, dbg, free(), rz_core_bind_t::getName, map(), NULL, PFMT64x, rz_cons_printf(), rz_name_filter(), rz_num_units(), RZ_OUTPUT_MODE_QUIET, rz_str_newf(), rz_str_rwx_i(), RZ_SYS_BITS_64, strdup(), and type.

Referenced by rz_core_debug_map_print().

◆ print_debug_maps_ascii_art()

static void print_debug_maps_ascii_art ( RzDebug dbg,
RzList maps,
ut64  addr,
int  colors 
)
static

Definition at line 568 of file cdebug.c.

568  {
569  ut64 mul; // The amount of address space a single console column will represent in bar graph
570  ut64 min = -1, max = 0;
571  int width = rz_cons_get_size(NULL) - 90;
572  RzListIter *iter;
573  RzDebugMap *map;
575  if (width < 1) {
576  width = 30;
577  }
579  mul = findMinMax(maps, &min, &max, 0, width);
580  ut64 last = min;
581  if (min != -1 && mul != 0) {
582  const char *color_prefix = ""; // Color escape code prefixed to string (address coloring)
583  const char *color_suffix = ""; // Color escape code appended to end of string
584  const char *fmtstr;
585  char humansz[8]; // Holds the human formatted size string [124K]
586  int skip = 0; // Number of maps to skip when re-calculating the minmax
587  rz_list_foreach (maps, iter, map) {
588  rz_num_units(humansz, sizeof(humansz), map->size); // Convert map size to human readable string
589  if (colors) {
590  color_suffix = Color_RESET;
591  if ((map->perm & 2) && (map->perm & 1)) { // Writable & Executable
592  color_prefix = pal->widget_sel;
593  } else if (map->perm & 2) { // Writable
594  color_prefix = pal->graph_false;
595  } else if (map->perm & 1) { // Executable
596  color_prefix = pal->graph_true;
597  } else {
598  color_prefix = "";
599  color_suffix = "";
600  }
601  } else {
602  color_prefix = "";
603  color_suffix = "";
604  }
605  if ((map->addr - last) > UT32_MAX) { // TODO: Comment what this is for
606  mul = findMinMax(maps, &min, &max, skip, width); // Recalculate minmax
607  }
608  skip++;
609  fmtstr = dbg->bits & RZ_SYS_BITS_64 // Prefix formatting string (before bar)
610  ? "map %4.8s %c %s0x%016" PFMT64x "%s |"
611  : "map %4.8s %c %s0x%08" PFMT64x "%s |";
612  rz_cons_printf(fmtstr, humansz,
613  (addr >= map->addr &&
614  addr < map->addr_end)
615  ? '*'
616  : '-',
617  color_prefix, map->addr, color_suffix); // * indicates map is within our current sought offset
618  int col;
619  for (col = 0; col < width; col++) { // Iterate over the available width/columns for bar graph
620  ut64 pos = min + (col * mul); // Current address space to check
621  ut64 npos = min + ((col + 1) * mul); // Next address space to check
622  if (map->addr < npos && map->addr_end > pos) {
623  rz_cons_printf("#"); // TODO: Comment what a # represents
624  } else {
625  rz_cons_printf("-");
626  }
627  }
628  fmtstr = dbg->bits & RZ_SYS_BITS_64 ? // Suffix formatting string (after bar)
629  "| %s0x%016" PFMT64x "%s %s %s\n"
630  : "| %s0x%08" PFMT64x "%s %s %s\n";
631  rz_cons_printf(fmtstr, color_prefix, map->addr_end, color_suffix,
632  rz_str_rwx_i(map->perm), map->name);
633  last = map->addr;
634  }
635  }
636 }
static RzILOpEffect * mul(cs_insn *insn, bool is_thumb)
Definition: arm_il32.c:539
static int cmp(const void *a, const void *b)
Definition: cdebug.c:530
static int findMinMax(RzList *maps, ut64 *min, ut64 *max, int skip, int width)
Find the min and max addresses in an RzList of maps.
Definition: cdebug.c:548
RZ_API int rz_cons_get_size(int *rows)
Definition: cons.c:1446
RZ_API RzCons * rz_cons_singleton(void)
Definition: cons.c:300
RZ_API void rz_list_sort(RZ_NONNULL RzList *list, RZ_NONNULL RzListComparator cmp)
Sorts via merge sort or via insertion sort a list.
Definition: list.c:743
struct @219 colors[]
#define Color_RESET
Definition: rz_cons.h:617
#define UT32_MAX
Definition: rz_types_base.h:99
RzConsPrintablePalette pal
Definition: rz_cons.h:491
RzConsContext * context
Definition: rz_cons.h:502
int pos
Definition: main.c:11

References addr, rz_debug_t::bits, cmp(), Color_RESET, colors, rz_cons_t::context, dbg, findMinMax(), rz_cons_printable_palette_t::graph_false, rz_cons_printable_palette_t::graph_true, map(), maps(), max, min, mul(), NULL, rz_cons_context_t::pal, PFMT64x, pos, rz_cons_get_size(), rz_cons_printf(), rz_cons_singleton(), rz_list_sort(), rz_num_units(), rz_str_rwx_i(), RZ_SYS_BITS_64, skip(), UT32_MAX, ut64(), rz_cons_printable_palette_t::widget_sel, and width.

Referenced by rz_debug_map_list_visual().

◆ rz_backtrace_free()

RZ_API void rz_backtrace_free ( RZ_NULLABLE RzBacktrace bt)

Definition at line 853 of file cdebug.c.

853  {
854  if (!bt) {
855  return;
856  }
857  free(bt->frame);
858  free(bt->desc);
859  free(bt->pcstr);
860  free(bt->spstr);
861  free(bt->flagdesc);
862  free(bt->flagdesc2);
863  free(bt);
864 }

References free().

Referenced by rz_core_debug_backtraces().

◆ rz_core_debug_attach()

RZ_IPI void rz_core_debug_attach ( RzCore core,
int  pid 
)

Definition at line 284 of file cdebug.c.

284  {
285  char buf[20];
286 
288  if (pid > 0) {
289  rz_debug_attach(core->dbg, pid);
290  } else {
291  if (core->file && core->io) {
292  rz_debug_attach(core->dbg, rz_io_fd_get_pid(core->io, core->file->fd));
293  }
294  }
295  rz_debug_select(core->dbg, core->dbg->pid, core->dbg->tid);
296  rz_config_set_i(core->config, "dbg.swstep", (core->dbg->cur && !core->dbg->cur->canstep));
297  rz_io_system(core->io, rz_strf(buf, "pid %d", core->dbg->pid));
298 }
RZ_API RzConfigNode * rz_config_set_i(RzConfig *cfg, RZ_NONNULL const char *name, const ut64 i)
Definition: config.c:419
RZ_API bool rz_debug_reg_profile_sync(RzDebug *dbg)
Definition: dreg.c:116
RZ_API int rz_debug_attach(RzDebug *dbg, int pid)
Definition: debug.c:445
RZ_API bool rz_debug_select(RzDebug *dbg, int pid, int tid)
Definition: debug.c:595
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
RZ_API char * rz_io_system(RzIO *io, const char *cmd)
Definition: io.c:411
RZ_API int rz_io_fd_get_pid(RzIO *io, int fd)
Definition: io_fd.c:92
#define rz_strf(buf,...)
Convenience macro for local temporary strings.
Definition: rz_str.h:59
RzIO * io
Definition: rz_core.h:313
RzCoreFile * file
Definition: rz_core.h:314
RzConfig * config
Definition: rz_core.h:300
struct rz_debug_plugin_t * cur
Definition: rz_debug.h:295

References rz_debug_plugin_t::canstep, rz_core_t::config, rz_debug_t::cur, rz_core_t::dbg, rz_core_file_t::fd, rz_core_t::file, rz_core_t::io, rz_debug_t::pid, pid, rz_config_set_i(), rz_debug_attach(), rz_debug_reg_profile_sync(), rz_debug_select(), rz_io_fd_get_pid(), rz_io_system(), rz_strf, and rz_debug_t::tid.

Referenced by cmd_debug_pid(), and rz_core_setup_debugger().

◆ rz_core_debug_backtraces()

RZ_API RZ_OWN RzList* rz_core_debug_backtraces ( RzCore core)

Get backtraces based on dbg.btdepth and dbg.btalgo.

Parameters
coreThe RzCore instance
Returns
A list of RzBacktrace

Definition at line 926 of file cdebug.c.

926  {
928  if (!list) {
929  return NULL;
930  }
931  RzListIter *iter;
932  RzDebugFrame *frame;
934  if (!bts) {
936  return NULL;
937  }
938  rz_list_foreach (list, iter, frame) {
940  if (!bt) {
942  rz_list_free(bts);
943  return NULL;
944  }
945  rz_list_append(bts, bt);
946  get_backtrace_info(core, frame, UT64_MAX, &bt->flagdesc, &bt->flagdesc2, &bt->pcstr, &bt->spstr);
947  bt->fcn = rz_analysis_get_fcn_in(core->analysis, frame->addr, 0);
948  bt->frame = RZ_NEWCOPY(RzDebugFrame, frame);
950  }
952  return bts;
953 }
RZ_API void rz_backtrace_free(RZ_NULLABLE RzBacktrace *bt)
Definition: cdebug.c:853
static void get_backtrace_info(RzCore *core, RzDebugFrame *frame, ut64 addr, char **flagdesc, char **flagdesc2, char **pcstr, char **spstr)
Definition: cdebug.c:866
RZ_DEPRECATE RZ_API RzAnalysisFunction * rz_analysis_get_fcn_in(RzAnalysis *analysis, ut64 addr, int type)
Definition: fcn.c:1687
RZ_API RzList * rz_debug_frames(RzDebug *dbg, ut64 at)
Definition: debug.c:1612
static void list(RzEgg *egg)
Definition: rz-gg.c:52
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
static const char * rz_str_get_null(const char *str)
Definition: rz_str.h:190
#define RZ_NEWCOPY(x, y)
Definition: rz_types.h:286
#define RZ_NEW0(x)
Definition: rz_types.h:284
char * flagdesc2
Definition: rz_debug.h:427
char * pcstr
Definition: rz_debug.h:424
char * flagdesc
Definition: rz_debug.h:426
RzDebugFrame * frame
Definition: rz_debug.h:421
char * spstr
Definition: rz_debug.h:425
char * desc
Definition: rz_debug.h:423
RzAnalysisFunction * fcn
Definition: rz_debug.h:422
RzAnalysis * analysis
Definition: rz_core.h:322

References rz_debug_frame_t::addr, rz_core_t::analysis, rz_core_t::dbg, rz_backtrace_t::desc, rz_backtrace_t::fcn, rz_backtrace_t::flagdesc, rz_backtrace_t::flagdesc2, rz_backtrace_t::frame, get_backtrace_info(), list(), NULL, rz_backtrace_t::pcstr, rz_analysis_get_fcn_in(), rz_backtrace_free(), rz_debug_frames(), rz_list_append(), rz_list_free(), rz_list_newf(), RZ_NEW0, RZ_NEWCOPY, rz_str_get_null(), rz_str_newf(), rz_backtrace_t::spstr, and UT64_MAX.

Referenced by rz_cmd_debug_display_bt_handler().

◆ rz_core_debug_bp_add_noreturn_func()

RZ_API void rz_core_debug_bp_add_noreturn_func ( RzCore core)

Put a breakpoint into every no-return function.

Parameters
coreCurrent RzCore instance
Returns
void

Definition at line 256 of file cdebug.c.

256  {
258  if (!symbols) {
259  RZ_LOG_ERROR("Unable to find symbols in the binary\n");
260  return;
261  }
262  RzBinSymbol *symbol;
263  RzListIter *iter;
264  RzBreakpointItem *bp;
265  int hwbp = rz_config_get_i(core->config, "dbg.hwbp");
266  rz_list_foreach (symbols, iter, symbol) {
267  if (symbol->type && !strcmp(symbol->type, RZ_BIN_TYPE_FUNC_STR)) {
268  if (rz_analysis_noreturn_at(core->analysis, symbol->vaddr)) {
269  bp = rz_debug_bp_add(core->dbg, symbol->vaddr, hwbp, false, 0, NULL, 0);
270  if (!bp) {
271  RZ_LOG_ERROR("Unable to add a breakpoint into a noreturn function %s at addr 0x%" PFMT64x "\n", symbol->name, symbol->vaddr);
272  return;
273  }
274  char *name = rz_str_newf("%s.%s", "sym", symbol->name);
275  if (!rz_bp_item_set_name(bp, name)) {
276  RZ_LOG_ERROR("Failed to set name for breakpoint at 0x%" PFMT64x "\n", symbol->vaddr);
277  }
278  free(name);
279  }
280  }
281  }
282 }
RZ_API bool rz_analysis_noreturn_at(RzAnalysis *analysis, ut64 addr)
Definition: analysis.c:597
RZ_DEPRECATE RZ_API RZ_BORROW RzList * rz_bin_get_symbols(RZ_NONNULL RzBin *bin)
Definition: bin.c:696
RzList * symbols(RzBinFile *bf)
Definition: bin_ne.c:102
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 ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:119
RZ_API RZ_BORROW RzBreakpointItem * rz_debug_bp_add(RZ_NONNULL RzDebug *dbg, ut64 addr, int hw, bool watch, int rw, RZ_NULLABLE const char *module, st64 m_delta)
Definition: debug.c:270
#define RZ_BIN_TYPE_FUNC_STR
Definition: rz_bin.h:119
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
const char * type
Definition: rz_bin.h:682
char * name
Definition: rz_bin.h:675
RzBin * bin
Definition: rz_core.h:298

References rz_core_t::analysis, rz_core_t::bin, rz_core_t::config, rz_core_t::dbg, free(), rz_bin_symbol_t::name, NULL, PFMT64x, rz_analysis_noreturn_at(), rz_bin_get_symbols(), RZ_BIN_TYPE_FUNC_STR, rz_bp_item_set_name(), rz_config_get_i(), rz_debug_bp_add(), RZ_LOG_ERROR, rz_str_newf(), symbols(), rz_bin_symbol_t::type, and rz_bin_symbol_t::vaddr.

Referenced by rz_cmd_debug_add_bp_noreturn_func_handler().

◆ rz_core_debug_breakpoint_toggle()

RZ_API void rz_core_debug_breakpoint_toggle ( RZ_NONNULL RzCore core,
ut64  addr 
)

Toggle breakpoint.

Parameters
coreRzCore instance
addrBreakpoint addr

Definition at line 235 of file cdebug.c.

235  {
236  rz_return_if_fail(core && core->dbg);
237  RzBreakpointItem *bpi = rz_bp_get_at(core->dbg->bp, addr);
238  if (bpi) {
239  rz_bp_del(core->dbg->bp, addr);
240  } else {
241  int hwbp = (int)rz_config_get_i(core->config, "dbg.hwbp");
242  bpi = rz_debug_bp_add(core->dbg, addr, hwbp, false, 0, NULL, 0);
243  if (!bpi) {
244  eprintf("Cannot set breakpoint at 0x%" PFMT64x "\n", addr);
245  }
246  }
247  rz_bp_enable(core->dbg->bp, addr, true, 0);
248 }
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 bool rz_bp_del(RzBreakpoint *bp, ut64 addr)
Definition: bp.c:315
RZ_API RzBreakpointItem * rz_bp_enable(RzBreakpoint *bp, ut64 addr, int set, int count)
Definition: bp.c:152
#define eprintf(x, y...)
Definition: rlcc.c:7
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100

References addr, eprintf, int, NULL, PFMT64x, rz_bp_del(), rz_bp_enable(), rz_bp_get_at(), rz_config_get_i(), rz_debug_bp_add(), and rz_return_if_fail.

Referenced by __break_points_cb(), __panel_breakpoint(), __set_breakpoints_on_cursor(), graph_breakpoint(), rz_cmd_debug_toggle_bp_handler(), rz_core_visual_cmd(), and visual_breakpoint().

◆ rz_core_debug_continue()

RZ_IPI void rz_core_debug_continue ( RzCore core)

Definition at line 81 of file cdebug.c.

81  {
82  if (rz_core_is_debug(core)) {
84  rz_reg_arena_swap(core->dbg->reg, true);
85 #if __linux__
86  core->dbg->continue_all_threads = true;
87 #endif
88  rz_debug_continue(core->dbg);
92  } else {
93  rz_core_esil_step(core, UT64_MAX, "0", NULL, false);
95  }
96 }
RZ_API void rz_reg_arena_swap(RzReg *reg, int copy)
Definition: arena.c:196
RZ_API bool rz_core_is_debug(RzCore *core)
Check whether the core is in debug mode (equivalent to cfg.debug)
Definition: cdebug.c:13
RZ_API int rz_core_esil_step(RzCore *core, ut64 until_addr, const char *until_expr, ut64 *prev_addr, bool stepOver)
Definition: cmd_analysis.c:860
RZ_IPI void rz_core_static_debug_stop(void *u)
Definition: cmd_debug.c:1565
RZ_API void rz_core_dbg_follow_seek_register(RzCore *core)
Seek to PC if needed.
Definition: cmd_debug.c:474
RZ_API void rz_cons_break_pop(void)
Definition: cons.c:361
RZ_API void rz_cons_break_push(RzConsBreak cb, void *user)
Definition: cons.c:357
RZ_API void rz_core_reg_update_flags(RzCore *core)
Update or create flags for all registers where it makes sense.
Definition: creg.c:106
RZ_API int rz_debug_continue(RzDebug *dbg)
Definition: debug.c:1332
bool continue_all_threads
Definition: rz_debug.h:272
RzReg * reg
Definition: rz_debug.h:286

References rz_debug_t::continue_all_threads, rz_core_t::dbg, NULL, rz_debug_t::reg, rz_cons_break_pop(), rz_cons_break_push(), rz_core_dbg_follow_seek_register(), rz_core_esil_step(), rz_core_is_debug(), rz_core_reg_update_flags(), rz_core_static_debug_stop(), rz_debug_continue(), rz_reg_arena_swap(), and UT64_MAX.

Referenced by __continue_cb(), __panels_process(), graph_continue(), rz_cmd_debug_continue_execution_handler(), and visual_nkey().

◆ rz_core_debug_continue_until()

RZ_API bool rz_core_debug_continue_until ( RzCore core,
ut64  addr,
ut64  to 
)

Definition at line 98 of file cdebug.c.

98  {
99  ut64 pc;
100  if (!strcmp(core->dbg->btalgo, "trace") && core->dbg->arch && !strcmp(core->dbg->arch, "x86") && core->dbg->bits == 4) {
101  unsigned long steps = 0;
102  long level = 0;
103  const char *pc_name = core->dbg->reg->name[RZ_REG_NAME_PC];
104  ut64 prev_pc = UT64_MAX;
105  bool prev_call = false;
106  bool prev_ret = false;
107  const char *sp_name = core->dbg->reg->name[RZ_REG_NAME_SP];
108  ut64 old_sp, cur_sp;
110  rz_list_free(core->dbg->call_frames);
111  core->dbg->call_frames = rz_list_new();
112  core->dbg->call_frames->free = free;
113  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_GPR, false);
114  old_sp = rz_debug_reg_get(core->dbg, sp_name);
115  while (true) {
116  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_GPR, false);
117  pc = rz_debug_reg_get(core->dbg, pc_name);
118  if (prev_call) {
119  ut32 ret_addr;
121  cur_sp = rz_debug_reg_get(core->dbg, sp_name);
122  (void)core->dbg->iob.read_at(core->dbg->iob.io, cur_sp, (ut8 *)&ret_addr,
123  sizeof(ret_addr));
124  frame->addr = ret_addr;
125  frame->size = old_sp - cur_sp;
126  frame->sp = cur_sp;
127  frame->bp = old_sp;
128  rz_list_prepend(core->dbg->call_frames, frame);
129  eprintf("%ld Call from 0x%08" PFMT64x " to 0x%08" PFMT64x " ret 0x%08" PFMT32x "\n",
130  level, prev_pc, pc, ret_addr);
131  level++;
132  old_sp = cur_sp;
133  prev_call = false;
134  } else if (prev_ret) {
136  if (head && head->addr != pc) {
137  eprintf("*");
138  } else {
140  eprintf("%ld", level);
141  level--;
142  }
143  eprintf(" Ret from 0x%08" PFMT64x " to 0x%08" PFMT64x "\n",
144  prev_pc, pc);
145  prev_ret = false;
146  }
147  if (steps % 500 == 0 || pc == addr) {
148  eprintf("At 0x%08" PFMT64x " after %lu steps\n", pc, steps);
149  }
150  if (rz_cons_is_breaked() || rz_debug_is_dead(core->dbg) || pc == addr) {
151  break;
152  }
153  if (is_x86_call(core->dbg, pc)) {
154  prev_pc = pc;
155  prev_call = true;
156  } else if (is_x86_ret(core->dbg, pc)) {
157  prev_pc = pc;
158  prev_ret = true;
159  }
160  rz_debug_step(core->dbg, 1);
161  steps++;
162  }
165  return true;
166  }
167  eprintf("Continue until 0x%08" PFMT64x "\n", addr);
168  rz_reg_arena_swap(core->dbg->reg, true);
169  if (rz_bp_add_sw(core->dbg->bp, addr, 0, RZ_PERM_X)) {
170  if (rz_debug_is_dead(core->dbg)) {
171  RZ_LOG_ERROR("Cannot continue, run ood?\n");
172  } else {
173  rz_debug_continue(core->dbg);
175  }
176  rz_bp_del(core->dbg->bp, addr);
177  } else {
178  RZ_LOG_ERROR("Cannot set breakpoint for continuing until 0x%08" PFMT64x "\n", addr);
179  return false;
180  }
181  return true;
182 }
#define PFMT32x
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
static bool is_x86_ret(RzDebug *dbg, ut64 addr)
Definition: cdebug.c:41
static bool is_x86_call(RzDebug *dbg, ut64 addr)
Definition: cdebug.c:17
RZ_API bool rz_cons_is_breaked(void)
Definition: cons.c:373
uint32_t ut32
RZ_API ut64 rz_debug_reg_get(RzDebug *dbg, const char *name)
Definition: dreg.c:99
RZ_API int rz_debug_reg_sync(RzDebug *dbg, int type, int write)
Definition: dreg.c:9
RZ_API int rz_debug_step(RzDebug *dbg, int steps)
Definition: debug.c:962
RZ_API bool rz_debug_is_dead(RzDebug *dbg)
Definition: debug.c:1632
RZ_API RZ_BORROW RzListIter * rz_list_prepend(RZ_NONNULL RzList *list, void *data)
Appends at the beginning of the list a new element.
Definition: list.c:316
RZ_API RZ_BORROW void * rz_list_get_bottom(RZ_NONNULL const RzList *list)
Returns the first element of the list.
Definition: list.c:467
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235
RZ_API RZ_OWN void * rz_list_pop_head(RZ_NONNULL RzList *list)
Removes and returns the first element of the list.
Definition: list.c:401
@ RZ_REG_TYPE_GPR
Definition: rz_reg.h:21
@ RZ_REG_NAME_SP
Definition: rz_reg.h:44
@ RZ_REG_NAME_PC
Definition: rz_reg.h:43
#define RZ_PERM_X
Definition: rz_types.h:95
char * arch
Definition: rz_debug.h:242
RzList * call_frames
Definition: rz_debug.h:284
char * btalgo
Definition: rz_debug.h:258
RzBreakpoint * bp
Definition: rz_debug.h:288
RzListFree free
Definition: rz_list.h:21
char * name[RZ_REG_NAME_LAST]
Definition: rz_reg.h:149
static int level
Definition: vmenus.c:2424

References addr, rz_debug_frame_t::addr, rz_debug_t::arch, rz_debug_t::bits, rz_debug_frame_t::bp, rz_debug_t::bp, rz_debug_t::btalgo, rz_debug_t::call_frames, rz_core_t::dbg, eprintf, rz_list_t::free, free(), test-lz4-versions::head, rz_io_bind_t::io, rz_debug_t::iob, is_x86_call(), is_x86_ret(), level, rz_reg_t::name, NULL, pc, PFMT32x, PFMT64x, rz_io_bind_t::read_at, rz_debug_t::reg, rz_bp_add_sw(), rz_bp_del(), rz_cons_break_pop(), rz_cons_break_push(), rz_cons_is_breaked(), rz_core_reg_update_flags(), rz_debug_continue(), rz_debug_is_dead(), rz_debug_reg_get(), rz_debug_reg_sync(), rz_debug_step(), rz_list_free(), rz_list_get_bottom(), rz_list_new(), rz_list_pop_head(), rz_list_prepend(), RZ_LOG_ERROR, RZ_NEW0, RZ_PERM_X, rz_reg_arena_swap(), RZ_REG_NAME_PC, RZ_REG_NAME_SP, RZ_REG_TYPE_GPR, rz_debug_frame_t::size, rz_debug_frame_t::sp, ut64(), and UT64_MAX.

Referenced by cmd_dcu(), rz_core_debug_single_step_in(), rz_core_setup_debugger(), and visual_nkey().

◆ rz_core_debug_map_print()

RZ_API void rz_core_debug_map_print ( RzCore core,
ut64  addr,
RzCmdStateOutput state 
)

Definition at line 481 of file cdebug.c.

481  {
482  rz_return_if_fail(core);
483  int i;
484  RzListIter *iter;
485  RzDebugMap *map;
486  PJ *pj = state->d.pj;
487  RzDebug *dbg = core->dbg;
488  if (!dbg) {
489  return;
490  }
491  RzOutputMode mode = state->mode;
493  if (mode == RZ_OUTPUT_MODE_RIZIN) {
494  rz_cons_print("fss+ " RZ_FLAGS_FS_DEBUG_MAPS "\n");
495  }
496  for (i = 0; i < 2; i++) { // Iterate over dbg::maps and dbg::maps_user
497  RzList *maps = rz_debug_map_list(dbg, (bool)i);
498  if (!maps) {
499  continue;
500  }
501  if (mode == RZ_OUTPUT_MODE_RIZIN) { // "dm*"
502  apply_maps_as_flags(core, maps, true);
503  continue;
504  }
505  rz_list_foreach (maps, iter, map) {
506  switch (mode) {
507  case RZ_OUTPUT_MODE_JSON: // "dmj"
509  break;
510  case RZ_OUTPUT_MODE_QUIET: // "dmq"
512  break;
513  case RZ_OUTPUT_MODE_LONG: // workaround for '.'
514  if (addr >= map->addr && addr < map->addr_end) {
516  }
517  break;
518  default:
520  break;
521  }
522  }
523  }
524  if (mode == RZ_OUTPUT_MODE_RIZIN) {
525  rz_cons_print("fss-\n");
526  }
528 }
lzma_index ** i
Definition: index.h:629
static void print_debug_map_line(RzDebug *dbg, RzDebugMap *map, ut64 addr, RzOutputMode mode)
Definition: cdebug.c:387
static void print_debug_map_json(RzDebugMap *map, PJ *pj)
Definition: cdebug.c:371
static void apply_maps_as_flags(RzCore *core, RzList *maps, bool print_only)
Definition: cdebug.c:437
RZ_API void rz_cmd_state_output_array_start(RzCmdStateOutput *state)
Mark the start of an array of elements in the output.
Definition: cmd_api.c:2558
RZ_API void rz_cmd_state_output_array_end(RzCmdStateOutput *state)
Mark the end of an array of elements in the output.
Definition: cmd_api.c:2572
RZ_API RZ_BORROW RzList * rz_debug_map_list(RzDebug *dbg, bool user_map)
Get RzList* of memory maps for the process currently being debugged.
Definition: dmap.c:98
#define RZ_FLAGS_FS_DEBUG_MAPS
Definition: rz_core.h:74
RzOutputMode
Enum to describe the way data are printed.
Definition: rz_types.h:38
@ RZ_OUTPUT_MODE_LONG
Definition: rz_types.h:44
@ RZ_OUTPUT_MODE_JSON
Definition: rz_types.h:40
@ RZ_OUTPUT_MODE_RIZIN
Definition: rz_types.h:41
Definition: rz_pj.h:12
Definition: dis.h:43

References addr, apply_maps_as_flags(), dbg, rz_core_t::dbg, i, map(), maps(), print_debug_map_json(), print_debug_map_line(), rz_cmd_state_output_array_end(), rz_cmd_state_output_array_start(), rz_debug_map_list(), RZ_FLAGS_FS_DEBUG_MAPS, RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_LONG, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_RIZIN, and rz_return_if_fail.

Referenced by rz_cmd_debug_list_maps_handler(), and rz_cmd_debug_map_current_handler().

◆ rz_core_debug_map_update_flags()

RZ_API void rz_core_debug_map_update_flags ( RzCore core)

Create or update flags for all current debug maps in the "maps" flagspace

Definition at line 462 of file cdebug.c.

462  {
463  rz_return_if_fail(core);
465  if (rz_debug_is_dead(core->dbg)) {
466  return;
467  }
468  rz_debug_map_sync(core->dbg);
469  rz_flag_space_push(core->flags, RZ_FLAGS_FS_DEBUG_MAPS);
470  RzList *maps = rz_debug_map_list(core->dbg, false);
471  if (maps) {
472  apply_maps_as_flags(core, maps, false);
473  }
474  maps = rz_debug_map_list(core->dbg, true);
475  if (maps) {
476  apply_maps_as_flags(core, maps, false);
477  }
478  rz_flag_space_pop(core->flags);
479 }
RZ_API bool rz_debug_map_sync(RzDebug *dbg)
Definition: dmap.c:33
RZ_API void rz_flag_unset_all_in_space(RzFlag *f, const char *space_name)
Unset all flag items in the space with the given name.
Definition: flag.c:692

References apply_maps_as_flags(), rz_core_t::dbg, rz_core_t::flags, maps(), rz_debug_is_dead(), rz_debug_map_list(), rz_debug_map_sync(), rz_flag_unset_all_in_space(), RZ_FLAGS_FS_DEBUG_MAPS, and rz_return_if_fail.

Referenced by rz_core_file_reopen(), and rz_main_rizin().

◆ rz_core_debug_plugin_print()

RZ_API RzCmdStatus rz_core_debug_plugin_print ( RzDebug dbg,
RzDebugPlugin plugin,
RzCmdStateOutput state,
int  count,
char *  spaces 
)

Definition at line 300 of file cdebug.c.

300  {
301  PJ *pj = state->d.pj;
302  switch (state->mode) {
303  case RZ_OUTPUT_MODE_QUIET: {
304  rz_cons_printf("%s\n", plugin->name);
305  break;
306  }
307  case RZ_OUTPUT_MODE_JSON: {
308  pj_o(pj);
309  pj_ks(pj, "arch", plugin->arch);
310  pj_ks(pj, "name", plugin->name);
311  pj_ks(pj, "license", plugin->license);
312  pj_end(pj);
313  break;
314  }
316  rz_cons_printf("%d %s %s %s%s\n",
317  count, (plugin == dbg->cur) ? "dbg" : "---",
318  plugin->name, spaces, plugin->license);
319  break;
320  }
321  default: {
324  }
325  }
326  return RZ_CMD_STATUS_OK;
327 }
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
const char * spaces(int count)
#define rz_warn_if_reached()
Definition: rz_assert.h:29
@ RZ_CMD_STATUS_OK
command handler exited in the right way
Definition: rz_cmd.h:24
@ RZ_CMD_STATUS_NONEXISTINGCMD
command does not exist
Definition: rz_cmd.h:28
@ RZ_OUTPUT_MODE_STANDARD
Definition: rz_types.h:39
const char * license
Definition: rz_debug.h:360
const char * arch
Definition: rz_debug.h:364
const char * name
Definition: rz_debug.h:359

References rz_debug_plugin_t::arch, count, rz_debug_t::cur, dbg, rz_debug_plugin_t::license, rz_debug_plugin_t::name, pj_end(), pj_ks(), pj_o(), RZ_CMD_STATUS_NONEXISTINGCMD, RZ_CMD_STATUS_OK, rz_cons_printf(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_STANDARD, rz_warn_if_reached, and spaces().

Referenced by rz_core_debug_plugins_print().

◆ rz_core_debug_plugins_print()

RZ_API RzCmdStatus rz_core_debug_plugins_print ( RzCore core,
RzCmdStateOutput state 
)

Definition at line 329 of file cdebug.c.

329  {
330  int count = 0;
331  char spaces[16];
332  memset(spaces, ' ', 15);
333  spaces[15] = 0;
334  RzDebug *dbg = core->dbg;
335  RzListIter *iter;
336  RzDebugPlugin *plugin;
338  if (!dbg) {
339  return RZ_CMD_STATUS_ERROR;
340  }
342  rz_list_foreach (dbg->plugins, iter, plugin) {
343  int sp = 8 - strlen(plugin->name);
344  spaces[sp] = 0;
346  if (status != RZ_CMD_STATUS_OK) {
347  return status;
348  }
349  spaces[sp] = ' ';
350  count++;
351  }
353  return RZ_CMD_STATUS_OK;
354 }
RZ_API RzCmdStatus rz_core_debug_plugin_print(RzDebug *dbg, RzDebugPlugin *plugin, RzCmdStateOutput *state, int count, char *spaces)
Definition: cdebug.c:300
return memset(p, 0, total)
static const char struct stat static buf struct stat static buf static vhangup int status
Definition: sflib.h:145
enum rz_cmd_status_t RzCmdStatus
@ RZ_CMD_STATUS_ERROR
command handler had issues while running (e.g. allocation error, etc.)
Definition: rz_cmd.h:26
RzList * plugins
Definition: rz_debug.h:297
static int sp
Definition: z80asm.c:91

References count, dbg, rz_core_t::dbg, memset(), rz_debug_plugin_t::name, rz_debug_t::plugins, rz_cmd_state_output_array_end(), rz_cmd_state_output_array_start(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_debug_plugin_print(), sp, spaces(), and status.

Referenced by cb_dbgbackend(), rz_cmd_debug_handler_list_handler(), rz_main_rizin(), and rz_plugins_debug_print_handler().

◆ rz_core_debug_print_status()

RZ_IPI void rz_core_debug_print_status ( RzCore core)

Definition at line 356 of file cdebug.c.

356  {
357  RzReg *reg = rz_core_reg_default(core);
358  RzList *ritems = rz_reg_filter_items_covered(reg->allregs);
359  if (ritems) {
360  rz_core_reg_print_diff(reg, ritems);
361  rz_list_free(ritems);
362  }
363  ut64 old_address = core->offset;
366  rz_core_seek(core, old_address, true);
367  rz_cons_flush();
368 }
RZ_API void rz_cons_flush(void)
Definition: cons.c:959
RZ_IPI void rz_core_reg_print_diff(RzReg *reg, RzList *items)
Print registers that have changed since the last step (drd/ard)
Definition: creg.c:116
RZ_API RzReg * rz_core_reg_default(RzCore *core)
Get the currently relevant RzReg.
Definition: creg.c:17
RZ_API int rz_core_print_disasm_instructions(RzCore *core, int nb_bytes, int nb_opcodes)
Definition: disasm.c:6030
#define reg(n)
RZ_API RZ_OWN RzList * rz_reg_filter_items_covered(RZ_BORROW RZ_NONNULL const RzList *regs)
Filter out all register items that are smaller than but covered entirely by some other register.
Definition: reg.c:489
RZ_API ut64 rz_reg_get_value_by_role(RzReg *reg, RzRegisterId role)
Definition: rvalue.c:181
RZ_API bool rz_core_seek(RzCore *core, ut64 addr, bool rb)
Seek to addr.
Definition: seek.c:116
ut64 offset
Definition: rz_core.h:301

References rz_core_t::offset, reg, rz_cons_flush(), rz_core_print_disasm_instructions(), rz_core_reg_default(), rz_core_reg_print_diff(), rz_core_seek(), rz_list_free(), rz_reg_filter_items_covered(), rz_reg_get_value_by_role(), RZ_REG_NAME_PC, and ut64().

Referenced by rz_core_prompt_loop().

◆ rz_core_debug_process_close()

RZ_API bool rz_core_debug_process_close ( RzCore core)

Close debug process (Kill debugee and all child processes)

Parameters
coreThe RzCore instance
Returns
success

Definition at line 707 of file cdebug.c.

707  {
708  rz_return_val_if_fail(core && core->dbg, false);
709  RzDebug *dbg = core->dbg;
710  // Stop trace session
711  if (dbg->session) {
713  dbg->session = NULL;
714  }
715 #ifndef SIGKILL
716 #define SIGKILL 9
717 #endif
718  // Kill debugee and all child processes
719  if (dbg->cur && dbg->cur->pids && dbg->pid != -1) {
720  RzList *list = dbg->cur->pids(dbg, dbg->pid);
721  RzListIter *iter;
722  RzDebugPid *p;
723  if (list) {
724  rz_list_foreach (list, iter, p) {
725  rz_debug_kill(dbg, p->pid, p->pid, SIGKILL);
726  rz_debug_detach(dbg, p->pid);
727  }
728  } else {
731  }
732  }
733  // Remove the target's registers from the flag list
735  // Reopen and rebase the original file
736  rz_core_io_file_open(core, core->io->desc->fd);
737  return true;
738 }
#define SIGKILL
RZ_API void rz_core_io_file_open(RZ_NONNULL RzCore *core, int fd)
Open file use read-only Permission.
Definition: cfile.c:1601
RZ_API void rz_core_debug_clear_register_flags(RzCore *core)
Definition: cmd_debug.c:1449
RZ_API void rz_debug_session_free(RzDebugSession *session)
Definition: dsession.c:11
void * p
Definition: libc.cpp:67
RZ_API int rz_debug_kill(RzDebug *dbg, int pid, int tid, int sig)
Definition: debug.c:1598
RZ_API int rz_debug_detach(RzDebug *dbg, int pid)
Definition: debug.c:583
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RzList *(* pids)(RzDebug *dbg, int pid)
Definition: rz_debug.h:376
RzDebugSession * session
Definition: rz_debug.h:311
int fd
Definition: rz_io.h:96
struct rz_io_desc_t * desc
Definition: rz_io.h:60

References rz_debug_t::cur, dbg, rz_core_t::dbg, rz_io_t::desc, rz_io_desc_t::fd, rz_core_t::io, list(), NULL, p, rz_debug_t::pid, rz_debug_plugin_t::pids, rz_core_debug_clear_register_flags(), rz_core_io_file_open(), rz_debug_detach(), rz_debug_kill(), rz_debug_session_free(), rz_return_val_if_fail, rz_debug_t::session, and SIGKILL.

Referenced by rz_cmd_debug_process_close_handler().

◆ rz_core_debug_single_step_in()

RZ_IPI void rz_core_debug_single_step_in ( RzCore core)

Definition at line 193 of file cdebug.c.

193  {
194  if (rz_core_is_debug(core)) {
195  if (core->print->cur_enabled) {
196  rz_core_debug_continue_until(core, core->offset, core->offset + core->print->cur);
197  core->print->cur_enabled = 0;
198  } else {
199  rz_core_debug_step_one(core, 1);
200  }
201  } else {
202  rz_core_esil_step(core, UT64_MAX, NULL, NULL, false);
204  }
205 }
RZ_API bool rz_core_debug_continue_until(RzCore *core, ut64 addr, ut64 to)
Definition: cdebug.c:98
RZ_API bool rz_core_debug_step_one(RzCore *core, int times)
Definition: cdebug.c:56
RzPrint * print
Definition: rz_core.h:327
bool cur_enabled
Definition: rz_print.h:130

References rz_print_t::cur, rz_print_t::cur_enabled, NULL, rz_core_t::offset, rz_core_t::print, rz_core_debug_continue_until(), rz_core_debug_step_one(), rz_core_esil_step(), rz_core_is_debug(), rz_core_reg_update_flags(), and UT64_MAX.

Referenced by __panel_single_step_in(), graph_single_step_in(), rz_core_visual_cmd(), and visual_nkey().

◆ rz_core_debug_single_step_over()

RZ_IPI void rz_core_debug_single_step_over ( RzCore core)

Definition at line 207 of file cdebug.c.

207  {
208  bool io_cache = rz_config_get_b(core->config, "io.cache");
209  rz_config_set_b(core->config, "io.cache", false);
210  if (rz_core_is_debug(core)) {
211  if (core->print->cur_enabled) {
213  rz_reg_arena_swap(core->dbg->reg, true);
218  core->print->cur_enabled = 0;
219  } else {
220  rz_core_debug_step_over(core, 1);
223  }
224  } else {
226  }
227  rz_config_set_b(core->config, "io.cache", io_cache);
228 }
RZ_API bool rz_core_debug_step_over(RzCore *core, int steps)
Step over.
Definition: cdebug.c:802
RZ_API void rz_core_analysis_esil_step_over(RZ_NONNULL RzCore *core)
Definition: cil.c:269
RZ_API bool rz_config_get_b(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:142
RZ_API RzConfigNode * rz_config_set_b(RzConfig *cfg, RZ_NONNULL const char *name, bool value)
Definition: config.c:201
RZ_API int rz_debug_continue_until_optype(RzDebug *dbg, int type, int over)
Definition: debug.c:1345
@ RZ_ANALYSIS_OP_TYPE_RET
Definition: rz_analysis.h:385

References rz_core_t::config, rz_print_t::cur_enabled, rz_core_t::dbg, rz_core_t::print, rz_debug_t::reg, RZ_ANALYSIS_OP_TYPE_RET, rz_config_get_b(), rz_config_set_b(), rz_cons_break_pop(), rz_cons_break_push(), rz_core_analysis_esil_step_over(), rz_core_dbg_follow_seek_register(), rz_core_debug_step_over(), rz_core_is_debug(), rz_core_reg_update_flags(), rz_core_static_debug_stop(), rz_debug_continue_until_optype(), and rz_reg_arena_swap().

Referenced by __panel_single_step_over(), graph_single_step_over(), rz_core_visual_cmd(), and visual_nkey().

◆ rz_core_debug_step_back()

RZ_API bool rz_core_debug_step_back ( RzCore core,
int  steps 
)

Step back.

Parameters
coreThe RzCore instance
stepsStep steps
Returns
success

Definition at line 777 of file cdebug.c.

777  {
778  if (!rz_core_is_debug(core)) {
779  if (!rz_core_esil_step_back(core)) {
780  RZ_LOG_ERROR("cannot step back\n");
781  return false;
782  }
783  return true;
784  }
785  if (!core->dbg->session) {
786  RZ_LOG_ERROR("session has not started\n");
787  return false;
788  }
789  if (rz_debug_step_back(core->dbg, steps) < 0) {
790  RZ_LOG_ERROR("stepping back failed\n");
791  return false;
792  }
794  return true;
795 }
RZ_API int rz_core_esil_step_back(RzCore *core)
RZ_API int rz_debug_step_back(RzDebug *dbg, int steps)
Definition: debug.c:1121

References rz_core_t::dbg, rz_core_esil_step_back(), rz_core_is_debug(), rz_core_reg_update_flags(), rz_debug_step_back(), RZ_LOG_ERROR, and rz_debug_t::session.

Referenced by rz_cmd_debug_step_back_handler().

◆ rz_core_debug_step_one()

RZ_API bool rz_core_debug_step_one ( RzCore core,
int  times 
)

Definition at line 56 of file cdebug.c.

56  {
57  if (rz_core_is_debug(core)) {
58  rz_reg_arena_swap(core->dbg->reg, true);
59  // sync registers for BSD PT_STEP/PT_CONT
60  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_GPR, false);
61  ut64 pc = rz_debug_reg_get(core->dbg, "PC");
62  rz_debug_trace_pc(core->dbg, pc);
63  if (!rz_debug_step(core->dbg, times)) {
64  eprintf("Step failed\n");
66  core->break_loop = true;
67  return false;
68  }
70  } else {
71  int i = 0;
72  do {
73  rz_core_esil_step(core, UT64_MAX, NULL, NULL, false);
75  i++;
76  } while (i < times);
77  }
78  return true;
79 }
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 times
Definition: sflib.h:70
bool break_loop
Definition: rz_core.h:373
RZ_API int rz_debug_trace_pc(RzDebug *dbg, ut64 pc)
Definition: trace.c:160

References rz_core_t::break_loop, rz_core_t::dbg, eprintf, i, NULL, pc, rz_debug_t::reg, rz_core_esil_step(), rz_core_is_debug(), rz_core_reg_update_flags(), rz_debug_reg_get(), rz_debug_reg_sync(), rz_debug_step(), rz_debug_trace_pc(), rz_reg_arena_swap(), RZ_REG_TYPE_GPR, times, ut64(), and UT64_MAX.

Referenced by loadGP(), rz_cmd_debug_step_handler(), and rz_core_debug_single_step_in().

◆ rz_core_debug_step_over()

RZ_API bool rz_core_debug_step_over ( RzCore core,
int  steps 
)

Step over.

Parameters
coreThe RzCore instance
stepsStep steps

Definition at line 802 of file cdebug.c.

802  {
803  if (rz_config_get_i(core->config, "dbg.skipover")) {
804  rz_core_debug_step_skip(core, steps);
805  return true;
806  }
807  if (!rz_core_is_debug(core)) {
808  for (int i = 0; i < steps; i++) {
810  }
811  return true;
812  }
813  bool hwbp = rz_config_get_b(core->config, "dbg.hwbp");
814  ut64 addr = rz_debug_reg_get(core->dbg, "PC");
815  RzBreakpointItem *bpi = rz_bp_get_at(core->dbg->bp, addr);
816  rz_bp_del(core->dbg->bp, addr);
817  rz_reg_arena_swap(core->dbg->reg, true);
818  rz_debug_step_over(core->dbg, steps);
819  if (bpi) {
820  (void)rz_debug_bp_add(core->dbg, addr, hwbp, false, 0, NULL, 0);
821  }
823  return true;
824 }
RZ_API bool rz_core_debug_step_skip(RzCore *core, int times)
Skip operations.
Definition: cdebug.c:831
RZ_API int rz_debug_step_over(RzDebug *dbg, int steps)
Definition: debug.c:1033

References addr, rz_debug_t::bp, rz_core_t::config, rz_core_t::dbg, i, NULL, rz_debug_t::reg, rz_bp_del(), rz_bp_get_at(), rz_config_get_b(), rz_config_get_i(), rz_core_analysis_esil_step_over(), rz_core_debug_step_skip(), rz_core_is_debug(), rz_core_reg_update_flags(), rz_debug_bp_add(), rz_debug_reg_get(), rz_debug_step_over(), rz_reg_arena_swap(), and ut64().

Referenced by rz_cmd_debug_step_over_handler(), and rz_core_debug_single_step_over().

◆ rz_core_debug_step_skip()

RZ_API bool rz_core_debug_step_skip ( RzCore core,
int  times 
)

Skip operations.

Parameters
coreThe RzCore instance
timesSkip op times

Definition at line 831 of file cdebug.c.

831  {
832  bool hwbp = rz_config_get_b(core->config, "dbg.hwbp");
833  ut64 addr = rz_debug_reg_get(core->dbg, "PC");
834  ut8 buf[64];
835  RzAnalysisOp aop;
836  RzBreakpointItem *bpi = rz_bp_get_at(core->dbg->bp, addr);
837  rz_reg_arena_swap(core->dbg->reg, true);
838  for (int i = 0; i < times; i++) {
839  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_GPR, false);
840  rz_io_read_at(core->io, addr, buf, sizeof(buf));
841  rz_analysis_op(core->analysis, &aop, addr, buf, sizeof(buf), RZ_ANALYSIS_OP_MASK_BASIC);
842  addr += aop.size;
843  }
844  rz_debug_reg_set(core->dbg, "PC", addr);
845  rz_reg_setv(core->analysis->reg, "PC", addr);
847  if (bpi) {
848  (void)rz_debug_bp_add(core->dbg, addr, hwbp, false, 0, NULL, 0);
849  }
850  return true;
851 }
RZ_API int rz_debug_reg_set(struct rz_debug_t *dbg, const char *name, ut64 num)
Definition: dreg.c:89
RZ_API int rz_analysis_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *data, int len, RzAnalysisOpMask mask)
Definition: op.c:96
RZ_API ut64 rz_reg_setv(RzReg *reg, const char *name, ut64 val)
Definition: reg.c:326
@ RZ_ANALYSIS_OP_MASK_BASIC
Definition: rz_analysis.h:440
RZ_API bool rz_io_read_at(RzIO *io, ut64 addr, ut8 *buf, int len)
Definition: io.c:300

References addr, rz_core_t::analysis, rz_debug_t::bp, rz_core_t::config, rz_core_t::dbg, i, rz_core_t::io, NULL, rz_analysis_t::reg, rz_debug_t::reg, rz_analysis_op(), RZ_ANALYSIS_OP_MASK_BASIC, rz_bp_get_at(), rz_config_get_b(), rz_core_reg_update_flags(), rz_debug_bp_add(), rz_debug_reg_get(), rz_debug_reg_set(), rz_debug_reg_sync(), rz_io_read_at(), rz_reg_arena_swap(), rz_reg_setv(), RZ_REG_TYPE_GPR, rz_analysis_op_t::size, times, and ut64().

Referenced by rz_cmd_debug_step_skip_handler(), and rz_core_debug_step_over().

◆ rz_core_debug_step_until_frame()

RZ_API bool rz_core_debug_step_until_frame ( RzCore core)

Step until end of frame.

Parameters
coreThe RzCore instance
Returns
success

Definition at line 745 of file cdebug.c.

745  {
746  rz_return_val_if_fail(core && core->dbg, false);
747  int maxLoops = 200000;
748  ut64 off, now = rz_debug_reg_get(core->dbg, "SP");
750  do {
751  if (rz_cons_is_breaked()) {
752  break;
753  }
754  if (rz_debug_is_dead(core->dbg)) {
755  break;
756  }
757  // XXX (HACK!)
758  rz_debug_step_over(core->dbg, 1);
759  off = rz_debug_reg_get(core->dbg, "SP");
760  // check breakpoint here
761  if (--maxLoops < 0) {
762  RZ_LOG_INFO("step loop limit exceeded\n");
763  break;
764  }
765  } while (off <= now);
768  return true;
769 }
int off
Definition: pal.c:13
#define RZ_LOG_INFO(fmtstr,...)
Definition: rz_log.h:54

References rz_core_t::dbg, NULL, off, rz_cons_break_pop(), rz_cons_break_push(), rz_cons_is_breaked(), rz_core_reg_update_flags(), rz_debug_is_dead(), rz_debug_reg_get(), rz_debug_step_over(), RZ_LOG_INFO, rz_return_val_if_fail, and ut64().

Referenced by rz_cmd_debug_step_frame_handler().

◆ rz_core_debug_sync_bits()

RZ_IPI void rz_core_debug_sync_bits ( RzCore core)

Definition at line 184 of file cdebug.c.

184  {
185  if (rz_core_is_debug(core)) {
186  ut64 asm_bits = rz_config_get_i(core->config, "asm.bits");
187  if (asm_bits != core->dbg->bits * 8) {
188  rz_config_set_i(core->config, "asm.bits", core->dbg->bits * 8);
189  }
190  }
191 }

References rz_debug_t::bits, rz_core_t::config, rz_core_t::dbg, rz_config_get_i(), rz_config_set_i(), rz_core_is_debug(), and ut64().

Referenced by rz_core_dbg_follow_seek_register(), and rz_core_visual_title().

◆ rz_core_is_debug()

◆ rz_debug_map_list_visual()

RZ_API void rz_debug_map_list_visual ( RzDebug dbg,
ut64  addr,
const char *  input,
int  colors 
)

Definition at line 638 of file cdebug.c.

638  {
639  if (!dbg) {
640  return;
641  }
642  int i;
643  for (i = 0; i < 2; i++) { // Iterate over dbg::maps and dbg::maps_user
644  RzList *maps = rz_debug_map_list(dbg, (bool)i);
645  if (!maps) {
646  continue;
647  }
649  }
650 }
static void print_debug_maps_ascii_art(RzDebug *dbg, RzList *maps, ut64 addr, int colors)
Definition: cdebug.c:568

References addr, colors, dbg, i, maps(), print_debug_maps_ascii_art(), and rz_debug_map_list().

Referenced by rz_cmd_debug_list_maps_ascii_handler().

◆ rz_debug_trace_print()

RZ_API void rz_debug_trace_print ( RzDebug dbg,
RzCmdStateOutput state,
ut64  offset 
)

Print all traces

Parameters
dbgcore->dbg
modeoutput mode, default RZ_OUTPUT_MODE_STANDARD
offsetoffset of address

Definition at line 658 of file cdebug.c.

658  {
660  int tag = dbg->trace->tag;
661  RzListIter *iter;
662  RzDebugTracepoint *trace;
663  rz_list_foreach (dbg->trace->traces, iter, trace) {
664  if (trace->tag && !(tag & trace->tag)) {
665  continue;
666  }
667  switch (state->mode) {
669  rz_cons_printf("0x%" PFMT64x "\n", trace->addr);
670  break;
672  rz_cons_printf("dt+ 0x%" PFMT64x " %d\n", trace->addr, trace->times);
673  break;
675  default:
676  rz_cons_printf("0x%08" PFMT64x " size=%d count=%d times=%d tag=%d\n",
677  trace->addr, trace->size, trace->count, trace->times, trace->tag);
678  break;
679  }
680  }
681 }
RzDebugTrace * trace
Definition: rz_debug.h:281
RzList * traces
Definition: rz_debug.h:220

References rz_debug_tracepoint_t::addr, rz_debug_tracepoint_t::count, dbg, PFMT64x, rz_cons_printf(), RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_RIZIN, RZ_OUTPUT_MODE_STANDARD, rz_return_if_fail, rz_debug_tracepoint_t::size, rz_debug_trace_t::tag, rz_debug_tracepoint_t::tag, test-lz4-versions::tag, rz_debug_tracepoint_t::times, rz_debug_t::trace, and rz_debug_trace_t::traces.

Referenced by rz_cmd_debug_traces_handler().

◆ rz_debug_traces_ascii()

RZ_API void rz_debug_traces_ascii ( RzDebug dbg,
ut64  offset 
)

Print trace info in ASCII Art

Parameters
dbgcore->dbg
offsetoffset of address

Definition at line 688 of file cdebug.c.

688  {
690  RzList *info_list = rz_debug_traces_info(dbg, offset);
691  RzTable *table = rz_table_new();
692  table->cons = rz_cons_singleton();
693  rz_table_visual_list(table, info_list, offset, 1,
695  char *s = rz_table_tostring(table);
696  rz_cons_printf("\n%s\n", s);
697  free(s);
698  rz_table_free(table);
699  rz_list_free(info_list);
700 }
voidpf uLong offset
Definition: ioapi.h:144
static RzSocket * s
Definition: rtr.c:28
RZ_API void rz_table_visual_list(RzTable *table, RzList *list, ut64 seek, ut64 len, int width, bool va)
Definition: table.c:1205
RZ_API void rz_table_free(RzTable *t)
Definition: table.c:114
RZ_API char * rz_table_tostring(RzTable *t)
Definition: table.c:510
RZ_API RzTable * rz_table_new(void)
Definition: table.c:103
void * cons
Definition: rz_table.h:53
int va
Definition: rz_io.h:63
RZ_API RZ_OWN RzList * rz_debug_traces_info(RzDebug *dbg, ut64 offset)
Definition: trace.c:218

References RzTable::cons, dbg, free(), rz_io_bind_t::io, rz_debug_t::iob, NULL, rz_cons_get_size(), rz_cons_printf(), rz_cons_singleton(), rz_debug_traces_info(), rz_list_free(), rz_return_if_fail, rz_table_free(), rz_table_new(), rz_table_tostring(), rz_table_visual_list(), s, and rz_io_t::va.

Referenced by rz_cmd_debug_traces_ascii_handler().