Rizin
unix-like reverse engineering framework and cli tools
linux_debug.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2015 Álvaro Felipe Melchor <alvaro.felipe91@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 /* __
5  -=(o '.
6  \.-.\
7  /| \\
8  '| ||
9  _\_):,_
10 */
11 
12 #ifndef LINUX_DEBUG_H
13 #define LINUX_DEBUG_H
14 
15 #include <limits.h>
16 #include <sys/ptrace.h>
17 
46 };
47 
66 };
67 
68 #if __ANDROID__
69 
70 #if __arm64__ || __aarch64__
71 #define RZ_DEBUG_REG_T struct user_pt_regs
72 
73 #ifndef NT_PRSTATUS
74 #define NT_PRSTATUS 1
75 #endif
76 
77 #else
78 #define RZ_DEBUG_REG_T struct pt_regs
79 #endif
80 
81 #else
82 
83 #include <sys/user.h>
84 #if __i386__ || __x86_64__
85 #define RZ_DEBUG_REG_T struct user_regs_struct
86 #elif __s390x__ || __s390__
87 #define RZ_DEBUG_REG_T struct _user_regs_struct
88 #if 0
89 // https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/s390/sys/user.h;hb=HEAD#l50
90  50 struct _user_regs_struct
91  51 {
92  52 struct _user_psw_struct psw; /* Program status word. */
93  53 unsigned long gprs[16]; /* General purpose registers. */
94  54 unsigned int acrs[16]; /* Access registers. */
95  55 unsigned long orig_gpr2; /* Original gpr2. */
96  56 struct _user_fpregs_struct fp_regs; /* Floating point registers. */
97  57 struct _user_per_struct per_info; /* Hardware tracing registers. */
98  58 unsigned long ieee_instruction_pointer; /* Always 0. */
99  59 };
100 #endif
101 #elif __arm64__ || __aarch64__
102 #include <asm/ptrace.h>
103 #ifndef NT_PRSTATUS
104 #define NT_PRSTATUS 1
105 #endif
106 #define RZ_DEBUG_REG_T struct user_pt_regs
107 #elif __arm__
108 #define RZ_DEBUG_REG_T struct user_regs
109 #elif __POWERPC__
110 struct powerpc_regs_t {
111  unsigned long gpr[32];
112  unsigned long nip;
113  unsigned long msr;
114  unsigned long orig_gpr3; /* Used for restarting system calls */
115  unsigned long ctr;
116  unsigned long link;
117  unsigned long xer;
118  unsigned long ccr;
119 #ifdef __powerpc64__
120  unsigned long softe; /* Soft enabled/disabled */
121 #else
122  unsigned long mq; /* 601 only (not used at present) */
123  /* Used on APUS to hold IPL value. */
124 #endif
125  unsigned long trap; /* Reason for being here */
126  /* N.B. for critical exceptions on 4xx, the dar and dsisr
127  fields are overloaded to hold srr0 and srr1. */
128  unsigned long dar; /* Fault registers */
129  unsigned long dsisr; /* on 4xx/Book-E used for ESR */
130  unsigned long result; /* Result of a system call */
131 };
132 #define RZ_DEBUG_REG_T struct powerpc_regs_t
133 #elif __riscv || __riscv__ || __riscv64__
134 
135 #include <sys/ucontext.h>
136 #include <asm/ptrace.h>
137 
138 // typedef ut64 riscv64_regs_t [65];
139 // #define RZ_DEBUG_REG_T riscv64_regs_t
140 #define RZ_DEBUG_REG_T struct user_regs_struct
141 // #define RZ_DEBUG_REG_T mcontext_t 77 784 in size (coz the fpu regs)
142 
143 #elif __mips__
144 
145 #include <sys/ucontext.h>
146 typedef ut64 mips64_regs_t[274];
147 #define RZ_DEBUG_REG_T mips64_regs_t
148 #endif
149 #endif
150 
151 // SIGTRAP si_codes from <asm/siginfo.h>
152 #if !defined(TRAP_BRKPT) && !defined(TRAP_TRACE)
153 #define TRAP_BRKPT 1
154 #define TRAP_TRACE 2
155 #define TRAP_BRANCH 3
156 #define TRAP_HWBKPT 4
157 #define TRAP_UNK 5
158 #endif
159 
160 // API
161 bool linux_set_options(RzDebug *dbg, int pid);
162 int linux_step(RzDebug *dbg);
164 int linux_attach(RzDebug *dbg, int pid);
166 RzDebugInfo *linux_info(RzDebug *dbg, const char *arg);
169 bool linux_select(RzDebug *dbg, int pid, int tid);
170 RzDebugPid *fill_pid_info(const char *info, const char *path, int tid);
171 int linux_reg_read(RzDebug *dbg, int type, ut8 *buf, int size);
172 int linux_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size);
174 bool linux_stop_threads(RzDebug *dbg, int except);
175 int linux_handle_signals(RzDebug *dbg, int tid);
176 int linux_dbg_wait(RzDebug *dbg, int pid);
178 int match_pid(const void *pid_o, const void *th_o);
179 
180 #endif
static RzILOpEffect * msr(cs_insn *insn, bool is_thumb)
Definition: arm_il32.c:1268
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35
static static fork const void static count static fd link
Definition: sflib.h:33
uint32_t ut32
RzDebug * dbg
Definition: desil.c:30
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
static void list(RzEgg *egg)
Definition: rz-gg.c:52
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
static const char struct stat static buf struct stat static buf static vhangup int status
Definition: sflib.h:145
char * linux_reg_profile(RzDebug *dbg)
Definition: linux_debug.c:55
int linux_handle_signals(RzDebug *dbg, int tid)
Definition: linux_debug.c:103
int linux_attach(RzDebug *dbg, int pid)
Definition: linux_debug.c:718
RzDebugPid * fill_pid_info(const char *info, const char *path, int tid)
Definition: linux_debug.c:789
int linux_dbg_wait(RzDebug *dbg, int pid)
Definition: linux_debug.c:502
RzList * linux_pid_list(int pid, RzList *list)
Definition: linux_debug.c:838
int match_pid(const void *pid_o, const void *th_o)
Definition: linux_debug.c:608
bool linux_attach_new_process(RzDebug *dbg, int pid)
Definition: linux_debug.c:451
bool linux_stop_threads(RzDebug *dbg, int except)
Definition: linux_debug.c:660
int linux_reg_read(RzDebug *dbg, int type, ut8 *buf, int size)
Definition: linux_debug.c:1090
RzList * linux_thread_list(RzDebug *dbg, int pid, RzList *list)
Definition: linux_debug.c:875
bool linux_set_options(RzDebug *dbg, int pid)
Definition: linux_debug.c:383
RzList * linux_desc_list(int pid)
Definition: linux_debug.c:1319
RzDebugInfo * linux_info(RzDebug *dbg, const char *arg)
Definition: linux_debug.c:745
RzDebugReasonType linux_ptrace_event(RzDebug *dbg, int pid, int status, bool dowait)
int linux_step(RzDebug *dbg)
Definition: linux_debug.c:369
int linux_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size)
Definition: linux_debug.c:1265
bool linux_select(RzDebug *dbg, int pid, int tid)
Definition: linux_debug.c:444
int type
Definition: mipsasm.c:17
RzDebugReasonType
Definition: rz_debug.h:89
ut64(WINAPI *w32_GetEnabledXStateFeatures)()