blob: e789324371dd7bc5bf41c75397dc58dce7821d49 [file] [log] [blame]
Juan Cespedes3df476b2009-05-28 19:17:17 +02001#ifndef _HCK_LTRACE_H
2#define _HCK_LTRACE_H
3
4#include <sys/types.h>
5#include <sys/time.h>
6#include <stdio.h>
7
8#include "defs.h"
9#include "dict.h"
10
11/* BREAKPOINT_LENGTH is defined in "sysdep.h" */
12#include "sysdep.h"
13
14#define MAX_LIBRARY 30
15
16#if defined HAVE_LIBIBERTY || defined HAVE_LIBSUPC__
17# define USE_DEMANGLE
18#endif
19
20extern char *command;
21
22extern int exiting; /* =1 if we have to exit ASAP */
23
24typedef struct Breakpoint Breakpoint;
25struct Breakpoint {
26 void *addr;
27 unsigned char orig_value[BREAKPOINT_LENGTH];
28 int enabled;
29 struct library_symbol *libsym;
30#ifdef __arm__
31 int thumb_mode;
32#endif
33};
34
35enum arg_type {
36 ARGTYPE_UNKNOWN = -1,
37 ARGTYPE_VOID,
38 ARGTYPE_INT,
39 ARGTYPE_UINT,
40 ARGTYPE_LONG,
41 ARGTYPE_ULONG,
42 ARGTYPE_OCTAL,
43 ARGTYPE_CHAR,
44 ARGTYPE_SHORT,
45 ARGTYPE_USHORT,
46 ARGTYPE_FLOAT, /* float value, may require index */
47 ARGTYPE_DOUBLE, /* double value, may require index */
48 ARGTYPE_ADDR,
49 ARGTYPE_FILE,
50 ARGTYPE_FORMAT, /* printf-like format */
51 ARGTYPE_STRING, /* NUL-terminated string */
52 ARGTYPE_STRING_N, /* String of known maxlen */
53 ARGTYPE_ARRAY, /* Series of values in memory */
54 ARGTYPE_ENUM, /* Enumeration */
55 ARGTYPE_STRUCT, /* Structure of values */
56 ARGTYPE_POINTER, /* Pointer to some other type */
57 ARGTYPE_COUNT /* number of ARGTYPE_* values */
58};
59
60typedef struct arg_type_info_t {
61 enum arg_type type;
62 union {
63 /* ARGTYPE_ENUM */
64 struct {
65 size_t entries;
66 char **keys;
67 int *values;
68 } enum_info;
69
70 /* ARGTYPE_ARRAY */
71 struct {
72 struct arg_type_info_t *elt_type;
73 size_t elt_size;
74 int len_spec;
75 } array_info;
76
77 /* ARGTYPE_STRING_N */
78 struct {
79 int size_spec;
80 } string_n_info;
81
82 /* ARGTYPE_STRUCT */
83 struct {
84 struct arg_type_info_t **fields; /* NULL-terminated */
85 size_t *offset;
86 size_t size;
87 } struct_info;
88
89 /* ARGTYPE_POINTER */
90 struct {
91 struct arg_type_info_t *info;
92 } ptr_info;
93
94 /* ARGTYPE_FLOAT */
95 struct {
96 size_t float_index;
97 } float_info;
98
99 /* ARGTYPE_DOUBLE */
100 struct {
101 size_t float_index;
102 } double_info;
103 } u;
104} arg_type_info;
105
106enum tof {
107 LT_TOF_NONE = 0,
108 LT_TOF_FUNCTION, /* A real library function */
109 LT_TOF_FUNCTIONR, /* Return from a real library function */
110 LT_TOF_SYSCALL, /* A syscall */
111 LT_TOF_SYSCALLR, /* Return from a syscall */
112 LT_TOF_STRUCT /* Not a function; read args from struct */
113};
114
115typedef struct Function Function;
116struct Function {
117 const char *name;
118 arg_type_info *return_info;
119 int num_params;
120 arg_type_info *arg_info[MAX_ARGS];
121 int params_right;
122 Function *next;
123};
124
125enum toplt {
126 LS_TOPLT_NONE = 0, /* PLT not used for this symbol. */
127 LS_TOPLT_EXEC, /* PLT for this symbol is executable. */
128 LS_TOPLT_POINT /* PLT for this symbol is a non-executable. */
129};
130
131extern Function *list_of_functions;
132extern char *PLTs_initialized_by_here;
133
134struct library_symbol {
135 char *name;
136 void *enter_addr;
137 char needs_init;
138 enum toplt plt_type;
139 char is_weak;
140 struct library_symbol *next;
141};
142
143struct callstack_element {
144 union {
145 int syscall;
146 struct library_symbol *libfunc;
147 } c_un;
148 int is_syscall;
149 void *return_addr;
150 struct timeval time_spent;
151};
152
153#define MAX_CALLDEPTH 64
154
155typedef enum Process_State Process_State;
156enum Process_State {
157 STATE_ATTACHED = 0,
158 STATE_BEING_CREATED,
159 STATE_IGNORED /* ignore this process (it's a fork and no -f was used) */
160};
161
162typedef struct Process Process;
163struct Process {
164 Process_State state;
165 Process *parent; /* needed by STATE_BEING_CREATED */
166 char *filename;
167 pid_t pid;
168 struct dict *breakpoints;
169 int breakpoints_enabled; /* -1:not enabled yet, 0:disabled, 1:enabled */
170 int mask_32bit; /* 1 if 64-bit ltrace is tracing 32-bit process */
171 unsigned int personality;
172 int tracesysgood; /* signal indicating a PTRACE_SYSCALL trap */
173
174 int callstack_depth;
175 struct callstack_element callstack[MAX_CALLDEPTH];
176 struct library_symbol *list_of_symbols;
177
178 /* Arch-dependent: */
179 void *instruction_pointer;
180 void *stack_pointer; /* To get return addr, args... */
181 void *return_addr;
182 Breakpoint *breakpoint_being_enabled;
183 void *arch_ptr;
184 short e_machine;
185 short need_to_reinitialize_breakpoints;
186#ifdef __arm__
187 int thumb_mode; /* ARM execution mode: 0: ARM, 1: Thumb */
188#endif
189
190 /* output: */
191 enum tof type_being_displayed;
192
193 Process *next;
194};
195
196typedef struct Event Event;
197struct Event {
198 Process *proc;
199 enum {
200 EVENT_NONE,
201 EVENT_SIGNAL,
202 EVENT_EXIT,
203 EVENT_EXIT_SIGNAL,
204 EVENT_SYSCALL,
205 EVENT_SYSRET,
206 EVENT_ARCH_SYSCALL,
207 EVENT_ARCH_SYSRET,
208 EVENT_CLONE,
209 EVENT_EXEC,
210 EVENT_BREAKPOINT,
211 EVENT_NEW /* in this case, proc is NULL */
212 } type;
213 union {
214 int ret_val; /* EVENT_EXIT */
215 int signum; /* EVENT_SIGNAL, EVENT_EXIT_SIGNAL */
216 int sysnum; /* EVENT_SYSCALL, EVENT_SYSRET */
217 void *brk_addr; /* EVENT_BREAKPOINT */
218 int newpid; /* EVENT_CLONE, EVENT_NEW */
219 } e_un;
220};
221
222struct opt_c_struct {
223 int count;
224 struct timeval tv;
225};
226extern struct dict *dict_opt_c;
227
228extern Process *list_of_processes;
229
230extern void *instruction_pointer;
231
232extern Event *next_event(void);
233extern Process * pid2proc(pid_t pid);
234extern void process_event(Event *event);
235extern void execute_program(Process *, char **);
236extern int display_arg(enum tof type, Process *proc, int arg_num, arg_type_info *info);
237extern Breakpoint *address2bpstruct(Process *proc, void *addr);
238extern void breakpoints_init(Process *proc);
239extern void insert_breakpoint(Process *proc, void *addr, struct library_symbol *libsym);
240extern void delete_breakpoint(Process *proc, void *addr);
241extern void enable_all_breakpoints(Process *proc);
242extern void disable_all_breakpoints(Process *proc);
243extern void reinitialize_breakpoints(Process *);
244
245extern Process *open_program(char *filename, pid_t pid);
246extern void open_pid(pid_t pid, int verbose);
247extern void show_summary(void);
248extern arg_type_info *lookup_prototype(enum arg_type at);
249
250/* Arch-dependent stuff: */
251extern char *pid2name(pid_t pid);
252extern void trace_set_options(Process *proc, pid_t pid);
253extern void trace_me(void);
254extern int trace_pid(pid_t pid);
255extern void untrace_pid(pid_t pid);
256extern void get_arch_dep(Process *proc);
257extern void *get_instruction_pointer(Process *proc);
258extern void set_instruction_pointer(Process *proc, void *addr);
259extern void *get_stack_pointer(Process *proc);
260extern void *get_return_addr(Process *proc, void *stack_pointer);
261extern void enable_breakpoint(pid_t pid, Breakpoint *sbp);
262extern void disable_breakpoint(pid_t pid, const Breakpoint *sbp);
263extern int syscall_p(Process *proc, int status, int *sysnum);
264extern void continue_process(pid_t pid);
265extern void continue_after_signal(pid_t pid, int signum);
266extern void continue_after_breakpoint(Process *proc, Breakpoint *sbp);
267extern void continue_enabling_breakpoint(pid_t pid, Breakpoint *sbp);
268extern long gimme_arg(enum tof type, Process *proc, int arg_num, arg_type_info *info);
269extern void save_register_args(enum tof type, Process *proc);
270extern int umovestr(Process *proc, void *addr, int len, void *laddr);
271extern int umovelong (Process *proc, void *addr, long *result, arg_type_info *info);
272extern int ffcheck(void *maddr);
273extern void *sym2addr(Process *, struct library_symbol *);
274
275#if 0 /* not yet */
276extern int umoven(Process *proc, void *addr, int len, void *laddr);
277#endif
278
279#endif