ltrace.h revision 138d41c7468ba77656170a869553e49b5409aa70
1#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
24struct breakpoint {
25	void *addr;
26	unsigned char orig_value[BREAKPOINT_LENGTH];
27	int enabled;
28	struct library_symbol *libsym;
29#ifdef __arm__
30	int thumb_mode;
31#endif
32};
33
34enum arg_type {
35	ARGTYPE_UNKNOWN = -1,
36	ARGTYPE_VOID,
37	ARGTYPE_INT,
38	ARGTYPE_UINT,
39	ARGTYPE_LONG,
40	ARGTYPE_ULONG,
41	ARGTYPE_OCTAL,
42	ARGTYPE_CHAR,
43	ARGTYPE_SHORT,
44	ARGTYPE_USHORT,
45	ARGTYPE_FLOAT,		/* float value, may require index */
46	ARGTYPE_DOUBLE,		/* double value, may require index */
47	ARGTYPE_ADDR,
48	ARGTYPE_FILE,
49	ARGTYPE_FORMAT,		/* printf-like format */
50	ARGTYPE_STRING,		/* NUL-terminated string */
51	ARGTYPE_STRING_N,	/* String of known maxlen */
52	ARGTYPE_ARRAY,		/* Series of values in memory */
53	ARGTYPE_ENUM,		/* Enumeration */
54	ARGTYPE_STRUCT,		/* Structure of values */
55	ARGTYPE_POINTER,	/* Pointer to some other type */
56	ARGTYPE_COUNT		/* number of ARGTYPE_* values */
57};
58
59typedef struct arg_type_info_t {
60	enum arg_type type;
61	union {
62		// ARGTYPE_ENUM
63		struct {
64			size_t entries;
65			char **keys;
66			int *values;
67		} enum_info;
68
69		// ARGTYPE_ARRAY
70		struct {
71			struct arg_type_info_t *elt_type;
72			size_t elt_size;
73			int len_spec;
74		} array_info;
75
76		// ARGTYPE_STRING_N
77		struct {
78			int size_spec;
79		} string_n_info;
80
81		// ARGTYPE_STRUCT
82		struct {
83			struct arg_type_info_t **fields;	// NULL-terminated
84			size_t *offset;
85			size_t size;
86		} struct_info;
87
88		// ARGTYPE_POINTER
89		struct {
90			struct arg_type_info_t *info;
91		} ptr_info;
92
93		// ARGTYPE_FLOAT
94		struct {
95			size_t float_index;
96		} float_info;
97
98		// ARGTYPE_DOUBLE
99		struct {
100			size_t float_index;
101		} double_info;
102	} u;
103} arg_type_info;
104
105enum tof {
106	LT_TOF_NONE = 0,
107	LT_TOF_FUNCTION,	/* A real library function */
108	LT_TOF_FUNCTIONR,	/* Return from a real library function */
109	LT_TOF_SYSCALL,		/* A syscall */
110	LT_TOF_SYSCALLR,	/* Return from a syscall */
111	LT_TOF_STRUCT		/* Not a function; read args from struct */
112};
113
114struct function {
115	const char *name;
116	arg_type_info *return_info;
117	int num_params;
118	arg_type_info *arg_info[MAX_ARGS];
119	int params_right;
120	struct function *next;
121};
122
123enum toplt {
124	LS_TOPLT_NONE = 0,	/* PLT not used for this symbol. */
125	LS_TOPLT_EXEC,		/* PLT for this symbol is executable. */
126	LS_TOPLT_POINT		/* PLT for this symbol is a non-executable. */
127};
128
129
130extern struct function *list_of_functions;
131extern char *PLTs_initialized_by_here;
132
133struct library_symbol {
134	char *name;
135	void *enter_addr;
136	struct breakpoint *brkpnt;
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
155struct process {
156	char *filename;
157	pid_t pid;
158	struct dict *breakpoints;
159	int breakpoints_enabled;	/* -1:not enabled yet, 0:disabled, 1:enabled */
160	int mask_32bit;		/* 1 if 64-bit ltrace is tracing 32-bit process.  */
161	unsigned int personality;
162	int tracesysgood;	/* signal indicating a PTRACE_SYSCALL trap */
163
164	int callstack_depth;
165	struct callstack_element callstack[MAX_CALLDEPTH];
166	struct library_symbol *list_of_symbols;
167
168	/* Arch-dependent: */
169	void *instruction_pointer;
170	void *stack_pointer;	/* To get return addr, args... */
171	void *return_addr;
172	struct breakpoint *breakpoint_being_enabled;
173	void *arch_ptr;
174	short e_machine;
175	short need_to_reinitialize_breakpoints;
176#ifdef __arm__
177	int thumb_mode; /* ARM execution mode: 0: ARM mode, 1: Thumb mode */
178#endif
179
180	/* output: */
181	enum tof type_being_displayed;
182
183	struct process *next;
184};
185
186struct event {
187	struct process *proc;
188	enum {
189		EVENT_NONE,
190		EVENT_SIGNAL,
191		EVENT_EXIT,
192		EVENT_EXIT_SIGNAL,
193		EVENT_SYSCALL,
194		EVENT_SYSRET,
195		EVENT_ARCH_SYSCALL,
196		EVENT_ARCH_SYSRET,
197		EVENT_FORK,
198		EVENT_EXEC,
199		EVENT_BREAKPOINT
200	} thing;
201	union {
202		int ret_val;	/* _EV_EXIT */
203		int signum;     /* _EV_SIGNAL, _EV_EXIT_SIGNAL */
204		int sysnum;     /* _EV_SYSCALL, _EV_SYSRET */
205		void *brk_addr;	/* _EV_BREAKPOINT */
206		int newpid;     /* _EV_FORK */
207	} e_un;
208};
209
210struct opt_c_struct {
211	int count;
212	struct timeval tv;
213};
214extern struct dict *dict_opt_c;
215
216extern struct process *list_of_processes;
217
218extern void *instruction_pointer;
219
220extern struct event *wait_for_something(void);
221extern struct process * pid2proc(pid_t pid);
222extern void process_event(struct event *event);
223extern void execute_program(struct process *, char **);
224extern int display_arg(enum tof type, struct process *proc, int arg_num, arg_type_info *info);
225extern struct breakpoint *address2bpstruct(struct process *proc, void *addr);
226extern void breakpoints_init(struct process *proc);
227extern void insert_breakpoint(struct process *proc, void *addr,
228			      struct library_symbol *libsym);
229extern void delete_breakpoint(struct process *proc, void *addr);
230extern void enable_all_breakpoints(struct process *proc);
231extern void disable_all_breakpoints(struct process *proc);
232extern void reinitialize_breakpoints(struct process *);
233
234extern struct process *open_program(char *filename, pid_t pid);
235extern void open_pid(pid_t pid, int verbose);
236extern void show_summary(void);
237extern arg_type_info *lookup_prototype(enum arg_type at);
238
239/* Arch-dependent stuff: */
240extern char *pid2name(pid_t pid);
241extern void trace_set_options(struct process *proc, pid_t pid);
242extern void trace_me(void);
243extern int trace_pid(pid_t pid);
244extern void untrace_pid(pid_t pid);
245extern void get_arch_dep(struct process *proc);
246extern void *get_instruction_pointer(struct process *proc);
247extern void set_instruction_pointer(struct process *proc, void *addr);
248extern void *get_stack_pointer(struct process *proc);
249extern void *get_return_addr(struct process *proc, void *stack_pointer);
250extern void enable_breakpoint(pid_t pid, struct breakpoint *sbp);
251extern void disable_breakpoint(pid_t pid, const struct breakpoint *sbp);
252extern int fork_p(struct process *proc, int sysnum);
253extern int exec_p(struct process *proc, int sysnum);
254extern int was_exec(struct process *proc, int status);
255extern int syscall_p(struct process *proc, int status, int *sysnum);
256extern void continue_process(pid_t pid);
257extern void continue_after_signal(pid_t pid, int signum);
258extern void continue_after_breakpoint(struct process *proc,
259				      struct breakpoint *sbp);
260extern void continue_enabling_breakpoint(pid_t pid, struct breakpoint *sbp);
261extern long gimme_arg(enum tof type, struct process *proc, int arg_num, arg_type_info *info);
262extern void save_register_args(enum tof type, struct process *proc);
263extern int umovestr(struct process *proc, void *addr, int len, void *laddr);
264extern int umovelong (struct process *proc, void *addr, long *result, arg_type_info *info);
265extern int ffcheck(void *maddr);
266extern void *sym2addr(struct process *, struct library_symbol *);
267
268#if 0				/* not yet */
269extern int umoven(struct process *proc, void *addr, int len, void *laddr);
270#endif
271
272#endif
273