common.h revision c805c624d4cd23674bbc18f9d0f97c5d8dcdff7c
1#ifndef COMMON_H 2#define COMMON_H 3 4#include <config.h> 5 6#include <sys/types.h> 7#include <sys/time.h> 8#include <stdio.h> 9 10#include "ltrace.h" 11#include "defs.h" 12#include "dict.h" 13#include "sysdep.h" 14#include "debug.h" 15#include "ltrace-elf.h" 16#include "read_config_file.h" 17#include "proc.h" 18 19#if defined HAVE_LIBIBERTY || defined HAVE_LIBSUPC__ 20# define USE_DEMANGLE 21#endif 22 23extern char * command; 24 25extern int exiting; /* =1 if we have to exit ASAP */ 26 27enum arg_type { 28 ARGTYPE_UNKNOWN = -1, 29 ARGTYPE_VOID, 30 ARGTYPE_INT, 31 ARGTYPE_UINT, 32 ARGTYPE_LONG, 33 ARGTYPE_ULONG, 34 ARGTYPE_OCTAL, 35 ARGTYPE_CHAR, 36 ARGTYPE_SHORT, 37 ARGTYPE_USHORT, 38 ARGTYPE_FLOAT, /* float value, may require index */ 39 ARGTYPE_DOUBLE, /* double value, may require index */ 40 ARGTYPE_ADDR, 41 ARGTYPE_FILE, 42 ARGTYPE_FORMAT, /* printf-like format */ 43 ARGTYPE_STRING, /* NUL-terminated string */ 44 ARGTYPE_STRING_N, /* String of known maxlen */ 45 ARGTYPE_ARRAY, /* Series of values in memory */ 46 ARGTYPE_ENUM, /* Enumeration */ 47 ARGTYPE_STRUCT, /* Structure of values */ 48 ARGTYPE_POINTER, /* Pointer to some other type */ 49 ARGTYPE_COUNT /* number of ARGTYPE_* values */ 50}; 51 52typedef struct arg_type_info_t { 53 enum arg_type type; 54 union { 55 /* ARGTYPE_ENUM */ 56 struct { 57 size_t entries; 58 char ** keys; 59 int * values; 60 } enum_info; 61 62 /* ARGTYPE_ARRAY */ 63 struct { 64 struct arg_type_info_t * elt_type; 65 size_t elt_size; 66 int len_spec; 67 } array_info; 68 69 /* ARGTYPE_STRING_N */ 70 struct { 71 int size_spec; 72 } string_n_info; 73 74 /* ARGTYPE_STRUCT */ 75 struct { 76 struct arg_type_info_t ** fields; /* NULL-terminated */ 77 size_t * offset; 78 size_t size; 79 } struct_info; 80 81 /* ARGTYPE_POINTER */ 82 struct { 83 struct arg_type_info_t * info; 84 } ptr_info; 85 86 /* ARGTYPE_FLOAT */ 87 struct { 88 size_t float_index; 89 } float_info; 90 91 /* ARGTYPE_DOUBLE */ 92 struct { 93 size_t float_index; 94 } double_info; 95 } u; 96} arg_type_info; 97 98enum tof { 99 LT_TOF_NONE = 0, 100 LT_TOF_FUNCTION, /* A real library function */ 101 LT_TOF_FUNCTIONR, /* Return from a real library function */ 102 LT_TOF_SYSCALL, /* A syscall */ 103 LT_TOF_SYSCALLR, /* Return from a syscall */ 104 LT_TOF_STRUCT /* Not a function; read args from struct */ 105}; 106 107typedef struct Function Function; 108struct Function { 109 const char * name; 110 arg_type_info * return_info; 111 int num_params; 112 arg_type_info * arg_info[MAX_ARGS]; 113 int params_right; 114 Function * next; 115}; 116 117extern Function * list_of_functions; 118extern char *PLTs_initialized_by_here; 119 120struct opt_c_struct { 121 int count; 122 struct timeval tv; 123}; 124 125#include "options.h" 126#include "output.h" 127#ifdef USE_DEMANGLE 128#include "demangle.h" 129#endif 130 131extern Dict * dict_opt_c; 132 133enum process_status { 134 ps_invalid, /* Failure. */ 135 ps_stop, /* Job-control stop. */ 136 ps_tracing_stop, 137 ps_sleeping, 138 ps_zombie, 139 ps_other, /* Necessary other states can be added as needed. */ 140}; 141 142/* Events */ 143enum ecb_status { 144 ecb_cont, /* The iteration should continue. */ 145 ecb_yield, /* The iteration should stop, yielding this 146 * event. */ 147 ecb_deque, /* Like ecb_stop, but the event should be removed 148 * from the queue. */ 149}; 150extern Event * next_event(void); 151extern Event * each_qd_event(enum ecb_status (* cb)(Event * event, void * data), 152 void * data); 153extern void enque_event(Event * event); 154extern void handle_event(Event * event); 155 156extern pid_t execute_program(const char * command, char ** argv); 157extern int display_arg(enum tof type, Process * proc, int arg_num, arg_type_info * info); 158extern void disable_all_breakpoints(Process * proc); 159 160extern void show_summary(void); 161extern arg_type_info * lookup_prototype(enum arg_type at); 162 163struct breakpoint; 164struct library_symbol; 165 166/* Arch-dependent stuff: */ 167extern char * pid2name(pid_t pid); 168extern pid_t process_leader(pid_t pid); 169extern int process_tasks(pid_t pid, pid_t **ret_tasks, size_t *ret_n); 170extern int process_stopped(pid_t pid); 171extern enum process_status process_status(pid_t pid); 172extern void trace_set_options(Process * proc, pid_t pid); 173extern int wait_for_proc(pid_t pid); 174extern void trace_me(void); 175extern int trace_pid(pid_t pid); 176extern void untrace_pid(pid_t pid); 177extern void get_arch_dep(Process * proc); 178extern void * get_instruction_pointer(Process * proc); 179extern void set_instruction_pointer(Process * proc, void * addr); 180extern void * get_stack_pointer(Process * proc); 181extern void * get_return_addr(Process * proc, void * stack_pointer); 182extern void set_return_addr(Process * proc, void * addr); 183extern void enable_breakpoint(Process * proc, struct breakpoint *sbp); 184extern void disable_breakpoint(Process * proc, struct breakpoint *sbp); 185extern int syscall_p(Process * proc, int status, int * sysnum); 186extern void continue_process(pid_t pid); 187extern void continue_after_signal(pid_t pid, int signum); 188extern void continue_after_syscall(Process *proc, int sysnum, int ret_p); 189extern void continue_after_breakpoint(Process * proc, struct breakpoint *sbp); 190extern void continue_after_vfork(Process * proc); 191extern long gimme_arg(enum tof type, Process * proc, int arg_num, arg_type_info * info); 192extern void save_register_args(enum tof type, Process * proc); 193extern int umovestr(Process * proc, void * addr, int len, void * laddr); 194extern int umovelong (Process * proc, void * addr, long * result, arg_type_info * info); 195extern size_t umovebytes (Process *proc, void * addr, void * laddr, size_t count); 196extern int ffcheck(void * maddr); 197extern void * sym2addr(Process *, struct library_symbol *); 198extern int linkmap_init(struct Process *); 199extern void arch_check_dbg(Process *proc); 200extern int task_kill (pid_t pid, int sig); 201 202/* Called when trace_me or primary trace_pid fail. This may plug in 203 * any platform-specific knowledge of why it could be so. */ 204void trace_fail_warning(pid_t pid); 205 206/* A pair of functions called to initiate a detachment request when 207 * ltrace is about to exit. Their job is to undo any effects that 208 * tracing had and eventually detach process, perhaps by way of 209 * installing a process handler. 210 * 211 * OS_LTRACE_EXITING_SIGHANDLER is called from a signal handler 212 * context right after the signal was captured. It returns 1 if the 213 * request was handled or 0 if it wasn't. 214 * 215 * If the call to OS_LTRACE_EXITING_SIGHANDLER didn't handle the 216 * request, OS_LTRACE_EXITING is called when the next event is 217 * generated. Therefore it's called in "safe" context, without 218 * re-entrancy concerns, but it's only called after an even is 219 * generated. */ 220int os_ltrace_exiting_sighandler(void); 221void os_ltrace_exiting(void); 222 223extern struct ltelf main_lte; 224 225#endif 226