2 * This file is part of ltrace.
3 * Copyright (C) 2012,2013 Petr Machata, Red Hat Inc.
4 * Copyright (C) 2006 Paul Gilliam, IBM Corporation
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27 #if defined(HAVE_LIBDW)
28 # include <elfutils/libdwfl.h>
36 LS_TOPLT_NONE = 0, /* PLT not used for this symbol. */
37 LS_TOPLT_EXEC, /* PLT for this symbol is executable. */
41 size_t arch_addr_hash(const arch_addr_t *addr);
42 int arch_addr_eq(const arch_addr_t *addr1, const arch_addr_t *addr2);
44 /* For handling -l. */
45 struct library_exported_name {
46 struct library_exported_name *next;
51 struct library_symbol {
52 struct library_symbol *next;
55 arch_addr_t enter_addr;
58 /* If this is non-NULL, this prototype is used instead of
59 * looking up one in LIB->protolib. */
60 struct prototype *proto;
64 /* This is relevant for PLT symbols. Latent PLT symbols are
65 * those that don't match any of the -e rules, but that might
66 * potentially become active if a library implementing them
67 * appears that matches a -l rule. Ltrace core is responsible
68 * for clearing latent flag. */
71 /* Delayed symbols are those for which a breakpoint shouldn't
72 * be enabled yet. They are similar to latent symbols, but
73 * backend is responsible for clearing the delayed flag. See
74 * proc_activate_delayed_symbol. */
77 struct arch_library_symbol_data arch;
78 struct os_library_symbol_data os;
81 /* Init LIBSYM. NAME will be freed when LIBSYM is destroyed if
82 * OWN_NAME. ARCH has to be initialized by a separate call. */
83 int library_symbol_init(struct library_symbol *libsym,
84 arch_addr_t addr, const char *name, int own_name,
85 enum toplt type_of_plt);
87 /* Copy library symbol SYM into the area pointed-to by RETP. Return 0
88 * on success or a negative value on failure. */
89 int library_symbol_clone(struct library_symbol *retp,
90 struct library_symbol *sym);
92 /* Destroy library symbol. This essentially just frees name if it's
93 * owned. It doesn't free the memory associated with SYM pointer
94 * itself. Returns 0 on success or a negative value in case of an
95 * error (which would be an out of memory condition). */
96 void library_symbol_destroy(struct library_symbol *sym);
98 /* Compare two library symbols. Returns a negative value, 0, or a
99 * positive value, much like strcmp. The function compares symbol
100 * addresses, and if those are equal, it compares symbol names. If
101 * those are equal, too, the symbols are considered equal. */
102 int library_symbol_cmp(struct library_symbol *a, struct library_symbol *b);
104 /* Set a name for library symbol. This frees the old name, if
106 void library_symbol_set_name(struct library_symbol *libsym,
107 const char *name, int own_name);
109 /* A function that can be used as library_each_symbol callback. Looks
110 * for a symbol SYM for which library_symbol_cmp(SYM, STANDARD)
112 enum callback_status library_symbol_equal_cb(struct library_symbol *libsym,
115 /* A function that can be used as library_each_symbol callback. Looks
116 * for a symbol SYM for which strcmp(SYM->name, NAME) == 0. */
117 enum callback_status library_symbol_named_cb(struct library_symbol *libsym,
120 /* A function that can be used as library_each_symbol callback. Looks
121 * for a delayed symbol. */
122 enum callback_status library_symbol_delayed_cb(struct library_symbol *libsym,
131 /* XXX we might consider sharing libraries across processes. Things
132 * like libc will be opened by every single process, no point cloning
133 * these everywhere. But for now, keep the ownership structure
136 struct library *next;
138 /* Unique key. Two library objects are considered equal, if
139 * they have the same key. */
142 /* Address where the library is mapped. */
145 /* Absolute address of the entry point. Useful for main
146 * binary, though I suppose the value might be useful for the
147 * dynamic linker, too (in case we ever want to do early
148 * process tracing). */
151 /* Address of PT_DYNAMIC segment. */
152 arch_addr_t dyn_addr;
154 /* Symbols associated with the library. This includes a
155 * symbols that don't have a breakpoint attached (yet). */
156 struct library_symbol *symbols;
158 /* List of names that this library implements, and that match
159 * -l filter. Each time a new library is mapped, its list of
160 * exports is examined, and corresponding PLT slots are
162 struct library_exported_name *exported_names;
164 /* Prototype library associated with this library. */
165 struct protolib *protolib;
168 const char *pathname;
170 enum library_type type;
173 char own_pathname : 1;
175 struct arch_library_data arch;
176 struct os_library_data os;
178 #if defined(HAVE_LIBDW)
184 int library_init(struct library *lib, enum library_type type);
186 /* Initialize RETP to a library identical to LIB. Symbols are not
187 * shared, but copied over. Returns 0 on success and a negative value
188 * in case of failure. */
189 int library_clone(struct library *retp, struct library *lib);
191 /* Destroy library. Doesn't free LIB itself. Symbols are destroyed
193 void library_destroy(struct library *lib);
195 /* Set library soname. Frees the old name if necessary. */
196 void library_set_soname(struct library *lib,
197 const char *new_name, int own_name);
199 /* Set library pathname. Frees the old name if necessary. */
200 void library_set_pathname(struct library *lib,
201 const char *new_name, int own_name);
203 /* Iterate through list of symbols of library LIB. See callback.h for
204 * notes on this interface. */
205 struct library_symbol *library_each_symbol
206 (struct library *lib, struct library_symbol *start_after,
207 enum callback_status (*cb)(struct library_symbol *, void *),
210 /* Add a new symbol SYM to LIB. SYM is assumed owned, we need to
211 * overwrite SYM->next. */
212 void library_add_symbol(struct library *lib, struct library_symbol *sym);
214 /* A function that can be used as proc_each_library callback. Looks
215 * for a library with the name passed in DATA. PROC is ignored. */
216 enum callback_status library_named_cb(struct process *proc,
217 struct library *lib, void *name);
219 /* A function that can be used as proc_each_library callback. Looks
220 * for a library with given base.
222 * NOTE: The key is passed as a POINTER to arch_addr_t (that
223 * because in general, arch_addr_t doesn't fit in void*). */
224 enum callback_status library_with_key_cb(struct process *proc,
225 struct library *lib, void *keyp);
227 /* XXX this should really be in backend.h (as on pmachata/revamp
228 * branch), or, on this branch, in common.h. But we need
229 * arch_addr_t (which should also be in backend.h, I reckon), so
230 * stuff it here for the time being. */
231 /* This function is implemented in the back end. It is called for all
232 * raw addresses as read from symbol tables etc. If necessary on
233 * given architecture, this function should translate the address
234 * according to .opd or other indirection mechanism. Returns 0 on
235 * success and a negative value on failure. */
237 int arch_translate_address(struct ltelf *lte,
238 arch_addr_t addr, arch_addr_t *ret);
239 /* This is the same function as arch_translate_address, except it's
240 * used at the point that we don't have ELF available anymore. */
241 int arch_translate_address_dyn(struct process *proc,
242 arch_addr_t addr, arch_addr_t *ret);
244 #endif /* _LIBRARY_H_ */