common.h revision cd972587a4c0d14d764b3d0a43d75f5941db14cc
1/* 2 * This file is part of ltrace. 3 * Copyright (C) 2011,2012 Petr Machata, Red Hat Inc. 4 * Copyright (C) 2010 Joe Damato 5 * Copyright (C) 2009 Juan Cespedes 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License as 9 * published by the Free Software Foundation; either version 2 of the 10 * License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, but 13 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 20 * 02110-1301 USA 21 */ 22 23#ifndef COMMON_H 24#define COMMON_H 25 26#include <config.h> 27 28#include <sys/types.h> 29#include <sys/time.h> 30#include <stdio.h> 31 32#include "ltrace.h" 33#include "defs.h" 34#include "dict.h" 35#include "sysdep.h" 36#include "debug.h" 37#include "ltrace-elf.h" 38#include "read_config_file.h" 39#include "proc.h" 40#include "forward.h" 41 42#if defined HAVE_LIBSUPC__ || defined HAVE_LIBSTDC__ 43# define USE_CXA_DEMANGLE 44#endif 45#if defined HAVE_LIBIBERTY || defined USE_CXA_DEMANGLE 46# define USE_DEMANGLE 47#endif 48 49extern char * command; 50 51extern int exiting; /* =1 if we have to exit ASAP */ 52 53typedef struct Function Function; 54struct Function { 55 const char * name; 56 struct param *params; 57 struct arg_type_info *return_info; 58 int own_return_info; 59 size_t num_params; 60 Function * next; 61}; 62 63extern Function * list_of_functions; 64extern char *PLTs_initialized_by_here; 65 66struct opt_c_struct { 67 int count; 68 struct timeval tv; 69}; 70 71#include "options.h" 72#include "output.h" 73#ifdef USE_DEMANGLE 74#include "demangle.h" 75#endif 76 77extern Dict * dict_opt_c; 78 79enum process_status { 80 ps_invalid, /* Failure. */ 81 ps_stop, /* Job-control stop. */ 82 ps_tracing_stop, 83 ps_sleeping, 84 ps_zombie, 85 ps_other, /* Necessary other states can be added as needed. */ 86}; 87 88/* Events */ 89extern Event * next_event(void); 90extern void handle_event(Event * event); 91 92extern pid_t execute_program(const char * command, char ** argv); 93 94extern void show_summary(void); 95 96struct breakpoint; 97struct library_symbol; 98 99struct breakpoint; 100 101/* Arch-dependent stuff: */ 102extern char * pid2name(pid_t pid); 103extern pid_t process_leader(pid_t pid); 104extern int process_tasks(pid_t pid, pid_t **ret_tasks, size_t *ret_n); 105extern int process_stopped(pid_t pid); 106extern enum process_status process_status(pid_t pid); 107extern void trace_set_options(struct Process *proc); 108extern int wait_for_proc(pid_t pid); 109extern void trace_me(void); 110extern int trace_pid(pid_t pid); 111extern void untrace_pid(pid_t pid); 112extern void get_arch_dep(Process * proc); 113extern void * get_instruction_pointer(Process * proc); 114extern void set_instruction_pointer(Process * proc, void * addr); 115extern void * get_stack_pointer(Process * proc); 116extern void * get_return_addr(Process * proc, void * stack_pointer); 117extern void set_return_addr(Process * proc, void * addr); 118extern void enable_breakpoint(struct Process *proc, struct breakpoint *sbp); 119extern void disable_breakpoint(struct Process *proc, struct breakpoint *sbp); 120extern int syscall_p(Process * proc, int status, int * sysnum); 121extern void continue_process(pid_t pid); 122extern void continue_after_signal(pid_t pid, int signum); 123extern void continue_after_syscall(Process *proc, int sysnum, int ret_p); 124extern void continue_after_breakpoint(struct Process *proc, struct breakpoint *sbp); 125extern void continue_after_vfork(Process * proc); 126extern size_t umovebytes (Process *proc, void * addr, void * laddr, size_t count); 127extern int ffcheck(void * maddr); 128extern void * sym2addr(Process *, struct library_symbol *); 129extern int linkmap_init(struct Process *proc, void *dyn_addr); 130extern void arch_check_dbg(Process *proc); 131extern int task_kill (pid_t pid, int sig); 132 133/* Called when trace_me or primary trace_pid fail. This may plug in 134 * any platform-specific knowledge of why it could be so. */ 135void trace_fail_warning(pid_t pid); 136 137/* A pair of functions called to initiate a detachment request when 138 * ltrace is about to exit. Their job is to undo any effects that 139 * tracing had and eventually detach process, perhaps by way of 140 * installing a process handler. 141 * 142 * OS_LTRACE_EXITING_SIGHANDLER is called from a signal handler 143 * context right after the signal was captured. It returns 1 if the 144 * request was handled or 0 if it wasn't. 145 * 146 * If the call to OS_LTRACE_EXITING_SIGHANDLER didn't handle the 147 * request, OS_LTRACE_EXITING is called when the next event is 148 * generated. Therefore it's called in "safe" context, without 149 * re-entrancy concerns, but it's only called after an event is 150 * generated. */ 151int os_ltrace_exiting_sighandler(void); 152void os_ltrace_exiting(void); 153 154int arch_elf_init(struct ltelf *lte, struct library *lib); 155void arch_elf_destroy(struct ltelf *lte); 156 157enum plt_status { 158 plt_fail, 159 plt_ok, 160 plt_default, 161}; 162 163enum plt_status arch_elf_add_plt_entry(struct Process *p, struct ltelf *l, 164 const char *n, GElf_Rela *r, size_t i, 165 struct library_symbol **ret); 166 167int arch_breakpoint_init(struct Process *proc, struct breakpoint *sbp); 168void arch_breakpoint_destroy(struct breakpoint *sbp); 169int arch_breakpoint_clone(struct breakpoint *retp, struct breakpoint *sbp); 170 171void arch_library_init(struct library *lib); 172void arch_library_destroy(struct library *lib); 173void arch_library_clone(struct library *retp, struct library *lib); 174 175int arch_library_symbol_init(struct library_symbol *libsym); 176void arch_library_symbol_destroy(struct library_symbol *libsym); 177int arch_library_symbol_clone(struct library_symbol *retp, 178 struct library_symbol *libsym); 179 180int arch_process_init(struct Process *proc); 181void arch_process_destroy(struct Process *proc); 182int arch_process_clone(struct Process *retp, struct Process *proc); 183int arch_process_exec(struct Process *proc); 184 185/* This is called after the dynamic linker is done with the 186 * process startup. */ 187void arch_dynlink_done(struct Process *proc); 188 189/* Format VALUE into STREAM. The dictionary of all arguments is given 190 * for purposes of evaluating array lengths and other dynamic 191 * expressions. Returns number of characters outputted, -1 in case of 192 * failure. */ 193int format_argument(FILE *stream, struct value *value, 194 struct value_dict *arguments); 195 196/* Called when process PROC was removed. */ 197void process_removed(struct Process *proc); 198 199#endif 200