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