2 * This file is part of ltrace.
3 * Copyright (C) 2010,2011,2012 Petr Machata, Red Hat Inc.
4 * Copyright (C) 2010 Joe Damato
5 * Copyright (C) 1998,2001,2008,2009 Juan Cespedes
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.
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.
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
30 #if defined(HAVE_LIBUNWIND)
31 # include <libunwind.h>
32 #endif /* defined(HAVE_LIBUNWIND) */
40 struct event_handler {
41 /* Event handler that overrides the default one. Should
42 * return NULL if the event was handled, otherwise the
43 * returned event is passed to the default handler. */
44 Event *(*on_event)(struct event_handler *self, Event *event);
46 /* Called when the event handler removal is requested. */
47 void (*destroy)(struct event_handler *self);
53 STATE_IGNORED /* ignore this process (it's a fork and no -f was used) */
61 struct callstack_element {
64 struct library_symbol * libfunc;
68 struct timeval time_spent;
69 struct fetch_context *fetch_context;
70 struct value_dict *arguments;
71 struct output_state out;
74 /* XXX We should get rid of this. */
75 #define MAX_CALLDEPTH 64
77 /* XXX We would rather have this all organized a little differently,
78 * have Process for the whole group and Task for what's there for
79 * per-thread stuff. But for now this is the less invasive way of
81 typedef struct Process Process;
83 enum process_state state;
84 Process * parent; /* needed by STATE_BEING_CREATED */
88 /* Dictionary of breakpoints (which is a mapping
89 * address->breakpoint). This is NULL for non-leader
90 * processes. XXX note that we store addresses (keys) by
91 * value. That assumes that arch_addr_t fits in host
95 int mask_32bit; /* 1 if 64-bit ltrace is tracing 32-bit process */
96 unsigned int personality;
97 int tracesysgood; /* signal indicating a PTRACE_SYSCALL trap */
99 size_t callstack_depth;
100 struct callstack_element callstack[MAX_CALLDEPTH];
102 /* Linked list of libraries in backwards order of mapping.
103 * The last element is the executed binary itself. */
104 struct library *libraries;
106 /* Arch-dependent: */
107 void * instruction_pointer;
108 void * stack_pointer; /* To get return addr, args... */
112 /* XXX We would like to replace this with a pointer to ABI
113 * object that would provide the relevant services, instead of
114 * checking the necessary flags in the back end ad
119 /* XXX this shoudl go to ARM's arch_process_data. */
121 int thumb_mode; /* ARM execution mode: 0: ARM, 1: Thumb */
124 #if defined(HAVE_LIBUNWIND)
125 /* libunwind address space */
126 unw_addr_space_t unwind_as;
128 #endif /* defined(HAVE_LIBUNWIND) */
131 struct event_handler *event_handler;
138 /* LEADER points to the leader thread of the POSIX.1 process.
139 If X->LEADER == X, then X is the leader thread and the
140 Process structures chained by NEXT represent other threads,
141 up until, but not including, the next leader thread.
142 LEADER may be NULL after the leader has already exited. In
143 that case this process is waiting to be collected. */
146 struct os_process_data os;
147 struct arch_process_data arch;
150 /* Initialize a process given a path to binary FILENAME, with a PID,
151 * and add the process to an internal chain of traced processes. */
152 int process_init(struct Process *proc, const char *filename, pid_t pid);
154 /* PROC underwent an exec. This is a bit like process_destroy
155 * followed by process_init, except that some state is kept and the
156 * process doesn't lose it's place in the list of processes. */
157 int process_exec(struct Process *proc);
159 /* Release any memory allocated for PROC (but not PROC itself). Does
160 * NOT remove PROC from internal chain.
162 * XXX clearly this init/destroy pair is different than others and
163 * should be fixed. process_init should presumably be separate from
165 void process_destroy(struct Process *proc);
167 struct Process *open_program(const char *filename, pid_t pid);
168 void open_pid(pid_t pid);
169 Process * pid2proc(pid_t pid);
171 /* Clone the contents of PROC into the memory referenced by RETP.
172 * Returns 0 on success or a negative value on failure. */
173 int process_clone(struct Process *retp, struct Process *proc, pid_t pid);
175 /* Iterate through the processes that ltrace currently traces. Tasks
176 * are considered to be processes for the purpose of this iterator.
177 * See callback.h for notes on iteration interfaces. */
178 Process *each_process(Process *start_after,
179 enum callback_status (*cb)(struct Process *proc,
183 /* Iterate through list of tasks of given process PROC. See
184 * callback.h for notes on iteration interfaces. */
185 Process *each_task(struct Process *proc, struct Process *start_after,
186 enum callback_status (*cb)(struct Process *proc,
190 void change_process_leader(Process *proc, Process *leader);
192 /* Remove process from the list of traced processes, drop any events
193 * in the event queue, destroy it and free memory. */
194 void remove_process(struct Process *proc);
196 void install_event_handler(Process *proc, struct event_handler *handler);
197 void destroy_event_handler(Process *proc);
199 /* Add a library LIB to the list of PROC's libraries. */
200 void proc_add_library(struct Process *proc, struct library *lib);
202 /* Remove LIB from list of PROC's libraries. Returns 0 if the library
203 * was found and unlinked, otherwise returns a negative value. */
204 int proc_remove_library(struct Process *proc, struct library *lib);
206 /* Clear a delayed flag. If a symbol is neither latent, nor delayed,
207 * a breakpoint is inserted for it. Returns 0 if the activation was
208 * successful or a negative value if it failed. Note that if a symbol
209 * is both latent and delayed, this will not enable the corresponding
211 int proc_activate_delayed_symbol(struct Process *proc,
212 struct library_symbol *libsym);
214 /* Iterate through the libraries of PROC. See callback.h for notes on
215 * iteration interfaces. */
216 struct library *proc_each_library(struct Process *proc, struct library *start,
217 enum callback_status (*cb)(struct Process *p,
222 /* Insert BP into PROC. */
223 int proc_add_breakpoint(struct Process *proc, struct breakpoint *bp);
225 /* Remove BP from PROC. This has no reason to fail in runtime. If it
226 * does not find BP in PROC, it's hard error guarded by assertion. */
227 void proc_remove_breakpoint(struct Process *proc, struct breakpoint *bp);
229 /* Iterate through the breakpoints of PROC. See callback.h for notes
230 * on iteration interfaces. */
231 void *proc_each_breakpoint(struct Process *proc, void *start,
232 enum callback_status (*cb)(struct Process *proc,
233 struct breakpoint *bp,
237 /* Iterate through the dynamic section at src_addr looking for D_TAG.
238 * If tag is found, fill it's value in RET and return 0.
239 * If tag is not found, return a negative value. */
240 int proc_find_dynamic_entry_addr(struct Process *proc, arch_addr_t src_addr,
241 int d_tag, arch_addr_t *ret);
243 /* Finds a symbol corresponding to LIBSYM in a process PROC. Returns
244 * 0 and sets *RETLIB and *RETSYM if the corresponding pointer is
245 * non-NULL. Returns a negative value when the symbols couldn't be
247 int proc_find_symbol(struct Process *proc, struct library_symbol *sym,
248 struct library **retlib, struct library_symbol **retsym);
250 /* Iterate through all symbols in all libraries of PROC. See
251 * callback.h for notes on this interface. */
252 struct library_symbol *proc_each_symbol
253 (struct Process *proc, struct library_symbol *start_after,
254 enum callback_status (*cb)(struct library_symbol *, void *),
257 #endif /* _PROC_H_ */