| Michael K. Edwards | ef4428a | 2011-03-06 20:39:18 +0000 | [diff] [blame] | 1 | #ifndef COMMON_H |
| 2 | #define COMMON_H |
| 3 | |
| Petr Machata | a06eb81 | 2011-07-08 19:23:25 +0200 | [diff] [blame] | 4 | #include <config.h> |
| Joe Damato | ab3b72c | 2010-10-31 00:21:53 -0700 | [diff] [blame] | 5 | #if defined(HAVE_LIBUNWIND) |
| 6 | #include <libunwind.h> |
| 7 | #endif /* defined(HAVE_LIBUNWIND) */ |
| 8 | |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 9 | #include <sys/types.h> |
| 10 | #include <sys/time.h> |
| 11 | #include <stdio.h> |
| 12 | |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 13 | #include "ltrace.h" |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 14 | #include "defs.h" |
| 15 | #include "dict.h" |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 16 | #include "sysdep.h" |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 17 | #include "debug.h" |
| Marc Kleine-Budde | 747c73d | 2010-02-03 20:23:20 +0100 | [diff] [blame] | 18 | #include "ltrace-elf.h" |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 19 | #include "read_config_file.h" |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 20 | |
| 21 | #if defined HAVE_LIBIBERTY || defined HAVE_LIBSUPC__ |
| 22 | # define USE_DEMANGLE |
| 23 | #endif |
| 24 | |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 25 | extern char * command; |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 26 | |
| 27 | extern int exiting; /* =1 if we have to exit ASAP */ |
| 28 | |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 29 | enum arg_type { |
| 30 | ARGTYPE_UNKNOWN = -1, |
| 31 | ARGTYPE_VOID, |
| 32 | ARGTYPE_INT, |
| 33 | ARGTYPE_UINT, |
| 34 | ARGTYPE_LONG, |
| 35 | ARGTYPE_ULONG, |
| 36 | ARGTYPE_OCTAL, |
| 37 | ARGTYPE_CHAR, |
| 38 | ARGTYPE_SHORT, |
| 39 | ARGTYPE_USHORT, |
| 40 | ARGTYPE_FLOAT, /* float value, may require index */ |
| 41 | ARGTYPE_DOUBLE, /* double value, may require index */ |
| 42 | ARGTYPE_ADDR, |
| 43 | ARGTYPE_FILE, |
| 44 | ARGTYPE_FORMAT, /* printf-like format */ |
| 45 | ARGTYPE_STRING, /* NUL-terminated string */ |
| 46 | ARGTYPE_STRING_N, /* String of known maxlen */ |
| 47 | ARGTYPE_ARRAY, /* Series of values in memory */ |
| 48 | ARGTYPE_ENUM, /* Enumeration */ |
| 49 | ARGTYPE_STRUCT, /* Structure of values */ |
| 50 | ARGTYPE_POINTER, /* Pointer to some other type */ |
| 51 | ARGTYPE_COUNT /* number of ARGTYPE_* values */ |
| 52 | }; |
| 53 | |
| 54 | typedef struct arg_type_info_t { |
| 55 | enum arg_type type; |
| 56 | union { |
| 57 | /* ARGTYPE_ENUM */ |
| 58 | struct { |
| 59 | size_t entries; |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 60 | char ** keys; |
| 61 | int * values; |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 62 | } enum_info; |
| 63 | |
| 64 | /* ARGTYPE_ARRAY */ |
| 65 | struct { |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 66 | struct arg_type_info_t * elt_type; |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 67 | size_t elt_size; |
| 68 | int len_spec; |
| 69 | } array_info; |
| 70 | |
| 71 | /* ARGTYPE_STRING_N */ |
| 72 | struct { |
| 73 | int size_spec; |
| 74 | } string_n_info; |
| 75 | |
| 76 | /* ARGTYPE_STRUCT */ |
| 77 | struct { |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 78 | struct arg_type_info_t ** fields; /* NULL-terminated */ |
| 79 | size_t * offset; |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 80 | size_t size; |
| 81 | } struct_info; |
| 82 | |
| 83 | /* ARGTYPE_POINTER */ |
| 84 | struct { |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 85 | struct arg_type_info_t * info; |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 86 | } ptr_info; |
| 87 | |
| 88 | /* ARGTYPE_FLOAT */ |
| 89 | struct { |
| 90 | size_t float_index; |
| 91 | } float_info; |
| 92 | |
| 93 | /* ARGTYPE_DOUBLE */ |
| 94 | struct { |
| 95 | size_t float_index; |
| 96 | } double_info; |
| 97 | } u; |
| 98 | } arg_type_info; |
| 99 | |
| 100 | enum tof { |
| 101 | LT_TOF_NONE = 0, |
| 102 | LT_TOF_FUNCTION, /* A real library function */ |
| 103 | LT_TOF_FUNCTIONR, /* Return from a real library function */ |
| 104 | LT_TOF_SYSCALL, /* A syscall */ |
| 105 | LT_TOF_SYSCALLR, /* Return from a syscall */ |
| 106 | LT_TOF_STRUCT /* Not a function; read args from struct */ |
| 107 | }; |
| 108 | |
| 109 | typedef struct Function Function; |
| 110 | struct Function { |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 111 | const char * name; |
| 112 | arg_type_info * return_info; |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 113 | int num_params; |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 114 | arg_type_info * arg_info[MAX_ARGS]; |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 115 | int params_right; |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 116 | Function * next; |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | enum toplt { |
| 120 | LS_TOPLT_NONE = 0, /* PLT not used for this symbol. */ |
| 121 | LS_TOPLT_EXEC, /* PLT for this symbol is executable. */ |
| 122 | LS_TOPLT_POINT /* PLT for this symbol is a non-executable. */ |
| 123 | }; |
| 124 | |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 125 | extern Function * list_of_functions; |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 126 | extern char *PLTs_initialized_by_here; |
| 127 | |
| 128 | struct library_symbol { |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 129 | char * name; |
| 130 | void * enter_addr; |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 131 | char needs_init; |
| 132 | enum toplt plt_type; |
| 133 | char is_weak; |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 134 | struct library_symbol * next; |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | struct callstack_element { |
| 138 | union { |
| 139 | int syscall; |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 140 | struct library_symbol * libfunc; |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 141 | } c_un; |
| 142 | int is_syscall; |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 143 | void * return_addr; |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 144 | struct timeval time_spent; |
| Petr Machata | 211f088 | 2010-11-03 18:42:18 +0100 | [diff] [blame] | 145 | void * arch_ptr; |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | #define MAX_CALLDEPTH 64 |
| 149 | |
| 150 | typedef enum Process_State Process_State; |
| 151 | enum Process_State { |
| 152 | STATE_ATTACHED = 0, |
| 153 | STATE_BEING_CREATED, |
| 154 | STATE_IGNORED /* ignore this process (it's a fork and no -f was used) */ |
| 155 | }; |
| 156 | |
| Petr Machata | 4007d74 | 2011-07-09 11:29:42 +0200 | [diff] [blame] | 157 | typedef struct Event_Handler Event_Handler; |
| 158 | struct Event_Handler { |
| 159 | /* Event handler that overrides the default one. Should |
| 160 | * return NULL if the event was handled, otherwise the |
| 161 | * returned event is passed to the default handler. */ |
| 162 | Event * (* on_event)(Event_Handler * self, Event * event); |
| 163 | |
| 164 | /* Called when the event handler removal is requested. */ |
| 165 | void (* destroy)(Event_Handler * self); |
| 166 | }; |
| 167 | |
| Petr Machata | 9a5420c | 2011-07-09 11:21:23 +0200 | [diff] [blame] | 168 | /* XXX We would rather have this all organized a little differently, |
| 169 | * have Process for the whole group and Task for what's there for |
| 170 | * per-thread stuff. But for now this is the less invasive way of |
| 171 | * structuring it. */ |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 172 | struct Process { |
| 173 | Process_State state; |
| Juan Cespedes | 2a61d19 | 2009-07-04 11:29:27 +0200 | [diff] [blame] | 174 | Process * parent; /* needed by STATE_BEING_CREATED */ |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 175 | char * filename; |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 176 | pid_t pid; |
| Petr Machata | 9a5420c | 2011-07-09 11:21:23 +0200 | [diff] [blame] | 177 | |
| 178 | /* Dictionary of breakpoints (which is a mapping |
| Petr Machata | 9294d82 | 2012-02-07 12:35:58 +0100 | [diff] [blame^] | 179 | * address->breakpoint). This is NULL for non-leader |
| Petr Machata | 9a5420c | 2011-07-09 11:21:23 +0200 | [diff] [blame] | 180 | * processes. */ |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 181 | Dict * breakpoints; |
| Petr Machata | 9a5420c | 2011-07-09 11:21:23 +0200 | [diff] [blame] | 182 | |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 183 | int breakpoints_enabled; /* -1:not enabled yet, 0:disabled, 1:enabled */ |
| 184 | int mask_32bit; /* 1 if 64-bit ltrace is tracing 32-bit process */ |
| 185 | unsigned int personality; |
| 186 | int tracesysgood; /* signal indicating a PTRACE_SYSCALL trap */ |
| 187 | |
| 188 | int callstack_depth; |
| 189 | struct callstack_element callstack[MAX_CALLDEPTH]; |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 190 | struct library_symbol * list_of_symbols; |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 191 | |
| Joe Damato | f0bd98b | 2010-11-08 15:47:42 -0800 | [diff] [blame] | 192 | int libdl_hooked; |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 193 | /* Arch-dependent: */ |
| Joe Damato | f0bd98b | 2010-11-08 15:47:42 -0800 | [diff] [blame] | 194 | void * debug; /* arch-dep process debug struct */ |
| 195 | long debug_state; /* arch-dep debug state */ |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 196 | void * instruction_pointer; |
| 197 | void * stack_pointer; /* To get return addr, args... */ |
| 198 | void * return_addr; |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 199 | void * arch_ptr; |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 200 | short e_machine; |
| 201 | short need_to_reinitialize_breakpoints; |
| 202 | #ifdef __arm__ |
| 203 | int thumb_mode; /* ARM execution mode: 0: ARM, 1: Thumb */ |
| 204 | #endif |
| 205 | |
| Joe Damato | ab3b72c | 2010-10-31 00:21:53 -0700 | [diff] [blame] | 206 | #if defined(HAVE_LIBUNWIND) |
| 207 | /* libunwind address space */ |
| 208 | unw_addr_space_t unwind_as; |
| 209 | void *unwind_priv; |
| 210 | #endif /* defined(HAVE_LIBUNWIND) */ |
| 211 | |
| Petr Machata | 4007d74 | 2011-07-09 11:29:42 +0200 | [diff] [blame] | 212 | /* Set in leader. */ |
| 213 | Event_Handler * event_handler; |
| 214 | |
| 215 | |
| Petr Machata | 9a5420c | 2011-07-09 11:21:23 +0200 | [diff] [blame] | 216 | /** |
| 217 | * Process chaining. |
| 218 | **/ |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 219 | Process * next; |
| Petr Machata | 9a5420c | 2011-07-09 11:21:23 +0200 | [diff] [blame] | 220 | |
| 221 | /* LEADER points to the leader thread of the POSIX.1 process. |
| 222 | If X->LEADER == X, then X is the leader thread and the |
| 223 | Process structures chained by NEXT represent other threads, |
| 224 | up until, but not including, the next leader thread. |
| 225 | LEADER may be NULL after the leader has already exited. In |
| 226 | that case this process is waiting to be collected. */ |
| 227 | Process * leader; |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 228 | }; |
| 229 | |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 230 | struct opt_c_struct { |
| 231 | int count; |
| 232 | struct timeval tv; |
| 233 | }; |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 234 | |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 235 | #include "options.h" |
| 236 | #include "output.h" |
| 237 | #ifdef USE_DEMANGLE |
| 238 | #include "demangle.h" |
| 239 | #endif |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 240 | |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 241 | extern Dict * dict_opt_c; |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 242 | |
| Petr Machata | 617ff0b | 2011-10-06 14:23:24 +0200 | [diff] [blame] | 243 | enum process_status { |
| 244 | ps_invalid, /* Failure. */ |
| 245 | ps_stop, /* Job-control stop. */ |
| 246 | ps_tracing_stop, |
| Petr Machata | cbe29c6 | 2011-09-27 02:27:58 +0200 | [diff] [blame] | 247 | ps_sleeping, |
| Petr Machata | 617ff0b | 2011-10-06 14:23:24 +0200 | [diff] [blame] | 248 | ps_zombie, |
| 249 | ps_other, /* Necessary other states can be added as needed. */ |
| 250 | }; |
| 251 | |
| Petr Machata | cebb884 | 2011-07-09 11:14:11 +0200 | [diff] [blame] | 252 | enum pcb_status { |
| 253 | pcb_stop, /* The iteration should stop. */ |
| 254 | pcb_cont, /* The iteration should continue. */ |
| 255 | }; |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 256 | |
| Petr Machata | 4007d74 | 2011-07-09 11:29:42 +0200 | [diff] [blame] | 257 | /* Process list */ |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 258 | extern Process * pid2proc(pid_t pid); |
| Petr Machata | cebb884 | 2011-07-09 11:14:11 +0200 | [diff] [blame] | 259 | extern void add_process(Process * proc); |
| 260 | extern void remove_process(Process * proc); |
| Petr Machata | cbe29c6 | 2011-09-27 02:27:58 +0200 | [diff] [blame] | 261 | extern void change_process_leader(Process * proc, Process * leader); |
| Petr Machata | cebb884 | 2011-07-09 11:14:11 +0200 | [diff] [blame] | 262 | extern Process *each_process(Process * start, |
| 263 | enum pcb_status (* cb)(Process * proc, void * data), |
| 264 | void * data); |
| Petr Machata | 9a5420c | 2011-07-09 11:21:23 +0200 | [diff] [blame] | 265 | extern Process *each_task(Process * start, |
| 266 | enum pcb_status (* cb)(Process * proc, void * data), |
| 267 | void * data); |
| 268 | |
| Petr Machata | 69a03e6 | 2011-07-09 11:29:12 +0200 | [diff] [blame] | 269 | /* Events */ |
| 270 | enum ecb_status { |
| 271 | ecb_cont, /* The iteration should continue. */ |
| 272 | ecb_yield, /* The iteration should stop, yielding this |
| 273 | * event. */ |
| 274 | ecb_deque, /* Like ecb_stop, but the event should be removed |
| 275 | * from the queue. */ |
| 276 | }; |
| 277 | extern Event * next_event(void); |
| 278 | extern Event * each_qd_event(enum ecb_status (* cb)(Event * event, void * data), |
| 279 | void * data); |
| 280 | extern void enque_event(Event * event); |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 281 | extern void handle_event(Event * event); |
| Petr Machata | 4007d74 | 2011-07-09 11:29:42 +0200 | [diff] [blame] | 282 | |
| 283 | extern void install_event_handler(Process * proc, Event_Handler * handler); |
| 284 | extern void destroy_event_handler(Process * proc); |
| 285 | |
| Petr Machata | 1b17dbf | 2011-07-08 19:22:52 +0200 | [diff] [blame] | 286 | extern pid_t execute_program(const char * command, char ** argv); |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 287 | extern int display_arg(enum tof type, Process * proc, int arg_num, arg_type_info * info); |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 288 | extern void disable_all_breakpoints(Process * proc); |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 289 | |
| Petr Machata | c7585b6 | 2011-07-08 22:58:12 +0200 | [diff] [blame] | 290 | extern Process * open_program(char * filename, pid_t pid, int init_breakpoints); |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 291 | extern void open_pid(pid_t pid); |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 292 | extern void show_summary(void); |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 293 | extern arg_type_info * lookup_prototype(enum arg_type at); |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 294 | |
| Petr Machata | 1974dbc | 2011-08-19 18:58:01 +0200 | [diff] [blame] | 295 | extern int do_init_elf(struct ltelf *lte, const char *filename); |
| Joe Damato | 7a2bdf8 | 2010-11-08 15:47:41 -0800 | [diff] [blame] | 296 | extern void do_close_elf(struct ltelf *lte); |
| 297 | extern int in_load_libraries(const char *name, struct ltelf *lte, size_t count, GElf_Sym *sym); |
| 298 | extern struct library_symbol *library_symbols; |
| 299 | extern void add_library_symbol(GElf_Addr addr, const char *name, |
| 300 | struct library_symbol **library_symbolspp, |
| 301 | enum toplt type_of_plt, int is_weak); |
| 302 | |
| Petr Machata | 534e00f | 2011-09-27 17:58:38 +0200 | [diff] [blame] | 303 | extern struct library_symbol * clone_library_symbol(struct library_symbol * s); |
| 304 | extern void destroy_library_symbol(struct library_symbol * s); |
| 305 | extern void destroy_library_symbol_chain(struct library_symbol * chain); |
| 306 | |
| Petr Machata | 9294d82 | 2012-02-07 12:35:58 +0100 | [diff] [blame^] | 307 | struct breakpoint; |
| 308 | |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 309 | /* Arch-dependent stuff: */ |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 310 | extern char * pid2name(pid_t pid); |
| Petr Machata | 9a5420c | 2011-07-09 11:21:23 +0200 | [diff] [blame] | 311 | extern pid_t process_leader(pid_t pid); |
| 312 | extern int process_tasks(pid_t pid, pid_t **ret_tasks, size_t *ret_n); |
| 313 | extern int process_stopped(pid_t pid); |
| Petr Machata | 617ff0b | 2011-10-06 14:23:24 +0200 | [diff] [blame] | 314 | extern enum process_status process_status(pid_t pid); |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 315 | extern void trace_set_options(Process * proc, pid_t pid); |
| Petr Machata | b4f9e0c | 2012-02-07 01:57:59 +0100 | [diff] [blame] | 316 | extern void wait_for_proc(pid_t pid); |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 317 | extern void trace_me(void); |
| 318 | extern int trace_pid(pid_t pid); |
| 319 | extern void untrace_pid(pid_t pid); |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 320 | extern void get_arch_dep(Process * proc); |
| 321 | extern void * get_instruction_pointer(Process * proc); |
| 322 | extern void set_instruction_pointer(Process * proc, void * addr); |
| 323 | extern void * get_stack_pointer(Process * proc); |
| 324 | extern void * get_return_addr(Process * proc, void * stack_pointer); |
| Juan Cespedes | 2a61d19 | 2009-07-04 11:29:27 +0200 | [diff] [blame] | 325 | extern void set_return_addr(Process * proc, void * addr); |
| Petr Machata | 9294d82 | 2012-02-07 12:35:58 +0100 | [diff] [blame^] | 326 | extern void enable_breakpoint(Process * proc, struct breakpoint *sbp); |
| 327 | extern void disable_breakpoint(Process * proc, struct breakpoint *sbp); |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 328 | extern int syscall_p(Process * proc, int status, int * sysnum); |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 329 | extern void continue_process(pid_t pid); |
| 330 | extern void continue_after_signal(pid_t pid, int signum); |
| Petr Machata | 43d2fe5 | 2011-11-02 13:25:49 +0100 | [diff] [blame] | 331 | extern void continue_after_syscall(Process *proc, int sysnum, int ret_p); |
| Petr Machata | 9294d82 | 2012-02-07 12:35:58 +0100 | [diff] [blame^] | 332 | extern void continue_after_breakpoint(Process * proc, struct breakpoint *sbp); |
| Petr Machata | cbe29c6 | 2011-09-27 02:27:58 +0200 | [diff] [blame] | 333 | extern void continue_after_vfork(Process * proc); |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 334 | extern long gimme_arg(enum tof type, Process * proc, int arg_num, arg_type_info * info); |
| 335 | extern void save_register_args(enum tof type, Process * proc); |
| 336 | extern int umovestr(Process * proc, void * addr, int len, void * laddr); |
| 337 | extern int umovelong (Process * proc, void * addr, long * result, arg_type_info * info); |
| Joe Damato | dfa3fa3 | 2010-11-08 15:47:35 -0800 | [diff] [blame] | 338 | extern size_t umovebytes (Process *proc, void * addr, void * laddr, size_t count); |
| Juan Cespedes | 8d1b92b | 2009-07-03 10:39:34 +0200 | [diff] [blame] | 339 | extern int ffcheck(void * maddr); |
| 340 | extern void * sym2addr(Process *, struct library_symbol *); |
| Joe Damato | f0bd98b | 2010-11-08 15:47:42 -0800 | [diff] [blame] | 341 | extern int linkmap_init(Process *, struct ltelf *); |
| 342 | extern void arch_check_dbg(Process *proc); |
| Petr Machata | 9a5420c | 2011-07-09 11:21:23 +0200 | [diff] [blame] | 343 | extern int task_kill (pid_t pid, int sig); |
| 344 | |
| Petr Machata | cec06ec | 2012-04-10 13:31:55 +0200 | [diff] [blame] | 345 | /* Called when trace_me or primary trace_pid fail. This may plug in |
| 346 | * any platform-specific knowledge of why it could be so. */ |
| 347 | void trace_fail_warning(pid_t pid); |
| 348 | |
| Petr Machata | ffe4cd2 | 2012-04-11 18:01:44 +0200 | [diff] [blame] | 349 | /* A pair of functions called to initiate a detachment request when |
| 350 | * ltrace is about to exit. Their job is to undo any effects that |
| 351 | * tracing had and eventually detach process, perhaps by way of |
| 352 | * installing a process handler. |
| 353 | * |
| 354 | * OS_LTRACE_EXITING_SIGHANDLER is called from a signal handler |
| 355 | * context right after the signal was captured. It returns 1 if the |
| 356 | * request was handled or 0 if it wasn't. |
| 357 | * |
| 358 | * If the call to OS_LTRACE_EXITING_SIGHANDLER didn't handle the |
| 359 | * request, OS_LTRACE_EXITING is called when the next event is |
| 360 | * generated. Therefore it's called in "safe" context, without |
| 361 | * re-entrancy concerns, but it's only called after an even is |
| 362 | * generated. */ |
| 363 | int os_ltrace_exiting_sighandler(void); |
| 364 | void os_ltrace_exiting(void); |
| Juan Cespedes | 3df476b | 2009-05-28 19:17:17 +0200 | [diff] [blame] | 365 | |
| Joe Damato | f0bd98b | 2010-11-08 15:47:42 -0800 | [diff] [blame] | 366 | extern struct ltelf main_lte; |
| Michael K. Edwards | ef4428a | 2011-03-06 20:39:18 +0000 | [diff] [blame] | 367 | |
| 368 | #endif |