common.h revision 40dc6353a443f2eed64fcada3bcf305e56855b15
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 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 162#include "ltrace.h" 163 164struct Process { 165 Process_State state; 166 Process *parent; /* needed by STATE_BEING_CREATED */ 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 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, 1: Thumb */ 189#endif 190 191 /* output: */ 192 enum tof type_being_displayed; 193 194 Process *next; 195}; 196 197struct opt_c_struct { 198 int count; 199 struct timeval tv; 200}; 201extern struct dict *dict_opt_c; 202 203extern Process *list_of_processes; 204 205extern void *instruction_pointer; 206 207extern Event *next_event(void); 208extern Process * pid2proc(pid_t pid); 209extern void process_event(Event *event); 210extern void execute_program(Process *, char **); 211extern int display_arg(enum tof type, Process *proc, int arg_num, arg_type_info *info); 212extern Breakpoint *address2bpstruct(Process *proc, void *addr); 213extern void breakpoints_init(Process *proc); 214extern void insert_breakpoint(Process *proc, void *addr, struct library_symbol *libsym); 215extern void delete_breakpoint(Process *proc, void *addr); 216extern void enable_all_breakpoints(Process *proc); 217extern void disable_all_breakpoints(Process *proc); 218extern void reinitialize_breakpoints(Process *); 219 220extern Process *open_program(char *filename, pid_t pid); 221extern void open_pid(pid_t pid, int verbose); 222extern void show_summary(void); 223extern arg_type_info *lookup_prototype(enum arg_type at); 224 225/* Arch-dependent stuff: */ 226extern char *pid2name(pid_t pid); 227extern void trace_set_options(Process *proc, pid_t pid); 228extern void trace_me(void); 229extern int trace_pid(pid_t pid); 230extern void untrace_pid(pid_t pid); 231extern void get_arch_dep(Process *proc); 232extern void *get_instruction_pointer(Process *proc); 233extern void set_instruction_pointer(Process *proc, void *addr); 234extern void *get_stack_pointer(Process *proc); 235extern void *get_return_addr(Process *proc, void *stack_pointer); 236extern void enable_breakpoint(pid_t pid, Breakpoint *sbp); 237extern void disable_breakpoint(pid_t pid, const Breakpoint *sbp); 238extern int syscall_p(Process *proc, int status, int *sysnum); 239extern void continue_process(pid_t pid); 240extern void continue_after_signal(pid_t pid, int signum); 241extern void continue_after_breakpoint(Process *proc, Breakpoint *sbp); 242extern void continue_enabling_breakpoint(pid_t pid, Breakpoint *sbp); 243extern long gimme_arg(enum tof type, Process *proc, int arg_num, arg_type_info *info); 244extern void save_register_args(enum tof type, Process *proc); 245extern int umovestr(Process *proc, void *addr, int len, void *laddr); 246extern int umovelong (Process *proc, void *addr, long *result, arg_type_info *info); 247extern int ffcheck(void *maddr); 248extern void *sym2addr(Process *, struct library_symbol *); 249 250#if 0 /* not yet */ 251extern int umoven(Process *proc, void *addr, int len, void *laddr); 252#endif 253 254#endif 255