Rizin
unix-like reverse engineering framework and cli tools
dreg.c File Reference
#include <rz_core.h>
#include <rz_debug.h>
#include <rz_cons.h>
#include <rz_reg.h>

Go to the source code of this file.

Functions

RZ_API int rz_debug_reg_sync (RzDebug *dbg, int type, int write)
 
RZ_API int rz_debug_reg_set (struct rz_debug_t *dbg, const char *name, ut64 num)
 
RZ_API ut64 rz_debug_reg_get (RzDebug *dbg, const char *name)
 
RZ_API ut64 rz_debug_num_callback (RzNum *userptr, const char *str, int *ok)
 
RZ_API bool rz_debug_reg_profile_sync (RzDebug *dbg)
 

Function Documentation

◆ rz_debug_num_callback()

RZ_API ut64 rz_debug_num_callback ( RzNum userptr,
const char *  str,
int ok 
)

Definition at line 104 of file dreg.c.

104  {
105  RzDebug *dbg = (RzDebug *)userptr;
108  if (!ri) {
109  *ok = 0;
110  return UT64_MAX;
111  }
112  *ok = 1;
113  return rz_reg_get_value(dbg->reg, ri);
114 }
RzDebug * dbg
Definition: desil.c:30
RZ_API int rz_debug_reg_sync(RzDebug *dbg, int type, int write)
Definition: dreg.c:9
@ ok
Definition: lz4.c:1706
RZ_API RzRegItem * rz_reg_get_by_role_or_name(RzReg *reg, const char *name)
Definition: reg.c:378
RZ_API ut64 rz_reg_get_value(RzReg *reg, RzRegItem *item)
Definition: rvalue.c:114
@ RZ_REG_TYPE_ANY
Definition: rz_reg.h:35
#define UT64_MAX
Definition: rz_types_base.h:86
RzReg * reg
Definition: rz_debug.h:286

References dbg, ok, rz_debug_t::reg, rz_debug_reg_sync(), rz_reg_get_by_role_or_name(), rz_reg_get_value(), RZ_REG_TYPE_ANY, cmd_descs_generate::str, and UT64_MAX.

Referenced by rz_debug_new().

◆ rz_debug_reg_get()

◆ rz_debug_reg_profile_sync()

RZ_API bool rz_debug_reg_profile_sync ( RzDebug dbg)

Definition at line 116 of file dreg.c.

116  {
117  if (dbg->cur->reg_profile) {
118  char *p = dbg->cur->reg_profile(dbg);
119  if (p) {
122  free(p);
123  } else {
124  RZ_LOG_WARN("Cannot retrieve reg profile from debug plugin (%s)\n", dbg->cur->name);
125  return false;
126  }
127  }
128  return true;
129 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
void * p
Definition: libc.cpp:67
RZ_API bool rz_reg_set_profile_string(RZ_NONNULL RzReg *reg, RZ_NONNULL const char *profile_str)
Parses a register profile string and sets up all registers accordingly in reg.
Definition: profile.c:431
#define RZ_LOG_WARN(fmtstr,...)
Definition: rz_log.h:56
const char * name
Definition: rz_debug.h:359
char *(* reg_profile)(RzDebug *dbg)
Definition: rz_debug.h:394
struct rz_debug_plugin_t * cur
Definition: rz_debug.h:295

References rz_debug_t::cur, dbg, free(), rz_debug_plugin_t::name, p, rz_debug_t::reg, rz_debug_plugin_t::reg_profile, rz_debug_reg_sync(), RZ_LOG_WARN, rz_reg_set_profile_string(), and RZ_REG_TYPE_ANY.

Referenced by core_file_do_load_for_debug(), rz_core_debug_attach(), and rz_debug_use().

◆ rz_debug_reg_set()

RZ_API int rz_debug_reg_set ( struct rz_debug_t dbg,
const char *  name,
ut64  num 
)

Definition at line 89 of file dreg.c.

89  {
91  if (!ri) {
92  return false;
93  }
94  rz_reg_set_value(dbg->reg, ri, num);
96  return true;
97 }
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 struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags void static offset const char static length static mode static who const char struct statfs static buf unsigned unsigned num
Definition: sflib.h:126
RZ_API bool rz_reg_set_value(RzReg *reg, RzRegItem *item, ut64 value)
Definition: rvalue.c:186

References dbg, num, rz_debug_t::reg, rz_debug_reg_sync(), rz_reg_get_by_role_or_name(), rz_reg_set_value(), and RZ_REG_TYPE_ANY.

Referenced by rz_core_debug_step_skip(), rz_core_reg_set_by_role_or_name(), and rz_debug_continue_kill().

◆ rz_debug_reg_sync()

RZ_API int rz_debug_reg_sync ( RzDebug dbg,
int  type,
int  write 
)

Definition at line 9 of file dreg.c.

9  {
10  int i, n, size;
11  if (!dbg || !dbg->reg || !dbg->cur) {
12  return false;
13  }
14  // There's no point in syncing a dead target
15  if (rz_debug_is_dead(dbg)) {
16  return false;
17  }
18  // Check if the functions needed are available
19  if (write && !dbg->cur->reg_write) {
20  return false;
21  }
22  if (!write && !dbg->cur->reg_read) {
23  return false;
24  }
25  // Sync all the types sequentially if asked
27  // Check to get the correct arena when using @ into reg profile (arena!=type)
28  // if request type is positive and the request regset don't have regs
29  if (i >= RZ_REG_TYPE_GPR && dbg->reg->regset[i].regs && !dbg->reg->regset[i].regs->length) {
30  // seek into the other arena for redirections.
31  for (n = RZ_REG_TYPE_GPR; n < RZ_REG_TYPE_LAST; n++) {
32  // get regset mask
33  int mask = dbg->reg->regset[n].maskregstype;
34  // convert request arena to mask value
35  int v = ((int)1 << i);
36  // skip checks on same request arena and check if this arena have inside the request arena type
37  if (n != i && (mask & v)) {
38  // eprintf(" req = %i arena = %i mask = %x search = %x \n", i, n, mask, v);
39  // eprintf(" request arena %i found at arena %i\n", i, n );
40  // if this arena have the request arena type, force to use this arena.
41  i = n;
42  break;
43  }
44  }
45  }
46  do {
47  if (write) {
49  if (!buf || !dbg->cur->reg_write(dbg, i, buf, size)) {
50  if (i == RZ_REG_TYPE_GPR) {
51  eprintf("rz_debug_reg: error writing "
52  "registers %d to %d\n",
53  i, dbg->tid);
54  }
55  if (type != RZ_REG_TYPE_ANY || i == RZ_REG_TYPE_GPR) {
56  free(buf);
57  return false;
58  }
59  }
60  free(buf);
61  } else {
62  // int bufsize = RZ_MAX (1024, dbg->reg->size*2); // i know. its hacky
63  int bufsize = dbg->reg->size;
64  // int bufsize = dbg->reg->regset[i].arena->size;
65  if (bufsize > 0) {
66  ut8 *buf = calloc(1 + 1, bufsize);
67  if (!buf) {
68  return false;
69  }
70  // we have already checked dbg->h and dbg->h->reg_read above
71  size = dbg->cur->reg_read(dbg, i, buf, bufsize);
72  // we need to check against zero because reg_read can return false
73  if (size > 0) {
74  rz_reg_set_bytes(dbg->reg, i, buf, size); // RZ_MIN (size, bufsize));
75  // free (buf);
76  // return true;
77  }
78  free(buf);
79  }
80  }
81  // DO NOT BREAK RZ_REG_TYPE_ANY PLEASE
82  // break;
83  // Continue the synchronization or just stop if it was asked only for a single type of regs
84  i++;
85  } while ((type == RZ_REG_TYPE_ANY) && (i < RZ_REG_TYPE_LAST));
86  return true;
87 }
#define mask()
lzma_index ** i
Definition: index.h:629
RZ_API bool rz_reg_set_bytes(RzReg *reg, int type, const ut8 *buf, const int len)
Definition: arena.c:92
RZ_API ut8 * rz_reg_get_bytes(RzReg *reg, int type, int *size)
Definition: arena.c:8
static static fork write
Definition: sflib.h:33
const char * v
Definition: dsignal.c:12
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
RZ_API bool rz_debug_is_dead(RzDebug *dbg)
Definition: debug.c:1632
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
int n
Definition: mipsasm.c:19
int type
Definition: mipsasm.c:17
#define eprintf(x, y...)
Definition: rlcc.c:7
@ RZ_REG_TYPE_GPR
Definition: rz_reg.h:21
@ RZ_REG_TYPE_LAST
Definition: rz_reg.h:34
static int
Definition: sfsocketcall.h:114
int(* reg_read)(RzDebug *dbg, int type, ut8 *buf, int size)
Callback to be used for RzBreakpoint. When called, RzBreakpoint.user points to the RzDebug.
Definition: rz_debug.h:392
int(* reg_write)(RzDebug *dbg, int type, const ut8 *buf, int size)
Definition: rz_debug.h:393
ut32 length
Definition: rz_list.h:22
ut32 maskregstype
which type of regs has this register set (logic mask with 1 << RZ_REG_TYPE_XXX)
Definition: rz_reg.h:141
RzList * regs
RzRegItem.
Definition: rz_reg.h:138
int size
Definition: rz_reg.h:156
RzRegSet regset[RZ_REG_TYPE_LAST]
Definition: rz_reg.h:150

References calloc(), rz_debug_t::cur, dbg, eprintf, free(), i, int, rz_list_t::length, mask, rz_reg_set_t::maskregstype, n, rz_debug_t::reg, rz_debug_plugin_t::reg_read, rz_debug_plugin_t::reg_write, rz_reg_set_t::regs, rz_reg_t::regset, rz_debug_is_dead(), rz_reg_get_bytes(), rz_reg_set_bytes(), RZ_REG_TYPE_ANY, RZ_REG_TYPE_GPR, RZ_REG_TYPE_LAST, rz_reg_t::size, rz_debug_t::tid, type, v, and write.

Referenced by __esil_step(), cmd_dcu(), cmd_regs_sync(), do_debug_trace_calls(), drx_add(), drx_del(), linux_remove_fork_bps(), linux_thread_list(), rz_cmd_debug_continue_mapped_io_handler(), rz_cmd_debug_step_prog_handler(), rz_core_arg_get(), rz_core_debug_continue_until(), rz_core_debug_step_one(), rz_core_debug_step_skip(), rz_core_link_stroff(), rz_core_reg_update_flags(), rz_core_rtr_gdb_cb(), rz_debug_add_checkpoint(), rz_debug_bp_hit(), rz_debug_continue_syscalls(), rz_debug_continue_until_optype(), rz_debug_drx_handler(), rz_debug_drx_unset_handler(), rz_debug_esil_stepi(), rz_debug_execute(), rz_debug_num_callback(), rz_debug_reg_get(), rz_debug_reg_profile_sync(), rz_debug_reg_set(), rz_debug_select(), rz_debug_session_restore_reg_mem(), rz_debug_trace_ins_after(), rz_debug_wait(), step_until_esil(), step_until_flag(), and step_until_inst().