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