Rizin
unix-like reverse engineering framework and cli tools
generic-all.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2022 GustavoLCR <gugulcr@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_debug.h>
5 
6 static ut64 read_ptr(RzDebug *dbg, ut64 at) {
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 }
13 
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
static RzList * backtrace_generic(RZ_BORROW RZ_NONNULL RzDebug *dbg)
Definition: generic-all.c:14
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
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
static ut64 rz_read_ble(const void *src, bool big_endian, int size)
Definition: rz_endian.h:517
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define RZ_NONNULL
Definition: rz_types.h:64
#define RZ_BORROW
Definition: rz_types.h:63
#define UT64_MAX
Definition: rz_types_base.h:86
RzAnalysis * analysis
Definition: rz_debug.h:305
RzReg * reg
Definition: rz_debug.h:286
int bits
Definition: rz_debug.h:243
RzIOBind iob
Definition: rz_debug.h:293
RzIOReadAt read_at
Definition: rz_io.h:240
RzIO * io
Definition: rz_io.h:232
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int sp
Definition: z80asm.c:91