Rizin
unix-like reverse engineering framework and cli tools
bt.c
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: 2009-2018 pancake <pancake@nopcode.org>
2
// SPDX-License-Identifier: LGPL-3.0-only
3
4
#include <
rz_analysis.h
>
5
6
#if __WINDOWS__
7
#include "
bt/windows-all.c
"
8
#endif
9
#include "
bt/generic-x86.c
"
10
#include "
bt/generic-x64.c
"
11
#include "
bt/fuzzy-all.c
"
12
13
typedef
RzList
*(*RzDebugFrameCallback)(
RzDebug
*
dbg
,
ut64
at);
14
15
static
void
prepend_current_pc
(
RzDebug
*
dbg
,
RzList
*
list
) {
16
RzDebugFrame
*frame;
17
const
char
*pcname;
18
if
(
list
) {
19
pcname =
rz_reg_get_name
(
dbg
->
reg
,
RZ_REG_NAME_PC
);
20
if
(pcname) {
21
ut64
addr
=
rz_reg_getv
(
dbg
->
reg
, pcname);
22
frame =
RZ_NEW0
(
RzDebugFrame
);
23
frame->
addr
=
addr
;
24
frame->
size
= 0;
25
rz_list_prepend
(
list
, frame);
26
}
27
}
28
}
29
30
#if HAVE_PTRACE
31
struct
frames_proxy_args {
32
RzDebugFrameCallback
cb
;
33
RzDebug
*
dbg
;
34
ut64
at;
35
};
36
37
static
void
*backtrace_proxy(
void
*user) {
38
struct
frames_proxy_args *
args
= user;
39
if
(
args
->cb) {
40
return
args
->cb(
args
->dbg,
args
->at);
41
}
42
return
NULL
;
43
}
44
#endif
45
46
static
RzList
*
rz_debug_native_frames
(
RzDebug
*
dbg
,
ut64
at) {
47
RzDebugFrameCallback
cb
=
NULL
;
48
if
(
dbg
->
btalgo
) {
49
if
(!strcmp(
dbg
->
btalgo
,
"fuzzy"
)) {
50
cb
=
backtrace_fuzzy
;
51
}
else
if
(!strcmp(
dbg
->
btalgo
,
"analysis"
)) {
52
if
(!strcmp(
dbg
->
arch
,
"x86"
)) {
53
if
(
dbg
->
bits
==
RZ_SYS_BITS_64
) {
54
cb
=
backtrace_x86_64_analysis
;
55
}
else
{
56
cb
=
backtrace_x86_32_analysis
;
57
}
58
}
else
{
59
eprintf
(
"Analysis backtrace not available for current architecture (%s)\n"
,
dbg
->
arch
);
60
return
NULL
;
61
}
62
}
63
}
64
if
(!
cb
) {
65
#if __WINDOWS__
66
cb
=
backtrace_windows
;
67
#else
68
if
(
dbg
->
bits
==
RZ_SYS_BITS_64
) {
69
cb
=
backtrace_x86_64
;
70
}
else
{
71
cb
=
backtrace_x86_32
;
72
}
73
#endif
74
}
75
76
RzList
*
list
;
77
if
(
dbg
->
btalgo
&& !strcmp(
dbg
->
btalgo
,
"trace"
)) {
78
list
=
rz_list_clone
(
dbg
->
call_frames
);
79
}
else
{
80
#if HAVE_PTRACE
81
struct
frames_proxy_args
args
= {
cb
,
dbg
, at };
82
list
= rz_debug_ptrace_func(
dbg
, backtrace_proxy, &
args
);
83
#else
84
list
=
cb
(
dbg
, at);
85
#endif
86
}
87
88
prepend_current_pc
(
dbg
,
list
);
89
return
list
;
90
}
RzDebugFrameCallback
RzList *(* RzDebugFrameCallback)(RzDebug *dbg, ut64 at)
Definition:
bt.c:13
prepend_current_pc
static void prepend_current_pc(RzDebug *dbg, RzList *list)
Definition:
bt.c:15
rz_debug_native_frames
static RzList * rz_debug_native_frames(RzDebug *dbg, ut64 at)
Definition:
bt.c:46
NULL
#define NULL
Definition:
cris-opc.c:27
dbg
RzDebug * dbg
Definition:
desil.c:30
fuzzy-all.c
backtrace_fuzzy
static RzList * backtrace_fuzzy(RzDebug *dbg, ut64 at)
Definition:
fuzzy-all.c:41
generic-x64.c
backtrace_x86_64
static RzList * backtrace_x86_64(RzDebug *dbg, ut64 at)
Definition:
generic-x64.c:4
backtrace_x86_64_analysis
static RzList * backtrace_x86_64_analysis(RzDebug *dbg, ut64 at)
Definition:
generic-x64.c:58
generic-x86.c
backtrace_x86_32
static RzList * backtrace_x86_32(RzDebug *dbg, ut64 at)
Definition:
generic-x86.c:12
backtrace_x86_32_analysis
static RzList * backtrace_x86_32_analysis(RzDebug *dbg, ut64 at)
Definition:
generic-x86.c:45
list
static void list(RzEgg *egg)
Definition:
rz-gg.c:52
rz_list_prepend
RZ_API RZ_BORROW RzListIter * rz_list_prepend(RZ_NONNULL RzList *list, void *data)
Appends at the beginning of the list a new element.
Definition:
list.c:316
rz_list_clone
RZ_API RZ_OWN RzList * rz_list_clone(RZ_NONNULL const RzList *list)
Shallow copies of the list (but doesn't free its elements)
Definition:
list.c:496
args
int args
Definition:
mipsasm.c:18
rz_reg_getv
RZ_API ut64 rz_reg_getv(RzReg *reg, const char *name)
Definition:
reg.c:332
rz_reg_get_name
RZ_API const char * rz_reg_get_name(RzReg *reg, int role)
Definition:
reg.c:147
eprintf
#define eprintf(x, y...)
Definition:
rlcc.c:7
rz_analysis.h
RZ_REG_NAME_PC
@ RZ_REG_NAME_PC
Definition:
rz_reg.h:43
RZ_SYS_BITS_64
@ RZ_SYS_BITS_64
Definition:
rz_sys.h:21
RZ_NEW0
#define RZ_NEW0(x)
Definition:
rz_types.h:284
rz_debug_frame_t
Definition:
rz_debug.h:119
rz_debug_frame_t::size
int size
Definition:
rz_debug.h:121
rz_debug_frame_t::addr
ut64 addr
Definition:
rz_debug.h:120
rz_debug_t
Definition:
rz_debug.h:241
rz_debug_t::arch
char * arch
Definition:
rz_debug.h:242
rz_debug_t::reg
RzReg * reg
Definition:
rz_debug.h:286
rz_debug_t::call_frames
RzList * call_frames
Definition:
rz_debug.h:284
rz_debug_t::btalgo
char * btalgo
Definition:
rz_debug.h:258
rz_debug_t::bits
int bits
Definition:
rz_debug.h:243
rz_list_t
Definition:
rz_list.h:18
windows-all.c
backtrace_windows
static RzList * backtrace_windows(RzDebug *dbg, ut64 at)
Definition:
windows-all.c:66
ut64
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
cb
static const char * cb[]
Definition:
z80_tab.h:176
addr
static int addr
Definition:
z80asm.c:58
librz
debug
p
native
bt.c
Generated by
1.9.1