ltrace.h revision c4e53a9c569cc0ca406ba947ddb97ca2cd0f32c0
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 155typedef enum Process_State Process_State; 156enum Process_State { 157 STATE_ATTACHED, 158 STATE_NEW, 159 STATE_FUTURE_CHILD, 160 STATE_FUTURE_CLONE 161}; 162 163typedef struct Process Process; 164struct Process { 165 Process_State state; 166 Process *parent; /* needed by STATE_FUTURE_CHILD and STATE_FUTURE_CLONE */ 167 char *filename; 168 pid_t pid; 169 struct dict *breakpoints; 170 int breakpoints_enabled; /* -1:not enabled yet, 0:disabled, 1:enabled */ 171 int mask_32bit; /* 1 if 64-bit ltrace is tracing 32-bit process. */ 172 unsigned int personality; 173 int tracesysgood; /* signal indicating a PTRACE_SYSCALL trap */ 174 175 int callstack_depth; 176 struct callstack_element callstack[MAX_CALLDEPTH]; 177 struct library_symbol *list_of_symbols; 178 179 /* Arch-dependent: */ 180 void *instruction_pointer; 181 void *stack_pointer; /* To get return addr, args... */ 182 void *return_addr; 183 struct breakpoint *breakpoint_being_enabled; 184 void *arch_ptr; 185 short e_machine; 186 short need_to_reinitialize_breakpoints; 187#ifdef __arm__ 188 int thumb_mode; /* ARM execution mode: 0: ARM mode, 1: Thumb mode */ 189#endif 190 191 /* output: */ 192 enum tof type_being_displayed; 193 194 Process *next; 195}; 196 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_FORK, 209 EVENT_CLONE, /* Like FORK, but parent and child share memory */ 210 EVENT_EXEC, 211 EVENT_BREAKPOINT 212 } thing; 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_FORK, EVENT_CLONE */ 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 struct event *next_event(void); 233extern Process * pid2proc(pid_t pid); 234extern void process_event(struct 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 struct breakpoint *address2bpstruct(Process *proc, void *addr); 238extern void breakpoints_init(Process *proc); 239extern void insert_breakpoint(Process *proc, void *addr, 240 struct library_symbol *libsym); 241extern void delete_breakpoint(Process *proc, void *addr); 242extern void enable_all_breakpoints(Process *proc); 243extern void disable_all_breakpoints(Process *proc); 244extern void reinitialize_breakpoints(Process *); 245 246extern Process *open_program(char *filename, pid_t pid); 247extern void open_pid(pid_t pid, int verbose); 248extern void show_summary(void); 249extern arg_type_info *lookup_prototype(enum arg_type at); 250 251/* Arch-dependent stuff: */ 252extern char *pid2name(pid_t pid); 253extern void trace_set_options(Process *proc, pid_t pid); 254extern void trace_me(void); 255extern int trace_pid(pid_t pid); 256extern void untrace_pid(pid_t pid); 257extern void get_arch_dep(Process *proc); 258extern void *get_instruction_pointer(Process *proc); 259extern void set_instruction_pointer(Process *proc, void *addr); 260extern void *get_stack_pointer(Process *proc); 261extern void *get_return_addr(Process *proc, void *stack_pointer); 262extern void enable_breakpoint(pid_t pid, struct breakpoint *sbp); 263extern void disable_breakpoint(pid_t pid, const struct breakpoint *sbp); 264extern int fork_p(Process *proc, int sysnum); 265extern int exec_p(Process *proc, int sysnum); 266extern int was_exec(Process *proc, int status); 267extern int syscall_p(Process *proc, int status, int *sysnum); 268extern void continue_process(pid_t pid); 269extern void continue_after_signal(pid_t pid, int signum); 270extern void continue_after_breakpoint(Process *proc, 271 struct breakpoint *sbp); 272extern void continue_enabling_breakpoint(pid_t pid, struct breakpoint *sbp); 273extern long gimme_arg(enum tof type, Process *proc, int arg_num, arg_type_info *info); 274extern void save_register_args(enum tof type, Process *proc); 275extern int umovestr(Process *proc, void *addr, int len, void *laddr); 276extern int umovelong (Process *proc, void *addr, long *result, arg_type_info *info); 277extern int ffcheck(void *maddr); 278extern void *sym2addr(Process *, struct library_symbol *); 279 280#if 0 /* not yet */ 281extern int umoven(Process *proc, void *addr, int len, void *laddr); 282#endif 283 284#endif 285