Rizin
unix-like reverse engineering framework and cli tools
generic-all.c File Reference
#include <rz_debug.h>

Go to the source code of this file.

Functions

static ut64 read_ptr (RzDebug *dbg, ut64 at)
 
static RzListbacktrace_generic (RZ_BORROW RZ_NONNULL RzDebug *dbg)
 

Function Documentation

◆ backtrace_generic()

static RzList* backtrace_generic ( RZ_BORROW RZ_NONNULL RzDebug dbg)
static

Definition at line 14 of file generic-all.c.

14  {
16  const size_t pointer_size = dbg->bits;
17  RzList *ret = rz_list_newf(free);
18  if (!ret) {
19  return NULL;
20  }
26  if (!frame) {
27  return ret;
28  }
29  frame->addr = pc;
30  frame->bp = bp;
31  frame->sp = sp;
32  frame->size = bp - sp;
33  sp = bp;
34  bp = read_ptr(dbg, sp);
35  sp += pointer_size;
36  if (!lr || lr == UT64_MAX) {
37  pc = read_ptr(dbg, sp);
38  sp += pointer_size;
39  } else {
40  pc = lr;
41  }
42  rz_list_push(ret, frame);
43 
44  do {
45  frame = RZ_NEW0(RzDebugFrame);
46  if (!frame) {
47  return ret;
48  }
49  frame->bp = bp;
50  frame->sp = sp;
51  frame->size = bp ? bp - sp : 0;
52  frame->addr = pc;
53  sp = bp;
54  if (sp) {
55  bp = read_ptr(dbg, sp);
56  sp += pointer_size;
57  pc = read_ptr(dbg, sp);
58  sp += pointer_size;
59  }
60  rz_list_push(ret, frame);
61  } while (sp && pc && pc != UT64_MAX);
62 
63  return ret;
64 }
#define NULL
Definition: cris-opc.c:27
RzDebug * dbg
Definition: desil.c:30
static ut64 read_ptr(RzDebug *dbg, ut64 at)
Definition: generic-all.c:6
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
RZ_API RZ_BORROW RzListIter * rz_list_push(RZ_NONNULL RzList *list, void *item)
Alias for rz_list_append.
Definition: list.c:60
RZ_API ut64 rz_reg_getv_by_role_or_name(RzReg *reg, const char *name)
Definition: reg.c:338
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define UT64_MAX
Definition: rz_types_base.h:86
RzReg * reg
Definition: rz_debug.h:286
int bits
Definition: rz_debug.h:243
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int sp
Definition: z80asm.c:91

References rz_debug_frame_t::addr, rz_debug_t::bits, rz_debug_frame_t::bp, dbg, free(), lr, NULL, pc, read_ptr(), rz_debug_t::reg, rz_list_newf(), rz_list_push(), RZ_NEW0, rz_reg_getv_by_role_or_name(), rz_return_val_if_fail, rz_debug_frame_t::size, sp, rz_debug_frame_t::sp, ut64(), and UT64_MAX.

Referenced by rz_debug_dmp_frames(), and rz_debug_winkd_frames().

◆ read_ptr()

static ut64 read_ptr ( RzDebug dbg,
ut64  at 
)
static

Definition at line 6 of file generic-all.c.

6  {
7  ut8 buf[8];
8  if (!dbg->iob.read_at(dbg->iob.io, at, buf, dbg->bits)) {
9  return UT64_MAX;
10  }
11  return rz_read_ble(buf, dbg->analysis->big_endian, dbg->bits * 8);
12 }
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
static ut64 rz_read_ble(const void *src, bool big_endian, int size)
Definition: rz_endian.h:517
RzAnalysis * analysis
Definition: rz_debug.h:305
RzIOBind iob
Definition: rz_debug.h:293
RzIOReadAt read_at
Definition: rz_io.h:240
RzIO * io
Definition: rz_io.h:232

References rz_debug_t::analysis, rz_analysis_t::big_endian, rz_debug_t::bits, dbg, rz_io_bind_t::io, rz_debug_t::iob, rz_io_bind_t::read_at, rz_read_ble(), and UT64_MAX.

Referenced by backtrace_generic().