Rizin
unix-like reverse engineering framework and cli tools
cmd_debug.c File Reference
#include <rz_core.h>
#include <rz_debug.h>
#include <sdb.h>
#include "rz_heap_glibc.h"
#include "../core_private.h"
#include "cmd_regs_meta.inc"

Go to the source code of this file.

Classes

struct  dot_trace_ght
 
struct  trace_node
 

Macros

#define TN_KEY_LEN   32
 
#define TN_KEY_FMT   "%" PFMT64u
 
#define CMD_CHECK_DEBUG_DEAD(core)
 
#define MAX_MAP_SIZE   (1024 * 1024 * 512)
 
#define P   rz_cons_printf
 
#define PS(X, Y)
 
#define CMD_REGS_PREFIX   debug
 
#define CMD_REGS_REG_PATH   dbg->reg
 
#define CMD_REGS_SYNC   cmd_regs_sync
 

Functions

static void set_profile_string (RzCore *core, const char *str)
 
static void cmd_debug_cont_syscall (RzCore *core, const char *_str)
 
static RzGraphNodeget_graphtrace_node (RzGraph *g, Sdb *nodes, struct trace_node *tn)
 
static void dot_trace_create_node (RTreeNode *n, RTreeVisitor *vis)
 
static void dot_trace_discover_child (RTreeNode *n, RTreeVisitor *vis)
 
static void dot_trace_traverse (RzCore *core, RTree *t, int fmt)
 
static int step_until (RzCore *core, ut64 addr)
 
static int step_until_esil (RzCore *core, const char *esilstr)
 
static bool is_repeatable_inst (RzCore *core, ut64 addr)
 
static bool step_until_inst (RzCore *core, const char *instr, bool regex)
 
RZ_API void rz_core_dbg_follow_seek_register (RzCore *core)
 Seek to PC if needed. More...
 
static bool step_until_optype (RzCore *core, RzList *optypes_list)
 
static int step_until_flag (RzCore *core, const char *flagstr)
 
static bool step_line (RzCore *core, int times)
 
static void cmd_debug_pid (RzCore *core, const char *input)
 
static void cmd_debug_backtrace (RzCore *core, ut64 len)
 
static int dump_maps (RzCore *core, int perm, const char *filename)
 
static void cmd_debug_current_modules (RzCore *core, RzOutputMode mode)
 
static void cmd_debug_modules (RzCore *core, RzCmdStateOutput *state)
 
static ut64 addroflib (RzCore *core, const char *libname)
 
static RzDebugMapget_closest_map (RzCore *core, ut64 addr)
 
static RzOutputMode rad2mode (int mode)
 
static bool get_bin_info (RzCore *core, const char *file, ut64 baseaddr, PJ *pj, int mode, bool symbols_only, RzCoreBinFilter *filter)
 
RZ_IPI RzCmdStatus rz_cmd_debug_list_maps_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_cmd_debug_allocate_maps_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_modules_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_cmd_debug_current_modules_handler (RzCore *core, int argc, const char **argv, RzOutputMode mode)
 
RZ_IPI RzCmdStatus rz_cmd_debug_deallocate_map_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_list_maps_ascii_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_map_current_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_dump_maps_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_dump_maps_all_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_dump_maps_writable_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI int rz_cmd_debug_dmi (void *data, const char *input)
 
RZ_IPI RzCmdStatus rz_debug_memory_permission_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_dmS_handler (RzCore *core, int argc, const char **argv, RzOutputMode m)
 
RZ_IPI RzCmdStatus rz_cmd_debug_dml_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_dmL_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI int rz_cmd_debug_heap_jemalloc (void *data, const char *input)
 
static void foreach_reg_set_or_clear (RzCore *core, bool set)
 
RZ_API void rz_core_debug_set_register_flags (RzCore *core)
 
RZ_API void rz_core_debug_clear_register_flags (RzCore *core)
 
static void backtrace_vars (RzCore *core, RzList *frames)
 
static void asciiart_backtrace (RzCore *core, RzList *frames)
 
RZ_IPI void rz_core_static_debug_stop (void *u)
 
RZ_IPI void rz_core_debug_bp_add (RzCore *core, ut64 addr, const char *arg_perm, bool hwbp, bool watch)
 
static RTreeNodeadd_trace_tree_child (HtUP *ht, RTree *t, RTreeNode *cur, ut64 addr)
 
static void trace_traverse_pre (RTreeNode *n, RTreeVisitor *vis)
 
static void trace_traverse (RTree *t)
 
static void do_debug_trace_calls (RzCore *core, ut64 from, ut64 to, ut64 final_addr)
 
static void debug_trace_calls (RzCore *core, ut64 from, ut64 to, ut64 final_addr)
 
static void rz_core_debug_esil (RzCore *core, const char *input)
 
static void rz_core_debug_kill (RzCore *core, const char *input)
 
static bool cmd_dcu (RzCore *core, const char *input)
 
RZ_IPI RzCmdStatus rz_cmd_debug_step_until_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_step_until_instr_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_step_until_instr_regex_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_step_until_optype_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_step_until_esil_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_step_until_flag_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_trace_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_traces_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_cmd_debug_traces_ascii_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_trace_add_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_trace_add_addrs_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_traces_reset_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI int rz_cmd_debug_trace_addr (void *data, const char *input)
 
RZ_IPI RzCmdStatus rz_cmd_debug_trace_calls_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_trace_esil_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_trace_esils_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_traces_esil_delete_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_traces_esil_i_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_trace_graph_handler (RzCore *core, int argc, const char **argv, RzOutputMode mode)
 
RZ_IPI RzCmdStatus rz_cmd_debug_trace_interactive_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_start_trace_session_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_stop_trace_session_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_save_trace_session_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_load_trace_session_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_list_trace_session_mmap_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_trace_tag_handler (RzCore *core, int argc, const char **argv)
 
static char * get_corefile_name (const char *raw_name, int pid)
 
static ut8getFileData (RzCore *core, const char *arg)
 
static void consumeBuffer (RzBuffer *buf, const char *cmd, const char *errmsg)
 
RZ_IPI int rz_cmd_debug (void *data, const char *input)
 
RZ_IPI RzCmdStatus rz_cmd_debug_add_bp_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_list_bp_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_cmd_debug_add_hw_bp_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_remove_bp_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_remove_all_bp_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_show_cur_bp_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_command_bp_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_add_cond_bp_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_disable_bp_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_enable_bp_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_toggle_bp_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_add_bp_noreturn_func_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_add_bp_module_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_name_bp_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_show_bp_index_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_list_bp_indexes_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_remove_bp_index_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_set_expr_bp_index_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_run_command_bp_index_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_enable_bp_index_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_disable_bp_index_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_toggle_bp_index_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_enable_bp_trace_index_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_disable_bp_trace_index_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_toggle_bp_trace_index_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_bp_plugin_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_remove_bp_plugin_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_display_bt_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_cmd_debug_display_bt_oneline_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_display_bt_local_vars_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_display_bt_ascii_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_bt_enable_bp_trace_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_bt_disable_bp_trace_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_bt_toggle_bp_trace_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_bp_set_expr_cur_offset_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_add_watchpoint_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_set_cond_bp_win_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_continue_execution_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_continue_back_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_continue_call_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_continue_unknown_call_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_continue_exception_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_continue_fork_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_continue_send_signal_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_continue_mapped_io_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_continue_ret_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_continue_traptrace_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI int rz_cmd_debug_continue_syscall (void *data, const char *input)
 
RZ_IPI int rz_cmd_debug_continue_until (void *data, const char *input)
 
RZ_IPI RzCmdStatus rz_cmd_debug_handler_list_handler (RzCore *core, int argc, const char **argv, RzCmdStateOutput *state)
 
RZ_IPI RzCmdStatus rz_cmd_debug_handler_set_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_process_profile_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_process_profile_edit_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_process_close_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_step_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_step_back_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_step_frame_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_step_cond_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_step_line_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_step_over_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_step_prog_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_cmd_debug_step_skip_handler (RzCore *core, int argc, const char **argv)
 
static bool cmd_regs_sync (RzCore *core, RzRegisterType type, bool write)
 
RZ_API void rz_core_debug_ri (RzCore *core)
 
RZ_IPI RzCmdStatus rz_debug_drx_handler (RzCore *core, int argc, const char **argv)
 
RZ_IPI RzCmdStatus rz_debug_drx_unset_handler (RzCore *core, int argc, const char **argv)
 

Variables

static const char * help_msg_d []
 
static const char * help_msg_dcs []
 
static const char * help_msg_dcu []
 
static const char * help_msg_dd []
 
static const char * help_msg_de []
 
static const char * help_msg_des []
 
static const char * help_msg_di []
 
static const char * help_msg_dk []
 
static const char * help_msg_dko []
 
static const char * help_msg_dmi []
 
static const char * help_msg_dp []
 
static const char * help_msg_dx []
 
static RzCore_core = NULL
 

Macro Definition Documentation

◆ CMD_CHECK_DEBUG_DEAD

#define CMD_CHECK_DEBUG_DEAD (   core)
Value:
do { \
if (rz_debug_is_dead(core->dbg)) { \
rz_cons_println("Debugging is not enabled. Run ood?"); \
} \
} while (0)
RZ_API bool rz_debug_is_dead(RzDebug *dbg)
Definition: debug.c:1632
@ RZ_CMD_STATUS_ERROR
command handler had issues while running (e.g. allocation error, etc.)
Definition: rz_cmd.h:26

Definition at line 19 of file cmd_debug.c.

◆ CMD_REGS_PREFIX

#define CMD_REGS_PREFIX   debug

Definition at line 3605 of file cmd_debug.c.

◆ CMD_REGS_REG_PATH

#define CMD_REGS_REG_PATH   dbg->reg

Definition at line 3606 of file cmd_debug.c.

◆ CMD_REGS_SYNC

#define CMD_REGS_SYNC   cmd_regs_sync

Definition at line 3610 of file cmd_debug.c.

◆ MAX_MAP_SIZE

#define MAX_MAP_SIZE   (1024 * 1024 * 512)

Definition at line 809 of file cmd_debug.c.

◆ P

#define P   rz_cons_printf

◆ PS

#define PS (   X,
 
)
Value:
{ \
escaped_str = rz_str_escape(Y); \
rz_cons_printf(X, escaped_str); \
free(escaped_str); \
}
#define X(x, b, m)
RZ_API RZ_OWN char * rz_str_escape(RZ_NONNULL const char *buf)
Definition: str.c:1550

◆ TN_KEY_FMT

#define TN_KEY_FMT   "%" PFMT64u

Definition at line 8 of file cmd_debug.c.

◆ TN_KEY_LEN

#define TN_KEY_LEN   32

Definition at line 7 of file cmd_debug.c.

Function Documentation

◆ add_trace_tree_child()

static RTreeNode* add_trace_tree_child ( HtUP *  ht,
RTree t,
RTreeNode cur,
ut64  addr 
)
static

Definition at line 1607 of file cmd_debug.c.

1607  {
1608  struct trace_node *t_node = ht_up_find(ht, addr, NULL);
1609  if (!t_node) {
1610  t_node = RZ_NEW0(struct trace_node);
1611  if (t_node) {
1612  t_node->addr = addr;
1613  t_node->refs = 1;
1614  ht_up_insert(ht, addr, t_node);
1615  }
1616  } else {
1617  t_node->refs++;
1618  }
1619  return rz_tree_add_node(t, cur, t_node);
1620 }
#define NULL
Definition: cris-opc.c:27
RZ_API RTreeNode * rz_tree_add_node(RTree *t, RTreeNode *node, void *child_data)
Definition: tree.c:99
#define RZ_NEW0(x)
Definition: rz_types.h:284
ut64 addr
Definition: cmd_debug.c:187
static int addr
Definition: z80asm.c:58

References addr, trace_node::addr, NULL, trace_node::refs, RZ_NEW0, and rz_tree_add_node().

Referenced by do_debug_trace_calls().

◆ addroflib()

static ut64 addroflib ( RzCore core,
const char *  libname 
)
static

Definition at line 923 of file cmd_debug.c.

923  {
924  RzListIter *iter;
925  RzDebugMap *map;
926  if (!core || !libname) {
927  return UT64_MAX;
928  }
929  rz_debug_map_sync(core->dbg);
930  // RzList *list = rz_debug_native_modules_get (core->dbg);
932  rz_list_foreach (list, iter, map) {
933  if (strstr(rz_file_basename(map->name), libname)) {
934  return map->addr;
935  }
936  }
937  rz_list_foreach (core->dbg->maps, iter, map) {
938  if (strstr(rz_file_basename(map->name), libname)) {
939  return map->addr;
940  }
941  }
942  return UT64_MAX;
943 }
RZ_API bool rz_debug_map_sync(RzDebug *dbg)
Definition: dmap.c:33
RZ_API RzList * rz_debug_modules_list(RzDebug *dbg)
Definition: dmap.c:29
size_t map(int syms, int left, int len)
Definition: enough.c:237
static void list(RzEgg *egg)
Definition: rz-gg.c:52
RZ_API const char * rz_file_basename(const char *path)
Definition: file.c:83
#define UT64_MAX
Definition: rz_types_base.h:86
RzDebug * dbg
Definition: rz_core.h:329
RzList * maps
Definition: rz_debug.h:306

References rz_core_t::dbg, list(), map(), rz_debug_t::maps, rz_debug_map_sync(), rz_debug_modules_list(), rz_file_basename(), and UT64_MAX.

Referenced by rz_cmd_debug_dmi().

◆ asciiart_backtrace()

static void asciiart_backtrace ( RzCore core,
RzList frames 
)
static

Definition at line 1514 of file cmd_debug.c.

1514  {
1515  // TODO: show local variables
1516  // TODO: show function/flags/symbols related
1517  // TODO: show contents of stack
1518  // TODO: honor scr.color
1519  RzDebugFrame *f;
1520  RzListIter *iter;
1521  bool mymap = false;
1522  // analysis vs debug ?
1523  const char *sp = rz_reg_get_name(core->analysis->reg, RZ_REG_NAME_SP);
1524  const char *bp = rz_reg_get_name(core->analysis->reg, RZ_REG_NAME_BP);
1525  if (!sp) {
1526  sp = "SP";
1527  }
1528  if (!bp) {
1529  bp = "BP";
1530  }
1531  ut64 dsp = rz_reg_getv(core->analysis->reg, sp);
1532  ut64 dbp = rz_reg_getv(core->analysis->reg, bp);
1533  RzDebugMap *map = rz_debug_map_get(core->dbg, dsp);
1534  if (!map) {
1535  mymap = true;
1536  map = RZ_NEW0(RzDebugMap);
1537  map->addr = UT64_MAX;
1538  map->addr_end = UT64_MAX;
1539  }
1540 
1541  rz_cons_printf("0x%016" PFMT64x " STACK END ^^^\n", map->addr);
1542  rz_cons_printf("0x%016" PFMT64x " STACK POINTER: %s\n", dsp, sp);
1543  rz_cons_printf(" .------------------------.\n");
1544  int n = 0;
1545  rz_list_foreach (frames, iter, f) {
1546  ut64 s = f->sp ? f->sp : dsp;
1547  ut64 b = f->bp ? f->bp : dbp;
1548  char *str = rz_str_newf("[frame %d]", n);
1549  rz_cons_printf("0x%016" PFMT64x " |%4s %10s | ; size %" PFMTDPTR "\n", s, sp, str, (ptrdiff_t)(s - b));
1550  free(str);
1551  rz_cons_printf(" | ... |\n");
1552  rz_cons_printf("0x%016" PFMT64x " |%4s 0x%016" PFMT64x " | %s\n", b, bp, f->addr, "; return address");
1553  rz_cons_printf(" )------------------------(\n");
1554  // eprintf ("0x%08llx 0x%08llx 0x%08llx\n", f->addr, s, b);
1555  n++;
1556  }
1557  rz_cons_printf(" | ... |\n");
1558  rz_cons_printf(" `------------------------'\n");
1559  rz_cons_printf("0x%016" PFMT64x " STACK BOTTOM\n", map->addr_end);
1560  if (mymap) {
1562  }
1563 }
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
RZ_API RzDebugMap * rz_debug_map_get(RzDebug *dbg, ut64 addr)
Definition: dmap.c:65
RZ_API void rz_debug_map_free(RzDebugMap *map)
Definition: dmap.c:77
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
int n
Definition: mipsasm.c:19
RZ_API ut64 rz_reg_getv(RzReg *reg, const char *name)
Definition: reg.c:332
RZ_API const char * rz_reg_get_name(RzReg *reg, int role)
Definition: reg.c:147
static RzSocket * s
Definition: rtr.c:28
@ RZ_REG_NAME_SP
Definition: rz_reg.h:44
@ RZ_REG_NAME_BP
Definition: rz_reg.h:46
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
#define PFMT64x
Definition: rz_types.h:393
#define PFMTDPTR
Definition: rz_types.h:405
int ptrdiff_t
Definition: sftypes.h:68
#define b(i)
Definition: sha256.c:42
#define f(i)
Definition: sha256.c:46
RzAnalysis * analysis
Definition: rz_core.h:322
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int sp
Definition: z80asm.c:91

References rz_core_t::analysis, b, rz_core_t::dbg, f, free(), map(), n, PFMT64x, PFMTDPTR, rz_analysis_t::reg, rz_cons_printf(), rz_debug_map_free(), rz_debug_map_get(), RZ_NEW0, rz_reg_get_name(), rz_reg_getv(), RZ_REG_NAME_BP, RZ_REG_NAME_SP, rz_str_newf(), s, sp, cmd_descs_generate::str, ut64(), and UT64_MAX.

Referenced by rz_cmd_debug_display_bt_ascii_handler().

◆ backtrace_vars()

static void backtrace_vars ( RzCore core,
RzList frames 
)
static

Definition at line 1453 of file cmd_debug.c.

1453  {
1454  RzDebugFrame *f;
1455  RzListIter *iter;
1456  // analysis vs debug ?
1457  const char *sp = rz_reg_get_name(core->analysis->reg, RZ_REG_NAME_SP);
1458  const char *bp = rz_reg_get_name(core->analysis->reg, RZ_REG_NAME_BP);
1459  if (!sp) {
1460  sp = "SP";
1461  }
1462  if (!bp) {
1463  bp = "BP";
1464  }
1465  RzReg *r = core->analysis->reg;
1466  ut64 dsp = rz_reg_getv(r, sp);
1467  ut64 dbp = rz_reg_getv(r, bp);
1468  int n = 0;
1469  rz_list_foreach (frames, iter, f) {
1470  ut64 s = f->sp ? f->sp : dsp;
1471  ut64 b = f->bp ? f->bp : dbp;
1472  rz_reg_setv(r, bp, s);
1473  rz_reg_setv(r, sp, b);
1475  char flagdesc[1024], flagdesc2[1024];
1476  RzFlagItem *fi = rz_flag_get_at(core->flags, f->addr, true);
1477  flagdesc[0] = flagdesc2[0] = 0;
1478  if (fi) {
1479  if (fi->offset != f->addr) {
1480  int delta = (int)(f->addr - fi->offset);
1481  if (delta > 0) {
1482  snprintf(flagdesc, sizeof(flagdesc),
1483  "%s+%d", fi->name, delta);
1484  } else if (delta < 0) {
1485  snprintf(flagdesc, sizeof(flagdesc),
1486  "%s%d", fi->name, delta);
1487  } else {
1488  snprintf(flagdesc, sizeof(flagdesc),
1489  "%s", fi->name);
1490  }
1491  } else {
1492  snprintf(flagdesc, sizeof(flagdesc),
1493  "%s", fi->name);
1494  }
1495  }
1497  RzAnalysisFunction *fcn = rz_analysis_get_fcn_in(core->analysis, f->addr, 0);
1498  // char *str = rz_str_newf ("[frame %d]", n);
1499  rz_cons_printf("%d 0x%08" PFMT64x " sp: 0x%08" PFMT64x " %-5d"
1500  "[%s] %s %s\n",
1501  n, f->addr, f->sp, (int)f->size,
1502  fcn ? fcn->name : "??", flagdesc, flagdesc2);
1503  rz_cons_push();
1504  char *res = rz_core_analysis_all_vars_display(core, fcn, true);
1505  rz_cons_pop();
1506  rz_cons_printf("%s", res);
1507  free(res);
1508  n++;
1509  }
1510  rz_reg_setv(r, bp, dbp);
1511  rz_reg_setv(r, sp, dsp);
1512 }
RZ_IPI char * rz_core_analysis_all_vars_display(RzCore *core, RzAnalysisFunction *fcn, bool add_name)
Definition: canalysis.c:6206
RZ_API void rz_cons_pop(void)
Definition: cons.c:876
RZ_API void rz_cons_push(void)
Definition: cons.c:860
#define r
Definition: crypto_rc6.c:12
RZ_DEPRECATE RZ_API RzAnalysisFunction * rz_analysis_get_fcn_in(RzAnalysis *analysis, ut64 addr, int type)
Definition: fcn.c:1687
RZ_API RzFlagItem * rz_flag_get_at(RzFlag *f, ut64 off, bool closest)
Definition: flag.c:404
snprintf
Definition: kernel.h:364
RZ_API ut64 rz_reg_setv(RzReg *reg, const char *name, ut64 val)
Definition: reg.c:326
static int
Definition: sfsocketcall.h:114
RzFlag * flags
Definition: rz_core.h:330
ut64 offset
Definition: rz_flag.h:38
char * name
Definition: rz_flag.h:35
static st64 delta
Definition: vmenus.c:2425

References rz_core_t::analysis, b, delta, f, rz_core_t::flags, free(), int, n, rz_analysis_function_t::name, rz_flag_item_t::name, rz_flag_item_t::offset, PFMT64x, r, rz_analysis_t::reg, rz_analysis_get_fcn_in(), rz_cons_pop(), rz_cons_printf(), rz_cons_push(), rz_core_analysis_all_vars_display(), rz_flag_get_at(), rz_reg_get_name(), rz_reg_getv(), RZ_REG_NAME_BP, RZ_REG_NAME_SP, rz_reg_setv(), s, snprintf, sp, and ut64().

Referenced by rz_cmd_debug_display_bt_local_vars_handler().

◆ cmd_dcu()

static bool cmd_dcu ( RzCore core,
const char *  input 
)
static

Definition at line 1947 of file cmd_debug.c.

1947  {
1948  const char *ptr = NULL;
1949  ut64 from, to, pc;
1950  bool dcu_range = false;
1951  bool invalid = (!input[0] || !input[1] || !input[2]);
1952  if (invalid || (input[2] != ' ' && input[2] != '.')) {
1954  return false;
1955  }
1956  to = UT64_MAX;
1957  if (input[2] == '.') {
1958  ptr = strchr(input + 3, ' ');
1959  if (ptr) { // TODO: put '\0' in *ptr to avoid
1960  from = rz_num_tail(core->num, core->offset, input + 2);
1961  if (ptr[1] == '.') {
1962  to = rz_num_tail(core->num, core->offset, ptr + 2);
1963  } else {
1964  to = rz_num_math(core->num, ptr + 1);
1965  }
1966  dcu_range = true;
1967  } else {
1968  from = rz_num_tail(core->num, core->offset, input + 2);
1969  }
1970  } else {
1971  ptr = strchr(input + 3, ' ');
1972  if (ptr) { // TODO: put '\0' in *ptr to avoid
1973  from = rz_num_math(core->num, input + 3);
1974  if (ptr[1] == '.') {
1975  to = rz_num_tail(core->num, core->offset, ptr + 2);
1976  } else {
1977  to = rz_num_math(core->num, ptr + 1);
1978  }
1979  dcu_range = true;
1980  } else {
1981  from = rz_num_math(core->num, input + 3);
1982  }
1983  }
1984  if (core->num->nc.errors && rz_cons_is_interactive()) {
1985  eprintf("Cannot continue until unknown address '%s'\n", core->num->nc.calc_buf);
1986  return false;
1987  }
1988  if (to == UT64_MAX) {
1989  to = from;
1990  }
1991  if (dcu_range) {
1993  do {
1994  if (rz_cons_is_breaked()) {
1995  break;
1996  }
1997  rz_debug_step(core->dbg, 1);
1998  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_GPR, false);
1999  pc = rz_debug_reg_get(core->dbg, "PC");
2000  eprintf("Continue 0x%08" PFMT64x " > 0x%08" PFMT64x " < 0x%08" PFMT64x "\n",
2001  from, pc, to);
2002  } while (pc < from || pc > to);
2004  } else {
2005  return rz_core_debug_continue_until(core, from, to);
2006  }
2007  return true;
2008 }
RZ_API bool rz_core_debug_continue_until(RzCore *core, ut64 addr, ut64 to)
Definition: cdebug.c:98
RZ_API void rz_core_cmd_help(const RzCore *core, const char *help[])
Definition: cmd.c:163
static const char * help_msg_dcu[]
Definition: cmd_debug.c:63
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 bool rz_cons_is_interactive(void)
Definition: cons.c:365
RZ_API bool rz_cons_is_breaked(void)
Definition: cons.c:373
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
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API ut64 rz_num_tail(RzNum *num, ut64 addr, const char *hex)
Definition: unum.c:775
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
Definition: unum.c:456
@ RZ_REG_TYPE_GPR
Definition: rz_reg.h:21
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
Definition: sfsocketcall.h:123
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr socklen_t static fromlen const void const struct sockaddr to
Definition: sfsocketcall.h:125
ut64 offset
Definition: rz_core.h:301
RzNum * num
Definition: rz_core.h:316
const char * calc_buf
Definition: rz_num.h:54
int errors
Definition: rz_num.h:50
RzNumCalc nc
division by zero happened
Definition: rz_num.h:67
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)

References rz_num_calc_t::calc_buf, rz_core_t::dbg, eprintf, rz_num_calc_t::errors, from, help_msg_dcu, input(), rz_num_t::nc, NULL, rz_core_t::num, rz_core_t::offset, pc, PFMT64x, rz_cons_break_pop(), rz_cons_break_push(), rz_cons_is_breaked(), rz_cons_is_interactive(), rz_core_cmd_help(), rz_core_debug_continue_until(), rz_debug_reg_get(), rz_debug_reg_sync(), rz_debug_step(), rz_num_math(), rz_num_tail(), RZ_REG_TYPE_GPR, to, ut64(), and UT64_MAX.

Referenced by rz_cmd_debug_continue_until().

◆ cmd_debug_backtrace()

static void cmd_debug_backtrace ( RzCore core,
ut64  len 
)
static

Definition at line 774 of file cmd_debug.c.

774  {
776  ut64 addr;
777  if (!len) {
778  rz_bp_traptrace_list(core->dbg->bp);
779  } else {
780  ut64 oaddr = 0LL;
781  eprintf("Trap tracing 0x%08" PFMT64x "-0x%08" PFMT64x "\n",
782  core->offset, core->offset + len);
783  rz_reg_arena_swap(core->dbg->reg, true);
784  rz_bp_traptrace_reset(core->dbg->bp, true);
785  rz_bp_traptrace_add(core->dbg->bp, core->offset, core->offset + len);
786  rz_bp_traptrace_enable(core->dbg->bp, true);
787  do {
788  ut8 buf[32];
789  rz_debug_continue(core->dbg);
790  addr = rz_debug_reg_get(core->dbg, "PC");
791  if (!addr) {
792  eprintf("pc=0\n");
793  break;
794  }
795  if (addr == oaddr) {
796  eprintf("pc=opc\n");
797  break;
798  }
799  oaddr = addr;
800  /* XXX Bottleneck..we need to reuse the bytes read by traptrace */
801  // XXX Do asm.arch should define the max size of opcode?
802  rz_io_read_at(core->io, addr, buf, 32); // XXX longer opcodes?
804  } while (rz_bp_traptrace_at(core->dbg->bp, addr, analop.size));
805  rz_bp_traptrace_enable(core->dbg->bp, false);
806  }
807 }
size_t len
Definition: 6502dis.c:15
static int analop(RzAnalysis *a, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, RzAnalysisOpMask mask)
RZ_API void rz_reg_arena_swap(RzReg *reg, int copy)
Definition: arena.c:196
RZ_API int rz_bp_traptrace_at(RzBreakpoint *bp, ut64 from, int len)
Definition: bp_traptrace.c:161
RZ_API void rz_bp_traptrace_list(RzBreakpoint *bp)
Definition: bp_traptrace.c:148
RZ_API void rz_bp_traptrace_enable(RzBreakpoint *bp, int enable)
Definition: bp_traptrace.c:25
RZ_API int rz_bp_traptrace_add(RzBreakpoint *bp, ut64 from, ut64 to)
Definition: bp_traptrace.c:71
RZ_API void rz_bp_traptrace_reset(RzBreakpoint *bp, int hard)
Definition: bp_traptrace.c:34
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
RZ_API int rz_debug_continue(RzDebug *dbg)
Definition: debug.c:1332
RZ_API int rz_analysis_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *data, int len, RzAnalysisOpMask mask)
Definition: op.c:96
@ 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
RzIO * io
Definition: rz_core.h:313
RzReg * reg
Definition: rz_debug.h:286
RzBreakpoint * bp
Definition: rz_debug.h:288

References addr, analop(), rz_core_t::analysis, rz_debug_t::bp, rz_core_t::dbg, eprintf, rz_core_t::io, len, rz_core_t::offset, PFMT64x, rz_debug_t::reg, rz_analysis_op(), RZ_ANALYSIS_OP_MASK_BASIC, rz_bp_traptrace_add(), rz_bp_traptrace_at(), rz_bp_traptrace_enable(), rz_bp_traptrace_list(), rz_bp_traptrace_reset(), rz_debug_continue(), rz_debug_reg_get(), rz_io_read_at(), rz_reg_arena_swap(), and ut64().

Referenced by rz_cmd_debug_continue_traptrace_handler().

◆ cmd_debug_cont_syscall()

static void cmd_debug_cont_syscall ( RzCore core,
const char *  _str 
)
static

Definition at line 204 of file cmd_debug.c.

204  {
205  // TODO : handle more than one stopping syscall
206  int i, *syscalls = NULL;
207  int count = 0;
208  if (_str && *_str) {
209  char *str = strdup(_str);
211  syscalls = calloc(sizeof(int), count);
212  for (i = 0; i < count; i++) {
213  const char *sysnumstr = rz_str_word_get0(str, i);
214  int sig = (int)rz_num_math(core->num, sysnumstr);
215  if (sig == -1) { // trace ALL syscalls
216  syscalls[i] = -1;
217  } else if (sig == 0) {
218  sig = rz_syscall_get_num(core->analysis->syscall, sysnumstr);
219  if (sig == -1) {
220  eprintf("Unknown syscall number\n");
221  free(str);
222  free(syscalls);
223  return;
224  }
225  syscalls[i] = sig;
226  }
227  }
228  eprintf("Running child until syscalls:");
229  for (i = 0; i < count; i++) {
230  eprintf("%d ", syscalls[i]);
231  }
232  eprintf("\n");
233  free(str);
234  } else {
235  eprintf("Running child until next syscall\n");
236  }
237  rz_reg_arena_swap(core->dbg->reg, true);
238  rz_debug_continue_syscalls(core->dbg, syscalls, count);
239  free(syscalls);
240 }
lzma_index ** i
Definition: index.h:629
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
RZ_API int rz_debug_continue_syscalls(RzDebug *dbg, int *sc, int n_sc)
Definition: debug.c:1507
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
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")
RZ_API int rz_str_word_set0(char *str)
Definition: str.c:423
RZ_API const char * rz_str_word_get0(const char *str, int idx)
Definition: str.c:598
RzSyscall * syscall
Definition: rz_analysis.h:570
RZ_API int rz_syscall_get_num(RzSyscall *s, const char *str)
Definition: syscall.c:376

References rz_core_t::analysis, calloc(), count, rz_core_t::dbg, eprintf, free(), i, int, NULL, rz_core_t::num, rz_debug_t::reg, rz_debug_continue_syscalls(), rz_num_math(), rz_reg_arena_swap(), rz_str_word_get0(), rz_str_word_set0(), rz_syscall_get_num(), cmd_descs_generate::str, strdup(), and rz_analysis_t::syscall.

Referenced by rz_cmd_debug_continue_fork_handler(), and rz_cmd_debug_continue_syscall().

◆ cmd_debug_current_modules()

static void cmd_debug_current_modules ( RzCore core,
RzOutputMode  mode 
)
static

Definition at line 861 of file cmd_debug.c.

861  { // "dmm"
862  ut64 addr = core->offset;
863  RzDebugMap *map;
864  RzList *list;
865  RzListIter *iter;
866  list = rz_debug_modules_list(core->dbg);
867  rz_list_foreach (list, iter, map) {
868  if (!(addr >= map->addr && addr < map->addr_end)) {
869  continue;
870  }
871  if (mode == RZ_OUTPUT_MODE_STANDARD) {
872  rz_cons_printf("0x%08" PFMT64x " 0x%08" PFMT64x " %s\n", map->addr, map->addr_end, map->file);
873  } else if (mode == RZ_OUTPUT_MODE_RIZIN) {
874  /* Escape backslashes (e.g. for Windows). */
875  char *escaped_path = rz_str_escape(map->file);
876  char *filtered_name = strdup(map->name);
877  rz_name_filter(filtered_name, 0, true);
878  rz_cons_printf("f mod.%s @ 0x%08" PFMT64x "\n",
879  filtered_name, map->addr);
880  rz_cons_printf("oba 0x%08" PFMT64x " %s\n", map->addr, escaped_path);
881  free(escaped_path);
882  free(filtered_name);
883  }
884  }
886 }
const char int mode
Definition: ioapi.h:137
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
RZ_API bool rz_name_filter(char *name, int len, bool strict)
Definition: name.c:43
@ RZ_OUTPUT_MODE_RIZIN
Definition: rz_types.h:41
@ RZ_OUTPUT_MODE_STANDARD
Definition: rz_types.h:39

References addr, rz_core_t::dbg, free(), list(), map(), rz_core_t::offset, PFMT64x, rz_cons_printf(), rz_debug_modules_list(), rz_list_free(), rz_name_filter(), RZ_OUTPUT_MODE_RIZIN, RZ_OUTPUT_MODE_STANDARD, rz_str_escape(), strdup(), and ut64().

Referenced by rz_cmd_debug_current_modules_handler().

◆ cmd_debug_modules()

static void cmd_debug_modules ( RzCore core,
RzCmdStateOutput state 
)
static

Definition at line 888 of file cmd_debug.c.

888  { // "dmm"
889  RzDebugMap *map;
890  RzList *list;
891  RzListIter *iter;
892  PJ *pj = state->d.pj;
893  RzOutputMode mode = state->mode;
895  list = rz_debug_modules_list(core->dbg);
896  rz_list_foreach (list, iter, map) {
897  if (mode == RZ_OUTPUT_MODE_STANDARD) {
898  rz_cons_printf("0x%08" PFMT64x " 0x%08" PFMT64x " %s\n", map->addr, map->addr_end, map->file);
899  } else if (mode == RZ_OUTPUT_MODE_JSON) {
900  /* Escape backslashes (e.g. for Windows). */
901  pj_o(pj);
902  pj_kn(pj, "addr", map->addr);
903  pj_kn(pj, "addr_end", map->addr_end);
904  pj_ks(pj, "file", map->file);
905  pj_ks(pj, "name", map->name);
906  pj_end(pj);
907  } else if (mode == RZ_OUTPUT_MODE_RIZIN) {
908  /* Escape backslashes (e.g. for Windows). */
909  char *escaped_path = rz_str_escape(map->file);
910  char *filtered_name = strdup(map->name);
911  rz_name_filter(filtered_name, 0, true);
912  rz_cons_printf("f mod.%s @ 0x%08" PFMT64x "\n",
913  filtered_name, map->addr);
914  rz_cons_printf("oba 0x%08" PFMT64x " %s\n", map->addr, escaped_path);
915  free(escaped_path);
916  free(filtered_name);
917  }
918  }
921 }
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 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
RzOutputMode
Enum to describe the way data are printed.
Definition: rz_types.h:38
@ RZ_OUTPUT_MODE_JSON
Definition: rz_types.h:40
Definition: rz_pj.h:12
Definition: dis.h:43

References rz_core_t::dbg, free(), list(), map(), PFMT64x, pj_end(), pj_kn(), pj_ks(), pj_o(), rz_cmd_state_output_array_end(), rz_cmd_state_output_array_start(), rz_cons_printf(), rz_debug_modules_list(), rz_list_free(), rz_name_filter(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_RIZIN, RZ_OUTPUT_MODE_STANDARD, rz_str_escape(), and strdup().

Referenced by rz_cmd_debug_dmi(), and rz_cmd_debug_modules_handler().

◆ cmd_debug_pid()

static void cmd_debug_pid ( RzCore core,
const char *  input 
)
static

Definition at line 640 of file cmd_debug.c.

640  {
641  int pid, sig;
642  const char *ptr;
643  switch (input[1]) {
644  case '\0': // "dp"
645  eprintf("Selected: %d %d\n", core->dbg->pid, core->dbg->tid);
646  rz_debug_pid_list(core->dbg, core->dbg->pid, 0);
647  break;
648  case '-': // "dp-"
649  if (input[2] == ' ') {
650  rz_debug_detach(core->dbg, rz_num_math(core->num, input + 2));
651  } else {
652  rz_debug_detach(core->dbg, core->dbg->pid);
653  }
654  break;
655  case 'c': // "dpc"
656  if (core->dbg->forked_pid != -1) {
657  if (input[2] == '*') {
658  eprintf("dp %d\n", core->dbg->forked_pid);
659  } else {
660  rz_debug_select(core->dbg, core->dbg->forked_pid, core->dbg->tid);
661  core->dbg->main_pid = core->dbg->forked_pid;
662  core->dbg->n_threads = 0;
663  core->dbg->forked_pid = -1;
664  }
665  } else {
666  eprintf("No recently forked children\n");
667  }
668  break;
669  case 'k': // "dpk"
670  /* stop, print, pass -- just use flags*/
671  /* XXX: not for threads? signal is for a whole process!! */
672  /* XXX: but we want fine-grained access to process resources */
673  pid = atoi(input + 2);
674  if (pid > 0) {
675  ptr = rz_str_trim_head_ro(input + 2);
676  ptr = strchr(ptr, ' ');
677  sig = ptr ? atoi(ptr + 1) : 0;
678  eprintf("Sending signal '%d' to pid '%d'\n", sig, pid);
679  rz_debug_kill(core->dbg, pid, false, sig);
680  } else
681  eprintf("cmd_debug_pid: Invalid arguments (%s)\n", input);
682  break;
683  case 'n': // "dpn"
684  eprintf("TODO: debug_fork: %d\n", rz_debug_child_fork(core->dbg));
685  break;
686  case 't': // "dpt"
687  switch (input[2]) {
688  case '\0': // "dpt"
689  rz_debug_thread_list(core->dbg, core->dbg->pid, 0);
690  break;
691  case 'j': // "dptj"
692  if (input[3] != ' ') { // "dptj"
693  rz_debug_thread_list(core->dbg, core->dbg->pid, 'j');
694  } else { // "dptj "
695  rz_debug_thread_list(core->dbg, atoi(input + 3), 'j');
696  }
697  break;
698  case ' ': // "dpt "
699  rz_debug_thread_list(core->dbg, atoi(input + 2), 0);
700  break;
701  case '=': // "dpt="
702  rz_debug_select(core->dbg, core->dbg->pid,
703  (int)rz_num_math(core->num, input + 3));
704  break;
705  case 'n': // "dptn"
706  eprintf("TODO: debug_clone: %d\n", rz_debug_child_clone(core->dbg));
707  break;
708  case '?': // "dpt?"
709  default:
711  break;
712  }
713  break;
714  case 'a': // "dpa"
715  if (input[2]) {
716  int pid = rz_num_math(core->num, input + 2);
717  rz_core_debug_attach(core, pid);
718  } else {
719  rz_core_debug_attach(core, 0);
720  }
721  break;
722  case 'f': // "dpf"
723  if (core->file && core->io) {
724  rz_debug_select(core->dbg, rz_io_fd_get_pid(core->io, core->file->fd),
725  rz_io_fd_get_tid(core->io, core->file->fd));
726  }
727  break;
728  case '=': // "dp="
729  rz_debug_select(core->dbg,
730  (int)rz_num_math(core->num, input + 2), core->dbg->tid);
731  core->dbg->main_pid = rz_num_math(core->num, input + 2);
732  break;
733  case 'l': // "dpl"
734  switch (input[2]) {
735  case '\0': // "dpl"
736  rz_debug_pid_list(core->dbg, 0, 0);
737  break;
738  case 'j': // "dplj"
739  rz_debug_pid_list(core->dbg, 0, 'j');
740  break;
741  }
742  break;
743  case 'j': // "dpj"
744  switch (input[2]) {
745  case '\0': // "dpj"
746  rz_debug_pid_list(core->dbg, core->dbg->pid, 'j');
747  break;
748  case ' ': // "dpj "
749  rz_debug_pid_list(core->dbg,
750  (int)RZ_MAX(0, (int)rz_num_math(core->num, input + 2)), 'j');
751  break;
752  }
753  break;
754  case 'e': // "dpe"
755  {
756  int pid = (input[2] == ' ') ? atoi(input + 2) : core->dbg->pid;
757  char *exe = rz_sys_pid_to_path(pid);
758  if (exe) {
759  rz_cons_println(exe);
760  free(exe);
761  }
762  } break;
763  case ' ': // "dp "
764  rz_debug_pid_list(core->dbg,
765  (int)RZ_MAX(0, (int)rz_num_math(core->num, input + 2)), 0);
766  break;
767  case '?': // "dp?"
768  default:
770  break;
771  }
772 }
RZ_IPI void rz_core_debug_attach(RzCore *core, int pid)
Definition: cdebug.c:284
static const char * help_msg_dp[]
Definition: cmd_debug.c:143
RZ_API void rz_cons_println(const char *str)
Definition: cons.c:233
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
RZ_API int rz_debug_child_clone(RzDebug *dbg)
Definition: debug.c:1626
RZ_API int rz_debug_child_fork(RzDebug *dbg)
Definition: debug.c:1620
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 int rz_debug_pid_list(RzDebug *dbg, int pid, char fmt)
Definition: pid.c:34
RZ_API int rz_debug_thread_list(RzDebug *dbg, int pid, char fmt)
Definition: pid.c:74
RZ_API int rz_io_fd_get_tid(RzIO *io, int fd)
Definition: io_fd.c:100
RZ_API int rz_io_fd_get_pid(RzIO *io, int fd)
Definition: io_fd.c:92
RZ_API const char * rz_str_trim_head_ro(const char *str)
Definition: str_trim.c:86
RZ_API char * rz_sys_pid_to_path(int pid)
Definition: sys.c:920
#define RZ_MAX(x, y)
RzCoreFile * file
Definition: rz_core.h:314
int forked_pid
Definition: rz_debug.h:249
int n_threads
Definition: rz_debug.h:250
int main_pid
Definition: rz_debug.h:246

References rz_core_t::dbg, eprintf, rz_core_file_t::fd, rz_core_t::file, rz_debug_t::forked_pid, free(), help_msg_dp, input(), rz_core_t::io, rz_debug_t::main_pid, rz_debug_t::n_threads, rz_core_t::num, rz_debug_t::pid, pid, rz_cons_println(), rz_core_cmd_help(), rz_core_debug_attach(), rz_debug_child_clone(), rz_debug_child_fork(), rz_debug_detach(), rz_debug_kill(), rz_debug_pid_list(), rz_debug_select(), rz_debug_thread_list(), rz_io_fd_get_pid(), rz_io_fd_get_tid(), RZ_MAX, rz_num_math(), rz_str_trim_head_ro(), rz_sys_pid_to_path(), and rz_debug_t::tid.

Referenced by rz_cmd_debug().

◆ cmd_regs_sync()

static bool cmd_regs_sync ( RzCore core,
RzRegisterType  type,
bool  write 
)
static

Definition at line 3607 of file cmd_debug.c.

3607  {
3608  return rz_debug_reg_sync(core->dbg, type, write);
3609 }
static static fork write
Definition: sflib.h:33
int type
Definition: mipsasm.c:17

References rz_core_t::dbg, rz_debug_reg_sync(), type, and write.

Referenced by rz_core_debug_ri().

◆ consumeBuffer()

static void consumeBuffer ( RzBuffer buf,
const char *  cmd,
const char *  errmsg 
)
static

Definition at line 2267 of file cmd_debug.c.

2267  {
2268  if (!buf) {
2269  if (errmsg) {
2270  rz_cons_printf("%s\n", errmsg);
2271  }
2272  return;
2273  }
2274  if (cmd) {
2275  rz_cons_printf("%s", cmd);
2276  }
2277  int i;
2278  rz_buf_seek(buf, 0, RZ_BUF_SET);
2279  for (i = 0; i < rz_buf_size(buf); i++) {
2280  ut8 tmp;
2281  if (!rz_buf_read8(buf, &tmp)) {
2282  return;
2283  }
2284  rz_cons_printf("%02x", tmp);
2285  }
2286  rz_cons_printf("\n");
2287 }
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 st64 rz_buf_seek(RZ_NONNULL RzBuffer *b, st64 addr, int whence)
Modify the current cursor position in the buffer.
Definition: buf.c:1166
RZ_API bool rz_buf_read8(RZ_NONNULL RzBuffer *b, RZ_NONNULL RZ_OUT ut8 *result)
Read a byte at the cursor in the buffer.
Definition: buf.c:860
#define RZ_BUF_SET
Definition: rz_buf.h:14
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225

References cmd, i, rz_buf_read8(), rz_buf_seek(), RZ_BUF_SET, rz_buf_size(), rz_cons_printf(), and autogen_x86imm::tmp.

Referenced by rz_cmd_debug().

◆ debug_trace_calls()

static void debug_trace_calls ( RzCore core,
ut64  from,
ut64  to,
ut64  final_addr 
)
static

Definition at line 1753 of file cmd_debug.c.

1753  {
1754  RzBreakpointItem *bp_final = NULL;
1755  int t = core->dbg->trace->enabled;
1756 
1757  if (rz_debug_is_dead(core->dbg)) {
1758  eprintf("No process to debug.");
1759  return;
1760  }
1761  core->dbg->trace->enabled = 0;
1763  rz_reg_arena_swap(core->dbg->reg, true);
1764  if (final_addr != UT64_MAX) {
1765  bool hwbp = rz_config_get_b(core->config, "dbg.hwbp");
1766  bp_final = rz_debug_bp_add(core->dbg, final_addr, hwbp, false, 0, NULL, 0);
1767  if (!bp_final) {
1768  eprintf("Cannot set breakpoint at final address (%" PFMT64x ")\n", final_addr);
1769  }
1770  }
1771  do_debug_trace_calls(core, from, to, final_addr);
1772  if (bp_final) {
1773  rz_bp_del(core->dbg->bp, final_addr);
1774  }
1775  _core = core;
1776  trace_traverse(core->dbg->tree);
1777  core->dbg->trace->enabled = t;
1779 }
RZ_API bool rz_bp_del(RzBreakpoint *bp, ut64 addr)
Definition: bp.c:315
RZ_IPI void rz_core_static_debug_stop(void *u)
Definition: cmd_debug.c:1565
static RzCore * _core
Definition: cmd_debug.c:1622
static void do_debug_trace_calls(RzCore *core, ut64 from, ut64 to, ut64 final_addr)
Definition: cmd_debug.c:1652
static void trace_traverse(RTree *t)
Definition: cmd_debug.c:1642
RZ_API bool rz_config_get_b(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:142
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
RzConfig * config
Definition: rz_core.h:300
RzDebugTrace * trace
Definition: rz_debug.h:281
RTree * tree
Definition: rz_debug.h:283

References _core, rz_debug_t::bp, rz_core_t::config, rz_core_t::dbg, do_debug_trace_calls(), rz_debug_trace_t::enabled, eprintf, from, NULL, PFMT64x, rz_debug_t::reg, rz_bp_del(), rz_config_get_b(), rz_cons_break_pop(), rz_cons_break_push(), rz_core_static_debug_stop(), rz_debug_bp_add(), rz_debug_is_dead(), rz_reg_arena_swap(), to, rz_debug_t::trace, trace_traverse(), rz_debug_t::tree, and UT64_MAX.

Referenced by rz_cmd_debug_trace_calls_handler().

◆ do_debug_trace_calls()

static void do_debug_trace_calls ( RzCore core,
ut64  from,
ut64  to,
ut64  final_addr 
)
static

Definition at line 1652 of file cmd_debug.c.

1652  {
1653  bool trace_libs = rz_config_get_i(core->config, "dbg.trace.libs");
1654  bool shallow_trace = rz_config_get_i(core->config, "dbg.trace.inrange");
1655  HtUP *tracenodes = core->dbg->tracenodes;
1656  RTree *tr = core->dbg->tree;
1657  RzDebug *dbg = core->dbg;
1658  ut64 debug_to = UT64_MAX;
1659  RTreeNode *cur;
1660  ut64 addr = 0;
1661  int n = 0;
1662 
1663  if (!trace_libs) {
1664 #if NOOP
1665  RzList *bounds = rz_core_get_boundaries_prot(core, -1, "dbg.program", "search");
1666  rz_list_free(bounds);
1667 #endif
1668  }
1669 
1670  /* set root if not already present */
1672  cur = tr->root;
1673 
1674  while (true) {
1675  ut8 buf[32];
1676  RzAnalysisOp aop;
1677  int addr_in_range;
1678 
1679  if (rz_cons_is_breaked()) {
1680  break;
1681  }
1682  if (rz_debug_is_dead(dbg)) {
1683  break;
1684  }
1685  if (debug_to != UT64_MAX && !rz_debug_continue_until(dbg, debug_to)) {
1686  break;
1687  }
1688  if (!rz_debug_step(dbg, 1)) {
1689  break;
1690  }
1691  debug_to = UT64_MAX;
1692  if (!rz_debug_reg_sync(dbg, RZ_REG_TYPE_GPR, false)) {
1693  break;
1694  }
1695  addr = rz_debug_reg_get(dbg, "PC");
1696  if (addr == final_addr) {
1697  // we finished the tracing so break the loop
1698  break;
1699  }
1700  addr_in_range = addr >= from && addr < to;
1701 
1702  rz_io_read_at(core->io, addr, buf, sizeof(buf));
1703  rz_analysis_op(core->analysis, &aop, addr, buf, sizeof(buf), RZ_ANALYSIS_OP_MASK_BASIC);
1704  eprintf("%d %" PFMT64x "\r", n++, addr);
1705  switch (aop.type) {
1710  ut64 called_addr;
1711  int called_in_range;
1712  // store regs
1713  // step into
1714  // get pc
1715  rz_debug_step(dbg, 1);
1717  called_addr = rz_debug_reg_get(dbg, "PC");
1718  called_in_range = called_addr >= from && called_addr < to;
1719  if (!called_in_range && addr_in_range && !shallow_trace) {
1720  debug_to = addr + aop.size;
1721  }
1722  if (addr_in_range || shallow_trace) {
1723  cur = add_trace_tree_child(tracenodes, tr, cur, addr);
1724  if (debug_to != UT64_MAX) {
1725  cur = cur->parent;
1726  }
1727  }
1728  // TODO: push pc+aop.length into the call path stack
1729  break;
1730  }
1731  case RZ_ANALYSIS_OP_TYPE_CALL: {
1732  int called_in_range = aop.jump >= from && aop.jump < to;
1733  if (!called_in_range && addr_in_range && !shallow_trace) {
1734  debug_to = aop.addr + aop.size;
1735  }
1736  if (addr_in_range || shallow_trace) {
1737  cur = add_trace_tree_child(tracenodes, tr, cur, addr);
1738  if (debug_to != UT64_MAX) {
1739  cur = cur->parent;
1740  }
1741  }
1742  break;
1743  }
1745  if (cur != tr->root) {
1746  cur = cur->parent;
1747  }
1748  break;
1749  }
1750  }
1751 }
static RTreeNode * add_trace_tree_child(HtUP *ht, RTree *t, RTreeNode *cur, ut64 addr)
Definition: cmd_debug.c:1607
RZ_API RZ_OWN RzList * rz_core_get_boundaries_prot(RzCore *core, int perm, const char *mode, const char *prefix)
Definition: cmd_search.c:577
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:119
RzDebug * dbg
Definition: desil.c:30
RZ_API int rz_debug_continue_until(RzDebug *dbg, ut64 addr)
Definition: debug.c:1434
@ RZ_ANALYSIS_OP_TYPE_ICALL
Definition: rz_analysis.h:381
@ RZ_ANALYSIS_OP_TYPE_CALL
Definition: rz_analysis.h:378
@ RZ_ANALYSIS_OP_TYPE_UCALL
Definition: rz_analysis.h:379
@ RZ_ANALYSIS_OP_TYPE_RET
Definition: rz_analysis.h:385
@ RZ_ANALYSIS_OP_TYPE_RCALL
Definition: rz_analysis.h:380
@ RZ_ANALYSIS_OP_TYPE_IRCALL
Definition: rz_analysis.h:382
#define tr(opcode, mask, lose, flags)
HtUP * tracenodes
Definition: rz_debug.h:282
struct rz_tree_node_t * parent
Definition: rz_tree.h:8

References add_trace_tree_child(), addr, rz_analysis_op_t::addr, rz_core_t::analysis, rz_core_t::config, dbg, rz_core_t::dbg, eprintf, from, rz_core_t::io, rz_analysis_op_t::jump, n, NULL, rz_tree_node_t::parent, PFMT64x, rz_analysis_op(), RZ_ANALYSIS_OP_MASK_BASIC, RZ_ANALYSIS_OP_TYPE_CALL, RZ_ANALYSIS_OP_TYPE_ICALL, RZ_ANALYSIS_OP_TYPE_IRCALL, RZ_ANALYSIS_OP_TYPE_RCALL, RZ_ANALYSIS_OP_TYPE_RET, RZ_ANALYSIS_OP_TYPE_UCALL, rz_config_get_i(), rz_cons_is_breaked(), rz_core_get_boundaries_prot(), rz_debug_continue_until(), rz_debug_is_dead(), rz_debug_reg_get(), rz_debug_reg_sync(), rz_debug_step(), rz_io_read_at(), rz_list_free(), RZ_REG_TYPE_GPR, rz_tree_add_node(), rz_analysis_op_t::size, to, tr, rz_debug_t::tracenodes, rz_debug_t::tree, rz_analysis_op_t::type, ut64(), and UT64_MAX.

Referenced by debug_trace_calls().

◆ dot_trace_create_node()

static void dot_trace_create_node ( RTreeNode n,
RTreeVisitor vis 
)
static

Definition at line 255 of file cmd_debug.c.

255  {
256  struct dot_trace_ght *data = (struct dot_trace_ght *)vis->data;
257  struct trace_node *tn = n->data;
258  if (tn)
259  get_graphtrace_node(data->graph, data->graphnodes, tn);
260 }
static RzGraphNode * get_graphtrace_node(RzGraph *g, Sdb *nodes, struct trace_node *tn)
Definition: cmd_debug.c:242
RzGraph * graph
Definition: cmd_debug.c:182
Sdb * graphnodes
Definition: cmd_debug.c:183
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4

References rz_tree_visitor_t::data, get_graphtrace_node(), dot_trace_ght::graph, dot_trace_ght::graphnodes, if(), and n.

Referenced by dot_trace_traverse().

◆ dot_trace_discover_child()

static void dot_trace_discover_child ( RTreeNode n,
RTreeVisitor vis 
)
static

Definition at line 262 of file cmd_debug.c.

262  {
263  struct dot_trace_ght *data = (struct dot_trace_ght *)vis->data;
264  RzGraph *g = data->graph;
265  Sdb *gnodes = data->graphnodes;
266  RTreeNode *parent = n->parent;
267  struct trace_node *tn = n->data;
268  struct trace_node *tn_parent = parent->data;
269 
270  if (tn && tn_parent) {
271  RzGraphNode *gn = get_graphtrace_node(g, gnodes, tn);
272  RzGraphNode *gn_parent = get_graphtrace_node(g, gnodes, tn_parent);
273 
274  if (!rz_graph_adjacent(g, gn_parent, gn))
275  rz_graph_add_edge(g, gn_parent, gn);
276  }
277 }
struct @667 g
RZ_API bool rz_graph_adjacent(const RzGraph *g, const RzGraphNode *from, const RzGraphNode *to)
Definition: graph.c:270
RZ_API void rz_graph_add_edge(RzGraph *g, RzGraphNode *from, RzGraphNode *to)
Definition: graph.c:199
Definition: sdb.h:63

References rz_tree_visitor_t::data, g, get_graphtrace_node(), dot_trace_ght::graph, dot_trace_ght::graphnodes, if(), n, rz_graph_add_edge(), and rz_graph_adjacent().

Referenced by dot_trace_traverse().

◆ dot_trace_traverse()

static void dot_trace_traverse ( RzCore core,
RTree t,
int  fmt 
)
static

Definition at line 279 of file cmd_debug.c.

279  {
280  const char *gfont = rz_config_get(core->config, "graph.font");
281  struct dot_trace_ght aux_data;
282  RTreeVisitor vis = { 0 };
283  const RzList *nodes;
284  RzListIter *iter;
285  RzGraphNode *n;
286 
287  if (fmt == 'i') {
288  rz_core_agraph_reset(core);
289  rz_core_cmd0(core, ".dtg*");
291  return;
292  }
293  aux_data.graph = rz_graph_new();
294  aux_data.graphnodes = sdb_new0();
295 
296  /* build a callgraph from the execution trace */
297  vis.data = &aux_data;
298  vis.pre_visit = (RTreeNodeVisitCb)dot_trace_create_node;
299  vis.discover_child = (RTreeNodeVisitCb)dot_trace_discover_child;
300  rz_tree_bfs(t, &vis);
301 
302  /* traverse the callgraph to print the dot file */
303  nodes = rz_graph_get_nodes(aux_data.graph);
304  if (fmt == 0) {
305  rz_cons_printf("digraph code {\n"
306  "graph [bgcolor=white];\n"
307  " node [color=lightgray, style=filled"
308  " shape=box fontname=\"%s\" fontsize=\"8\"];\n",
309  gfont);
310  }
311  rz_list_foreach (nodes, iter, n) {
312  struct trace_node *tn = (struct trace_node *)n->data;
313  const RzList *neighbours = rz_graph_get_neighbours(aux_data.graph, n);
314  RzListIter *it_n;
315  RzGraphNode *w;
316 
317  if (!fmt && tn) {
318  rz_cons_printf("\"0x%08" PFMT64x "\" [URL=\"0x%08" PFMT64x
319  "\" color=\"lightgray\" label=\"0x%08" PFMT64x
320  " (%d)\"]\n",
321  tn->addr, tn->addr, tn->addr, tn->refs);
322  }
323  rz_list_foreach (neighbours, it_n, w) {
324  struct trace_node *tv = (struct trace_node *)w->data;
325 
326  if (tv && tn) {
327  if (fmt) {
328  rz_cons_printf("agn 0x%08" PFMT64x "\n", tn->addr);
329  rz_cons_printf("agn 0x%08" PFMT64x "\n", tv->addr);
330  rz_cons_printf("age 0x%08" PFMT64x " 0x%08" PFMT64x "\n",
331  tn->addr, tv->addr);
332  } else {
333  rz_cons_printf("\"0x%08" PFMT64x "\" -> \"0x%08" PFMT64x
334  "\" [color=\"red\"];\n",
335  tn->addr, tv->addr);
336  }
337  }
338  }
339  }
340  if (!fmt) {
341  rz_cons_printf("}\n");
342  }
343 
344  rz_graph_free(aux_data.graph);
345  sdb_free(aux_data.graphnodes);
346 }
RZ_IPI void rz_core_agraph_print_interactive(RzCore *core)
Definition: cagraph.c:88
RZ_IPI void rz_core_agraph_reset(RzCore *core)
Definition: cagraph.c:8
RZ_API int rz_core_cmd0(RzCore *core, const char *cmd)
Definition: cmd.c:5428
static void dot_trace_discover_child(RTreeNode *n, RTreeVisitor *vis)
Definition: cmd_debug.c:262
static void dot_trace_create_node(RTreeNode *n, RTreeVisitor *vis)
Definition: cmd_debug.c:255
RZ_API RZ_BORROW const char * rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:75
#define w
Definition: crypto_rc6.c:13
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 tv
Definition: sflib.h:79
RZ_API RzGraph * rz_graph_new(void)
Definition: graph.c:108
RZ_API const RzList * rz_graph_get_nodes(const RzGraph *g)
Definition: graph.c:265
RZ_API const RzList * rz_graph_get_neighbours(const RzGraph *g, const RzGraphNode *n)
Definition: graph.c:245
RZ_API void rz_graph_free(RzGraph *g)
Definition: graph.c:124
RZ_API void rz_tree_bfs(RTree *t, RTreeVisitor *vis)
Definition: tree.c:132
void(* RTreeNodeVisitCb)(RTreeNode *n, RTreeVisitor *vis)
Definition: rz_tree.h:27
RZ_API Sdb * sdb_new0(void)
Definition: sdb.c:43
RZ_API bool sdb_free(Sdb *s)
Definition: sdb.c:206

References trace_node::addr, rz_core_t::config, dot_trace_create_node(), dot_trace_discover_child(), dot_trace_ght::graph, dot_trace_ght::graphnodes, if(), n, PFMT64x, trace_node::refs, rz_config_get(), rz_cons_printf(), rz_core_agraph_print_interactive(), rz_core_agraph_reset(), rz_core_cmd0(), rz_graph_free(), rz_graph_get_neighbours(), rz_graph_get_nodes(), rz_graph_new(), rz_tree_bfs(), sdb_free(), sdb_new0(), tv, and w.

Referenced by rz_cmd_debug_trace_graph_handler(), and rz_cmd_debug_trace_interactive_handler().

◆ dump_maps()

static int dump_maps ( RzCore core,
int  perm,
const char *  filename 
)
static

XXX: TODO: read by blocks!!1

Definition at line 810 of file cmd_debug.c.

810  {
811  RzDebugMap *map;
812  RzListIter *iter;
813  rz_debug_map_sync(core->dbg); // update process memory maps
814  ut64 addr = core->offset;
815  int do_dump = false;
816  int ret = !rz_list_empty(core->dbg->maps);
817  rz_list_foreach (core->dbg->maps, iter, map) {
818  do_dump = false;
819  if (perm == -1) {
820  if (addr >= map->addr && addr < map->addr_end) {
821  do_dump = true;
822  }
823  } else if (perm == 0) {
824  do_dump = true;
825  } else if (perm == (map->perm & perm)) {
826  do_dump = true;
827  }
828  if (do_dump) {
829  ut8 *buf = malloc(map->size);
830  // TODO: use mmap here. we need a portable implementation
831  if (!buf) {
832  eprintf("Cannot allocate 0x%08" PFMT64x " bytes\n", map->size);
833  free(buf);
835  continue;
836  }
837  if (map->size > MAX_MAP_SIZE) {
838  eprintf("Do not dumping 0x%08" PFMT64x " because it's too big\n", map->addr);
839  free(buf);
840  continue;
841  }
842  rz_io_read_at(core->io, map->addr, buf, map->size);
843  char *file = filename
844  ? strdup(filename)
845  : rz_str_newf("0x%08" PFMT64x "-0x%08" PFMT64x "-%s.dmp",
846  map->addr, map->addr_end, rz_str_rwx_i(map->perm));
847  if (!rz_file_dump(file, buf, map->size, 0)) {
848  eprintf("Cannot write '%s'\n", file);
849  ret = 0;
850  } else {
851  eprintf("Dumped %d byte(s) into %s\n", (int)map->size, file);
852  }
853  free(file);
854  free(buf);
855  }
856  }
857  // eprintf ("No debug region found here\n");
858  return ret;
859 }
#define MAX_MAP_SIZE
Definition: cmd_debug.c:809
const char * filename
Definition: ioapi.h:137
void * malloc(size_t size)
Definition: malloc.c:123
RZ_API bool rz_file_dump(const char *file, const ut8 *buf, int len, bool append)
Definition: file.c:838
RZ_API const char * rz_str_rwx_i(int rwx)
Definition: str.c:332
Definition: gzappend.c:170

References addr, rz_core_t::dbg, eprintf, free(), rz_core_t::io, malloc(), map(), rz_debug_t::maps, MAX_MAP_SIZE, rz_core_t::offset, PFMT64x, rz_debug_map_sync(), rz_file_dump(), rz_io_read_at(), rz_str_newf(), rz_str_rwx_i(), strdup(), and ut64().

Referenced by rz_cmd_debug_dump_maps_all_handler(), rz_cmd_debug_dump_maps_handler(), and rz_cmd_debug_dump_maps_writable_handler().

◆ foreach_reg_set_or_clear()

static void foreach_reg_set_or_clear ( RzCore core,
bool  set 
)
static

Definition at line 1428 of file cmd_debug.c.

1428  {
1429  RzReg *reg = rz_core_reg_default(core);
1431  RzListIter *it;
1432  RzRegItem *reg_item;
1433  rz_list_foreach (regs, it, reg_item) {
1434  if (set) {
1435  const ut64 value = rz_reg_get_value(reg, reg_item);
1436  rz_flag_set(core->flags, reg_item->name, value, reg_item->size / 8);
1437  } else {
1438  rz_flag_unset_name(core->flags, reg_item->name);
1439  }
1440  }
1441 }
static char * regs[]
Definition: analysis_sh.c:203
static int value
Definition: cmd_api.c:93
RZ_API RzReg * rz_core_reg_default(RzCore *core)
Get the currently relevant RzReg.
Definition: creg.c:17
RZ_API RzFlagItem * rz_flag_set(RzFlag *f, const char *name, ut64 off, ut32 size)
Definition: flag.c:521
RZ_API bool rz_flag_unset_name(RzFlag *f, const char *name)
Definition: flag.c:670
#define reg(n)
RZ_API const RzList * rz_reg_get_list(RzReg *reg, int type)
Definition: reg.c:389
RZ_API ut64 rz_reg_get_value(RzReg *reg, RzRegItem *item)
Definition: rvalue.c:114
int size
in bits> 8,16,32,64 ... 128/256
Definition: rz_reg.h:120
char * name
Definition: rz_reg.h:118

References rz_core_t::flags, rz_reg_item_t::name, reg, regs, rz_core_reg_default(), rz_flag_set(), rz_flag_unset_name(), rz_reg_get_list(), rz_reg_get_value(), RZ_REG_TYPE_GPR, rz_reg_item_t::size, ut64(), and value.

Referenced by rz_core_debug_clear_register_flags(), and rz_core_debug_set_register_flags().

◆ get_bin_info()

static bool get_bin_info ( RzCore core,
const char *  file,
ut64  baseaddr,
PJ pj,
int  mode,
bool  symbols_only,
RzCoreBinFilter *  filter 
)
static

Definition at line 980 of file cmd_debug.c.

981  {
982  int fd;
983  if ((fd = rz_io_fd_open(core->io, file, RZ_PERM_R, 0)) == -1) {
984  return false;
985  }
986  RzBinOptions opt = { 0 };
987  opt.obj_opts.elf_load_sections = true;
988  opt.obj_opts.elf_checks_sections = true;
989  opt.obj_opts.elf_checks_segments = true;
990  opt.fd = fd;
991  opt.sz = rz_io_fd_size(core->io, fd);
992  opt.obj_opts.baseaddr = baseaddr;
993  RzBinFile *obf = rz_bin_cur(core->bin);
994  RzBinFile *bf = rz_bin_open_io(core->bin, &opt);
995  if (!bf) {
996  rz_io_fd_close(core->io, fd);
997  return false;
998  }
999  int action = RZ_CORE_BIN_ACC_ALL & ~RZ_CORE_BIN_ACC_INFO;
1000  if (symbols_only || filter->name) {
1001  action = RZ_CORE_BIN_ACC_SYMBOLS;
1002  } else if (mode == RZ_MODE_SET || mode == RZ_MODE_RIZINCMD) {
1003  action &= ~RZ_CORE_BIN_ACC_ENTRIES & ~RZ_CORE_BIN_ACC_MAIN & ~RZ_CORE_BIN_ACC_MAPS;
1004  }
1005  if (mode == RZ_MODE_SET) {
1006  rz_core_bin_apply_info(core, core->bin->cur, action);
1007  } else {
1010  rz_core_bin_print(core, bf, action, filter, &state, NULL);
1013  }
1014  rz_bin_file_delete(core->bin, bf);
1015  rz_bin_file_set_cur_binfile(core->bin, obf);
1016  rz_io_fd_close(core->io, fd);
1017  return true;
1018 }
RZ_API bool rz_bin_file_set_cur_binfile(RzBin *bin, RzBinFile *bf)
Definition: bfile.c:288
RZ_API bool rz_bin_file_delete(RzBin *bin, RzBinFile *bf)
Definition: bfile.c:213
RZ_API RzBinFile * rz_bin_open_io(RzBin *bin, RzBinOptions *opt)
Definition: bin.c:283
RZ_API RzBinFile * rz_bin_cur(RzBin *bin)
Definition: bin.c:895
RZ_API bool rz_core_bin_apply_info(RzCore *r, RzBinFile *binfile, ut32 mask)
Definition: cbin.c:261
RZ_API bool rz_core_bin_print(RzCore *core, RZ_NONNULL RzBinFile *bf, ut32 mask, RzCoreBinFilter *filter, RzCmdStateOutput *state, RzList *hashes)
Print (to RzCons or inside RzCmdStateOutput) the binary information specified in mask.
Definition: cbin.c:386
RZ_API bool rz_cmd_state_output_init(RZ_NONNULL RzCmdStateOutput *state, RzOutputMode mode)
Initialize a RzCmdStateOutput structure and its inner fields based on the provided mode.
Definition: cmd_api.c:2634
RZ_API void rz_cmd_state_output_fini(RZ_NONNULL RzCmdStateOutput *state)
Clear the inner fields of RzCmdStateOutput structure, but do not free it.
Definition: cmd_api.c:2603
RZ_API void rz_cmd_state_output_print(RZ_NONNULL RzCmdStateOutput *state)
Print the output accumulated in state to RzCons, if necessary.
Definition: cmd_api.c:2668
static RzOutputMode rad2mode(int mode)
Definition: cmd_debug.c:964
RZ_API ut64 rz_io_fd_size(RzIO *io, int fd)
Definition: io_fd.c:42
RZ_API int rz_io_fd_open(RzIO *io, const char *uri, int flags, int mode)
Definition: io_fd.c:6
RZ_API bool rz_io_fd_close(RzIO *io, int fd)
Definition: io_fd.c:11
#define RZ_PERM_R
Definition: rz_types.h:93
#define RZ_MODE_SET
Definition: rz_types.h:27
#define RZ_MODE_RIZINCMD
Definition: rz_types.h:26
XX curplugin == o->plugin.
Definition: rz_bin.h:298
RZ_DEPRECATE RzBinFile * cur
never use this in new code! Get a file from the binfiles list or track it yourself.
Definition: rz_bin.h:330
Represent the output state of a command handler.
Definition: rz_cmd.h:91
RzBin * bin
Definition: rz_core.h:298
static const z80_opcode fd[]
Definition: z80_tab.h:997
static int baseaddr
Definition: z80asm.c:79

References test-lz4-speed::action, baseaddr, rz_core_t::bin, rz_bin_t::cur, fd, rz_core_t::io, NULL, rad2mode(), rz_bin_cur(), rz_bin_file_delete(), rz_bin_file_set_cur_binfile(), rz_bin_open_io(), rz_cmd_state_output_fini(), rz_cmd_state_output_init(), rz_cmd_state_output_print(), rz_core_bin_apply_info(), rz_core_bin_print(), rz_io_fd_close(), rz_io_fd_open(), rz_io_fd_size(), RZ_MODE_RIZINCMD, RZ_MODE_SET, and RZ_PERM_R.

Referenced by rz_cmd_debug_dmi().

◆ get_closest_map()

static RzDebugMap* get_closest_map ( RzCore core,
ut64  addr 
)
static

Definition at line 945 of file cmd_debug.c.

945  {
946  RzListIter *iter;
947  RzDebugMap *map;
948 
949  rz_debug_map_sync(core->dbg);
951  rz_list_foreach (list, iter, map) {
952  if (addr != UT64_MAX && (addr >= map->addr && addr < map->addr_end)) {
953  return map;
954  }
955  }
956  rz_list_foreach (core->dbg->maps, iter, map) {
957  if (addr != UT64_MAX && (addr >= map->addr && addr < map->addr_end)) {
958  return map;
959  }
960  }
961  return NULL;
962 }

References addr, rz_core_t::dbg, list(), map(), rz_debug_t::maps, NULL, rz_debug_map_sync(), rz_debug_modules_list(), and UT64_MAX.

Referenced by rz_cmd_debug_dmi().

◆ get_corefile_name()

static char* get_corefile_name ( const char *  raw_name,
int  pid 
)
static

Definition at line 2256 of file cmd_debug.c.

2256  {
2257  return (!*raw_name) ? rz_str_newf("core.%u", pid) : rz_str_trim_dup(raw_name);
2258 }
RZ_API char * rz_str_trim_dup(const char *str)
Definition: str_trim.c:78

References pid, rz_str_newf(), and rz_str_trim_dup().

Referenced by rz_cmd_debug().

◆ get_graphtrace_node()

static RzGraphNode* get_graphtrace_node ( RzGraph g,
Sdb nodes,
struct trace_node tn 
)
static

Definition at line 242 of file cmd_debug.c.

242  {
243  RzGraphNode *gn;
244  char tn_key[TN_KEY_LEN];
245 
246  snprintf(tn_key, TN_KEY_LEN, TN_KEY_FMT, tn->addr);
247  gn = (RzGraphNode *)(size_t)sdb_num_get(nodes, tn_key, NULL);
248  if (!gn) {
249  gn = rz_graph_add_node(g, tn);
250  sdb_num_set(nodes, tn_key, (ut64)(size_t)gn, 0);
251  }
252  return gn;
253 }
#define TN_KEY_LEN
Definition: cmd_debug.c:7
#define TN_KEY_FMT
Definition: cmd_debug.c:8
RZ_API int sdb_num_set(Sdb *s, const char *key, ut64 v, ut32 cas)
Definition: num.c:25
RZ_API ut64 sdb_num_get(Sdb *s, const char *key, ut32 *cas)
Definition: num.c:13
RZ_API RzGraphNode * rz_graph_add_node(RzGraph *g, void *data)
Definition: graph.c:153

References trace_node::addr, g, NULL, rz_graph_add_node(), sdb_num_get(), sdb_num_set(), snprintf, TN_KEY_FMT, TN_KEY_LEN, and ut64().

Referenced by dot_trace_create_node(), and dot_trace_discover_child().

◆ getFileData()

static ut8* getFileData ( RzCore core,
const char *  arg 
)
static

Definition at line 2260 of file cmd_debug.c.

2260  {
2261  if (*arg == '$') {
2262  return (ut8 *)rz_cmd_alias_get(core->rcmd, arg, 1);
2263  }
2264  return (ut8 *)rz_file_slurp(arg, NULL);
2265 }
RZ_API char * rz_cmd_alias_get(RzCmd *cmd, const char *k, int remote)
Definition: cmd_api.c:501
RZ_API RZ_OWN char * rz_file_slurp(const char *str, RZ_NULLABLE size_t *usz)
Definition: file.c:454
RzCmd * rcmd
Definition: rz_core.h:319

References NULL, rz_core_t::rcmd, rz_cmd_alias_get(), and rz_file_slurp().

Referenced by rz_cmd_debug().

◆ is_repeatable_inst()

static bool is_repeatable_inst ( RzCore core,
ut64  addr 
)
static

Definition at line 408 of file cmd_debug.c.

408  {
409  // we have read the bytes already
411  bool ret = op && ((op->prefix & RZ_ANALYSIS_OP_PREFIX_REP) || (op->prefix & RZ_ANALYSIS_OP_PREFIX_REPNE));
413  return ret;
414 }
RZ_API RzAnalysisOp * rz_core_op_analysis(RzCore *core, ut64 addr, RzAnalysisOpMask mask)
Definition: core.c:2880
RZ_API void rz_analysis_op_free(void *op)
Definition: op.c:61
@ RZ_ANALYSIS_OP_PREFIX_REP
Definition: rz_analysis.h:348
@ RZ_ANALYSIS_OP_PREFIX_REPNE
Definition: rz_analysis.h:349
@ RZ_ANALYSIS_OP_MASK_ALL
Definition: rz_analysis.h:447
Definition: dis.c:32

References addr, rz_analysis_op_free(), RZ_ANALYSIS_OP_MASK_ALL, RZ_ANALYSIS_OP_PREFIX_REP, RZ_ANALYSIS_OP_PREFIX_REPNE, and rz_core_op_analysis().

Referenced by step_until_inst().

◆ rad2mode()

static RzOutputMode rad2mode ( int  mode)
static

Definition at line 964 of file cmd_debug.c.

964  {
965  switch (mode) {
966  case RZ_MODE_PRINT:
967  default:
969  case RZ_MODE_JSON:
970  return RZ_OUTPUT_MODE_JSON;
971  case RZ_MODE_SIMPLE:
972  return RZ_OUTPUT_MODE_QUIET;
973  case RZ_MODE_SIMPLEST:
975  case RZ_MODE_RIZINCMD:
976  return RZ_OUTPUT_MODE_RIZIN;
977  }
978 }
#define RZ_MODE_SIMPLEST
Definition: rz_types.h:31
#define RZ_MODE_PRINT
Definition: rz_types.h:25
#define RZ_MODE_JSON
Definition: rz_types.h:29
#define RZ_MODE_SIMPLE
Definition: rz_types.h:28
@ RZ_OUTPUT_MODE_QUIET
Definition: rz_types.h:42
@ RZ_OUTPUT_MODE_QUIETEST
Definition: rz_types.h:47

References RZ_MODE_JSON, RZ_MODE_PRINT, RZ_MODE_RIZINCMD, RZ_MODE_SIMPLE, RZ_MODE_SIMPLEST, RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_QUIETEST, RZ_OUTPUT_MODE_RIZIN, and RZ_OUTPUT_MODE_STANDARD.

Referenced by get_bin_info(), and rz_cmd_debug_dmi().

◆ rz_cmd_debug()

RZ_IPI int rz_cmd_debug ( void *  data,
const char *  input 
)

Definition at line 2289 of file cmd_debug.c.

2289  {
2290  RzCore *core = (RzCore *)data;
2291  int follow = 0;
2292 
2293  if (!strncmp(input, "ate", 3)) {
2294  char *now = rz_time_date_now_to_string();
2295  rz_cons_printf("%s\n", now);
2296  free(now);
2297  return 0;
2298  }
2299 
2300  switch (input[0]) {
2301  case 'd': // "ddd"
2302  switch (input[1]) {
2303  case '\0': // "ddd"
2304  rz_debug_desc_list(core->dbg, 0);
2305  break;
2306  case '*': // "dtd*"
2307  rz_debug_desc_list(core->dbg, 1);
2308  break;
2309  case 's': // "dtds"
2310  {
2311  ut64 off = UT64_MAX;
2312  int fd = atoi(input + 2);
2313  char *str = strchr(input + 2, ' ');
2314  if (str)
2315  off = rz_num_math(core->num, str + 1);
2316  if (off == UT64_MAX || !rz_debug_desc_seek(core->dbg, fd, off)) {
2317  RzBuffer *buf = rz_core_syscallf(core, "lseek", "%d, 0x%" PFMT64x ", %d", fd, off, 0);
2318  consumeBuffer(buf, "dx ", "Cannot seek");
2319  }
2320  } break;
2321  case 't': { // "ddt" <ttypath>
2322  RzBuffer *buf = rz_core_syscall(core, "close", 0);
2323  consumeBuffer(buf, "dx ", "Cannot close");
2324  break;
2325  }
2326  case 'd': // "ddd"
2327  {
2328  ut64 newfd = UT64_MAX;
2329  int fd = atoi(input + 2);
2330  char *str = strchr(input + 3, ' ');
2331  if (str)
2332  newfd = rz_num_math(core->num, str + 1);
2333  if (newfd == UT64_MAX || !rz_debug_desc_dup(core->dbg, fd, newfd)) {
2334  RzBuffer *buf = rz_core_syscallf(core, "dup2", "%d, %d", fd, (int)newfd);
2335  if (buf) {
2336  consumeBuffer(buf, "dx ", NULL);
2337  } else {
2338  eprintf("Cannot dup %d %d\n", fd, (int)newfd);
2339  }
2340  }
2341  } break;
2342  case 'r': {
2343  ut64 off = UT64_MAX;
2344  ut64 len = UT64_MAX;
2345  int fd = atoi(input + 2);
2346  char *str = strchr(input + 2, ' ');
2347  if (str)
2348  off = rz_num_math(core->num, str + 1);
2349  if (str)
2350  str = strchr(str + 1, ' ');
2351  if (str)
2352  len = rz_num_math(core->num, str + 1);
2353  if (len == UT64_MAX || off == UT64_MAX ||
2354  !rz_debug_desc_read(core->dbg, fd, off, len)) {
2355  consumeBuffer(rz_core_syscallf(core, "read", "%d, 0x%" PFMT64x ", %d",
2356  fd, off, (int)len),
2357  "dx ", "Cannot read");
2358  }
2359  } break;
2360  case 'w': {
2361  ut64 off = UT64_MAX;
2362  ut64 len = UT64_MAX;
2363  int fd = atoi(input + 2);
2364  char *str = strchr(input + 2, ' ');
2365  if (str)
2366  off = rz_num_math(core->num, str + 1);
2367  if (str)
2368  str = strchr(str + 1, ' ');
2369  if (str)
2370  len = rz_num_math(core->num, str + 1);
2371  if (len == UT64_MAX || off == UT64_MAX ||
2372  !rz_debug_desc_write(core->dbg, fd, off, len)) {
2373  RzBuffer *buf = rz_core_syscallf(core, "write", "%d, 0x%" PFMT64x ", %d", fd, off, (int)len);
2374  consumeBuffer(buf, "dx ", "Cannot write");
2375  }
2376  break;
2377  }
2378  case '-': // "dd-"
2379  {
2380  int fd = atoi(input + 2);
2381  // rz_core_cmdf (core, "dxs close %d", (int)rz_num_math ( core->num, input + 2));
2382  RzBuffer *buf = rz_core_syscallf(core, "close", "%d", fd);
2383  consumeBuffer(buf, "dx ", "Cannot close");
2384  break;
2385  }
2386  case ' ': // "dd"
2387  {
2388  // TODO: handle read, readwrite, append
2389  RzBuffer *buf = rz_core_syscallf(core, "open", "%s, %d, %d", input + 2, 2, 0644);
2390  consumeBuffer(buf, "dx ", "Cannot open");
2391  break;
2392  }
2393  case '?':
2394  default:
2396  break;
2397  }
2398  break;
2399  case 'H': // "dH"
2400  eprintf("TODO: transplant process\n");
2401  break;
2402  case 'p': // "dp"
2403  cmd_debug_pid(core, input);
2404  break;
2405  case 'i': // "di"
2406  {
2407  RzDebugInfo *rdi = rz_debug_info(core->dbg, input + 2);
2409  char *escaped_str;
2410  switch (input[1]) {
2411  case '\0': // "di"
2412 #define P rz_cons_printf
2413 #define PS(X, Y) \
2414  { \
2415  escaped_str = rz_str_escape(Y); \
2416  rz_cons_printf(X, escaped_str); \
2417  free(escaped_str); \
2418  }
2419  if (rdi) {
2420  const char *s = rz_signal_to_string(core->dbg->reason.signum);
2421  P("type=%s\n", rz_debug_reason_to_string(core->dbg->reason.type));
2422  P("signal=%s\n", s ? s : "none");
2423  P("signum=%d\n", core->dbg->reason.signum);
2424  P("sigpid=%d\n", core->dbg->reason.tid);
2425  P("addr=0x%" PFMT64x "\n", core->dbg->reason.addr);
2426  P("bp_addr=0x%" PFMT64x "\n", core->dbg->reason.bp_addr);
2427  P("inbp=%s\n", rz_str_bool(core->dbg->reason.bp_addr));
2428  P("baddr=0x%" PFMT64x "\n", rz_debug_get_baddr(core->dbg, NULL));
2429  P("pid=%d\n", rdi->pid);
2430  P("tid=%d\n", rdi->tid);
2431  P("stopaddr=0x%" PFMT64x "\n", core->dbg->stopaddr);
2432  if (rdi->uid != -1) {
2433  P("uid=%d\n", rdi->uid);
2434  }
2435  if (rdi->gid != -1) {
2436  P("gid=%d\n", rdi->gid);
2437  }
2438  if (rdi->usr) {
2439  P("usr=%s\n", rdi->usr);
2440  }
2441  if (rdi->exe && *rdi->exe) {
2442  P("exe=%s\n", rdi->exe);
2443  }
2444  if (rdi->cmdline && *rdi->cmdline) {
2445  P("cmdline=%s\n", rdi->cmdline);
2446  }
2447  if (rdi->cwd && *rdi->cwd) {
2448  P("cwd=%s\n", rdi->cwd);
2449  }
2450  if (rdi->kernel_stack && *rdi->kernel_stack) {
2451  P("kernel_stack=\n%s\n", rdi->kernel_stack);
2452  }
2453  }
2454  if (stop != -1) {
2455  P("stopreason=%d\n", stop);
2456  }
2457  break;
2458  case 'f': // "dif" "diff"
2459  if (input[1] == '?') {
2460  eprintf("Usage: dif $a $b # diff two alias files\n");
2461  } else {
2462  char *arg = strchr(input, ' ');
2463  if (arg) {
2465  char *arg2 = strchr(arg, ' ');
2466  if (arg2) {
2467  *arg2++ = 0;
2468  char *a = (char *)getFileData(core, arg);
2469  char *b = (char *)getFileData(core, arg2);
2470  if (a && b) {
2471  RzDiff *dff = rz_diff_lines_new(a, b, NULL);
2472  char *uni = rz_diff_unified_text(dff, arg, arg2, false, false);
2473  rz_diff_free(dff);
2474  rz_cons_printf("%s\n", uni);
2475  free(uni);
2476  } else {
2477  eprintf("Cannot open those alias files\n");
2478  }
2479  free(a);
2480  free(b);
2481  }
2482  free(arg);
2483  } else {
2484  eprintf("Usage: dif $a $b # diff two alias files\n");
2485  }
2486  }
2487  break;
2488  case '*': // "di*"
2489  if (rdi) {
2490  rz_cons_printf("f dbg.signal @ %d\n", core->dbg->reason.signum);
2491  rz_cons_printf("f dbg.sigpid @ %d\n", core->dbg->reason.tid);
2492  rz_cons_printf("f dbg.inbp @ %d\n", core->dbg->reason.bp_addr ? 1 : 0);
2493  rz_cons_printf("f dbg.sigaddr @ 0x%" PFMT64x "\n", core->dbg->reason.addr);
2494  rz_cons_printf("f dbg.baddr @ 0x%" PFMT64x "\n", rz_debug_get_baddr(core->dbg, NULL));
2495  rz_cons_printf("f dbg.pid @ %d\n", rdi->pid);
2496  rz_cons_printf("f dbg.tid @ %d\n", rdi->tid);
2497  rz_cons_printf("f dbg.uid @ %d\n", rdi->uid);
2498  rz_cons_printf("f dbg.gid @ %d\n", rdi->gid);
2499  }
2500  break;
2501  case 'j': // "dij"
2502  P("{");
2503  if (rdi) {
2504  const char *s = rz_signal_to_string(core->dbg->reason.signum);
2505  P("\"type\":\"%s\",", rz_debug_reason_to_string(core->dbg->reason.type));
2506  P("\"signal\":\"%s\",", s ? s : "none");
2507  P("\"signum\":%d,", core->dbg->reason.signum);
2508  P("\"sigpid\":%d,", core->dbg->reason.tid);
2509  P("\"addr\":%" PFMT64d ",", core->dbg->reason.addr);
2510  P("\"inbp\":%s,", rz_str_bool(core->dbg->reason.bp_addr));
2511  P("\"baddr\":%" PFMT64d ",", rz_debug_get_baddr(core->dbg, NULL));
2512  P("\"stopaddr\":%" PFMT64d ",", core->dbg->stopaddr);
2513  P("\"pid\":%d,", rdi->pid);
2514  P("\"tid\":%d,", rdi->tid);
2515  P("\"uid\":%d,", rdi->uid);
2516  P("\"gid\":%d,", rdi->gid);
2517  if (rdi->usr) {
2518  PS("\"usr\":\"%s\",", rdi->usr);
2519  }
2520  if (rdi->exe) {
2521  PS("\"exe\":\"%s\",", rdi->exe);
2522  }
2523  if (rdi->cmdline) {
2524  PS("\"cmdline\":\"%s\",", rdi->cmdline);
2525  }
2526  if (rdi->cwd) {
2527  PS("\"cwd\":\"%s\",", rdi->cwd);
2528  }
2529  }
2530  P("\"stopreason\":%d}\n", stop);
2531  break;
2532 #undef P
2533 #undef PS
2534  case 'q': {
2535  const char *r = rz_debug_reason_to_string(core->dbg->reason.type);
2536  if (!r) {
2537  r = "none";
2538  }
2539  rz_cons_printf("%s at 0x%08" PFMT64x "\n", r, core->dbg->stopaddr);
2540  } break;
2541  case '?': // "di?"
2542  default:
2544  break;
2545  }
2547  } break;
2548  case 'e': // "de"
2549  rz_core_debug_esil(core, input + 1);
2550  break;
2551  case 'g': // "dg"
2552  if (core->dbg->cur && core->dbg->cur->gcore) {
2553  if (core->dbg->pid == -1) {
2554  eprintf("Not debugging, can't write core.\n");
2555  break;
2556  }
2557  char *corefile = get_corefile_name(input + 1, core->dbg->pid);
2558  eprintf("Writing to file '%s'\n", corefile);
2559  rz_file_rm(corefile);
2560  RzBuffer *dst = rz_buf_new_file(corefile, O_RDWR | O_CREAT, 0644);
2561  if (dst) {
2562  if (!core->dbg->cur->gcore(core->dbg, corefile, dst)) {
2563  eprintf("dg: coredump failed\n");
2564  }
2565  rz_buf_free(dst);
2566  } else {
2567  perror("rz_buf_new_file");
2568  }
2569  free(corefile);
2570  }
2571  break;
2572  case 'k': // "dk"
2573  rz_core_debug_kill(core, input + 1);
2574  break;
2575 #if __WINDOWS__
2576  case 'W': // "dW"
2577  if (input[1] == 'i') {
2579  } else {
2580  rz_w32_print_windows(core->dbg);
2581  }
2582  break;
2583 #endif
2584  case 'w': // "dw"
2586  for (; !rz_cons_is_breaked();) {
2587  int pid = atoi(input + 1);
2588  // int opid = core->dbg->pid = pid;
2589  int res = rz_debug_kill(core->dbg, pid, 0, 0);
2590  if (!res) {
2591  break;
2592  }
2593  rz_sys_usleep(200);
2594  }
2596  break;
2597  case 'x': // "dx"
2598  switch (input[1]) {
2599  case ' ': { // "dx "
2600  ut8 bytes[4096];
2601  if (strlen(input + 2) < 4096) {
2602  int bytes_len = rz_hex_str2bin(input + 2, bytes);
2603  if (bytes_len > 0)
2604  rz_debug_execute(core->dbg,
2605  bytes, bytes_len, 0);
2606  else
2607  eprintf("Invalid hexpairs\n");
2608  } else
2609  eprintf("Injection opcodes so long\n");
2610  break;
2611  }
2612  case 'a': { // "dxa"
2613  RzAsmCode *acode;
2614  rz_asm_set_pc(core->rasm, core->offset);
2615  acode = rz_asm_massemble(core->rasm, input + 2);
2616  if (acode) {
2617  rz_reg_arena_push(core->dbg->reg);
2618  rz_debug_execute(core->dbg, acode->bytes, acode->len, 0);
2619  rz_reg_arena_pop(core->dbg->reg);
2620  }
2621  rz_asm_code_free(acode);
2622  break;
2623  }
2624  case 'e': { // "dxe"
2625  RzEgg *egg = core->egg;
2626  RzBuffer *b;
2627  const char *asm_arch = rz_config_get(core->config, "asm.arch");
2628  int asm_bits = rz_config_get_i(core->config, "asm.bits");
2629  const char *asm_os = rz_config_get(core->config, "asm.os");
2630  rz_egg_setup(egg, asm_arch, asm_bits, 0, asm_os);
2631  rz_egg_reset(egg);
2632  rz_egg_load(egg, input + 1, 0);
2633  rz_egg_compile(egg);
2634  b = rz_egg_get_bin(egg);
2635  rz_asm_set_pc(core->rasm, core->offset);
2636  rz_reg_arena_push(core->dbg->reg);
2637  ut64 tmpsz;
2638  const ut8 *tmp = rz_buf_data(b, &tmpsz);
2639  rz_debug_execute(core->dbg, tmp, tmpsz, 0);
2640  rz_reg_arena_pop(core->dbg->reg);
2641  break;
2642  }
2643  case 'r': // "dxr"
2644  rz_reg_arena_push(core->dbg->reg);
2645  if (input[2] == ' ') {
2646  ut8 bytes[4096];
2647  if (strlen(input + 2) < 4096) {
2648  int bytes_len = rz_hex_str2bin(input + 2,
2649  bytes);
2650  if (bytes_len > 0) {
2651  rz_debug_execute(core->dbg,
2652  bytes, bytes_len,
2653  0);
2654  } else {
2655  eprintf("Invalid hexpairs\n");
2656  }
2657  } else
2658  eprintf("Injection opcodes so long\n");
2659  }
2660  rz_reg_arena_pop(core->dbg->reg);
2661  break;
2662  case 's': // "dxs"
2663  if (input[2]) {
2664  char *str;
2665  str = rz_core_cmd_str(core, sdb_fmt("gs %s", input + 2));
2666  rz_core_cmdf(core, "dx %s", str); //`gs %s`", input + 2);
2667  free(str);
2668  } else {
2669  eprintf("Missing parameter used in gs by dxs\n");
2670  }
2671  break;
2672  case '?': // "dx?"
2673  default:
2675  break;
2676  }
2677  break;
2678  case '?': // "d?"
2679  default:
2681  break;
2682  }
2683  if (follow > 0) {
2685  }
2686  return 0;
2687 }
RZ_API void * rz_asm_code_free(RzAsmCode *acode)
Definition: acode.c:11
RZ_API int rz_reg_arena_push(RzReg *reg)
Definition: arena.c:236
RZ_API void rz_reg_arena_pop(RzReg *reg)
Definition: arena.c:216
RZ_API int rz_asm_set_pc(RzAsm *a, ut64 pc)
Definition: asm.c:533
RZ_API RzAsmCode * rz_asm_massemble(RzAsm *a, const char *assembly)
Definition: asm.c:814
static ut8 bytes[32]
Definition: asm_arc.c:23
RZ_API int rz_core_cmdf(RzCore *core, const char *fmt,...)
Definition: cmd.c:5413
RZ_API char * rz_core_cmd_str(RzCore *core, const char *cmd)
Executes a rizin command and returns the stdout as a string.
Definition: cmd.c:5513
static const char * help_msg_di[]
Definition: cmd_debug.c:103
#define PS(X, Y)
#define P
static char * get_corefile_name(const char *raw_name, int pid)
Definition: cmd_debug.c:2256
static const char * help_msg_d[]
Definition: cmd_debug.c:27
static const char * help_msg_dd[]
Definition: cmd_debug.c:72
static void cmd_debug_pid(RzCore *core, const char *input)
Definition: cmd_debug.c:640
static void consumeBuffer(RzBuffer *buf, const char *cmd, const char *errmsg)
Definition: cmd_debug.c:2267
static ut8 * getFileData(RzCore *core, const char *arg)
Definition: cmd_debug.c:2260
RZ_API void rz_core_dbg_follow_seek_register(RzCore *core)
Seek to PC if needed.
Definition: cmd_debug.c:474
static void rz_core_debug_esil(RzCore *core, const char *input)
Definition: cmd_debug.c:1781
static void rz_core_debug_kill(RzCore *core, const char *input)
Definition: cmd_debug.c:1870
static const char * help_msg_dx[]
Definition: cmd_debug.c:168
RZ_API int rz_debug_desc_seek(RzDebug *dbg, int fd, ut64 addr)
Definition: ddesc.c:57
RZ_API int rz_debug_desc_list(RzDebug *dbg, int rad)
Definition: ddesc.c:71
RZ_API int rz_debug_desc_dup(RzDebug *dbg, int fd, int newfd)
Definition: ddesc.c:43
RZ_API int rz_debug_desc_write(RzDebug *dbg, int fd, ut64 addr, int len)
Definition: ddesc.c:64
RZ_API int rz_debug_desc_read(RzDebug *dbg, int fd, ut64 addr, int len)
Definition: ddesc.c:50
RZ_API RZ_OWN RzDiff * rz_diff_lines_new(RZ_BORROW const char *a, RZ_BORROW const char *b, RZ_NULLABLE RzDiffIgnoreLine ignore)
Returns the structure needed to diff lines.
Definition: diff.c:219
RZ_API void rz_diff_free(RZ_NULLABLE RzDiff *diff)
frees the diff structure
Definition: diff.c:295
RZ_API void rz_egg_reset(RzEgg *egg)
Definition: egg.c:128
RZ_API int rz_egg_compile(RzEgg *egg)
Definition: egg.c:394
RZ_API RzBuffer * rz_egg_get_bin(RzEgg *egg)
Definition: egg.c:423
RZ_API void rz_egg_load(RzEgg *egg, const char *code, int format)
Definition: egg.c:202
RZ_API bool rz_egg_setup(RzEgg *egg, const char *arch, int bits, int endian, const char *os)
Definition: egg.c:139
RZ_API char * sdb_fmt(const char *fmt,...)
Definition: fmt.c:26
RZ_API RzBuffer * rz_core_syscall(RzCore *core, const char *name, const char *args)
Definition: core.c:3305
RZ_API RzBuffer * rz_core_syscallf(RzCore *core, const char *name, const char *fmt,...)
Definition: core.c:3292
RZ_API const char * rz_debug_reason_to_string(int type)
Definition: debug.c:639
RZ_API RzDebugInfo * rz_debug_info(RzDebug *dbg, const char *arg)
Definition: debug.c:18
RZ_API ut64 rz_debug_get_baddr(RzDebug *dbg, const char *file)
Definition: debug.c:1682
RZ_API ut64 rz_debug_execute(RzDebug *dbg, const ut8 *buf, int len, int restore)
Definition: debug.c:510
RZ_API RzDebugReasonType rz_debug_stop_reason(RzDebug *dbg)
Definition: debug.c:670
RZ_API void rz_debug_info_free(RzDebugInfo *rdi)
Definition: debug.c:28
char * dst
Definition: lz4.h:724
int off
Definition: pal.c:13
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
Definition: buf.c:1253
RZ_DEPRECATE RZ_API RZ_BORROW ut8 * rz_buf_data(RZ_NONNULL RzBuffer *b, RZ_NONNULL RZ_OUT ut64 *size)
Return a borrowed array of bytes representing the buffer data.
Definition: buf.c:1287
RZ_API RZ_OWN RzBuffer * rz_buf_new_file(const char *file, int perm, int mode)
Creates a new buffer from a file.
Definition: buf.c:317
RzDebugReasonType
Definition: rz_debug.h:89
RZ_API bool rz_file_rm(const char *file)
Definition: file.c:865
RZ_API int rz_hex_str2bin(const char *in, ut8 *out)
Convert an input string in into the binary form in out.
Definition: hex.c:444
RZ_API const char * rz_signal_to_string(int code)
Definition: signal.c:63
RZ_API const char * rz_str_bool(int b)
Definition: str.c:3896
RZ_API int rz_sys_usleep(int usecs)
Sleep for usecs microseconds.
Definition: sys.c:317
RZ_API RZ_OWN char * rz_time_date_now_to_string(void)
Returns the timestamp in string format of the current time (now)
Definition: time.c:278
#define PFMT64d
Definition: rz_types.h:394
#define O_CREAT
Definition: sftypes.h:489
#define O_RDWR
Definition: sftypes.h:488
#define a(i)
Definition: sha256.c:41
ut8 * bytes
Definition: rz_asm.h:80
RzEgg * egg
Definition: rz_core.h:332
RzAsm * rasm
Definition: rz_core.h:323
bool(* gcore)(RzDebug *dbg, char *path, RzBuffer *dest)
Definition: rz_debug.h:385
ut64 stopaddr
Definition: rz_debug.h:278
RzDebugReason reason
Definition: rz_debug.h:276
struct rz_debug_plugin_t * cur
Definition: rz_debug.h:295
Definition: diff.c:89
RZ_API RZ_OWN char * rz_diff_unified_text(RZ_NONNULL RzDiff *diff, RZ_NULLABLE const char *from, RZ_NULLABLE const char *to, bool show_time, bool color)
Produces a diff output with A and B inputs presented immediately adjacent to each other.
Definition: unified_diff.c:333
RZ_API void rz_w32_identify_window(void)
RZ_API void rz_w32_print_windows(RzDebug *dbg)

References a, rz_debug_reason_t::addr, b, rz_debug_reason_t::bp_addr, bytes, rz_asm_code_t::bytes, cmd_debug_pid(), rz_core_t::config, consumeBuffer(), rz_debug_t::cur, rz_core_t::dbg, dst, rz_core_t::egg, eprintf, fd, free(), rz_debug_plugin_t::gcore, get_corefile_name(), getFileData(), help_msg_d, help_msg_dd, help_msg_di, help_msg_dx, input(), len, rz_asm_code_t::len, NULL, rz_core_t::num, O_CREAT, O_RDWR, off, rz_core_t::offset, P, PFMT64d, PFMT64x, rz_debug_t::pid, pid, PS, r, rz_core_t::rasm, rdi, rz_debug_t::reason, rz_debug_t::reg, rz_asm_code_free(), rz_asm_massemble(), rz_asm_set_pc(), rz_buf_data(), rz_buf_free(), rz_buf_new_file(), rz_config_get(), rz_config_get_i(), rz_cons_break_pop(), rz_cons_break_push(), rz_cons_is_breaked(), rz_cons_printf(), rz_core_cmd_help(), rz_core_cmd_str(), rz_core_cmdf(), rz_core_dbg_follow_seek_register(), rz_core_debug_esil(), rz_core_debug_kill(), rz_core_static_debug_stop(), rz_core_syscall(), rz_core_syscallf(), rz_debug_desc_dup(), rz_debug_desc_list(), rz_debug_desc_read(), rz_debug_desc_seek(), rz_debug_desc_write(), rz_debug_execute(), rz_debug_get_baddr(), rz_debug_info(), rz_debug_info_free(), rz_debug_kill(), rz_debug_reason_to_string(), rz_debug_stop_reason(), rz_diff_free(), rz_diff_lines_new(), rz_diff_unified_text(), rz_egg_compile(), rz_egg_get_bin(), rz_egg_load(), rz_egg_reset(), rz_egg_setup(), rz_file_rm(), rz_hex_str2bin(), rz_num_math(), rz_reg_arena_pop(), rz_reg_arena_push(), rz_signal_to_string(), rz_str_bool(), rz_str_trim_head_ro(), rz_sys_usleep(), rz_time_date_now_to_string(), rz_w32_identify_window(), rz_w32_print_windows(), s, sdb_fmt(), rz_debug_reason_t::signum, rz_debug_t::stopaddr, cmd_descs_generate::str, strdup(), rz_debug_reason_t::tid, autogen_x86imm::tmp, rz_debug_reason_t::type, ut64(), and UT64_MAX.

Referenced by rz_core_cmd_init(), and rzshell_cmddescs_init().

◆ rz_cmd_debug_add_bp_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_add_bp_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2690 of file cmd_debug.c.

2690  {
2691  bool hwbp = rz_config_get_b(core->config, "dbg.hwbp");
2692  rz_core_debug_bp_add(core, core->offset, NULL, hwbp, false);
2693  return RZ_CMD_STATUS_OK;
2694 }
RZ_IPI void rz_core_debug_bp_add(RzCore *core, ut64 addr, const char *arg_perm, bool hwbp, bool watch)
Definition: cmd_debug.c:1574
@ RZ_CMD_STATUS_OK
command handler exited in the right way
Definition: rz_cmd.h:24

References rz_core_t::config, NULL, rz_core_t::offset, RZ_CMD_STATUS_OK, rz_config_get_b(), and rz_core_debug_bp_add().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_add_bp_module_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_add_bp_module_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2854 of file cmd_debug.c.

2854  {
2855  bool hwbp = rz_config_get_b(core->config, "dbg.hwbp");
2856  ut64 delta = rz_num_math(core->num, argv[2]);
2857  RzBreakpointItem *bp = rz_debug_bp_add(core->dbg, 0, hwbp, false, 0, argv[1], delta);
2858  if (!bp) {
2859  RZ_LOG_ERROR("Cannot set breakpoint.\n");
2860  }
2861  return RZ_CMD_STATUS_OK;
2862 }
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58

References argv, rz_core_t::config, rz_core_t::dbg, delta, rz_core_t::num, RZ_CMD_STATUS_OK, rz_config_get_b(), rz_debug_bp_add(), RZ_LOG_ERROR, rz_num_math(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_add_bp_noreturn_func_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_add_bp_noreturn_func_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2848 of file cmd_debug.c.

2848  {
2850  return RZ_CMD_STATUS_OK;
2851 }
RZ_API void rz_core_debug_bp_add_noreturn_func(RzCore *core)
Put a breakpoint into every no-return function.
Definition: cdebug.c:256

References RZ_CMD_STATUS_OK, and rz_core_debug_bp_add_noreturn_func().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_add_cond_bp_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_add_cond_bp_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2812 of file cmd_debug.c.

2812  {
2813  RzBreakpointItem *bp = rz_bp_get_at(core->dbg->bp, core->offset);
2814  if (!bp) {
2815  RZ_LOG_ERROR("No breakpoint defined at 0x%08" PFMT64x "\n", core->offset);
2816  return RZ_CMD_STATUS_ERROR;
2817  }
2818  if (!rz_bp_item_set_cond(bp, argv[1])) {
2819  RZ_LOG_ERROR("Failed to set condition for breakpoint at 0x%08" PFMT64x "\n", core->offset);
2820  return RZ_CMD_STATUS_ERROR;
2821  }
2822  return RZ_CMD_STATUS_OK;
2823 }
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_item_set_cond(RZ_NONNULL RzBreakpointItem *item, RZ_NULLABLE const char *cond)
set the condition for a RzBreakpointItem
Definition: bp.c:423

References argv, rz_debug_t::bp, rz_core_t::dbg, rz_core_t::offset, PFMT64x, rz_bp_get_at(), rz_bp_item_set_cond(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, and RZ_LOG_ERROR.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_add_hw_bp_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_add_hw_bp_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2764 of file cmd_debug.c.

2764  {
2765  rz_core_debug_bp_add(core, core->offset, NULL, true, false);
2766  return RZ_CMD_STATUS_OK;
2767 }

References NULL, rz_core_t::offset, RZ_CMD_STATUS_OK, and rz_core_debug_bp_add().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_add_watchpoint_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_add_watchpoint_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3208 of file cmd_debug.c.

3208  {
3209  bool hwbp = rz_config_get_b(core->config, "dbg.hwbp");
3210  rz_core_debug_bp_add(core, core->offset, argv[1], hwbp, true);
3211  return RZ_CMD_STATUS_OK;
3212 }

References argv, rz_core_t::config, rz_core_t::offset, RZ_CMD_STATUS_OK, rz_config_get_b(), and rz_core_debug_bp_add().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_allocate_maps_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_allocate_maps_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1029 of file cmd_debug.c.

1029  {
1030  CMD_CHECK_DEBUG_DEAD(core);
1031  ut64 addr = core->offset;
1032  int size = (int)rz_num_math(core->num, argv[1]);
1033  rz_debug_map_alloc(core->dbg, addr, size, false);
1034  return RZ_CMD_STATUS_OK;
1035 }
#define CMD_CHECK_DEBUG_DEAD(core)
Definition: cmd_debug.c:19
RZ_API RzDebugMap * rz_debug_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp)
Definition: dmap.c:46
voidpf void uLong size
Definition: ioapi.h:138

References addr, argv, CMD_CHECK_DEBUG_DEAD, rz_core_t::dbg, int, rz_core_t::num, rz_core_t::offset, RZ_CMD_STATUS_OK, rz_debug_map_alloc(), rz_num_math(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_bp_plugin_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_bp_plugin_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3014 of file cmd_debug.c.

3014  {
3015  if (argc == 1) {
3016  rz_bp_plugin_list(core->dbg->bp);
3017  } else if (argc == 2) {
3018  if (!rz_bp_use(core->dbg->bp, argv[1])) {
3019  RZ_LOG_ERROR("Failed to set breakpoint plugin handler to %s\n", argv[1]);
3020  return RZ_CMD_STATUS_ERROR;
3021  }
3022  }
3023  return RZ_CMD_STATUS_OK;
3024 }
RZ_API void rz_bp_plugin_list(RzBreakpoint *bp)
Definition: bp_plugin.c:61
RZ_API int rz_bp_use(RZ_NONNULL RzBreakpoint *bp, RZ_NONNULL const char *name)
Definition: bp_plugin.c:47

References argv, rz_debug_t::bp, rz_core_t::dbg, rz_bp_plugin_list(), rz_bp_use(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, and RZ_LOG_ERROR.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_bp_set_expr_cur_offset_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_bp_set_expr_cur_offset_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3186 of file cmd_debug.c.

3186  {
3187  if (argc == 1) {
3188  RzBreakpointItem *bpi;
3189  RzListIter *iter;
3190  rz_list_foreach (core->dbg->bp->bps, iter, bpi) {
3191  rz_cons_printf("0x%08" PFMT64x " %s\n", bpi->addr, rz_str_get(bpi->expr));
3192  }
3193  } else if (argc == 2) {
3194  RzBreakpointItem *bpi = rz_bp_get_at(core->dbg->bp, core->offset);
3195  if (!bpi) {
3196  RZ_LOG_ERROR("No breakpoint found at current offset: 0x%" PFMT64x "\n", core->offset);
3197  return RZ_CMD_STATUS_ERROR;
3198  }
3199  if (!rz_bp_item_set_expr(bpi, argv[1])) {
3200  RZ_LOG_ERROR("Failed to set expression\n");
3201  return RZ_CMD_STATUS_ERROR;
3202  }
3203  }
3204  return RZ_CMD_STATUS_OK;
3205 }
RZ_API bool rz_bp_item_set_expr(RZ_NONNULL RzBreakpointItem *item, RZ_NULLABLE const char *expr)
set the expr for a RzBreakpointItem
Definition: bp.c:467
static const char * rz_str_get(const char *str)
Definition: rz_str.h:187
char * expr
Definition: rz_bp.h:61
ut64 addr
Definition: rz_bp.h:45
RzList * bps
Definition: rz_bp.h:93

References rz_bp_item_t::addr, argv, rz_debug_t::bp, rz_bp_t::bps, rz_core_t::dbg, rz_bp_item_t::expr, rz_core_t::offset, PFMT64x, rz_bp_get_at(), rz_bp_item_set_expr(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_printf(), RZ_LOG_ERROR, and rz_str_get().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_bt_disable_bp_trace_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_bt_disable_bp_trace_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3167 of file cmd_debug.c.

3167  {
3168  if (!rz_bp_set_trace(core->dbg->bp, core->offset, false)) {
3169  RZ_LOG_ERROR("Failed to enable trace for breakpoint at 0x%" PFMT64x "\n", core->offset);
3170  }
3171  return RZ_CMD_STATUS_OK;
3172 }
RZ_API int rz_bp_set_trace(RzBreakpoint *bp, ut64 addr, int set)
Definition: bp.c:329

References rz_debug_t::bp, rz_core_t::dbg, rz_core_t::offset, PFMT64x, rz_bp_set_trace(), RZ_CMD_STATUS_OK, and RZ_LOG_ERROR.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_bt_enable_bp_trace_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_bt_enable_bp_trace_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3159 of file cmd_debug.c.

3159  {
3160  if (!rz_bp_set_trace(core->dbg->bp, core->offset, true)) {
3161  RZ_LOG_ERROR("Failed to enable trace for breakpoint at 0x%" PFMT64x "\n", core->offset);
3162  }
3163  return RZ_CMD_STATUS_OK;
3164 }

References rz_debug_t::bp, rz_core_t::dbg, rz_core_t::offset, PFMT64x, rz_bp_set_trace(), RZ_CMD_STATUS_OK, and RZ_LOG_ERROR.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_bt_toggle_bp_trace_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_bt_toggle_bp_trace_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3175 of file cmd_debug.c.

3175  {
3176  RzBreakpointItem *bpi = rz_bp_get_in(core->dbg->bp, core->offset, 0);
3177  if (!bpi) {
3178  RZ_LOG_ERROR("No breakpoint found at 0x%" PFMT64x "\n", core->offset);
3179  } else {
3180  bpi->trace = !bpi->trace;
3181  }
3182  return RZ_CMD_STATUS_OK;
3183 }
RZ_API RzBreakpointItem * rz_bp_get_in(RzBreakpoint *bp, ut64 addr, int perm)
Definition: bp.c:139
int trace
Definition: rz_bp.h:51

References rz_debug_t::bp, rz_core_t::dbg, rz_core_t::offset, PFMT64x, rz_bp_get_in(), RZ_CMD_STATUS_OK, RZ_LOG_ERROR, and rz_bp_item_t::trace.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_command_bp_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_command_bp_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2798 of file cmd_debug.c.

2798  {
2799  RzBreakpointItem *bp = rz_bp_get_at(core->dbg->bp, core->offset);
2800  if (!bp) {
2801  RZ_LOG_ERROR("No breakpoint defined at 0x%08" PFMT64x "\n", core->offset);
2802  return RZ_CMD_STATUS_ERROR;
2803  }
2804  if (!rz_bp_item_set_data(bp, argv[1])) {
2805  RZ_LOG_ERROR("Failed to set data for breakpoint at 0x%08" PFMT64x "\n", core->offset);
2806  return RZ_CMD_STATUS_ERROR;
2807  }
2808  return RZ_CMD_STATUS_OK;
2809 }
RZ_API bool rz_bp_item_set_data(RZ_NONNULL RzBreakpointItem *item, RZ_NULLABLE const char *data)
set the data for a RzBreakpointItem
Definition: bp.c:445

References argv, rz_debug_t::bp, rz_core_t::dbg, rz_core_t::offset, PFMT64x, rz_bp_get_at(), rz_bp_item_set_data(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, and RZ_LOG_ERROR.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_continue_back_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_continue_back_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3257 of file cmd_debug.c.

3257  {
3258  CMD_CHECK_DEBUG_DEAD(core);
3260 
3261  if (!rz_debug_continue_back(core->dbg)) {
3262  eprintf("cannot continue back\n");
3263  return RZ_CMD_STATUS_ERROR;
3264  }
3265 
3268  return RZ_CMD_STATUS_OK;
3269 }
RZ_API bool rz_debug_continue_back(RzDebug *dbg)
Definition: debug.c:1442

References CMD_CHECK_DEBUG_DEAD, rz_core_t::dbg, eprintf, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_break_pop(), rz_cons_break_push(), rz_core_dbg_follow_seek_register(), rz_core_static_debug_stop(), and rz_debug_continue_back().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_continue_call_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_continue_call_handler ( RzCore core,
int  argc,
const char **  argv 
)

◆ rz_cmd_debug_continue_exception_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_continue_exception_handler ( RzCore core,
int  argc,
const char **  argv 
)

◆ rz_cmd_debug_continue_execution_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_continue_execution_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3236 of file cmd_debug.c.

3236  {
3237  CMD_CHECK_DEBUG_DEAD(core);
3239 
3240  if (argc == 2) {
3241  int old_pid = core->dbg->pid;
3242  // using rz_num instead of atoi
3243  int pid = rz_num_math(core->num, argv[1]);
3244  rz_debug_select(core->dbg, pid, core->dbg->tid);
3245  rz_core_debug_continue(core);
3246  rz_debug_select(core->dbg, old_pid, core->dbg->tid);
3247  } else {
3248  rz_core_debug_continue(core);
3249  }
3250 
3253  return RZ_CMD_STATUS_OK;
3254 }
RZ_IPI void rz_core_debug_continue(RzCore *core)
Definition: cdebug.c:81

References argv, CMD_CHECK_DEBUG_DEAD, rz_core_t::dbg, rz_core_t::num, rz_debug_t::pid, pid, RZ_CMD_STATUS_OK, rz_cons_break_pop(), rz_cons_break_push(), rz_core_dbg_follow_seek_register(), rz_core_debug_continue(), rz_core_static_debug_stop(), rz_debug_select(), rz_num_math(), and rz_debug_t::tid.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_continue_fork_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_continue_fork_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3308 of file cmd_debug.c.

3308  {
3309  CMD_CHECK_DEBUG_DEAD(core);
3311 
3312  eprintf("[+] Running 'dcs vfork fork clone' behind the scenes...\n");
3313  // we should stop in fork, vfork, and clone syscalls
3314  cmd_debug_cont_syscall(core, "vfork fork clone");
3315 
3318  return RZ_CMD_STATUS_OK;
3319 }
static void cmd_debug_cont_syscall(RzCore *core, const char *_str)
Definition: cmd_debug.c:204

References CMD_CHECK_DEBUG_DEAD, cmd_debug_cont_syscall(), rz_core_t::dbg, eprintf, RZ_CMD_STATUS_OK, rz_cons_break_pop(), rz_cons_break_push(), rz_core_dbg_follow_seek_register(), and rz_core_static_debug_stop().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_continue_mapped_io_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_continue_mapped_io_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3347 of file cmd_debug.c.

3347  {
3348  CMD_CHECK_DEBUG_DEAD(core);
3350  RzIOMap *s;
3351  ut64 pc;
3352  int n = 0;
3353  bool t = core->dbg->trace->enabled;
3354  core->dbg->trace->enabled = false;
3356  do {
3357  rz_debug_step(core->dbg, 1);
3358  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_GPR, false);
3359  pc = rz_debug_reg_get(core->dbg, "PC");
3360  eprintf(" %d %" PFMT64x "\r", n++, pc);
3361  s = rz_io_map_get(core->io, pc);
3362  if (rz_cons_is_breaked()) {
3363  break;
3364  }
3365  } while (!s);
3366  eprintf("\n");
3367  core->dbg->trace->enabled = t;
3369  return RZ_CMD_STATUS_OK;
3370 }
RZ_API RzIOMap * rz_io_map_get(RzIO *io, ut64 addr)
Definition: io_map.c:176

References CMD_CHECK_DEBUG_DEAD, rz_core_t::dbg, rz_debug_trace_t::enabled, eprintf, rz_core_t::io, n, pc, PFMT64x, RZ_CMD_STATUS_OK, rz_cons_break_pop(), rz_cons_break_push(), rz_cons_is_breaked(), rz_core_static_debug_stop(), rz_debug_reg_get(), rz_debug_reg_sync(), rz_debug_step(), rz_io_map_get(), RZ_REG_TYPE_GPR, s, rz_debug_t::trace, and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_continue_ret_handler()

◆ rz_cmd_debug_continue_send_signal_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_continue_send_signal_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3322 of file cmd_debug.c.

3322  {
3323  CMD_CHECK_DEBUG_DEAD(core);
3325 
3326  rz_reg_arena_swap(core->dbg->reg, true);
3327  int signum = rz_num_math(core->num, argv[1]);
3328 
3329  if (argc == 3) {
3330  int old_pid = core->dbg->pid;
3331  int old_tid = core->dbg->tid;
3332  int pid = rz_num_math(core->num, argv[2]);
3333  int tid = pid; // XXX
3334  rz_debug_select(core->dbg, pid, tid);
3336  rz_debug_select(core->dbg, old_pid, old_tid);
3337  } else {
3339  }
3340 
3343  return RZ_CMD_STATUS_OK;
3344 }
RZ_API int rz_debug_continue_kill(RzDebug *dbg, int sig)
Definition: debug.c:1141
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync const char const char static newpath const char static pathname unsigned long static filedes void static end_data_segment signum
Definition: sflib.h:79

References argv, CMD_CHECK_DEBUG_DEAD, rz_core_t::dbg, rz_core_t::num, rz_debug_t::pid, pid, rz_debug_t::reg, RZ_CMD_STATUS_OK, rz_cons_break_pop(), rz_cons_break_push(), rz_core_dbg_follow_seek_register(), rz_core_static_debug_stop(), rz_debug_continue_kill(), rz_debug_select(), rz_num_math(), rz_reg_arena_swap(), signum, and rz_debug_t::tid.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_continue_syscall()

RZ_IPI int rz_cmd_debug_continue_syscall ( void *  data,
const char *  input 
)

Definition at line 3400 of file cmd_debug.c.

3400  {
3401  RzCore *core = (RzCore *)data;
3402  CMD_CHECK_DEBUG_DEAD(core);
3404  switch (input[0]) {
3405  case '*':
3406  cmd_debug_cont_syscall(core, "-1");
3407  break;
3408  case ' ':
3409  cmd_debug_cont_syscall(core, input + 2);
3410  break;
3411  case '\0':
3413  break;
3414  default:
3415  case '?':
3417  break;
3418  }
3421  return RZ_CMD_STATUS_OK;
3422 }
static const char * help_msg_dcs[]
Definition: cmd_debug.c:55

References CMD_CHECK_DEBUG_DEAD, cmd_debug_cont_syscall(), rz_core_t::dbg, help_msg_dcs, input(), NULL, RZ_CMD_STATUS_OK, rz_cons_break_pop(), rz_cons_break_push(), rz_core_cmd_help(), rz_core_dbg_follow_seek_register(), and rz_core_static_debug_stop().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_continue_traptrace_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_continue_traptrace_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3386 of file cmd_debug.c.

3386  {
3387  CMD_CHECK_DEBUG_DEAD(core);
3389  if (argc == 1) {
3390  cmd_debug_backtrace(core, 0);
3391  } else {
3392  cmd_debug_backtrace(core, rz_num_math(core->num, argv[1]));
3393  }
3396  return RZ_CMD_STATUS_OK;
3397 }
static void cmd_debug_backtrace(RzCore *core, ut64 len)
Definition: cmd_debug.c:774

References argv, CMD_CHECK_DEBUG_DEAD, cmd_debug_backtrace(), rz_core_t::dbg, rz_core_t::num, RZ_CMD_STATUS_OK, rz_cons_break_pop(), rz_cons_break_push(), rz_core_dbg_follow_seek_register(), rz_core_static_debug_stop(), and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_continue_unknown_call_handler()

◆ rz_cmd_debug_continue_until()

RZ_IPI int rz_cmd_debug_continue_until ( void *  data,
const char *  input 
)

Definition at line 3425 of file cmd_debug.c.

3425  {
3426  RzCore *core = (RzCore *)data;
3427  CMD_CHECK_DEBUG_DEAD(core);
3429  if (input[0] == '?') {
3431  } else if (input[0] == '.' || input[0] == '\0') {
3432  cmd_dcu(core, "cu $$");
3433  } else {
3434  char *tmpinp = rz_str_newf("cu %s", input + 1);
3435  cmd_dcu(core, tmpinp);
3436  free(tmpinp);
3437  }
3440  return RZ_CMD_STATUS_OK;
3441 }
static bool cmd_dcu(RzCore *core, const char *input)
Definition: cmd_debug.c:1947

References CMD_CHECK_DEBUG_DEAD, cmd_dcu(), rz_core_t::dbg, free(), help_msg_dcu, input(), RZ_CMD_STATUS_OK, rz_cons_break_pop(), rz_cons_break_push(), rz_core_cmd_help(), rz_core_dbg_follow_seek_register(), rz_core_static_debug_stop(), and rz_str_newf().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_current_modules_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_current_modules_handler ( RzCore core,
int  argc,
const char **  argv,
RzOutputMode  mode 
)

Definition at line 1045 of file cmd_debug.c.

1045  {
1046  CMD_CHECK_DEBUG_DEAD(core);
1048  return RZ_CMD_STATUS_OK;
1049 }
static void cmd_debug_current_modules(RzCore *core, RzOutputMode mode)
Definition: cmd_debug.c:861

References CMD_CHECK_DEBUG_DEAD, cmd_debug_current_modules(), and RZ_CMD_STATUS_OK.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_deallocate_map_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_deallocate_map_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1052 of file cmd_debug.c.

1052  {
1053  CMD_CHECK_DEBUG_DEAD(core);
1054  RzListIter *iter;
1055  RzDebugMap *map;
1056  ut64 addr = core->offset;
1057  rz_list_foreach (core->dbg->maps, iter, map) {
1058  if (addr >= map->addr && addr < map->addr_end) {
1059  rz_debug_map_dealloc(core->dbg, map);
1060  rz_debug_map_sync(core->dbg);
1061  return RZ_CMD_STATUS_OK;
1062  }
1063  }
1064  eprintf("The address doesn't match with any map.\n");
1065  return RZ_CMD_STATUS_ERROR;
1066 }
RZ_API int rz_debug_map_dealloc(RzDebug *dbg, RzDebugMap *map)
Definition: dmap.c:54

References addr, CMD_CHECK_DEBUG_DEAD, rz_core_t::dbg, eprintf, map(), rz_debug_t::maps, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_debug_map_dealloc(), rz_debug_map_sync(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_disable_bp_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_disable_bp_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2826 of file cmd_debug.c.

2826  {
2827  if (!rz_bp_enable(core->dbg->bp, core->offset, false, 1)) {
2828  RZ_LOG_ERROR("Failed to disable breakpoint at 0x%" PFMT64x "\n", core->offset);
2829  }
2830  return RZ_CMD_STATUS_OK;
2831 }
RZ_API RzBreakpointItem * rz_bp_enable(RzBreakpoint *bp, ut64 addr, int set, int count)
Definition: bp.c:152

References rz_debug_t::bp, rz_core_t::dbg, rz_core_t::offset, PFMT64x, rz_bp_enable(), RZ_CMD_STATUS_OK, and RZ_LOG_ERROR.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_disable_bp_index_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_disable_bp_index_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2949 of file cmd_debug.c.

2949  {
2950  RzBreakpointItem *bpi;
2951  int index = rz_num_math(core->num, argv[1]);
2952  bpi = rz_bp_get_index(core->dbg->bp, index);
2953  if (!bpi) {
2954  RZ_LOG_ERROR("Unable to find breakpoint with index %d\n", index);
2955  return RZ_CMD_STATUS_ERROR;
2956  }
2957  bpi->enabled = false;
2958  return RZ_CMD_STATUS_OK;
2959 }
RZ_API RzBreakpointItem * rz_bp_get_index(RzBreakpoint *bp, int idx)
Definition: bp.c:347
int enabled
Definition: rz_bp.h:53

References argv, rz_debug_t::bp, rz_core_t::dbg, rz_bp_item_t::enabled, rz_core_t::num, rz_bp_get_index(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, RZ_LOG_ERROR, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_disable_bp_trace_index_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_disable_bp_trace_index_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2988 of file cmd_debug.c.

2988  {
2989  RzBreakpointItem *bpi;
2990  int index = rz_num_math(core->num, argv[1]);
2991  bpi = rz_bp_get_index(core->dbg->bp, index);
2992  if (!bpi) {
2993  RZ_LOG_ERROR("Unable to find breakpoint with index %d\n", index);
2994  return RZ_CMD_STATUS_ERROR;
2995  }
2996  bpi->trace = false;
2997  return RZ_CMD_STATUS_OK;
2998 }

References argv, rz_debug_t::bp, rz_core_t::dbg, rz_core_t::num, rz_bp_get_index(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, RZ_LOG_ERROR, rz_num_math(), and rz_bp_item_t::trace.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_display_bt_ascii_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_display_bt_ascii_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3147 of file cmd_debug.c.

3147  {
3148  RzList *list = rz_debug_frames(core->dbg, UT64_MAX);
3149  if (!list) {
3150  RZ_LOG_ERROR("Unable to find debug backtrace frames\n");
3151  return RZ_CMD_STATUS_ERROR;
3152  }
3153  asciiart_backtrace(core, list);
3154  rz_list_free(list);
3155  return RZ_CMD_STATUS_OK;
3156 }
static void asciiart_backtrace(RzCore *core, RzList *frames)
Definition: cmd_debug.c:1514
RZ_API RzList * rz_debug_frames(RzDebug *dbg, ut64 at)
Definition: debug.c:1612

References asciiart_backtrace(), rz_core_t::dbg, list(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_debug_frames(), rz_list_free(), RZ_LOG_ERROR, and UT64_MAX.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_display_bt_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_display_bt_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 3037 of file cmd_debug.c.

3037  {
3039  if (!list) {
3040  RZ_LOG_ERROR("Unable to find debug backtrace frames\n");
3041  return RZ_CMD_STATUS_ERROR;
3042  }
3043  RzOutputMode mode = state->mode;
3044  if (mode == RZ_OUTPUT_MODE_RIZIN) {
3046  rz_cons_printf("f-bt.*\n");
3047  }
3048 
3049  int i = 0;
3050  RzListIter *iter;
3051  RzBacktrace *bt;
3052  PJ *pj = state->d.pj;
3054  rz_list_foreach (list, iter, bt) {
3055  switch (mode) {
3056  case RZ_OUTPUT_MODE_STANDARD: {
3057  rz_cons_printf("%d %s sp: %s %-5d"
3058  "[%s] %s %s\n",
3059  i++, bt->pcstr, bt->spstr, bt->frame->size, bt->fcn ? bt->fcn->name : "??", rz_str_get(bt->flagdesc), rz_str_get(bt->flagdesc2));
3060  break;
3061  }
3062  case RZ_OUTPUT_MODE_RIZIN: {
3063  rz_cons_printf("f bt.frame%d @ 0x%08" PFMT64x "\n", i, bt->frame->addr);
3064  rz_cons_printf("f bt.frame%d.stack %d @ 0x%08" PFMT64x "\n", i, bt->frame->size, bt->frame->sp);
3065  i++;
3066  break;
3067  }
3068  case RZ_OUTPUT_MODE_JSON: {
3069  pj_o(pj);
3070  pj_ki(pj, "idx", i);
3071  pj_kn(pj, "pc", bt->frame->addr);
3072  pj_kn(pj, "sp", bt->frame->sp);
3073  pj_ki(pj, "frame_size", bt->frame->size);
3074  pj_ks(pj, "fname", bt->fcn ? bt->fcn->name : "");
3075  pj_ks(pj, "desc", bt->desc);
3076  pj_end(pj);
3077  i++;
3078  break;
3079  }
3080  case RZ_OUTPUT_MODE_QUIET: {
3081  rz_cons_printf("%s\n", bt->pcstr);
3082  break;
3083  }
3084  default:
3086  break;
3087  }
3088  }
3090  rz_list_free(list);
3091  return RZ_CMD_STATUS_OK;
3092 }
RZ_API RZ_OWN RzList * rz_core_debug_backtraces(RzCore *core)
Get backtraces based on dbg.btdepth and dbg.btalgo.
Definition: cdebug.c:926
RZ_API void rz_list_reverse(RZ_NONNULL RzList *list)
Reverses the list.
Definition: list.c:477
#define rz_warn_if_reached()
Definition: rz_assert.h:29
RZ_API PJ * pj_ki(PJ *j, const char *k, int d)
Definition: pj.c:149
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

References rz_debug_frame_t::addr, rz_backtrace_t::desc, rz_backtrace_t::fcn, rz_backtrace_t::flagdesc, rz_backtrace_t::flagdesc2, rz_backtrace_t::frame, i, list(), rz_analysis_function_t::name, rz_backtrace_t::pcstr, PFMT64x, pj_end(), pj_ki(), pj_kn(), pj_ks(), pj_o(), rz_cmd_state_output_array_end(), rz_cmd_state_output_array_start(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_printf(), rz_core_debug_backtraces(), rz_list_free(), rz_list_reverse(), RZ_LOG_ERROR, RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_RIZIN, RZ_OUTPUT_MODE_STANDARD, rz_str_get(), rz_warn_if_reached, rz_debug_frame_t::size, rz_debug_frame_t::sp, and rz_backtrace_t::spstr.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_display_bt_local_vars_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_display_bt_local_vars_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3135 of file cmd_debug.c.

3135  {
3136  RzList *list = rz_debug_frames(core->dbg, UT64_MAX);
3137  if (!list) {
3138  RZ_LOG_ERROR("Unable to find debug backtrace frames\n");
3139  return RZ_CMD_STATUS_ERROR;
3140  }
3141  backtrace_vars(core, list);
3142  rz_list_free(list);
3143  return RZ_CMD_STATUS_OK;
3144 }
static void backtrace_vars(RzCore *core, RzList *frames)
Definition: cmd_debug.c:1453

References backtrace_vars(), rz_core_t::dbg, list(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_debug_frames(), rz_list_free(), RZ_LOG_ERROR, and UT64_MAX.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_display_bt_oneline_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_display_bt_oneline_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3095 of file cmd_debug.c.

3095  {
3096  int mode = 0;
3097  if (argc > 1) {
3098  if (!strcmp(argv[1], "b")) {
3099  mode = 1;
3100  } else if (!strcmp(argv[1], "s")) {
3101  mode = 2;
3102  }
3103  }
3104  RzList *list = rz_debug_frames(core->dbg, UT64_MAX);
3105  if (!list) {
3106  RZ_LOG_ERROR("Unable to find debug backtrace frames\n");
3107  return RZ_CMD_STATUS_ERROR;
3108  }
3109  int i = 0;
3110  RzListIter *iter;
3111  RzDebugFrame *frame;
3113  rz_list_foreach (list, iter, frame) {
3114  if (i != 0) {
3115  rz_cons_printf(" ");
3116  }
3117  switch (mode) {
3118  case 0:
3119  rz_cons_printf("0x08%" PFMT64x, frame->addr);
3120  break;
3121  case 1:
3122  rz_cons_printf("0x08%" PFMT64x, frame->bp);
3123  break;
3124  case 2:
3125  rz_cons_printf("0x08%" PFMT64x, frame->sp);
3126  break;
3127  }
3128  }
3129  rz_cons_newline();
3130  rz_list_free(list);
3131  return RZ_CMD_STATUS_OK;
3132 }
RZ_API void rz_cons_newline(void)
Definition: cons.c:1274

References rz_debug_frame_t::addr, argv, rz_debug_frame_t::bp, rz_core_t::dbg, i, list(), PFMT64x, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_newline(), rz_cons_printf(), rz_debug_frames(), rz_list_free(), rz_list_reverse(), RZ_LOG_ERROR, rz_debug_frame_t::sp, and UT64_MAX.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_dmi()

RZ_IPI int rz_cmd_debug_dmi ( void *  data,
const char *  input 
)

Definition at line 1117 of file cmd_debug.c.

1117  {
1118  RzCore *core = (RzCore *)data;
1119  CMD_CHECK_DEBUG_DEAD(core);
1120  RzListIter *iter;
1121  RzDebugMap *map;
1122  ut64 addr = core->offset;
1123  switch (input[0]) {
1124  case '\0': // "dmi" alias of "dmm"
1125  {
1126  RzCmdStateOutput state = { 0 };
1128  cmd_debug_modules(core, &state);
1131  rz_cons_flush();
1132  break;
1133  }
1134  case ' ': // "dmi "
1135  case '*': // "dmi*"
1136  case 'v': // "dmiv"
1137  case 'j': // "dmij"
1138  case 'q': // "dmiq"
1139  case 'a': // "dmia"
1140  {
1141  const char *libname = NULL, *symname = NULL, *a0;
1142  int mode;
1143  ut64 baddr = 0LL;
1144  char *ptr;
1145  int i = 1;
1146  bool symbols_only = true;
1147  if (input[0] == 'a') {
1148  symbols_only = false;
1149  input++;
1150  }
1151  PJ *pj = NULL;
1152  switch (input[0]) {
1153  case 's':
1154  mode = RZ_MODE_SET;
1155  break;
1156  case '*':
1158  break;
1159  case 'j':
1160  mode = RZ_MODE_JSON;
1161  pj = pj_new();
1162  if (!pj) {
1163  return false;
1164  }
1165  break;
1166  case 'q':
1167  mode = input[1] == 'q' ? input++, RZ_MODE_SIMPLEST : RZ_MODE_SIMPLE;
1168  break;
1169  default:
1170  mode = RZ_MODE_PRINT;
1171  break;
1172  }
1173  ptr = strdup(input[0] ? rz_str_trim_head_ro(input + 1) : "");
1174  if (!ptr || !*ptr) {
1175  rz_core_cmd(core, "dmm", 0);
1176  free(ptr);
1177  pj_free(pj);
1178  break;
1179  }
1180  if (symbols_only) {
1181  i = rz_str_word_set0(ptr);
1182  }
1183  switch (i) {
1184  case 2:
1185  symname = rz_str_word_get0(ptr, 1);
1186  // fall through
1187  case 1:
1188  a0 = rz_str_word_get0(ptr, 0);
1189  addr = rz_num_get(core->num, a0);
1190  if (!addr || addr == UT64_MAX) {
1191  libname = rz_str_word_get0(ptr, 0);
1192  }
1193  break;
1194  }
1195  if (libname && !addr) {
1196  addr = addroflib(core, rz_file_basename(libname));
1197  if (addr == UT64_MAX) {
1198  eprintf("Unknown library, or not found in dm\n");
1199  }
1200  }
1201  map = get_closest_map(core, addr);
1202  if (map) {
1203  RzCoreBinFilter filter;
1204  filter.offset = UT64_MAX;
1205  filter.name = (char *)symname;
1206  baddr = map->addr;
1207 
1208  if (libname) {
1209  const char *file = map->file ? map->file : map->name;
1210  char *newfile = NULL;
1211  if (!rz_file_exists(file)) {
1212  newfile = rz_file_temp("memlib");
1213  if (newfile) {
1214  file = newfile;
1215  rz_core_dump(core, file, baddr, map->size, false);
1216  }
1217  }
1218  get_bin_info(core, file, baddr, pj, mode, symbols_only, &filter);
1219  if (newfile) {
1220  if (!rz_file_rm(newfile)) {
1221  eprintf("Error when removing %s\n", newfile);
1222  }
1223  free(newfile);
1224  }
1225  } else {
1226  RzBinFile *bf = rz_bin_cur(core->bin);
1227  if (bf) {
1228  rz_bin_set_baddr(core->bin, map->addr);
1231  rz_core_bin_print(core, bf, RZ_CORE_BIN_ACC_SYMBOLS, &filter, &state, NULL);
1234  rz_bin_set_baddr(core->bin, baddr);
1235  }
1236  }
1237  }
1238  if (mode == RZ_MODE_JSON) {
1240  pj_free(pj);
1241  }
1242  free(ptr);
1243  } break;
1244  case '.': // "dmi."
1245  {
1246  map = get_closest_map(core, addr);
1247  if (map) {
1248  ut64 closest_addr = UT64_MAX;
1250  RzBinSymbol *symbol, *closest_symbol = NULL;
1251 
1252  rz_list_foreach (symbols, iter, symbol) {
1253  if (symbol->vaddr > addr) {
1254  if (symbol->vaddr - addr < closest_addr) {
1255  closest_addr = symbol->vaddr - addr;
1256  closest_symbol = symbol;
1257  }
1258  } else {
1259  if (addr - symbol->vaddr < closest_addr) {
1260  closest_addr = addr - symbol->vaddr;
1261  closest_symbol = symbol;
1262  }
1263  }
1264  }
1265  RzBinFile *bf = rz_bin_cur(core->bin);
1266  if (closest_symbol && bf) {
1267  RzCoreBinFilter filter;
1268  filter.offset = UT64_MAX;
1269  filter.name = (char *)closest_symbol->name;
1270 
1271  rz_bin_set_baddr(core->bin, map->addr);
1274  rz_core_bin_print(core, bf, RZ_CORE_BIN_ACC_SYMBOLS, &filter, &state, NULL);
1277  }
1278  }
1279  } break;
1280  default:
1282  break;
1283  }
1284  return RZ_CMD_STATUS_OK;
1285 }
RZ_DEPRECATE RZ_API RZ_BORROW RzList * rz_bin_get_symbols(RZ_NONNULL RzBin *bin)
Definition: bin.c:696
RZ_API void rz_bin_set_baddr(RzBin *bin, ut64 baddr)
Definition: bin.c:549
static ut64 baddr(RzBinFile *bf)
Definition: bin_any.c:58
RzList * symbols(RzBinFile *bf)
Definition: bin_ne.c:102
RZ_API bool rz_core_dump(RzCore *core, const char *file, ut64 addr, ut64 size, int append)
Definition: cio.c:50
RZ_API int rz_core_cmd(RzCore *core, const char *cstr, int log)
Definition: cmd.c:5328
static void cmd_debug_modules(RzCore *core, RzCmdStateOutput *state)
Definition: cmd_debug.c:888
static const char * help_msg_dmi[]
Definition: cmd_debug.c:133
static ut64 addroflib(RzCore *core, const char *libname)
Definition: cmd_debug.c:923
static bool get_bin_info(RzCore *core, const char *file, ut64 baseaddr, PJ *pj, int mode, bool symbols_only, RzCoreBinFilter *filter)
Definition: cmd_debug.c:980
static RzDebugMap * get_closest_map(RzCore *core, ut64 addr)
Definition: cmd_debug.c:945
RZ_API void rz_cons_flush(void)
Definition: cons.c:959
a0
Definition: insn-good.s.cs:704
static bool filter(RzParse *p, ut64 addr, RzFlag *f, RzAnalysisHint *hint, char *data, char *str, int len, bool big_endian)
Definition: filter.c:185
RZ_API char * rz_file_temp(const char *prefix)
Definition: file.c:1048
RZ_API bool rz_file_exists(const char *str)
Definition: file.c:192
RZ_API ut64 rz_num_get(RzNum *num, const char *str)
Definition: unum.c:172
RZ_API PJ * pj_new(void)
Definition: pj.c:25
RZ_API const char * pj_string(PJ *pj)
Definition: pj.c:57
RZ_API void pj_free(PJ *j)
Definition: pj.c:34
char * name
Definition: rz_bin.h:675

References a0, addr, addroflib(), baddr(), rz_core_t::bin, CMD_CHECK_DEBUG_DEAD, cmd_debug_modules(), eprintf, filter(), free(), get_bin_info(), get_closest_map(), help_msg_dmi, i, input(), map(), rz_bin_symbol_t::name, NULL, rz_core_t::num, rz_core_t::offset, pj_free(), pj_new(), pj_string(), rad2mode(), rz_bin_cur(), rz_bin_get_symbols(), rz_bin_set_baddr(), rz_cmd_state_output_fini(), rz_cmd_state_output_init(), rz_cmd_state_output_print(), RZ_CMD_STATUS_OK, rz_cons_flush(), rz_cons_println(), rz_core_bin_print(), rz_core_cmd(), rz_core_cmd_help(), rz_core_dump(), rz_file_basename(), rz_file_exists(), rz_file_rm(), rz_file_temp(), RZ_MODE_JSON, RZ_MODE_PRINT, RZ_MODE_RIZINCMD, RZ_MODE_SET, RZ_MODE_SIMPLE, RZ_MODE_SIMPLEST, rz_num_get(), RZ_OUTPUT_MODE_STANDARD, rz_str_trim_head_ro(), rz_str_word_get0(), rz_str_word_set0(), strdup(), symbols(), ut64(), UT64_MAX, and rz_bin_symbol_t::vaddr.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_dml_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_dml_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1374 of file cmd_debug.c.

1374  {
1375  CMD_CHECK_DEBUG_DEAD(core);
1376  RzListIter *iter;
1377  RzDebugMap *map;
1378  ut64 addr = core->offset;
1379  rz_debug_map_sync(core->dbg); // update process memory maps
1380  rz_list_foreach (core->dbg->maps, iter, map) {
1381  if (addr >= map->addr && addr < map->addr_end) {
1382  size_t sz;
1383  char *buf = rz_file_slurp(argv[1], &sz);
1384  // TODO: use mmap here. we need a portable implementation
1385  if (!buf) {
1386  eprintf("Cannot allocate 0x%08" PFMT64x " byte(s)\n", map->size);
1387  return RZ_CMD_STATUS_ERROR;
1388  }
1389  rz_io_write_at(core->io, map->addr, (const ut8 *)buf, sz);
1390  if (sz != map->size)
1391  eprintf("File size differs from region size (%" PFMT64u " vs %" PFMT64d ")\n",
1392  (ut64)sz, map->size);
1393  eprintf("Loaded %" PFMT64u " byte(s) into the map region at 0x%08" PFMT64x "\n",
1394  (ut64)sz, map->addr);
1395  free(buf);
1396  return RZ_CMD_STATUS_OK;
1397  }
1398  }
1399  eprintf("No debug region found here\n");
1400  return RZ_CMD_STATUS_ERROR;
1401 }
RZ_API bool rz_io_write_at(RzIO *io, ut64 addr, const ut8 *buf, int len)
Definition: io.c:358
#define PFMT64u
Definition: rz_types.h:395

References addr, argv, CMD_CHECK_DEBUG_DEAD, rz_core_t::dbg, eprintf, free(), rz_core_t::io, map(), rz_debug_t::maps, rz_core_t::offset, PFMT64d, PFMT64u, PFMT64x, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_debug_map_sync(), rz_file_slurp(), rz_io_write_at(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_dmL_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_dmL_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1404 of file cmd_debug.c.

1404  {
1405  CMD_CHECK_DEBUG_DEAD(core);
1406  int size;
1407  ut64 addr;
1408  addr = core->offset;
1409  size = (int)rz_num_math(core->num, argv[1]);
1410  rz_debug_map_alloc(core->dbg, addr, size, true);
1411  return RZ_CMD_STATUS_OK;
1412 }

References addr, argv, CMD_CHECK_DEBUG_DEAD, rz_core_t::dbg, int, rz_core_t::num, rz_core_t::offset, RZ_CMD_STATUS_OK, rz_debug_map_alloc(), rz_num_math(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_dmS_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_dmS_handler ( RzCore core,
int  argc,
const char **  argv,
RzOutputMode  m 
)

Definition at line 1318 of file cmd_debug.c.

1318  {
1319  CMD_CHECK_DEBUG_DEAD(core);
1320  RzListIter *iter;
1321  RzDebugMap *map;
1322  ut64 addr;
1323  const char *libname = NULL, *sectname = NULL, *mode = "";
1324  ut64 baddr = 0LL;
1325  if (m == RZ_OUTPUT_MODE_RIZIN) {
1326  mode = "-r ";
1327  }
1328  addr = UT64_MAX;
1329  if (argc == 3) {
1330  sectname = argv[2];
1331  }
1332  if (argc >= 2) {
1333  if (IS_DIGIT(*argv[1])) {
1334  const char *a0 = argv[1];
1335  addr = rz_num_math(core->num, a0);
1336  } else {
1337  addr = UT64_MAX;
1338  }
1339  if (!addr || addr == UT64_MAX) {
1340  libname = argv[1];
1341  }
1342  }
1343  rz_debug_map_sync(core->dbg); // update process memory maps
1345  rz_list_foreach (list, iter, map) {
1346  if ((!libname ||
1347  (addr != UT64_MAX && (addr >= map->addr && addr < map->addr_end)) ||
1348  (libname != NULL && (strstr(map->name, libname))))) {
1349  baddr = map->addr;
1350  char *res;
1351  const char *file = map->file ? map->file : map->name;
1352  char *name = rz_str_escape((char *)rz_file_basename(file));
1353  char *filesc = rz_str_escape(file);
1354  /* TODO: do not spawn. use RzBin API */
1355  if (sectname) {
1356  char *sect = rz_str_escape(sectname);
1357  res = rz_sys_cmd_strf("env RZ_BIN_PREFIX=\"%s\" rz-bin %s-B 0x%08" PFMT64x " -S \"%s\" | grep \"%s\"", name, mode, baddr, filesc, sect);
1358  free(sect);
1359  } else {
1360  res = rz_sys_cmd_strf("env RZ_BIN_PREFIX=\"%s\" rz-bin %s-B 0x%08" PFMT64x " -S \"%s\"", name, mode, baddr, filesc);
1361  }
1362  free(filesc);
1363  rz_cons_println(res);
1364  free(name);
1365  free(res);
1366  if (libname || addr != UT64_MAX) { // only single match requested
1367  break;
1368  }
1369  }
1370  }
1371  return RZ_CMD_STATUS_OK;
1372 }
#define IS_DIGIT(x)
Definition: rz_str_util.h:11
RZ_API char * rz_sys_cmd_strf(const char *cmd,...) RZ_PRINTF_CHECK(1
Definition: z80asm.h:102

References a0, addr, argv, baddr(), CMD_CHECK_DEBUG_DEAD, rz_core_t::dbg, free(), IS_DIGIT, list(), regress::m, map(), NULL, rz_core_t::num, PFMT64x, RZ_CMD_STATUS_OK, rz_cons_println(), rz_debug_map_sync(), rz_debug_modules_list(), rz_file_basename(), rz_num_math(), RZ_OUTPUT_MODE_RIZIN, rz_str_escape(), rz_sys_cmd_strf(), ut64(), and UT64_MAX.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_dump_maps_all_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_dump_maps_all_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1103 of file cmd_debug.c.

1103  {
1104  CMD_CHECK_DEBUG_DEAD(core);
1105  dump_maps(core, 0, NULL);
1106  return RZ_CMD_STATUS_OK;
1107 }
static int dump_maps(RzCore *core, int perm, const char *filename)
Definition: cmd_debug.c:810

References CMD_CHECK_DEBUG_DEAD, dump_maps(), NULL, and RZ_CMD_STATUS_OK.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_dump_maps_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_dump_maps_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1092 of file cmd_debug.c.

1092  {
1093  CMD_CHECK_DEBUG_DEAD(core);
1094  if (argc == 2) {
1095  dump_maps(core, -1, argv[1]);
1096  } else if (argc == 1) {
1097  dump_maps(core, -1, NULL);
1098  }
1099  return RZ_CMD_STATUS_OK;
1100 }

References argv, CMD_CHECK_DEBUG_DEAD, dump_maps(), NULL, and RZ_CMD_STATUS_OK.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_dump_maps_writable_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_dump_maps_writable_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1110 of file cmd_debug.c.

1110  {
1111  CMD_CHECK_DEBUG_DEAD(core);
1112  dump_maps(core, RZ_PERM_RW, NULL);
1113  return RZ_CMD_STATUS_OK;
1114 }
#define RZ_PERM_RW
Definition: rz_types.h:96

References CMD_CHECK_DEBUG_DEAD, dump_maps(), NULL, RZ_CMD_STATUS_OK, and RZ_PERM_RW.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_enable_bp_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_enable_bp_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2834 of file cmd_debug.c.

2834  {
2835  if (!rz_bp_enable(core->dbg->bp, core->offset, true, 1)) { // correct value of count?
2836  RZ_LOG_ERROR("Failed to enable breakpoint at 0x%" PFMT64x "\n", core->offset);
2837  }
2838  return RZ_CMD_STATUS_OK;
2839 }

References rz_debug_t::bp, rz_core_t::dbg, rz_core_t::offset, PFMT64x, rz_bp_enable(), RZ_CMD_STATUS_OK, and RZ_LOG_ERROR.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_enable_bp_index_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_enable_bp_index_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2936 of file cmd_debug.c.

2936  {
2937  RzBreakpointItem *bpi;
2938  int index = rz_num_math(core->num, argv[1]);
2939  bpi = rz_bp_get_index(core->dbg->bp, index);
2940  if (!bpi) {
2941  RZ_LOG_ERROR("Unable to find breakpoint with index %d\n", index);
2942  return RZ_CMD_STATUS_ERROR;
2943  }
2944  bpi->enabled = true;
2945  return RZ_CMD_STATUS_OK;
2946 }

References argv, rz_debug_t::bp, rz_core_t::dbg, rz_bp_item_t::enabled, rz_core_t::num, rz_bp_get_index(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, RZ_LOG_ERROR, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_enable_bp_trace_index_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_enable_bp_trace_index_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2975 of file cmd_debug.c.

2975  {
2976  RzBreakpointItem *bpi;
2977  int index = rz_num_math(core->num, argv[1]);
2978  bpi = rz_bp_get_index(core->dbg->bp, index);
2979  if (!bpi) {
2980  RZ_LOG_ERROR("Unable to find breakpoint with index %d\n", index);
2981  return RZ_CMD_STATUS_ERROR;
2982  }
2983  bpi->trace = true;
2984  return RZ_CMD_STATUS_OK;
2985 }

References argv, rz_debug_t::bp, rz_core_t::dbg, rz_core_t::num, rz_bp_get_index(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, RZ_LOG_ERROR, rz_num_math(), and rz_bp_item_t::trace.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_handler_list_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_handler_list_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 3443 of file cmd_debug.c.

3443  {
3444  return rz_core_debug_plugins_print(core, state);
3445 }
RZ_API RzCmdStatus rz_core_debug_plugins_print(RzCore *core, RzCmdStateOutput *state)
Definition: cdebug.c:329

References rz_core_debug_plugins_print().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_handler_set_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_handler_set_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3447 of file cmd_debug.c.

3447  {
3448  return bool2status(rz_config_set(core->config, "dbg.backend", argv[1]));
3449 }
RZ_API RzConfigNode * rz_config_set(RzConfig *cfg, RZ_NONNULL const char *name, const char *value)
Definition: config.c:267
static RzCmdStatus bool2status(bool val)
Definition: core_private.h:208

References argv, bool2status(), rz_core_t::config, and rz_config_set().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_heap_jemalloc()

RZ_IPI int rz_cmd_debug_heap_jemalloc ( void *  data,
const char *  input 
)

Definition at line 1415 of file cmd_debug.c.

1415  {
1416  RzCore *core = (RzCore *)data;
1417  CMD_CHECK_DEBUG_DEAD(core);
1418 #if HAVE_JEMALLOC
1419  if (core->rasm->bits == 64) {
1420  return cmd_dbg_map_jemalloc_64(core, input);
1421  } else {
1422  return cmd_dbg_map_jemalloc_32(core, input);
1423  }
1424 #endif
1425  return RZ_CMD_STATUS_ERROR;
1426 }
int bits
Definition: rz_asm.h:100

References rz_asm_t::bits, CMD_CHECK_DEBUG_DEAD, input(), rz_core_t::rasm, and RZ_CMD_STATUS_ERROR.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_list_bp_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_list_bp_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 2697 of file cmd_debug.c.

2697  {
2700  RzListIter *iter;
2701  PJ *pj = state->d.pj;
2702  RzTable *t = state->d.t;
2704  rz_cmd_state_output_set_columnsf(state, "XXdsssssssss", "start", "end", "size",
2705  "perm", "hwsw", "type", "state", "valid", "cmd", "cond", "name", "module");
2706 
2707  rz_list_foreach (core->dbg->bp->bps, iter, b) {
2708  switch (state->mode) {
2710  rz_cons_printf("0x%08" PFMT64x " - 0x%08" PFMT64x
2711  " %d %s %s %s %s %s cmd=\"%s\" cond=\"%s\" "
2712  "name=\"%s\" module=\"%s\"\n",
2713  b->addr, b->addr + b->size, b->size,
2714  rz_str_rwx_i(b->perm),
2715  b->hw ? "hw" : "sw",
2716  b->trace ? "trace" : "break",
2717  b->enabled ? "enabled" : "disabled",
2718  rz_bp_is_valid(core->dbg->bp, b) ? "valid" : "invalid",
2719  rz_str_get(b->data),
2720  rz_str_get(b->cond),
2721  rz_str_get(b->name),
2722  rz_str_get(b->module_name));
2723  break;
2724  case RZ_OUTPUT_MODE_TABLE:
2725  rz_table_add_rowf(t, "XXdsssssssss", b->addr, b->addr + b->size, b->size,
2726  rz_str_rwx_i(b->perm), b->hw ? "hw" : "sw", b->trace ? "trace" : "break",
2727  b->enabled ? "enabled" : "disabled", rz_bp_is_valid(core->dbg->bp, b) ? "valid" : "invalid",
2728  rz_str_get(b->data), rz_str_get(b->cond), rz_str_get(b->name), rz_str_get(b->module_name));
2729  break;
2730  case RZ_OUTPUT_MODE_RIZIN:
2731  if (b->module_name) {
2732  rz_cons_printf("dbm %s %" PFMT64d "\n", b->module_name, b->module_delta);
2733  } else {
2734  rz_cons_printf("db @ 0x%08" PFMT64x "\n", b->addr);
2735  }
2736  break;
2737  case RZ_OUTPUT_MODE_JSON:
2738  pj_o(pj);
2739  pj_kN(pj, "addr", b->addr);
2740  pj_ki(pj, "size", b->size);
2741  pj_ks(pj, "perm", rz_str_rwx_i(b->perm));
2742  pj_kb(pj, "hw", b->hw);
2743  pj_kb(pj, "trace", b->trace);
2744  pj_kb(pj, "enabled", b->enabled);
2745  pj_kb(pj, "valid", rz_bp_is_valid(core->dbg->bp, b));
2746  pj_ks(pj, "data", rz_str_get(b->data));
2747  pj_ks(pj, "cond", rz_str_get(b->cond));
2748  pj_end(pj);
2749  break;
2750  case RZ_OUTPUT_MODE_QUIET:
2751  rz_cons_printf("0x%08" PFMT64x "\n", b->addr);
2752  break;
2753  default:
2755  break;
2756  }
2757  }
2759 
2760  return RZ_CMD_STATUS_OK;
2761 }
RZ_API bool rz_bp_is_valid(RzBreakpoint *bp, RzBreakpointItem *b)
Definition: bp.c:406
RZ_API void rz_cmd_state_output_set_columnsf(RzCmdStateOutput *state, const char *fmt,...)
Specify the columns of the command output.
Definition: cmd_api.c:2589
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API PJ * pj_kb(PJ *j, const char *k, bool v)
Definition: pj.c:177
RZ_API PJ * pj_kN(PJ *j, const char *k, st64 n)
Definition: pj.c:128
RZ_API void rz_table_add_rowf(RzTable *t, const char *fmt,...)
Definition: table.c:316
@ RZ_OUTPUT_MODE_TABLE
Definition: rz_types.h:46

References b, rz_debug_t::bp, rz_bp_t::bps, rz_core_t::dbg, PFMT64d, PFMT64x, pj_end(), pj_kb(), pj_ki(), pj_kN(), pj_ks(), pj_o(), rz_bp_is_valid(), rz_cmd_state_output_array_end(), rz_cmd_state_output_array_start(), rz_cmd_state_output_set_columnsf(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_printf(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_QUIET, RZ_OUTPUT_MODE_RIZIN, RZ_OUTPUT_MODE_STANDARD, RZ_OUTPUT_MODE_TABLE, rz_return_val_if_fail, rz_str_get(), rz_str_rwx_i(), rz_table_add_rowf(), and rz_warn_if_reached.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_list_bp_indexes_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_list_bp_indexes_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2892 of file cmd_debug.c.

2892  {
2893  RzBreakpointItem *bpi;
2894  RzListIter *iter;
2895  unsigned int index = 0;
2896  rz_list_foreach (core->dbg->bp->bps, iter, bpi) {
2897  if (!bpi) {
2898  RZ_LOG_ERROR("Unable to find breakpoint at index %d\n", index);
2899  } else {
2900  rz_cons_printf("%d 0x%08" PFMT64x " E:%d T:%d\n", index, bpi->addr, bpi->enabled, bpi->trace);
2901  }
2902  index++;
2903  }
2904  return RZ_CMD_STATUS_OK;
2905 }

References rz_bp_item_t::addr, rz_debug_t::bp, rz_bp_t::bps, rz_core_t::dbg, rz_bp_item_t::enabled, PFMT64x, RZ_CMD_STATUS_OK, rz_cons_printf(), RZ_LOG_ERROR, and rz_bp_item_t::trace.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_list_maps_ascii_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_list_maps_ascii_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1069 of file cmd_debug.c.

1069  {
1070  CMD_CHECK_DEBUG_DEAD(core);
1071  rz_debug_map_sync(core->dbg);
1072  rz_debug_map_list_visual(core->dbg, core->offset, argv[0] + 2,
1073  rz_config_get_i(core->config, "scr.color"));
1074  return RZ_CMD_STATUS_OK;
1075 }
RZ_API void rz_debug_map_list_visual(RzDebug *dbg, ut64 addr, const char *input, int colors)
Definition: cdebug.c:638

References argv, CMD_CHECK_DEBUG_DEAD, rz_core_t::config, rz_core_t::dbg, rz_core_t::offset, RZ_CMD_STATUS_OK, rz_config_get_i(), rz_debug_map_list_visual(), and rz_debug_map_sync().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_list_maps_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_list_maps_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 1021 of file cmd_debug.c.

1021  {
1022  CMD_CHECK_DEBUG_DEAD(core);
1023  rz_debug_map_sync(core->dbg); // update process memory maps
1024  rz_core_debug_map_print(core, core->offset, state);
1025  return RZ_CMD_STATUS_OK;
1026 }
RZ_API void rz_core_debug_map_print(RzCore *core, ut64 addr, RzCmdStateOutput *state)
Definition: cdebug.c:481

References CMD_CHECK_DEBUG_DEAD, rz_core_t::dbg, rz_core_t::offset, RZ_CMD_STATUS_OK, rz_core_debug_map_print(), and rz_debug_map_sync().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_list_trace_session_mmap_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_list_trace_session_mmap_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2242 of file cmd_debug.c.

2242  {
2243  if (core->dbg->session) {
2245  }
2246  return RZ_CMD_STATUS_OK;
2247 }
RZ_API void rz_debug_session_list_memory(RzDebug *dbg)
Definition: dsession.c:185
RzDebugSession * session
Definition: rz_debug.h:311

References rz_core_t::dbg, RZ_CMD_STATUS_OK, rz_debug_session_list_memory(), and rz_debug_t::session.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_load_trace_session_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_load_trace_session_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2231 of file cmd_debug.c.

2231  {
2232  if (core->dbg->session) {
2234  core->dbg->session = NULL;
2235  }
2236  core->dbg->session = rz_debug_session_new();
2237  rz_debug_session_load(core->dbg, argv[1]);
2238  return RZ_CMD_STATUS_OK;
2239 }
RZ_API void rz_debug_session_free(RzDebugSession *session)
Definition: dsession.c:11
RZ_API RzDebugSession * rz_debug_session_new(void)
Definition: dsession.c:33
RZ_API bool rz_debug_session_load(RzDebug *dbg, const char *path)
Definition: dsession.c:727

References argv, rz_core_t::dbg, NULL, RZ_CMD_STATUS_OK, rz_debug_session_free(), rz_debug_session_load(), rz_debug_session_new(), and rz_debug_t::session.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_map_current_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_map_current_handler ( RzCore core,
int  argc,
const char **  argv 
)

◆ rz_cmd_debug_modules_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_modules_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 1038 of file cmd_debug.c.

1038  {
1039  CMD_CHECK_DEBUG_DEAD(core);
1040  cmd_debug_modules(core, state);
1041  return RZ_CMD_STATUS_OK;
1042 }

References CMD_CHECK_DEBUG_DEAD, cmd_debug_modules(), and RZ_CMD_STATUS_OK.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_name_bp_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_name_bp_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2865 of file cmd_debug.c.

2865  {
2866  RzBreakpointItem *bp = rz_bp_get_at(core->dbg->bp, core->offset);
2867  if (!bp) {
2868  RZ_LOG_ERROR("No breakpoint found at 0x%08" PFMT64x "\n", core->offset);
2869  return RZ_CMD_STATUS_ERROR;
2870  } else if (argc == 1) {
2871  if (bp->name) {
2872  rz_cons_println(bp->name);
2873  }
2874  } else if (argc == 2) {
2875  rz_bp_item_set_name(bp, argv[1]);
2876  }
2877  return RZ_CMD_STATUS_OK;
2878 }
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
char * name
Definition: rz_bp.h:42

References argv, rz_debug_t::bp, rz_core_t::dbg, rz_bp_item_t::name, rz_core_t::offset, PFMT64x, rz_bp_get_at(), rz_bp_item_set_name(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_println(), and RZ_LOG_ERROR.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_process_close_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_process_close_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3497 of file cmd_debug.c.

3497  {
3498  CMD_CHECK_DEBUG_DEAD(core);
3500 }
RZ_API bool rz_core_debug_process_close(RzCore *core)
Close debug process (Kill debugee and all child processes)
Definition: cdebug.c:707

References bool2status(), CMD_CHECK_DEBUG_DEAD, and rz_core_debug_process_close().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_process_profile_edit_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_process_profile_edit_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3485 of file cmd_debug.c.

3485  {
3486  char *out = rz_core_editor(core, NULL, core->io->envprofile);
3487  if (!out) {
3488  return RZ_CMD_STATUS_ERROR;
3489  }
3490  free(core->io->envprofile);
3491  core->io->envprofile = out;
3492  rz_cons_printf("%s\n", core->io->envprofile);
3493  return RZ_CMD_STATUS_OK;
3494 }
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
RZ_API RZ_OWN char * rz_core_editor(const RzCore *core, RZ_NULLABLE const char *file, RZ_NULLABLE const char *str)
Definition: core.c:3214
char * envprofile
Definition: rz_io.h:82

References rz_io_t::envprofile, free(), rz_core_t::io, NULL, out, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_printf(), and rz_core_editor().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_process_profile_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_process_profile_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3452 of file cmd_debug.c.

3452  {
3453  RzList *list = rz_list_new();
3454  int i;
3455  for (i = 1; i < argc; i++) {
3456  RzList *l = rz_str_split_duplist_n(argv[i], "=", 1, false);
3457  if (!l) {
3458  rz_list_free(list);
3459  return RZ_CMD_STATUS_ERROR;
3460  }
3461  size_t llen = rz_list_length(l);
3462  if (llen < 2) {
3463  rz_list_free(list);
3464  rz_list_free(l);
3465  return RZ_CMD_STATUS_ERROR;
3466  }
3467  char *key = rz_list_get_n(l, 0);
3468  char *val = rz_list_get_n(l, 1);
3469  if (RZ_STR_ISEMPTY(key) || RZ_STR_ISEMPTY(val)) {
3470  RZ_LOG_ERROR("Make sure to use the format <key>=<value> without spaces.\n");
3471  rz_list_free(l);
3472  continue;
3473  }
3474  rz_list_append(list, (void *)argv[i]);
3475  rz_list_free(l);
3476  }
3477  char *str = rz_list_to_str(list, '\n');
3478  set_profile_string(core, str);
3479  free(str);
3480  rz_list_free(list);
3481  return RZ_CMD_STATUS_OK;
3482 }
ut16 val
Definition: armass64_const.h:6
static void set_profile_string(RzCore *core, const char *str)
Definition: cmd_debug.c:192
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 key
Definition: sflib.h:118
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 char * rz_list_to_str(RZ_NONNULL RzList *list, char ch)
Casts a RzList containg strings into a concatenated string.
Definition: list.c:785
RZ_API RZ_BORROW void * rz_list_get_n(RZ_NONNULL const RzList *list, ut32 n)
Returns the N-th element of the list.
Definition: list.c:574
RZ_API ut32 rz_list_length(RZ_NONNULL const RzList *list)
Returns the length of the list.
Definition: list.c:109
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
#define RZ_STR_ISEMPTY(x)
Definition: rz_str.h:67
RZ_API RzList * rz_str_split_duplist_n(const char *str, const char *c, int n, bool trim)
Split the string str according to the substring c and returns a RzList with the result.
Definition: str.c:3485

References argv, free(), i, key, list(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_list_append(), rz_list_free(), rz_list_get_n(), rz_list_length(), rz_list_new(), rz_list_to_str(), RZ_LOG_ERROR, RZ_STR_ISEMPTY, rz_str_split_duplist_n(), set_profile_string(), cmd_descs_generate::str, and val.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_remove_all_bp_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_remove_all_bp_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2778 of file cmd_debug.c.

2778  {
2779  if (!rz_bp_del_all(core->dbg->bp)) {
2780  RZ_LOG_ERROR("Failed to delete all breakpoints\n");
2781  return RZ_CMD_STATUS_ERROR;
2782  }
2783  return RZ_CMD_STATUS_OK;
2784 }
RZ_API bool rz_bp_del_all(RzBreakpoint *bp)
Definition: bp.c:303

References rz_debug_t::bp, rz_core_t::dbg, rz_bp_del_all(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, and RZ_LOG_ERROR.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_remove_bp_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_remove_bp_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2770 of file cmd_debug.c.

2770  {
2771  if (!rz_bp_del(core->dbg->bp, core->offset)) {
2772  RZ_LOG_ERROR("Failed to delete breakpoint at 0x%" PFMT64x "\n", core->offset);
2773  }
2774  return RZ_CMD_STATUS_OK;
2775 }

References rz_debug_t::bp, rz_core_t::dbg, rz_core_t::offset, PFMT64x, rz_bp_del(), RZ_CMD_STATUS_OK, and RZ_LOG_ERROR.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_remove_bp_index_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_remove_bp_index_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2908 of file cmd_debug.c.

2908  {
2909  ut64 addr;
2910  for (int i = 1; i < argc; i++) {
2911  addr = rz_num_math(core->num, argv[i]);
2912  if (!rz_bp_del_index(core->dbg->bp, addr)) {
2913  RZ_LOG_ERROR("No breakpoint found at %" PFMT64x "\n", addr);
2914  }
2915  }
2916  return RZ_CMD_STATUS_OK;
2917 }
RZ_API int rz_bp_del_index(RzBreakpoint *bp, int idx)
Definition: bp.c:364

References addr, argv, rz_debug_t::bp, rz_core_t::dbg, i, rz_core_t::num, PFMT64x, rz_bp_del_index(), RZ_CMD_STATUS_OK, RZ_LOG_ERROR, rz_num_math(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_remove_bp_plugin_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_remove_bp_plugin_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3027 of file cmd_debug.c.

3027  {
3028  for (int i = 1; i < argc; i++) {
3029  if (!rz_bp_plugin_del(core->dbg->bp, argv[i])) {
3030  RZ_LOG_ERROR("Failed to delete breakpoint plugin handler: %s\n", argv[i]);
3031  }
3032  }
3033  return RZ_CMD_STATUS_OK;
3034 }
RZ_API int rz_bp_plugin_del(RzBreakpoint *bp, const char *name)
Definition: bp_plugin.c:6

References argv, rz_debug_t::bp, rz_core_t::dbg, i, rz_bp_plugin_del(), RZ_CMD_STATUS_OK, and RZ_LOG_ERROR.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_run_command_bp_index_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_run_command_bp_index_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2928 of file cmd_debug.c.

2928  {
2929  int index = rz_num_math(core->num, argv[1]);
2930  RzBreakpointItem *bpi = rz_bp_get_index(core->dbg->bp, index);
2931  rz_bp_item_set_data(bpi, argv[2]);
2932  return RZ_CMD_STATUS_OK;
2933 }

References argv, rz_debug_t::bp, rz_core_t::dbg, rz_core_t::num, rz_bp_get_index(), rz_bp_item_set_data(), RZ_CMD_STATUS_OK, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_save_trace_session_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_save_trace_session_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2221 of file cmd_debug.c.

2221  {
2222  if (!core->dbg->session) {
2223  RZ_LOG_ERROR("No session started\n");
2224  return RZ_CMD_STATUS_ERROR;
2225  }
2226  rz_debug_session_save(core->dbg->session, argv[1]);
2227  return RZ_CMD_STATUS_OK;
2228 }
RZ_API bool rz_debug_session_save(RzDebugSession *session, const char *path)
Definition: dsession.c:445

References argv, rz_core_t::dbg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_debug_session_save(), RZ_LOG_ERROR, and rz_debug_t::session.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_set_cond_bp_win_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_set_cond_bp_win_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3215 of file cmd_debug.c.

3215  {
3216 #if __WINDOWS__
3217  bool res;
3218  if (argc > 2) {
3219  res = rz_w32_add_winmsg_breakpoint(core->dbg, argv[1], argv[2]);
3220  } else {
3221  res = rz_w32_add_winmsg_breakpoint(core->dbg, argv[1], NULL);
3222  }
3223  if (res) {
3224  rz_cons_print("Breakpoint set.\n");
3225  } else {
3226  rz_cons_print("Breakpoint not set.\n");
3227  }
3228 #else
3229  RZ_LOG_ERROR("This command is only meant for Windows systems and cannot be used by your system\n");
3230 #endif
3231 
3232  return RZ_CMD_STATUS_OK;
3233 }
RZ_API bool rz_w32_add_winmsg_breakpoint(RzDebug *dbg, const char *msg_name, const char *window_id)

References argv, rz_core_t::dbg, NULL, RZ_CMD_STATUS_OK, RZ_LOG_ERROR, and rz_w32_add_winmsg_breakpoint().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_set_expr_bp_index_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_set_expr_bp_index_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2920 of file cmd_debug.c.

2920  {
2921  int index = rz_num_math(core->num, argv[1]);
2922  RzBreakpointItem *bpi = rz_bp_get_index(core->dbg->bp, index);
2923  rz_bp_item_set_expr(bpi, argv[2]);
2924  return RZ_CMD_STATUS_OK;
2925 }

References argv, rz_debug_t::bp, rz_core_t::dbg, rz_core_t::num, rz_bp_get_index(), rz_bp_item_set_expr(), RZ_CMD_STATUS_OK, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_show_bp_index_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_show_bp_index_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2881 of file cmd_debug.c.

2881  {
2882  const int index = rz_bp_get_index_at(core->dbg->bp, core->offset);
2883  if (index == -1) {
2884  RZ_LOG_ERROR("No breakpoint found at %" PFMT64x "\n", core->offset);
2885  } else {
2886  rz_cons_printf("%d\n", index);
2887  }
2888  return RZ_CMD_STATUS_OK;
2889 }
RZ_API int rz_bp_get_index_at(RzBreakpoint *bp, ut64 addr)
Definition: bp.c:354

References rz_debug_t::bp, rz_core_t::dbg, rz_core_t::offset, PFMT64x, rz_bp_get_index_at(), RZ_CMD_STATUS_OK, rz_cons_printf(), and RZ_LOG_ERROR.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_show_cur_bp_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_show_cur_bp_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2787 of file cmd_debug.c.

2787  {
2788  RzBreakpointItem *cur = rz_bp_get_at(core->dbg->bp, core->offset);
2789  if (!cur) {
2790  rz_cons_printf("No breakpoint found at current offset (0x%" PFMT64x ")\n", core->offset);
2791  return RZ_CMD_STATUS_ERROR;
2792  }
2793  rz_cons_printf("breakpoint %s %s %s\n", rz_str_rwx_i(cur->perm), cur->enabled ? "enabled" : "disabled", cur->name ? cur->name : "");
2794  return RZ_CMD_STATUS_OK;
2795 }
int perm
Definition: rz_bp.h:49

References rz_debug_t::bp, rz_core_t::dbg, rz_bp_item_t::enabled, rz_bp_item_t::name, rz_core_t::offset, rz_bp_item_t::perm, PFMT64x, rz_bp_get_at(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_printf(), and rz_str_rwx_i().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_start_trace_session_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_start_trace_session_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2195 of file cmd_debug.c.

2195  {
2196  if (rz_debug_is_dead(core->dbg)) {
2197  RZ_LOG_ERROR("Cannot start session outside of debug mode, run ood?\n");
2198  return RZ_CMD_STATUS_ERROR;
2199  }
2200  if (core->dbg->session) {
2201  RZ_LOG_ERROR("Session already started\n");
2202  return RZ_CMD_STATUS_ERROR;
2203  }
2204  core->dbg->session = rz_debug_session_new();
2206  return RZ_CMD_STATUS_OK;
2207 }
RZ_API bool rz_debug_add_checkpoint(RzDebug *dbg)
Definition: dsession.c:58

References rz_core_t::dbg, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_debug_add_checkpoint(), rz_debug_is_dead(), rz_debug_session_new(), RZ_LOG_ERROR, and rz_debug_t::session.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_step_back_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_step_back_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3511 of file cmd_debug.c.

3511  {
3512  CMD_CHECK_DEBUG_DEAD(core);
3513  const int times = (int)rz_num_math(core->num, argv[1]);
3514  bool ret = rz_core_debug_step_back(core, times);
3516  return bool2status(ret);
3517 }
RZ_API bool rz_core_debug_step_back(RzCore *core, int steps)
Step back.
Definition: cdebug.c:777
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

References argv, bool2status(), CMD_CHECK_DEBUG_DEAD, int, rz_core_t::num, rz_core_dbg_follow_seek_register(), rz_core_debug_step_back(), rz_num_math(), and times.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_step_cond_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_step_cond_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3528 of file cmd_debug.c.

3528  {
3529  CMD_CHECK_DEBUG_DEAD(core);
3530  int n = 0;
3532  do {
3533  if (rz_cons_is_breaked()) {
3534  break;
3535  }
3536  rz_debug_step(core->dbg, 1);
3537  if (rz_debug_is_dead(core->dbg)) {
3538  core->break_loop = true;
3539  break;
3540  }
3542  n++;
3543  } while (!rz_num_conditional(core->num, argv[1]));
3545  RZ_LOG_INFO("stopped after %d instructions\n", n);
3547  return RZ_CMD_STATUS_OK;
3548 }
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
#define RZ_LOG_INFO(fmtstr,...)
Definition: rz_log.h:54
RZ_API int rz_num_conditional(RzNum *num, const char *str)
Definition: unum.c:603
bool break_loop
Definition: rz_core.h:373

References argv, rz_core_t::break_loop, CMD_CHECK_DEBUG_DEAD, rz_core_t::dbg, n, rz_core_t::num, RZ_CMD_STATUS_OK, rz_cons_break_pop(), rz_cons_break_push(), rz_cons_is_breaked(), rz_core_dbg_follow_seek_register(), rz_core_reg_update_flags(), rz_core_static_debug_stop(), rz_debug_is_dead(), rz_debug_step(), RZ_LOG_INFO, and rz_num_conditional().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_step_frame_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_step_frame_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3520 of file cmd_debug.c.

3520  {
3521  CMD_CHECK_DEBUG_DEAD(core);
3522  bool ret = rz_core_debug_step_until_frame(core);
3524  return bool2status(ret);
3525 }
RZ_API bool rz_core_debug_step_until_frame(RzCore *core)
Step until end of frame.
Definition: cdebug.c:745

References bool2status(), CMD_CHECK_DEBUG_DEAD, rz_core_dbg_follow_seek_register(), and rz_core_debug_step_until_frame().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_step_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_step_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3503 of file cmd_debug.c.

3503  {
3504  const int times = (int)rz_num_math(core->num, argv[1]);
3505  bool ret = rz_core_debug_step_one(core, times);
3507  return bool2status(ret);
3508 }
RZ_API bool rz_core_debug_step_one(RzCore *core, int times)
Definition: cdebug.c:56

References argv, bool2status(), int, rz_core_t::num, rz_core_dbg_follow_seek_register(), rz_core_debug_step_one(), rz_num_math(), and times.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_step_line_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_step_line_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3551 of file cmd_debug.c.

3551  {
3552  CMD_CHECK_DEBUG_DEAD(core);
3553  const int times = (int)rz_num_math(core->num, argv[1]);
3554  rz_reg_arena_swap(core->dbg->reg, true);
3555  bool ret = step_line(core, times);
3557  return bool2status(ret);
3558 }
static bool step_line(RzCore *core, int times)
Definition: cmd_debug.c:598

References argv, bool2status(), CMD_CHECK_DEBUG_DEAD, rz_core_t::dbg, int, rz_core_t::num, rz_debug_t::reg, rz_core_dbg_follow_seek_register(), rz_num_math(), rz_reg_arena_swap(), step_line(), and times.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_step_over_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_step_over_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3561 of file cmd_debug.c.

3561  {
3562  CMD_CHECK_DEBUG_DEAD(core);
3563  const int times = (int)rz_num_math(core->num, argv[1]);
3564  bool ret = rz_core_debug_step_over(core, times);
3566  return bool2status(ret);
3567 }
RZ_API bool rz_core_debug_step_over(RzCore *core, int steps)
Step over.
Definition: cdebug.c:802

References argv, bool2status(), CMD_CHECK_DEBUG_DEAD, int, rz_core_t::num, rz_core_dbg_follow_seek_register(), rz_core_debug_step_over(), rz_num_math(), and times.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_step_prog_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_step_prog_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3570 of file cmd_debug.c.

3570  {
3571  CMD_CHECK_DEBUG_DEAD(core);
3572  const int times = (int)rz_num_math(core->num, argv[1]);
3573  rz_reg_arena_swap(core->dbg->reg, true);
3574  ut8 buf[64];
3575  for (int i = 0; i < times; i++) {
3576  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_GPR, false);
3577  ut64 addr = rz_debug_reg_get(core->dbg, "PC");
3578  rz_io_read_at(core->io, addr, buf, sizeof(buf));
3579  RzAnalysisOp aop;
3580  rz_analysis_op(core->analysis, &aop, addr, buf, sizeof(buf), RZ_ANALYSIS_OP_MASK_BASIC);
3581  if (aop.type == RZ_ANALYSIS_OP_TYPE_CALL) {
3582  RzBinObject *o = rz_bin_cur_object(core->bin);
3583  RzBinSection *s = rz_bin_get_section_at(o, aop.jump, true);
3584  if (!s) {
3585  rz_debug_step_over(core->dbg, times);
3586  continue;
3587  }
3588  }
3589  rz_debug_step(core->dbg, 1);
3590  }
3593  return RZ_CMD_STATUS_OK;
3594 }
RZ_API RzBinObject * rz_bin_cur_object(RzBin *bin)
Definition: bin.c:900
RZ_API RZ_BORROW RzBinSection * rz_bin_get_section_at(RzBinObject *o, ut64 off, int va)
Find the binary section at offset off.
Definition: bin.c:611
RZ_API int rz_debug_step_over(RzDebug *dbg, int steps)
Definition: debug.c:1033

References addr, rz_core_t::analysis, argv, rz_core_t::bin, CMD_CHECK_DEBUG_DEAD, rz_core_t::dbg, i, int, rz_core_t::io, rz_analysis_op_t::jump, rz_core_t::num, rz_debug_t::reg, rz_analysis_op(), RZ_ANALYSIS_OP_MASK_BASIC, RZ_ANALYSIS_OP_TYPE_CALL, rz_bin_cur_object(), rz_bin_get_section_at(), RZ_CMD_STATUS_OK, rz_core_dbg_follow_seek_register(), rz_core_reg_update_flags(), rz_debug_reg_get(), rz_debug_reg_sync(), rz_debug_step(), rz_debug_step_over(), rz_io_read_at(), rz_num_math(), rz_reg_arena_swap(), RZ_REG_TYPE_GPR, s, times, rz_analysis_op_t::type, and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_step_skip_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_step_skip_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3597 of file cmd_debug.c.

3597  {
3598  CMD_CHECK_DEBUG_DEAD(core);
3599  const int times = (int)rz_num_math(core->num, argv[1]);
3600  bool ret = rz_core_debug_step_skip(core, times);
3602  return bool2status(ret);
3603 }
RZ_API bool rz_core_debug_step_skip(RzCore *core, int times)
Skip operations.
Definition: cdebug.c:831

References argv, bool2status(), CMD_CHECK_DEBUG_DEAD, int, rz_core_t::num, rz_core_dbg_follow_seek_register(), rz_core_debug_step_skip(), rz_num_math(), and times.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_step_until_esil_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_step_until_esil_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2046 of file cmd_debug.c.

2046  {
2047  step_until_esil(core, argv[1]);
2049  return RZ_CMD_STATUS_OK;
2050 }
static int step_until_esil(RzCore *core, const char *esilstr)
Definition: cmd_debug.c:381

References argv, RZ_CMD_STATUS_OK, rz_core_dbg_follow_seek_register(), and step_until_esil().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_step_until_flag_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_step_until_flag_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2053 of file cmd_debug.c.

2053  {
2054  step_until_flag(core, argv[1]);
2056  return RZ_CMD_STATUS_OK;
2057 }
static int step_until_flag(RzCore *core, const char *flagstr)
Definition: cmd_debug.c:562

References argv, RZ_CMD_STATUS_OK, rz_core_dbg_follow_seek_register(), and step_until_flag().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_step_until_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_step_until_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2011 of file cmd_debug.c.

2011  {
2012  rz_reg_arena_swap(core->dbg->reg, true);
2013  step_until(core, rz_num_math(core->num, argv[1]));
2015  return RZ_CMD_STATUS_OK;
2016 }
static int step_until(RzCore *core, ut64 addr)
Definition: cmd_debug.c:352

References argv, rz_core_t::dbg, rz_core_t::num, rz_debug_t::reg, RZ_CMD_STATUS_OK, rz_core_dbg_follow_seek_register(), rz_num_math(), rz_reg_arena_swap(), and step_until().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_step_until_instr_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_step_until_instr_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2019 of file cmd_debug.c.

2019  {
2020  if (!step_until_inst(core, argv[1], false)) {
2021  return RZ_CMD_STATUS_ERROR;
2022  }
2024  return RZ_CMD_STATUS_OK;
2025 }
static bool step_until_inst(RzCore *core, const char *instr, bool regex)
Definition: cmd_debug.c:416

References argv, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_dbg_follow_seek_register(), and step_until_inst().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_step_until_instr_regex_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_step_until_instr_regex_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2028 of file cmd_debug.c.

2028  {
2029  if (!step_until_inst(core, argv[1], true)) {
2030  return RZ_CMD_STATUS_ERROR;
2031  }
2033  return RZ_CMD_STATUS_OK;
2034 }

References argv, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_dbg_follow_seek_register(), and step_until_inst().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_step_until_optype_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_step_until_optype_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2037 of file cmd_debug.c.

2037  {
2038  RzList *optypes_list = rz_list_new_from_array((const void **)argv + 1, argc - 1);
2039  step_until_optype(core, optypes_list);
2041  rz_list_free(optypes_list);
2042  return RZ_CMD_STATUS_OK;
2043 }
static bool step_until_optype(RzCore *core, RzList *optypes_list)
Definition: cmd_debug.c:486
RZ_API RZ_OWN RzList * rz_list_new_from_array(RZ_NONNULL const void **arr, size_t arr_size)
Allocates a new RzList and adds an array elements to it.
Definition: list.c:260

References argv, RZ_CMD_STATUS_OK, rz_core_dbg_follow_seek_register(), rz_list_free(), rz_list_new_from_array(), and step_until_optype().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_stop_trace_session_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_stop_trace_session_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2210 of file cmd_debug.c.

2210  {
2211  if (!core->dbg->session) {
2212  RZ_LOG_ERROR("No session started\n");
2213  return RZ_CMD_STATUS_ERROR;
2214  }
2216  core->dbg->session = NULL;
2217  return RZ_CMD_STATUS_OK;
2218 }

References rz_core_t::dbg, NULL, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_debug_session_free(), RZ_LOG_ERROR, and rz_debug_t::session.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_toggle_bp_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_toggle_bp_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2842 of file cmd_debug.c.

2842  {
2844  return RZ_CMD_STATUS_OK;
2845 }
RZ_API void rz_core_debug_breakpoint_toggle(RZ_NONNULL RzCore *core, ut64 addr)
Toggle breakpoint.
Definition: cdebug.c:235

References rz_core_t::offset, RZ_CMD_STATUS_OK, and rz_core_debug_breakpoint_toggle().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_toggle_bp_index_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_toggle_bp_index_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2962 of file cmd_debug.c.

2962  {
2963  RzBreakpointItem *bpi;
2964  int index = rz_num_math(core->num, argv[1]);
2965  bpi = rz_bp_get_index(core->dbg->bp, index);
2966  if (!bpi) {
2967  RZ_LOG_ERROR("Unable to find breakpoint with index %d\n", index);
2968  return RZ_CMD_STATUS_ERROR;
2969  }
2970  bpi->enabled = !bpi->enabled;
2971  return RZ_CMD_STATUS_OK;
2972 }

References argv, rz_debug_t::bp, rz_core_t::dbg, rz_bp_item_t::enabled, rz_core_t::num, rz_bp_get_index(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, RZ_LOG_ERROR, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_toggle_bp_trace_index_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_toggle_bp_trace_index_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3001 of file cmd_debug.c.

3001  {
3002  RzBreakpointItem *bpi;
3003  int index = rz_num_math(core->num, argv[1]);
3004  bpi = rz_bp_get_index(core->dbg->bp, index);
3005  if (!bpi) {
3006  RZ_LOG_ERROR("Unable to find breakpoint with index %d\n", index);
3007  return RZ_CMD_STATUS_ERROR;
3008  }
3009  bpi->trace = !bpi->enabled;
3010  return RZ_CMD_STATUS_OK;
3011 }

References argv, rz_debug_t::bp, rz_core_t::dbg, rz_bp_item_t::enabled, rz_core_t::num, rz_bp_get_index(), RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, RZ_LOG_ERROR, rz_num_math(), and rz_bp_item_t::trace.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_trace_add_addrs_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_trace_add_addrs_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2106 of file cmd_debug.c.

2106  {
2107  for (int i = 1; i < argc; ++i) {
2108  ut64 addr = rz_num_get(NULL, argv[i]);
2109  RzDebugTracepoint *t = rz_debug_trace_add(core->dbg, addr, 1);
2110  if (!t) {
2111  RZ_LOG_ERROR("Cannot add trace at address %" PFMT64x ".\n", addr);
2112  return RZ_CMD_STATUS_ERROR;
2113  }
2114  }
2115  return RZ_CMD_STATUS_OK;
2116 }
RZ_API RzDebugTracepoint * rz_debug_trace_add(RzDebug *dbg, ut64 addr, int size)
Definition: trace.c:261

References addr, argv, rz_core_t::dbg, i, NULL, PFMT64x, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_debug_trace_add(), RZ_LOG_ERROR, rz_num_get(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_trace_add_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_trace_add_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2087 of file cmd_debug.c.

2087  {
2088  int count = argc > 1 ? rz_num_math(core->num, argv[1]) : 1;
2090  if (!op) {
2091  RZ_LOG_ERROR("Cannot analyze opcode at 0x%08" PFMT64x "\n", core->offset);
2092  return RZ_CMD_STATUS_ERROR;
2093  }
2094 
2095  RzDebugTracepoint *tp = rz_debug_trace_add(core->dbg, core->offset, op->size);
2096  if (!tp) {
2098  return RZ_CMD_STATUS_ERROR;
2099  }
2100  tp->count = count;
2102  return RZ_CMD_STATUS_OK;
2103 }
@ RZ_ANALYSIS_OP_MASK_HINT
Definition: rz_analysis.h:443

References argv, rz_debug_tracepoint_t::count, count, rz_core_t::dbg, rz_core_t::num, rz_core_t::offset, PFMT64x, rz_analysis_op_free(), RZ_ANALYSIS_OP_MASK_HINT, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_op_analysis(), rz_debug_trace_add(), RZ_LOG_ERROR, and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_trace_addr()

RZ_IPI int rz_cmd_debug_trace_addr ( void *  data,
const char *  input 
)

Definition at line 2128 of file cmd_debug.c.

2128  {
2129  RzCore *core = (RzCore *)data;
2130  rz_debug_trace_at(core->dbg, input);
2131  return 0;
2132 }
RZ_API void rz_debug_trace_at(RzDebug *dbg, const char *str)
Definition: trace.c:194

References rz_core_t::dbg, input(), and rz_debug_trace_at().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_trace_calls_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_trace_calls_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2135 of file cmd_debug.c.

2135  {
2136  ut64 from = argc > 1 ? rz_num_math(core->num, argv[1]) : 0;
2137  ut64 to = argc > 2 ? rz_num_math(core->num, argv[2]) : UT64_MAX;
2138  ut64 addr = argc > 3 ? rz_num_math(core->num, argv[3]) : UT64_MAX;
2139 
2140  debug_trace_calls(core, from, to, addr);
2141  return RZ_CMD_STATUS_OK;
2142 }
static void debug_trace_calls(RzCore *core, ut64 from, ut64 to, ut64 final_addr)
Definition: cmd_debug.c:1753

References addr, argv, debug_trace_calls(), from, rz_core_t::num, RZ_CMD_STATUS_OK, rz_num_math(), to, ut64(), and UT64_MAX.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_trace_esil_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_trace_esil_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2145 of file cmd_debug.c.

2145  {
2147  int idx = rz_num_math(core->num, argv[1]);
2149  return RZ_CMD_STATUS_OK;
2150 }
RZ_IPI void rz_core_analysis_esil_init(RzCore *core)
Definition: cil.c:43
RZ_API void rz_analysis_esil_trace_show(RzAnalysisEsil *esil, int idx)
Definition: esil_trace.c:456
int idx
Definition: setup.py:197
struct rz_analysis_esil_t * esil
Definition: rz_analysis.h:584

References rz_core_t::analysis, argv, rz_analysis_t::esil, setup::idx, rz_core_t::num, rz_analysis_esil_trace_show(), RZ_CMD_STATUS_OK, rz_core_analysis_esil_init(), and rz_num_math().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_trace_esils_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_trace_esils_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2153 of file cmd_debug.c.

2153  {
2156  return RZ_CMD_STATUS_OK;
2157 }
RZ_API void rz_analysis_esil_trace_list(RzAnalysisEsil *esil)
Definition: esil_trace.c:434

References rz_core_t::analysis, rz_analysis_t::esil, rz_analysis_esil_trace_list(), RZ_CMD_STATUS_OK, and rz_core_analysis_esil_init().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_trace_graph_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_trace_graph_handler ( RzCore core,
int  argc,
const char **  argv,
RzOutputMode  mode 
)

Definition at line 2183 of file cmd_debug.c.

2183  {
2185  return RZ_CMD_STATUS_OK;
2186 }
RZ_IPI int rz_output_mode_to_char(RzOutputMode mode)
Definition: cmd_api.c:73
static void dot_trace_traverse(RzCore *core, RTree *t, int fmt)
Definition: cmd_debug.c:279

References rz_core_t::dbg, dot_trace_traverse(), RZ_CMD_STATUS_OK, rz_output_mode_to_char(), and rz_debug_t::tree.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_trace_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_trace_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2060 of file cmd_debug.c.

2060  {
2061  RzDebugTracepoint *t = rz_debug_trace_get(core->dbg, core->offset);
2062  if (!t) {
2063  RZ_LOG_ERROR("Cannot find any debug trace at address %" PFMT64x ".\n", core->offset);
2064  return RZ_CMD_STATUS_ERROR;
2065  }
2066 
2067  rz_cons_printf("offset = 0x%" PFMT64x "\n", t->addr);
2068  rz_cons_printf("opsize = %d\n", t->size);
2069  rz_cons_printf("times = %d\n", t->times);
2070  rz_cons_printf("count = %d\n", t->count);
2071  return RZ_CMD_STATUS_OK;
2072 }
RZ_API RzDebugTracepoint * rz_debug_trace_get(RzDebug *dbg, ut64 addr)
Definition: trace.c:200

References rz_debug_tracepoint_t::addr, rz_debug_tracepoint_t::count, rz_core_t::dbg, rz_core_t::offset, PFMT64x, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_cons_printf(), rz_debug_trace_get(), RZ_LOG_ERROR, rz_debug_tracepoint_t::size, and rz_debug_tracepoint_t::times.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_trace_interactive_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_trace_interactive_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2189 of file cmd_debug.c.

2189  {
2190  dot_trace_traverse(core, core->dbg->tree, 'i');
2191  return RZ_CMD_STATUS_OK;
2192 }

References rz_core_t::dbg, dot_trace_traverse(), RZ_CMD_STATUS_OK, and rz_debug_t::tree.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_trace_tag_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_trace_tag_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2250 of file cmd_debug.c.

2250  {
2251  int tag = rz_num_math(core->num, argv[1]);
2252  rz_debug_trace_tag(core->dbg, tag);
2253  return RZ_CMD_STATUS_OK;
2254 }
RZ_API int rz_debug_trace_tag(RzDebug *dbg, int tag)
Definition: trace.c:41

References argv, rz_core_t::dbg, rz_core_t::num, RZ_CMD_STATUS_OK, rz_debug_trace_tag(), rz_num_math(), and test-lz4-versions::tag.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_traces_ascii_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_traces_ascii_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2081 of file cmd_debug.c.

2081  {
2082  rz_debug_traces_ascii(core->dbg, core->offset);
2083  return RZ_CMD_STATUS_OK;
2084 }
RZ_API void rz_debug_traces_ascii(RzDebug *dbg, ut64 offset)
Definition: cdebug.c:688

References rz_core_t::dbg, rz_core_t::offset, RZ_CMD_STATUS_OK, and rz_debug_traces_ascii().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_traces_esil_delete_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_traces_esil_delete_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2160 of file cmd_debug.c.

2160  {
2162  if (core->analysis->esil) {
2165  }
2166  return RZ_CMD_STATUS_OK;
2167 }
RZ_API void rz_analysis_il_trace_instruction_free(RzILTraceInstruction *instruction)
Definition: il_trace.c:53
RZ_API RzPVector * rz_pvector_new(RzPVectorFree free)
Definition: vector.c:302
void(* RzPVectorFree)(void *e)
Definition: rz_vector.h:43
RZ_API void rz_pvector_free(RzPVector *vec)
Definition: vector.c:336
RzAnalysisEsilTrace * trace
Definition: rz_analysis.h:1077

References rz_core_t::analysis, rz_analysis_t::esil, rz_analysis_esil_trace_t::instructions, rz_analysis_il_trace_instruction_free(), RZ_CMD_STATUS_OK, rz_core_analysis_esil_init(), rz_pvector_free(), rz_pvector_new(), and rz_analysis_esil_t::trace.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_traces_esil_i_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_traces_esil_i_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2170 of file cmd_debug.c.

2170  {
2173  if (!op) {
2174  RZ_LOG_ERROR("Cannot analyze opcode at 0x%08" PFMT64x "\n", core->offset);
2175  return RZ_CMD_STATUS_ERROR;
2176  }
2179  return RZ_CMD_STATUS_OK;
2180 }
RZ_API RzAnalysisOp * rz_core_analysis_op(RzCore *core, ut64 addr, int mask)
Definition: canalysis.c:1033
RZ_API void rz_analysis_esil_trace_op(RzAnalysisEsil *esil, RZ_NONNULL RzAnalysisOp *op)
Definition: esil_trace.c:271
@ RZ_ANALYSIS_OP_MASK_ESIL
Definition: rz_analysis.h:441

References rz_core_t::analysis, rz_analysis_t::esil, rz_core_t::offset, PFMT64x, rz_analysis_esil_trace_op(), rz_analysis_op_free(), RZ_ANALYSIS_OP_MASK_ESIL, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_core_analysis_esil_init(), rz_core_analysis_op(), and RZ_LOG_ERROR.

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_traces_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_traces_handler ( RzCore core,
int  argc,
const char **  argv,
RzCmdStateOutput state 
)

Definition at line 2075 of file cmd_debug.c.

2075  {
2076  rz_debug_trace_print(core->dbg, state, core->offset);
2077  return RZ_CMD_STATUS_OK;
2078 }
RZ_API void rz_debug_trace_print(RzDebug *dbg, RzCmdStateOutput *state, ut64 offset)
Definition: cdebug.c:658

References rz_core_t::dbg, rz_core_t::offset, RZ_CMD_STATUS_OK, and rz_debug_trace_print().

Referenced by rzshell_cmddescs_init().

◆ rz_cmd_debug_traces_reset_handler()

RZ_IPI RzCmdStatus rz_cmd_debug_traces_reset_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 2119 of file cmd_debug.c.

2119  {
2120  rz_tree_reset(core->dbg->tree);
2121  rz_debug_trace_free(core->dbg->trace);
2123  core->dbg->trace = rz_debug_trace_new();
2124  return RZ_CMD_STATUS_OK;
2125 }
RZ_API void rz_debug_tracenodes_reset(RzDebug *dbg)
Definition: debug.c:411
RZ_API void rz_tree_reset(RTree *t)
Definition: tree.c:85
RZ_API void rz_debug_trace_free(RzDebugTrace *trace)
Definition: trace.c:29
RZ_API RzDebugTrace * rz_debug_trace_new(void)
Definition: trace.c:7

References rz_core_t::dbg, RZ_CMD_STATUS_OK, rz_debug_trace_free(), rz_debug_trace_new(), rz_debug_tracenodes_reset(), rz_tree_reset(), rz_debug_t::trace, and rz_debug_t::tree.

Referenced by rzshell_cmddescs_init().

◆ rz_core_dbg_follow_seek_register()

RZ_API void rz_core_dbg_follow_seek_register ( RzCore core)

Seek to PC if needed.

Parameters
coreThe RzCore instance

Definition at line 474 of file cmd_debug.c.

474  {
475  ut64 follow = rz_config_get_i(core->config, "dbg.follow");
476  if (follow <= 0) {
477  return;
478  }
479  ut64 pc = rz_debug_reg_get(core->dbg, "PC");
480  if ((pc < core->offset) || (pc > (core->offset + follow))) {
481  rz_core_seek_to_register(core, "PC", false);
482  }
484 }
RZ_IPI void rz_core_debug_sync_bits(RzCore *core)
Definition: cdebug.c:184
RZ_IPI bool rz_core_seek_to_register(RzCore *core, const char *regname, bool is_silent)
Definition: cmd_seek.c:22
voidpf uLong offset
Definition: ioapi.h:144

References rz_core_t::config, rz_core_t::dbg, rz_core_t::offset, pc, rz_config_get_i(), rz_core_debug_sync_bits(), rz_core_seek_to_register(), rz_debug_reg_get(), and ut64().

Referenced by rz_cmd_debug(), rz_cmd_debug_continue_back_handler(), rz_cmd_debug_continue_call_handler(), rz_cmd_debug_continue_exception_handler(), rz_cmd_debug_continue_execution_handler(), rz_cmd_debug_continue_fork_handler(), rz_cmd_debug_continue_ret_handler(), rz_cmd_debug_continue_send_signal_handler(), rz_cmd_debug_continue_syscall(), rz_cmd_debug_continue_traptrace_handler(), rz_cmd_debug_continue_unknown_call_handler(), rz_cmd_debug_continue_until(), rz_cmd_debug_step_back_handler(), rz_cmd_debug_step_cond_handler(), rz_cmd_debug_step_frame_handler(), rz_cmd_debug_step_handler(), rz_cmd_debug_step_line_handler(), rz_cmd_debug_step_over_handler(), rz_cmd_debug_step_prog_handler(), rz_cmd_debug_step_skip_handler(), rz_cmd_debug_step_until_esil_handler(), rz_cmd_debug_step_until_flag_handler(), rz_cmd_debug_step_until_handler(), rz_cmd_debug_step_until_instr_handler(), rz_cmd_debug_step_until_instr_regex_handler(), rz_cmd_debug_step_until_optype_handler(), rz_core_debug_continue(), and rz_core_debug_single_step_over().

◆ rz_core_debug_bp_add()

RZ_IPI void rz_core_debug_bp_add ( RzCore core,
ut64  addr,
const char *  arg_perm,
bool  hwbp,
bool  watch 
)

Definition at line 1574 of file cmd_debug.c.

1574  {
1575  RzBreakpointItem *bpi;
1576  int rw = 0;
1577 
1578  if (watch) {
1579  rw = rz_str_rwx(arg_perm);
1580  rw &= RZ_PERM_RWX; // filter out the rwx bits only
1581  if (rw == 0) {
1582  RZ_LOG_WARN("Invalid permissions provided for setting watchpoint. Defaulting to \"rw\".\n");
1583  rw = RZ_PERM_RW;
1584  }
1585  }
1586  bpi = rz_debug_bp_add(core->dbg, addr, hwbp, watch, rw, NULL, 0);
1587  if (!bpi) {
1588  RZ_LOG_ERROR("Cannot set breakpoint at 0x%" PFMT64x "\n", addr);
1589  return;
1590  }
1592  if (f) {
1593  if (addr > f->offset) {
1594  char *name = rz_str_newf("%s+0x%" PFMT64x, f->name, addr - f->offset);
1595  rz_bp_item_set_name(bpi, name);
1596  free(name);
1597  } else {
1598  bpi->name = strdup(f->name);
1599  }
1600  } else {
1601  char *name = rz_str_newf("0x%08" PFMT64x, addr);
1602  rz_bp_item_set_name(bpi, name);
1603  free(name);
1604  }
1605 }
RZ_API RzFlagItem * rz_core_flag_get_by_spaces(RzFlag *f, ut64 off)
Definition: core.c:2280
#define RZ_LOG_WARN(fmtstr,...)
Definition: rz_log.h:56
RZ_API int rz_str_rwx(const char *str)
Definition: str.c:318
#define RZ_PERM_RWX
Definition: rz_types.h:98

References addr, rz_core_t::dbg, f, rz_core_t::flags, free(), rz_bp_item_t::name, NULL, PFMT64x, rz_bp_item_set_name(), rz_core_flag_get_by_spaces(), rz_debug_bp_add(), RZ_LOG_ERROR, RZ_LOG_WARN, RZ_PERM_RW, RZ_PERM_RWX, rz_str_newf(), rz_str_rwx(), and strdup().

Referenced by __watch_points_cb(), rz_cmd_debug_add_bp_handler(), rz_cmd_debug_add_hw_bp_handler(), and rz_cmd_debug_add_watchpoint_handler().

◆ rz_core_debug_clear_register_flags()

RZ_API void rz_core_debug_clear_register_flags ( RzCore core)

Definition at line 1449 of file cmd_debug.c.

1449  {
1450  foreach_reg_set_or_clear(core, false);
1451 }
static void foreach_reg_set_or_clear(RzCore *core, bool set)
Definition: cmd_debug.c:1428

References foreach_reg_set_or_clear().

Referenced by rz_core_analysis_types_propagation(), and rz_core_debug_process_close().

◆ rz_core_debug_esil()

static void rz_core_debug_esil ( RzCore core,
const char *  input 
)
static

Definition at line 1781 of file cmd_debug.c.

1781  {
1782  switch (input[0]) {
1783  case '\0': // "de"
1784  // list
1786  break;
1787  case ' ': // "de "
1788  {
1789  char *line = strdup(input + 1);
1790  char *p, *q;
1791  int done = 0;
1792  int perm = 0, dev = 0;
1793  p = strchr(line, ' ');
1794  if (p) {
1795  *p++ = 0;
1796  if (strchr(line, 'r'))
1797  perm |= RZ_PERM_R;
1798  if (strchr(line, 'w'))
1799  perm |= RZ_PERM_W;
1800  if (strchr(line, 'x'))
1801  perm |= RZ_PERM_X;
1802  q = strchr(p, ' ');
1803  if (q) {
1804  *q++ = 0;
1805  dev = p[0];
1806  if (q) {
1807  rz_debug_esil_watch(core->dbg, perm, dev, q);
1808  done = 1;
1809  }
1810  }
1811  }
1812  if (!done) {
1813  const char *help_de_msg[] = {
1814  "Usage:", "de", " [perm] [reg|mem] [expr]",
1815  NULL
1816  };
1817  rz_core_cmd_help(core, help_de_msg);
1818  }
1819  free(line);
1820  } break;
1821  case '-': // "de-"
1823  break;
1824  case 'c': // "dec"
1825  if (rz_debug_esil_watch_empty(core->dbg)) {
1826  eprintf("Error: no esil watchpoints defined\n");
1827  } else {
1829  rz_debug_esil_prestep(core->dbg, rz_config_get_i(core->config, "esil.prestep"));
1830  rz_debug_esil_continue(core->dbg);
1831  }
1832  break;
1833  case 's': // "des"
1834  if (input[1] == 'u' && input[2] == ' ') { // "desu"
1835  ut64 addr, naddr, fin = rz_num_math(core->num, input + 2);
1837  addr = rz_debug_reg_get(core->dbg, "PC");
1838  while (addr != fin) {
1839  rz_debug_esil_prestep(core->dbg, rz_config_get_i(core->config, "esil.prestep"));
1840  rz_debug_esil_step(core->dbg, 1);
1841  naddr = rz_debug_reg_get(core->dbg, "PC");
1842  if (naddr == addr) {
1843  eprintf("Detected loophole\n");
1844  break;
1845  }
1846  addr = naddr;
1847  }
1848  } else if (input[1] == '?' || !input[1]) {
1850  } else {
1852  rz_debug_esil_prestep(core->dbg, rz_config_get_i(core->config, "esil.prestep"));
1853  // continue
1854  rz_debug_esil_step(core->dbg, rz_num_math(core->num, input + 1));
1855  }
1856  break;
1857  case '?': // "de?"
1858  default: {
1860  // TODO #7967 help refactor: move to detail
1861  rz_cons_printf("Examples:\n"
1862  " de r r rip # stop when reads rip\n"
1863  " de rw m ADDR # stop when read or write in ADDR\n"
1864  " de w r rdx # stop when rdx register is modified\n"
1865  " de x m FROM..TO # stop when rip in range\n");
1866  } break;
1867  }
1868 }
RZ_API void rz_core_analysis_esil_reinit(RZ_NONNULL RzCore *core)
Reinitialize ESIL.
Definition: cil.c:54
static const char * help_msg_de[]
Definition: cmd_debug.c:85
static const char * help_msg_des[]
Definition: cmd_debug.c:96
RZ_API ut64 rz_debug_esil_continue(RzDebug *dbg)
Definition: desil.c:304
RZ_API ut64 rz_debug_esil_step(RzDebug *dbg, ut32 count)
Definition: desil.c:280
RZ_API void rz_debug_esil_prestep(RzDebug *d, int p)
Definition: desil.c:214
RZ_API void rz_debug_esil_watch_list(RzDebug *dbg)
Definition: desil.c:341
RZ_API int rz_debug_esil_watch_empty(RzDebug *dbg)
Definition: desil.c:313
RZ_API void rz_debug_esil_watch_reset(RzDebug *dbg)
Definition: desil.c:336
RZ_API void rz_debug_esil_watch(RzDebug *dbg, int rwx, int dev, const char *expr)
Definition: desil.c:317
struct tab * done
Definition: enough.c:233
void * p
Definition: libc.cpp:67
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask dev
Definition: sflib.h:88
line
Definition: setup.py:34
#define RZ_PERM_W
Definition: rz_types.h:94
#define RZ_PERM_X
Definition: rz_types.h:95

References addr, rz_core_t::config, rz_core_t::dbg, dev, done, eprintf, free(), help_msg_de, help_msg_des, input(), setup::line, NULL, rz_core_t::num, p, rz_config_get_i(), rz_cons_printf(), rz_core_analysis_esil_reinit(), rz_core_cmd_help(), rz_debug_esil_continue(), rz_debug_esil_prestep(), rz_debug_esil_step(), rz_debug_esil_watch(), rz_debug_esil_watch_empty(), rz_debug_esil_watch_list(), rz_debug_esil_watch_reset(), rz_debug_reg_get(), rz_num_math(), RZ_PERM_R, RZ_PERM_W, RZ_PERM_X, strdup(), and ut64().

Referenced by rz_cmd_debug().

◆ rz_core_debug_kill()

static void rz_core_debug_kill ( RzCore core,
const char *  input 
)
static

Definition at line 1870 of file cmd_debug.c.

1870  {
1871  if (!input || *input == '?') {
1872  if (input && input[1]) {
1873  const char *signame, *arg = input + 1;
1874  int signum = atoi(arg);
1875  if (signum > 0) {
1876  signame = rz_signal_to_string(signum);
1877  if (signame)
1878  rz_cons_println(signame);
1879  } else {
1881  if (signum > 0) {
1882  rz_cons_printf("%d\n", signum);
1883  }
1884  }
1885  } else {
1887  }
1888  } else if (*input == 'o') {
1889  switch (input[1]) {
1890  case 0: // "dko" - list signal skip/conts
1892  break;
1893  case ' ': // dko SIGNAL
1894  if (input[2]) {
1895  char *p, *name = strdup(input + 2);
1896  int signum = atoi(name);
1897  p = strchr(name, ' ');
1898  if (p)
1899  *p++ = 0; /* got SIGNAL and an action */
1900  // Actions:
1901  // - pass
1902  // - trace
1903  // - stop
1904  if (signum < 1)
1906  if (signum > 0) {
1907  if (!p || !p[0]) { // stop (the usual)
1908  rz_debug_signal_setup(core->dbg, signum, 0);
1909  } else if (*p == 's') { // skip
1911  } else if (*p == 'c') { // cont
1913  } else {
1914  eprintf("Invalid option: %s\n", p);
1915  }
1916  } else {
1917  eprintf("Invalid signal: %s\n", input + 2);
1918  }
1919  free(name);
1920  break;
1921  }
1922  /* fall through */
1923  case '?':
1924  default: {
1926  // TODO #7967 help refactor: move to detail
1927  rz_cons_println("NOTE: [signal] can be a number or a string that resolves with dk?\n"
1928  " skip means do not enter into the signal handler\n"
1929  " continue means enter into the signal handler");
1930  }
1931  }
1932  } else if (*input == 'j') {
1934  } else if (!*input) {
1936  } else {
1937  int sig = atoi(input);
1938  char *p = strchr(input, '=');
1939  if (p) {
1940  rz_debug_kill_setup(core->dbg, sig, rz_num_math(core->num, p + 1));
1941  } else {
1942  rz_debug_kill(core->dbg, core->dbg->pid, core->dbg->tid, sig);
1943  }
1944  }
1945 }
static const char * help_msg_dko[]
Definition: cmd_debug.c:125
static const char * help_msg_dk[]
Definition: cmd_debug.c:113
RZ_API void rz_debug_signal_setup(RzDebug *dbg, int num, int opt)
Definition: dsignal.c:147
RZ_API void rz_debug_signal_list(RzDebug *dbg, RzOutputMode mode)
Definition: dsignal.c:119
RZ_API int rz_debug_kill_setup(RzDebug *dbg, int sig, int action)
Definition: dsignal.c:171
@ RZ_DBG_SIGNAL_CONT
Definition: rz_debug.h:71
@ RZ_DBG_SIGNAL_SKIP
Definition: rz_debug.h:72
RZ_API int rz_signal_from_string(const char *str)
Definition: signal.c:52

References rz_core_t::dbg, eprintf, free(), help_msg_dk, help_msg_dko, input(), rz_core_t::num, p, rz_debug_t::pid, rz_cons_printf(), rz_cons_println(), rz_core_cmd_help(), RZ_DBG_SIGNAL_CONT, RZ_DBG_SIGNAL_SKIP, rz_debug_kill(), rz_debug_kill_setup(), rz_debug_signal_list(), rz_debug_signal_setup(), rz_num_math(), RZ_OUTPUT_MODE_JSON, RZ_OUTPUT_MODE_STANDARD, rz_signal_from_string(), rz_signal_to_string(), signum, strdup(), and rz_debug_t::tid.

Referenced by rz_cmd_debug().

◆ rz_core_debug_ri()

RZ_API void rz_core_debug_ri ( RzCore core)

Definition at line 3616 of file cmd_debug.c.

3616  {
3617  const RzList *list = rz_reg_get_list(core->dbg->reg, RZ_REG_TYPE_GPR);
3619 }
static bool cmd_regs_sync(RzCore *core, RzRegisterType type, bool write)
Definition: cmd_debug.c:3607
RZ_IPI void rz_regs_show_valgroup(RzCore *core, RzReg *reg, RzCmdRegSync sync_cb, const RzList *list)
Definition: cmd_regs.c:423

References cmd_regs_sync(), rz_core_t::dbg, list(), rz_debug_t::reg, rz_reg_get_list(), RZ_REG_TYPE_GPR, and rz_regs_show_valgroup().

Referenced by rz_core_visual_debugtraces().

◆ rz_core_debug_set_register_flags()

RZ_API void rz_core_debug_set_register_flags ( RzCore core)

Definition at line 1443 of file cmd_debug.c.

1443  {
1444  rz_flag_space_push(core->flags, RZ_FLAGS_FS_REGISTERS);
1445  foreach_reg_set_or_clear(core, true);
1446  rz_flag_space_pop(core->flags);
1447 }
#define RZ_FLAGS_FS_REGISTERS
Definition: rz_core.h:61

References rz_core_t::flags, foreach_reg_set_or_clear(), and RZ_FLAGS_FS_REGISTERS.

◆ rz_core_static_debug_stop()

◆ rz_debug_drx_handler()

RZ_IPI RzCmdStatus rz_debug_drx_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3621 of file cmd_debug.c.

3621  {
3622  if (argc <= 1) {
3623  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_DRX, false);
3624  rz_debug_drx_list(core->dbg);
3625  return RZ_CMD_STATUS_OK;
3626  }
3627  if (argc != 5) {
3628  return RZ_CMD_STATUS_WRONG_ARGS;
3629  }
3630  int n = (int)rz_num_math(core->num, argv[1]);
3631  ut64 off = rz_num_math(core->num, argv[2]);
3632  int len = (int)rz_num_math(core->num, argv[3]);
3633  int perm = rz_str_rwx(argv[4]);
3634  if (len == -1) {
3635  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_DRX, false);
3636  rz_debug_drx_set(core->dbg, n, 0, 0, 0, 0);
3637  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_DRX, true);
3638  } else {
3639  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_DRX, false);
3640  rz_debug_drx_set(core->dbg, n, off, len, perm, 0);
3641  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_DRX, true);
3642  }
3643  return RZ_CMD_STATUS_OK;
3644 }
RZ_API int rz_debug_drx_set(RzDebug *dbg, int idx, ut64 addr, int len, int rwx, int g)
Definition: debug.c:1668
RZ_API void rz_debug_drx_list(RzDebug *dbg)
Definition: debug.c:1662
@ RZ_CMD_STATUS_WRONG_ARGS
command handler could not handle the arguments passed to it
Definition: rz_cmd.h:25
@ RZ_REG_TYPE_DRX
Definition: rz_reg.h:22

References argv, rz_core_t::dbg, int, len, n, rz_core_t::num, off, RZ_CMD_STATUS_OK, RZ_CMD_STATUS_WRONG_ARGS, rz_debug_drx_list(), rz_debug_drx_set(), rz_debug_reg_sync(), rz_num_math(), RZ_REG_TYPE_DRX, rz_str_rwx(), and ut64().

Referenced by rzshell_cmddescs_init().

◆ rz_debug_drx_unset_handler()

RZ_IPI RzCmdStatus rz_debug_drx_unset_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 3646 of file cmd_debug.c.

3646  {
3648  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_DRX, false);
3649  rz_debug_drx_unset(core->dbg, atoi(argv[1] + 2));
3650  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_DRX, true);
3651  return RZ_CMD_STATUS_OK;
3652 }
RZ_API int rz_debug_drx_unset(RzDebug *dbg, int idx)
Definition: debug.c:1675

References argv, rz_core_t::dbg, RZ_CMD_STATUS_OK, RZ_CMD_STATUS_WRONG_ARGS, rz_debug_drx_unset(), rz_debug_reg_sync(), RZ_REG_TYPE_DRX, and rz_return_val_if_fail.

Referenced by rzshell_cmddescs_init().

◆ rz_debug_memory_permission_handler()

RZ_IPI RzCmdStatus rz_debug_memory_permission_handler ( RzCore core,
int  argc,
const char **  argv 
)

Definition at line 1288 of file cmd_debug.c.

1288  {
1289  CMD_CHECK_DEBUG_DEAD(core);
1290  RzListIter *iter;
1291  RzDebugMap *map;
1292  ut64 addr = 0, size = 0;
1293  int perms;
1294  if (argc == 3) { // dmp <size> <perms> @ <addr>
1295  addr = core->offset;
1296  size = rz_num_math(core->num, argv[1]);
1297  perms = rz_str_rwx(argv[2]);
1298  rz_debug_map_protect(core->dbg, addr, (int)size, perms);
1299  } else if (argc == 2) { // dmp <perms>
1300  addr = UT64_MAX;
1301  rz_list_foreach (core->dbg->maps, iter, map) {
1302  if (core->offset >= map->addr && core->offset < map->addr_end) {
1303  addr = map->addr;
1304  size = map->size;
1305  break;
1306  }
1307  }
1308  perms = rz_str_rwx(argv[1]);
1309  if (addr != UT64_MAX && perms >= 0) {
1310  rz_debug_map_protect(core->dbg, addr, (int)size, perms);
1311  } else {
1312  return RZ_CMD_STATUS_ERROR;
1313  }
1314  }
1315  return RZ_CMD_STATUS_OK;
1316 }
RZ_API int rz_debug_map_protect(RzDebug *dbg, ut64 addr, int size, int perms)
Definition: debug.c:1655

References addr, argv, CMD_CHECK_DEBUG_DEAD, rz_core_t::dbg, map(), rz_debug_t::maps, rz_core_t::num, rz_core_t::offset, RZ_CMD_STATUS_ERROR, RZ_CMD_STATUS_OK, rz_debug_map_protect(), rz_num_math(), rz_str_rwx(), ut64(), and UT64_MAX.

Referenced by rzshell_cmddescs_init().

◆ set_profile_string()

static void set_profile_string ( RzCore core,
const char *  str 
)
static

Definition at line 192 of file cmd_debug.c.

192  {
193  char *file = strdup(rz_config_get(core->config, "dbg.profile"));
194  if (RZ_STR_ISEMPTY(file)) {
195  free(file);
196  file = rz_file_temp("rz-run");
197  rz_config_set(core->config, "dbg.profile", file);
198  }
199  rz_file_dump(file, (const ut8 *)str, (int)strlen(str), 0);
200  rz_file_dump(file, (const ut8 *)"\n", 1, 1);
201  free(file);
202 }

References rz_core_t::config, free(), rz_config_get(), rz_config_set(), rz_file_dump(), rz_file_temp(), RZ_STR_ISEMPTY, cmd_descs_generate::str, and strdup().

Referenced by rz_cmd_debug_process_profile_handler().

◆ step_line()

static bool step_line ( RzCore core,
int  times 
)
static

Definition at line 598 of file cmd_debug.c.

598  {
599  char file[512], file2[512];
600  int find_meta, line = -1, line2 = -1;
601  char *tmp_ptr = NULL;
602  ut64 off = rz_debug_reg_get(core->dbg, "PC");
603  if (off == 0LL) {
604  RZ_LOG_ERROR("cannot 'drn PC'\n");
605  return false;
606  }
607  file[0] = 0;
608  file2[0] = 0;
609  if (rz_bin_addr2line(core->bin, off, file, sizeof(file), &line)) {
610  char *ptr = rz_file_slurp_line(file, line, 0);
611  RZ_LOG_INFO("--> 0x%08" PFMT64x " %s : %d\n", off, file, line);
612  RZ_LOG_INFO("--> %s\n", ptr);
613  find_meta = false;
614  free(ptr);
615  } else {
616  RZ_LOG_INFO("--> Stepping until dwarf line\n");
617  find_meta = true;
618  }
619  do {
620  rz_debug_step(core->dbg, 1);
621  off = rz_debug_reg_get(core->dbg, "PC");
622  if (!rz_bin_addr2line(core->bin, off, file2, sizeof(file2), &line2)) {
623  if (find_meta) {
624  continue;
625  }
627  RZ_LOG_ERROR("cannot retrieve dwarf info at 0x%08" PFMT64x "\n", off);
628  return false;
629  }
630  } while (!strcmp(file, file2) && line == line2);
631 
632  RZ_LOG_INFO("--> 0x%08" PFMT64x " %s : %d\n", off, file2, line2);
633  tmp_ptr = rz_file_slurp_line(file2, line2, 0);
634  RZ_LOG_INFO("--> %s\n", tmp_ptr);
635  free(tmp_ptr);
637  return true;
638 }
RZ_DEPRECATE RZ_API bool rz_bin_addr2line(RzBin *bin, ut64 addr, char *file, int len, int *line)
Definition: dbginfo.c:194
RZ_API bool RZ_API char * rz_file_slurp_line(const char *file, int line, int context)
Definition: file.c:673

References rz_core_t::bin, rz_core_t::dbg, free(), setup::line, NULL, off, PFMT64x, rz_bin_addr2line(), rz_core_reg_update_flags(), rz_debug_reg_get(), rz_debug_step(), rz_file_slurp_line(), RZ_LOG_ERROR, RZ_LOG_INFO, and ut64().

Referenced by rz_cmd_debug_step_line_handler().

◆ step_until()

static int step_until ( RzCore core,
ut64  addr 
)
static

Definition at line 352 of file cmd_debug.c.

352  {
353  ut64 off = rz_debug_reg_get(core->dbg, "PC");
354  if (!off) {
355  eprintf("Cannot 'drn PC'\n");
356  return false;
357  }
358  if (!addr) {
359  eprintf("Cannot continue until address 0\n");
360  return false;
361  }
363  do {
364  if (rz_cons_is_breaked()) {
365  core->break_loop = true;
366  break;
367  }
368  if (rz_debug_is_dead(core->dbg)) {
369  core->break_loop = true;
370  break;
371  }
372  rz_debug_step(core->dbg, 1);
373  off = rz_debug_reg_get(core->dbg, "PC");
374  // check breakpoint here
375  } while (off != addr);
378  return true;
379 }

References addr, rz_core_t::break_loop, rz_core_t::dbg, eprintf, 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(), and ut64().

Referenced by rz_cmd_debug_step_until_handler().

◆ step_until_esil()

static int step_until_esil ( RzCore core,
const char *  esilstr 
)
static

Definition at line 381 of file cmd_debug.c.

381  {
382  if (!core || !esilstr || !core->dbg || !core->dbg->analysis || !core->dbg->analysis->esil) {
383  eprintf("Not initialized %p. Run 'aei' first.\n", core->analysis->esil);
384  return false;
385  }
387  for (;;) {
388  if (rz_cons_is_breaked()) {
389  core->break_loop = true;
390  break;
391  }
392  if (rz_debug_is_dead(core->dbg)) {
393  core->break_loop = true;
394  break;
395  }
396  rz_debug_step(core->dbg, 1);
397  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_ANY, false);
398  if (rz_analysis_esil_condition(core->analysis->esil, esilstr)) {
399  eprintf("ESIL BREAK!\n");
400  break;
401  }
402  }
405  return true;
406 }
RZ_API int rz_analysis_esil_condition(RzAnalysisEsil *esil, const char *str)
Definition: esil.c:3113
@ RZ_REG_TYPE_ANY
Definition: rz_reg.h:35
RzAnalysis * analysis
Definition: rz_debug.h:305

References rz_core_t::analysis, rz_debug_t::analysis, rz_core_t::break_loop, rz_core_t::dbg, eprintf, rz_analysis_t::esil, NULL, rz_analysis_esil_condition(), rz_cons_break_pop(), rz_cons_break_push(), rz_cons_is_breaked(), rz_core_reg_update_flags(), rz_debug_is_dead(), rz_debug_reg_sync(), rz_debug_step(), and RZ_REG_TYPE_ANY.

Referenced by rz_cmd_debug_step_until_esil_handler().

◆ step_until_flag()

static int step_until_flag ( RzCore core,
const char *  flagstr 
)
static

Definition at line 562 of file cmd_debug.c.

562  {
563  const RzList *list;
564  RzListIter *iter;
565  RzFlagItem *flag;
566  ut64 pc;
567 
568  if (!core || !flagstr || !core->dbg) {
569  RZ_LOG_ERROR("wrong state\n");
570  return false;
571  }
573  for (;;) {
574  if (rz_cons_is_breaked()) {
575  break;
576  }
577  if (rz_debug_is_dead(core->dbg)) {
578  break;
579  }
580  rz_debug_step(core->dbg, 1);
581  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_ANY, false);
582  pc = rz_debug_reg_get(core->dbg, "PC");
583  list = rz_flag_get_list(core->flags, pc);
584  rz_list_foreach (list, iter, flag) {
585  if (flag->realname && strstr(flag->realname, flagstr)) {
586  rz_cons_printf("[ 0x%08" PFMT64x " ] %s\n",
587  flag->offset, flag->realname);
588  goto beach;
589  }
590  }
591  }
592 beach:
595  return true;
596 }
RZ_API const RzList * rz_flag_get_list(RzFlag *f, ut64 off)
Definition: flag.c:475
char * realname
Definition: rz_flag.h:36

References rz_core_t::dbg, rz_core_t::flags, list(), NULL, rz_flag_item_t::offset, pc, PFMT64x, rz_flag_item_t::realname, rz_cons_break_pop(), rz_cons_break_push(), rz_cons_is_breaked(), rz_cons_printf(), rz_core_reg_update_flags(), rz_debug_is_dead(), rz_debug_reg_get(), rz_debug_reg_sync(), rz_debug_step(), rz_flag_get_list(), RZ_LOG_ERROR, RZ_REG_TYPE_ANY, and ut64().

Referenced by rz_cmd_debug_step_until_flag_handler().

◆ step_until_inst()

static bool step_until_inst ( RzCore core,
const char *  instr,
bool  regex 
)
static

Definition at line 416 of file cmd_debug.c.

416  {
417  rz_return_val_if_fail(core, false);
418  instr = rz_str_trim_head_ro(instr);
419  if (!instr || !core->dbg) {
420  RZ_LOG_ERROR("wrong debugger state\n");
421  return false;
422  }
423  RzAsmOp asmop;
424  ut8 buf[32];
425  ut64 pc;
426  int ret;
427  bool is_x86 = rz_str_startswith(rz_config_get(core->config, "asm.arch"), "x86");
429  for (;;) {
430  if (rz_cons_is_breaked()) {
431  break;
432  }
433  if (rz_debug_is_dead(core->dbg)) {
434  break;
435  }
436  pc = rz_debug_reg_get(core->dbg, "PC");
437  if (is_x86 && is_repeatable_inst(core, pc)) {
438  rz_debug_step_over(core->dbg, 1);
439  } else {
440  rz_debug_step(core->dbg, 1);
441  }
442  pc = rz_debug_reg_get(core->dbg, "PC");
443  rz_debug_reg_sync(core->dbg, RZ_REG_TYPE_ANY, false);
444  /* TODO: disassemble instruction and strstr */
445  rz_asm_set_pc(core->rasm, pc);
446  // TODO: speedup if instructions are in the same block as the previous
447  rz_io_read_at(core->io, pc, buf, sizeof(buf));
448  ret = rz_asm_disassemble(core->rasm, &asmop, buf, sizeof(buf));
449  eprintf("0x%08" PFMT64x " %d %s\n", pc, ret, rz_asm_op_get_asm(&asmop)); // asmop.buf_asm);
450  if (ret > 0) {
451  const char *buf_asm = rz_asm_op_get_asm(&asmop);
452  if (regex) {
453  if (rz_regex_match(instr, "e", buf_asm)) {
454  eprintf("Stop.\n");
455  break;
456  }
457  } else {
458  if (strstr(buf_asm, instr)) {
459  eprintf("Stop.\n");
460  break;
461  }
462  }
463  }
464  }
467  return true;
468 }
RZ_API char * rz_asm_op_get_asm(RzAsmOp *op)
Definition: aop.c:37
RZ_API int rz_asm_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
Definition: asm.c:543
static bool is_repeatable_inst(RzCore *core, ut64 addr)
Definition: cmd_debug.c:408
RZ_API int rz_regex_match(const char *pattern, const char *flags, const char *text)
Definition: regcomp.c:142
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

References rz_core_t::config, rz_core_t::dbg, eprintf, rz_core_t::io, is_repeatable_inst(), NULL, pc, PFMT64x, rz_core_t::rasm, rz_asm_disassemble(), rz_asm_op_get_asm(), rz_asm_set_pc(), rz_config_get(), 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_reg_sync(), rz_debug_step(), rz_debug_step_over(), rz_io_read_at(), RZ_LOG_ERROR, RZ_REG_TYPE_ANY, rz_regex_match(), rz_return_val_if_fail, rz_str_startswith(), rz_str_trim_head_ro(), and ut64().

Referenced by rz_cmd_debug_step_until_instr_handler(), and rz_cmd_debug_step_until_instr_regex_handler().

◆ step_until_optype()

static bool step_until_optype ( RzCore core,
RzList optypes_list 
)
static

Definition at line 486 of file cmd_debug.c.

486  {
488  ut8 buf[32];
489  ut64 pc;
490  int res = true;
491 
492  RzListIter *iter;
493  char *optype;
494 
495  if (!core || !core->dbg) {
496  RZ_LOG_ERROR("wrong state\n");
497  res = false;
498  goto end;
499  }
500  if (!optypes_list) {
501  RZ_LOG_ERROR("missing optypes. Usage example: 'dsuo ucall ujmp'\n");
502  res = false;
503  goto end;
504  }
505 
506  bool debugMode = rz_config_get_b(core->config, "cfg.debug");
507 
509  for (;;) {
510  if (rz_cons_is_breaked()) {
511  core->break_loop = true;
512  break;
513  }
514  if (debugMode) {
515  if (rz_debug_is_dead(core->dbg)) {
516  core->break_loop = true;
517  break;
518  }
519  rz_debug_step(core->dbg, 1);
520  pc = rz_debug_reg_get(core->dbg, core->dbg->reg->name[RZ_REG_NAME_PC]);
521  // 'Copy' from rz_debug_step_soft
522  if (!core->dbg->iob.read_at) {
523  RZ_LOG_ERROR("ERROR\n");
524  res = false;
525  goto cleanup_after_push;
526  }
527  if (!core->dbg->iob.read_at(core->dbg->iob.io, pc, buf, sizeof(buf))) {
528  RZ_LOG_ERROR("ERROR\n");
529  res = false;
530  goto cleanup_after_push;
531  }
532  } else {
533  rz_core_esil_step(core, UT64_MAX, NULL, NULL, false);
534  pc = rz_reg_getv(core->analysis->reg, "PC");
535  }
536  rz_io_read_at(core->io, pc, buf, sizeof(buf));
537 
538  if (rz_analysis_op(core->dbg->analysis, &op, pc, buf, sizeof(buf), RZ_ANALYSIS_OP_MASK_BASIC) < 1) {
539  RZ_LOG_ERROR("rz_analysis_op failed\n");
540  res = false;
541  goto cleanup_after_push;
542  }
543 
544  // This is slow because we do lots of strcmp's.
545  // To improve this, the function rz_analysis_optype_string_to_int should be implemented
546  // I also don't check if the opcode type exists.
547  const char *optype_str = rz_analysis_optype_to_string(op.type);
548  rz_list_foreach (optypes_list, iter, optype) {
549  if (!strcmp(optype_str, optype)) {
550  goto cleanup_after_push;
551  }
552  }
553  }
554 
555 cleanup_after_push:
558 end:
559  return res;
560 }
ut8 op
Definition: 6502dis.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_API const char * rz_analysis_optype_to_string(int type)
Definition: op.c:310
ut8 optype
Definition: pic_pic18.c:32
@ RZ_REG_NAME_PC
Definition: rz_reg.h:43
Definition: op.c:222
RzIOBind iob
Definition: rz_debug.h:293
RzIOReadAt read_at
Definition: rz_io.h:240
RzIO * io
Definition: rz_io.h:232
char * name[RZ_REG_NAME_LAST]
Definition: rz_reg.h:149

References rz_core_t::analysis, rz_debug_t::analysis, rz_core_t::break_loop, rz_core_t::config, rz_core_t::dbg, test_evm::end, rz_core_t::io, rz_io_bind_t::io, rz_debug_t::iob, rz_reg_t::name, NULL, op, optype, pc, rz_io_bind_t::read_at, rz_analysis_t::reg, rz_debug_t::reg, rz_analysis_op(), RZ_ANALYSIS_OP_MASK_BASIC, rz_analysis_optype_to_string(), rz_config_get_b(), rz_cons_break_pop(), rz_cons_break_push(), rz_cons_is_breaked(), rz_core_esil_step(), rz_core_reg_update_flags(), rz_debug_is_dead(), rz_debug_reg_get(), rz_debug_step(), rz_io_read_at(), RZ_LOG_ERROR, rz_reg_getv(), RZ_REG_NAME_PC, ut64(), and UT64_MAX.

Referenced by rz_cmd_debug_step_until_optype_handler(), and rz_il_step_until_opt_handler().

◆ trace_traverse()

static void trace_traverse ( RTree t)
static

Definition at line 1642 of file cmd_debug.c.

1642  {
1643  RTreeVisitor vis = { 0 };
1644 
1645  /* clear the line on stderr, because somebody has written there */
1646  fprintf(stderr, "\x1b[2K\r");
1647  fflush(stderr);
1649  rz_tree_dfs(t, &vis);
1650 }
static void trace_traverse_pre(RTreeNode *n, RTreeVisitor *vis)
Definition: cmd_debug.c:1624
RZ_API void rz_tree_dfs(RTree *t, RTreeVisitor *vis)
Definition: tree.c:124
void(* pre_visit)(RTreeNode *, struct rz_tree_visitor_t *)
Definition: rz_tree.h:22

References rz_tree_visitor_t::pre_visit, rz_tree_dfs(), and trace_traverse_pre().

Referenced by debug_trace_calls().

◆ trace_traverse_pre()

static void trace_traverse_pre ( RTreeNode n,
RTreeVisitor vis 
)
static

Definition at line 1624 of file cmd_debug.c.

1624  {
1625  const char *name = "";
1626  struct trace_node *tn = n->data;
1627  unsigned int i;
1628  if (!tn)
1629  return;
1630  for (i = 0; i < n->depth - 1; i++) {
1631  rz_cons_printf(" ");
1632  }
1633  if (_core) {
1634  RzFlagItem *f = rz_flag_get_at(_core->flags, tn->addr, true);
1635  if (f) {
1636  name = f->name;
1637  }
1638  }
1639  rz_cons_printf(" 0x%08" PFMT64x " refs %d %s\n", tn->addr, tn->refs, name);
1640 }

References _core, trace_node::addr, f, rz_core_t::flags, i, n, PFMT64x, trace_node::refs, rz_cons_printf(), and rz_flag_get_at().

Referenced by trace_traverse().

Variable Documentation

◆ _core

◆ help_msg_d

const char* help_msg_d[]
static
Initial value:
= {
"Usage:", "d", " # Debug commands",
"db", "[?]", "Breakpoints commands",
"dbt", "[?]", "Display backtrace based on dbg.btdepth and dbg.btalgo",
"dc", "[?]", "Continue execution",
"dd", "[?]", "File descriptors (!fd in r1)",
"de", "[-sc] [perm] [rm] [e]", "Debug with ESIL (see de?)",
"dg", " <file>", "Generate a core-file (WIP)",
"dH", " [handler]", "Transplant process to a new handler",
"di", "[?]", "Show debugger backend information (See dh)",
"dk", "[?]", "List, send, get, set, signal handlers of child",
"dL", "[?]", "List or set debugger handler",
"dm", "[?]", "Show memory maps",
"do", "[?]", "Open process (reload, alias for 'oo')",
"doc", "", "Close debug session",
"dp", "[?]", "List, attach to process or thread id",
"dr", "[?]", "Cpu registers",
"ds", "[?]", "Step, over, source line",
"dt", "[?]", "Display instruction traces",
"dw", " <pid>", "Block prompt until pid dies",
"dx", "[?]", "Inject and run code on target process (See gs)",
}

Definition at line 27 of file cmd_debug.c.

Referenced by rz_cmd_debug().

◆ help_msg_dcs

const char* help_msg_dcs[]
static
Initial value:
= {
"Usage:", "dcs", " Continue until syscall",
"dcs", "", "Continue until next syscall",
"dcs [str]", "", "Continue until next call to the 'str' syscall",
"dcs", "*", "Trace all syscalls, a la strace",
}

Definition at line 55 of file cmd_debug.c.

Referenced by rz_cmd_debug_continue_syscall().

◆ help_msg_dcu

const char* help_msg_dcu[]
static
Initial value:
= {
"Usage:", "dcu", " Continue until address",
"dcu.", "", "Alias for dcu $$ (continue until current address",
"dcu", " address", "Continue until address",
"dcu", " [..tail]", "Continue until the range",
"dcu", " [from] [to]", "Continue until the range",
}

Definition at line 63 of file cmd_debug.c.

Referenced by cmd_dcu(), and rz_cmd_debug_continue_until().

◆ help_msg_dd

const char* help_msg_dd[]
static
Initial value:
= {
"Usage: dd", "", "Descriptors commands",
"dd", "", "List file descriptors",
"dd", " <file>", "Open and map that file into the UI",
"dd-", "<fd>", "Close stdout fd",
"dd*", "", "List file descriptors (in rizin commands)",
"dds", " <fd> <off>", "Seek given fd)",
"ddd", " <fd1> <fd2>", "Dup2 from fd1 to fd2",
"ddr", " <fd> <size>", "Read N bytes from fd",
"ddw", " <fd> <hexpairs>", "Write N bytes to fd",
}

Definition at line 72 of file cmd_debug.c.

Referenced by rz_cmd_debug().

◆ help_msg_de

const char* help_msg_de[]
static
Initial value:
= {
"Usage:", "de", "[-sc] [perm] [rm] [expr]",
"de", "", "List esil watchpoints",
"de-*", "", "Delete all esil watchpoints",
"de", " [perm] [rm] [addr|reg|from..to]", "Stop on condition",
"dec", "", "Continue execution until matching expression",
"des", "[?] [N]", "Step-in N instructions with esildebug",
"desu", " [addr]", "Esildebug until specific address",
}

Definition at line 85 of file cmd_debug.c.

Referenced by rz_core_debug_esil().

◆ help_msg_des

const char* help_msg_des[]
static
Initial value:
= {
"Usage:", "des", "[u] [arg]",
"des", " [N]", "step-in N instructions with esildebug",
"desu", " [addr]", "esildebug until specific address",
}

Definition at line 96 of file cmd_debug.c.

Referenced by rz_core_debug_esil().

◆ help_msg_di

const char* help_msg_di[]
static
Initial value:
= {
"Usage: di", "", "Debugger target information",
"di", "", "Show debugger target information",
"di*", "", "Same as above, but in rizin commands",
"diq", "", "Same as above, but in one line",
"dij", "", "Same as above, but in JSON format",
"dif", " [$a] [$b]", "Compare two files (or $alias files)",
}

Definition at line 103 of file cmd_debug.c.

Referenced by rz_cmd_debug().

◆ help_msg_dk

const char* help_msg_dk[]
static
Initial value:
= {
"Usage: dk", "", "Signal commands",
"dk", "", "List all signal handlers of child process",
"dk", " <signal>", "Send KILL signal to child",
"dk", " <signal>=1", "Set signal handler for <signal> in child",
"dk?", "<signal>", "Name/signum resolver",
"dko", "[?] <signal>", "Reset skip or cont options for given signal",
"dko", " <signal> [|skip|cont]", "On signal SKIP handler or CONT into",
"dkj", "", "List all signal handlers in JSON",
}

Definition at line 113 of file cmd_debug.c.

Referenced by rz_core_debug_kill().

◆ help_msg_dko

const char* help_msg_dko[]
static
Initial value:
= {
"Usage:", "dko", " # Signal handling commands",
"dko", "", "List existing signal handling",
"dko", " [signal]", "Clear handling for a signal",
"dko", " [signal] [skip|cont]", "Set handling for a signal",
}

Definition at line 125 of file cmd_debug.c.

Referenced by rz_core_debug_kill().

◆ help_msg_dmi

const char* help_msg_dmi[]
static
Initial value:
= {
"Usage: dmi", "", " # List/Load Symbols",
"dmi", "[j|q|*] [libname] [symname]", "List symbols of target lib",
"dmia", "[j|q|*] [libname]", "List all info of target lib",
"dmi*", "", "List symbols of target lib in rizin commands",
"dmi.", "", "List closest symbol to the current address",
"dmiv", "", "Show address of given symbol for given lib",
}

Definition at line 133 of file cmd_debug.c.

Referenced by rz_cmd_debug_dmi().

◆ help_msg_dp

const char* help_msg_dp[]
static
Initial value:
= {
"Usage:", "dp", " # Process commands",
"dp", "", "List current pid and children",
"dp", " <pid>", "List children of pid",
"dpj", " <pid>", "List children of pid in JSON format",
"dpl", "", "List all attachable pids",
"dplj", "", "List all attachable pids in JSON format",
"dp-", " <pid>", "Detach select pid",
"dp=", "<pid>", "Select pid",
"dpa", " <pid>", "Attach and select pid",
"dpc", "", "Select forked pid (see dbg.forks)",
"dpc*", "", "Display forked pid (see dbg.forks)",
"dpe", "", "Show path to executable",
"dpf", "", "Attach to pid like file fd // HACK",
"dpk", " <pid> [<signal>]", "Send signal to process (default 0)",
"dpn", "", "Create new process (fork)",
"dptn", "", "Create new thread (clone)",
"dpt", "", "List threads of current pid",
"dptj", "", "List threads of current pid in JSON format",
"dpt", " <pid>", "List threads of process",
"dptj", " <pid>", "List threads of process in JSON format",
"dpt=", "<thread>", "Attach to thread",
}

Definition at line 143 of file cmd_debug.c.

Referenced by cmd_debug_pid().

◆ help_msg_dx

const char* help_msg_dx[]
static
Initial value:
= {
"Usage: dx", "", " # Code injection commands",
"dx", " <opcode>...", "Inject opcodes",
"dxa", " nop", "Assemble code and inject",
"dxe", " egg-expr", "Compile egg expression and inject it",
"dxr", " <opcode>...", "Inject opcodes and restore state",
"dxs", " write 1, 0x8048, 12", "Syscall injection (see gs)",
"\nExamples:", "", "",
"dx", " 9090", "Inject two x86 nop",
"\"dxa mov eax,6;mov ebx,0;int 0x80\"", "", "Inject and restore state",
}

Definition at line 168 of file cmd_debug.c.

Referenced by rz_cmd_debug().