Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 1 | /* Internal definitions for libdwfl. |
Roland McGrath | 2c7d0dd | 2011-01-04 19:29:53 -0800 | [diff] [blame] | 2 | Copyright (C) 2005-2011 Red Hat, Inc. |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 3 | This file is part of elfutils. |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 4 | |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 5 | This file is free software; you can redistribute it and/or modify |
| 6 | it under the terms of either |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 7 | |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 8 | * the GNU Lesser General Public License as published by the Free |
| 9 | Software Foundation; either version 3 of the License, or (at |
| 10 | your option) any later version |
| 11 | |
| 12 | or |
| 13 | |
| 14 | * the GNU General Public License as published by the Free |
| 15 | Software Foundation; either version 2 of the License, or (at |
| 16 | your option) any later version |
| 17 | |
| 18 | or both in parallel, as here. |
| 19 | |
| 20 | elfutils is distributed in the hope that it will be useful, but |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 21 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 23 | General Public License for more details. |
| 24 | |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 25 | You should have received copies of the GNU General Public License and |
| 26 | the GNU Lesser General Public License along with this program. If |
| 27 | not, see <http://www.gnu.org/licenses/>. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 28 | |
| 29 | #ifndef _LIBDWFLP_H |
| 30 | #define _LIBDWFLP_H 1 |
| 31 | |
Roland McGrath | 55d34a5 | 2007-06-08 22:22:01 +0000 | [diff] [blame] | 32 | #ifndef PACKAGE_NAME |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 33 | # include <config.h> |
| 34 | #endif |
| 35 | #include <libdwfl.h> |
| 36 | #include <libebl.h> |
| 37 | #include <assert.h> |
| 38 | #include <errno.h> |
| 39 | #include <stdbool.h> |
| 40 | #include <stdlib.h> |
| 41 | #include <string.h> |
| 42 | |
Roland McGrath | 4959bf8 | 2005-08-09 10:31:08 +0000 | [diff] [blame] | 43 | #include "../libdw/libdwP.h" /* We need its INTDECLs. */ |
| 44 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 45 | /* gettext helper macros. */ |
| 46 | #define _(Str) dgettext ("elfutils", Str) |
| 47 | |
| 48 | #define DWFL_ERRORS \ |
| 49 | DWFL_ERROR (NOERROR, N_("no error")) \ |
| 50 | DWFL_ERROR (UNKNOWN_ERROR, N_("unknown error")) \ |
| 51 | DWFL_ERROR (NOMEM, N_("out of memory")) \ |
| 52 | DWFL_ERROR (ERRNO, N_("See errno")) \ |
| 53 | DWFL_ERROR (LIBELF, N_("See elf_errno")) \ |
| 54 | DWFL_ERROR (LIBDW, N_("See dwarf_errno")) \ |
| 55 | DWFL_ERROR (LIBEBL, N_("See ebl_errno (XXX missing)")) \ |
Roland McGrath | bca4315 | 2009-01-05 23:59:32 -0800 | [diff] [blame] | 56 | DWFL_ERROR (ZLIB, N_("gzip decompression failed")) \ |
| 57 | DWFL_ERROR (BZLIB, N_("bzip2 decompression failed")) \ |
Roland McGrath | 2416964 | 2009-08-26 02:26:34 -0700 | [diff] [blame] | 58 | DWFL_ERROR (LZMA, N_("LZMA decompression failed")) \ |
Roland McGrath | 07d4f2f | 2005-10-28 06:56:24 +0000 | [diff] [blame] | 59 | DWFL_ERROR (UNKNOWN_MACHINE, N_("no support library found for machine")) \ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 60 | DWFL_ERROR (NOREL, N_("Callbacks missing for ET_REL file")) \ |
| 61 | DWFL_ERROR (BADRELTYPE, N_("Unsupported relocation type")) \ |
| 62 | DWFL_ERROR (BADRELOFF, N_("r_offset is bogus")) \ |
| 63 | DWFL_ERROR (BADSTROFF, N_("offset out of range")) \ |
| 64 | DWFL_ERROR (RELUNDEF, N_("relocation refers to undefined symbol")) \ |
| 65 | DWFL_ERROR (CB, N_("Callback returned failure")) \ |
| 66 | DWFL_ERROR (NO_DWARF, N_("No DWARF information found")) \ |
| 67 | DWFL_ERROR (NO_SYMTAB, N_("No symbol table found")) \ |
| 68 | DWFL_ERROR (NO_PHDR, N_("No ELF program headers")) \ |
| 69 | DWFL_ERROR (OVERLAP, N_("address range overlaps an existing module")) \ |
| 70 | DWFL_ERROR (ADDR_OUTOFRANGE, N_("address out of range")) \ |
| 71 | DWFL_ERROR (NO_MATCH, N_("no matching address range")) \ |
| 72 | DWFL_ERROR (TRUNCATED, N_("image truncated")) \ |
Roland McGrath | 59ea7f3 | 2007-10-04 08:50:09 +0000 | [diff] [blame] | 73 | DWFL_ERROR (ALREADY_ELF, N_("ELF file opened")) \ |
Roland McGrath | e47ab76 | 2005-11-17 03:16:00 +0000 | [diff] [blame] | 74 | DWFL_ERROR (BADELF, N_("not a valid ELF file")) \ |
Roland McGrath | ed431dd | 2010-05-06 00:52:51 -0700 | [diff] [blame] | 75 | DWFL_ERROR (WEIRD_TYPE, N_("cannot handle DWARF type description")) \ |
Roland McGrath | 5ad466d | 2011-01-11 10:17:01 -0800 | [diff] [blame] | 76 | DWFL_ERROR (WRONG_ID_ELF, N_("ELF file does not match build ID")) \ |
| 77 | DWFL_ERROR (BAD_PRELINK, N_("corrupt .gnu.prelink_undo section data")) |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 78 | |
| 79 | #define DWFL_ERROR(name, text) DWFL_E_##name, |
| 80 | typedef enum { DWFL_ERRORS DWFL_E_NUM } Dwfl_Error; |
| 81 | #undef DWFL_ERROR |
| 82 | |
| 83 | #define OTHER_ERROR(name) ((unsigned int) DWFL_E_##name << 16) |
| 84 | #define DWFL_E(name, errno) (OTHER_ERROR (name) | (errno)) |
| 85 | |
Roland McGrath | d11f9cb | 2008-03-26 20:51:59 +0000 | [diff] [blame] | 86 | extern int __libdwfl_canon_error (Dwfl_Error) internal_function; |
| 87 | extern void __libdwfl_seterrno (Dwfl_Error) internal_function; |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 88 | |
| 89 | struct Dwfl |
| 90 | { |
| 91 | const Dwfl_Callbacks *callbacks; |
| 92 | |
| 93 | Dwfl_Module *modulelist; /* List in order used by full traversals. */ |
| 94 | |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 95 | GElf_Addr offline_next_address; |
Roland McGrath | b4d6f0f | 2008-08-25 22:55:17 +0000 | [diff] [blame] | 96 | |
| 97 | GElf_Addr segment_align; /* Smallest granularity of segments. */ |
| 98 | |
| 99 | /* Binary search table in three parallel malloc'd arrays. */ |
| 100 | size_t lookup_elts; /* Elements in use. */ |
| 101 | size_t lookup_alloc; /* Elements allococated. */ |
| 102 | GElf_Addr *lookup_addr; /* Start address of segment. */ |
| 103 | Dwfl_Module **lookup_module; /* Module associated with segment, or null. */ |
| 104 | int *lookup_segndx; /* User segment index, or -1. */ |
| 105 | |
| 106 | /* Cache from last dwfl_report_segment call. */ |
| 107 | const void *lookup_tail_ident; |
| 108 | GElf_Off lookup_tail_vaddr; |
| 109 | GElf_Off lookup_tail_offset; |
| 110 | int lookup_tail_ndx; |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 111 | }; |
| 112 | |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 113 | #define OFFLINE_REDZONE 0x10000 |
| 114 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 115 | struct dwfl_file |
| 116 | { |
| 117 | char *name; |
| 118 | int fd; |
Roland McGrath | 59ea7f3 | 2007-10-04 08:50:09 +0000 | [diff] [blame] | 119 | bool valid; /* The build ID note has been matched. */ |
Roland McGrath | e4c22ea | 2007-10-23 13:07:39 +0000 | [diff] [blame] | 120 | bool relocated; /* Partial relocation of all sections done. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 121 | |
| 122 | Elf *elf; |
Roland McGrath | 1743d7f | 2010-11-12 16:46:47 -0800 | [diff] [blame] | 123 | |
| 124 | /* This is the lowest p_vaddr in this ELF file, aligned to p_align. |
| 125 | For a file without phdrs, this is zero. */ |
| 126 | GElf_Addr vaddr; |
| 127 | |
| 128 | /* This is an address chosen for synchronization between the main file |
Roland McGrath | 2c7d0dd | 2011-01-04 19:29:53 -0800 | [diff] [blame] | 129 | and the debug file. See dwfl_module_getdwarf.c for how it's chosen. */ |
Roland McGrath | 1743d7f | 2010-11-12 16:46:47 -0800 | [diff] [blame] | 130 | GElf_Addr address_sync; |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | struct Dwfl_Module |
| 134 | { |
| 135 | Dwfl *dwfl; |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 136 | struct Dwfl_Module *next; /* Link on Dwfl.modulelist. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 137 | |
| 138 | void *userdata; |
| 139 | |
| 140 | char *name; /* Iterator name for this module. */ |
| 141 | GElf_Addr low_addr, high_addr; |
| 142 | |
| 143 | struct dwfl_file main, debug; |
Roland McGrath | 1743d7f | 2010-11-12 16:46:47 -0800 | [diff] [blame] | 144 | GElf_Addr main_bias; |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 145 | Ebl *ebl; |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 146 | GElf_Half e_type; /* GElf_Ehdr.e_type cache. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 147 | Dwfl_Error elferr; /* Previous failure to open main file. */ |
| 148 | |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 149 | struct dwfl_relocation *reloc_info; /* Relocatable sections. */ |
| 150 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 151 | struct dwfl_file *symfile; /* Either main or debug. */ |
| 152 | Elf_Data *symdata; /* Data in the ELF symbol table section. */ |
| 153 | size_t syments; /* sh_size / sh_entsize of that section. */ |
Mark Wielaard | ef431cd | 2011-10-31 23:17:06 +0100 | [diff] [blame] | 154 | int first_global; /* Index of first global symbol of table. */ |
Ulrich Drepper | e1812e1 | 2006-07-12 07:46:03 +0000 | [diff] [blame] | 155 | Elf_Data *symstrdata; /* Data for its string table. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 156 | Elf_Data *symxndxdata; /* Data in the extended section index table. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 157 | |
| 158 | Dwarf *dw; /* libdw handle for its debugging info. */ |
Roland McGrath | fe8b42e | 2009-07-08 14:54:16 -0700 | [diff] [blame] | 159 | |
| 160 | Dwfl_Error symerr; /* Previous failure to load symbols. */ |
| 161 | Dwfl_Error dwerr; /* Previous failure to load DWARF. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 162 | |
| 163 | /* Known CU's in this module. */ |
| 164 | struct dwfl_cu *first_cu, **cu; |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 165 | |
| 166 | void *lazy_cu_root; /* Table indexed by Dwarf_Off of CU. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 167 | |
| 168 | struct dwfl_arange *aranges; /* Mapping of addresses in module to CUs. */ |
Roland McGrath | fe8b42e | 2009-07-08 14:54:16 -0700 | [diff] [blame] | 169 | |
| 170 | void *build_id_bits; /* malloc'd copy of build ID bits. */ |
| 171 | GElf_Addr build_id_vaddr; /* Address where they reside, 0 if unknown. */ |
| 172 | int build_id_len; /* -1 for prior failure, 0 if unset. */ |
| 173 | |
| 174 | unsigned int ncu; |
| 175 | unsigned int lazycu; /* Possible users, deleted when none left. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 176 | unsigned int naranges; |
| 177 | |
Roland McGrath | 3c84db3 | 2009-06-24 17:41:40 -0700 | [diff] [blame] | 178 | Dwarf_CFI *dwarf_cfi; /* Cached DWARF CFI for this module. */ |
| 179 | Dwarf_CFI *eh_cfi; /* Cached EH CFI for this module. */ |
| 180 | |
Roland McGrath | b4d6f0f | 2008-08-25 22:55:17 +0000 | [diff] [blame] | 181 | int segment; /* Index of first segment table entry. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 182 | bool gc; /* Mark/sweep flag. */ |
| 183 | }; |
| 184 | |
| 185 | |
| 186 | |
| 187 | /* Information cached about each CU in Dwfl_Module.dw. */ |
| 188 | struct dwfl_cu |
| 189 | { |
| 190 | /* This caches libdw information about the CU. It's also the |
| 191 | address passed back to users, so we take advantage of the |
| 192 | fact that it's placed first to cast back. */ |
| 193 | Dwarf_Die die; |
| 194 | |
| 195 | Dwfl_Module *mod; /* Pointer back to containing module. */ |
| 196 | |
| 197 | struct dwfl_cu *next; /* CU immediately following in the file. */ |
| 198 | |
| 199 | struct Dwfl_Lines *lines; |
| 200 | }; |
| 201 | |
| 202 | struct Dwfl_Lines |
| 203 | { |
| 204 | struct dwfl_cu *cu; |
| 205 | |
| 206 | /* This is what the opaque Dwfl_Line * pointers we pass to users are. |
| 207 | We need to recover pointers to our struct dwfl_cu and a record in |
| 208 | libdw's Dwarf_Line table. To minimize the memory used in addition |
| 209 | to libdw's Dwarf_Lines buffer, we just point to our own index in |
| 210 | this table, and have one pointer back to the CU. The indices here |
| 211 | match those in libdw's Dwarf_CU.lines->info table. */ |
| 212 | struct Dwfl_Line |
| 213 | { |
| 214 | unsigned int idx; /* My index in the dwfl_cu.lines table. */ |
| 215 | } idx[0]; |
| 216 | }; |
| 217 | |
| 218 | static inline struct dwfl_cu * |
Ulrich Drepper | e1812e1 | 2006-07-12 07:46:03 +0000 | [diff] [blame] | 219 | dwfl_linecu_inline (const Dwfl_Line *line) |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 220 | { |
| 221 | const struct Dwfl_Lines *lines = ((const void *) line |
| 222 | - offsetof (struct Dwfl_Lines, |
| 223 | idx[line->idx])); |
| 224 | return lines->cu; |
| 225 | } |
Ulrich Drepper | e1812e1 | 2006-07-12 07:46:03 +0000 | [diff] [blame] | 226 | #define dwfl_linecu dwfl_linecu_inline |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 227 | |
Roland McGrath | 1743d7f | 2010-11-12 16:46:47 -0800 | [diff] [blame] | 228 | static inline GElf_Addr |
| 229 | dwfl_adjusted_address (Dwfl_Module *mod, GElf_Addr addr) |
| 230 | { |
| 231 | return addr + mod->main_bias; |
| 232 | } |
| 233 | |
| 234 | static inline GElf_Addr |
| 235 | dwfl_deadjust_address (Dwfl_Module *mod, GElf_Addr addr) |
| 236 | { |
| 237 | return addr - mod->main_bias; |
| 238 | } |
| 239 | |
| 240 | static inline Dwarf_Addr |
| 241 | dwfl_adjusted_dwarf_addr (Dwfl_Module *mod, Dwarf_Addr addr) |
| 242 | { |
| 243 | return dwfl_adjusted_address (mod, (addr |
| 244 | - mod->debug.address_sync |
| 245 | + mod->main.address_sync)); |
| 246 | } |
| 247 | |
| 248 | static inline Dwarf_Addr |
| 249 | dwfl_deadjust_dwarf_addr (Dwfl_Module *mod, Dwarf_Addr addr) |
| 250 | { |
| 251 | return (dwfl_deadjust_address (mod, addr) |
| 252 | - mod->main.address_sync |
| 253 | + mod->debug.address_sync); |
| 254 | } |
| 255 | |
| 256 | static inline GElf_Addr |
| 257 | dwfl_adjusted_st_value (Dwfl_Module *mod, GElf_Addr addr) |
| 258 | { |
| 259 | if (mod->symfile == &mod->main) |
| 260 | return dwfl_adjusted_address (mod, addr); |
| 261 | return dwfl_adjusted_dwarf_addr (mod, addr); |
| 262 | } |
| 263 | |
| 264 | static inline GElf_Addr |
| 265 | dwfl_deadjust_st_value (Dwfl_Module *mod, GElf_Addr addr) |
| 266 | { |
| 267 | if (mod->symfile == &mod->main) |
| 268 | return dwfl_deadjust_address (mod, addr); |
| 269 | return dwfl_deadjust_dwarf_addr (mod, addr); |
| 270 | } |
| 271 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 272 | /* This describes a contiguous address range that lies in a single CU. |
| 273 | We condense runs of Dwarf_Arange entries for the same CU into this. */ |
| 274 | struct dwfl_arange |
| 275 | { |
| 276 | struct dwfl_cu *cu; |
| 277 | size_t arange; /* Index in Dwarf_Aranges. */ |
| 278 | }; |
| 279 | |
| 280 | |
| 281 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 282 | extern void __libdwfl_module_free (Dwfl_Module *mod) internal_function; |
| 283 | |
Roland McGrath | a605a3c | 2009-04-19 18:27:01 -0700 | [diff] [blame] | 284 | /* Find the main ELF file, update MOD->elferr and/or MOD->main.elf. */ |
| 285 | extern void __libdwfl_getelf (Dwfl_Module *mod) internal_function; |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 286 | |
| 287 | /* Process relocations in debugging sections in an ET_REL file. |
Roland McGrath | e4c22ea | 2007-10-23 13:07:39 +0000 | [diff] [blame] | 288 | FILE must be opened with ELF_C_READ_MMAP_PRIVATE or ELF_C_READ, |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 289 | to make it possible to relocate the data in place (or ELF_C_RDWR or |
| 290 | ELF_C_RDWR_MMAP if you intend to modify the Elf file on disk). After |
Roland McGrath | e4c22ea | 2007-10-23 13:07:39 +0000 | [diff] [blame] | 291 | this, dwarf_begin_elf on FILE will read the relocated data. |
| 292 | |
| 293 | When DEBUG is false, apply partial relocation to all sections. */ |
| 294 | extern Dwfl_Error __libdwfl_relocate (Dwfl_Module *mod, Elf *file, bool debug) |
| 295 | internal_function; |
| 296 | |
| 297 | /* Process (simple) relocations in arbitrary section TSCN of an ET_REL file. |
| 298 | RELOCSCN is SHT_REL or SHT_RELA and TSCN is its sh_info target section. */ |
| 299 | extern Dwfl_Error __libdwfl_relocate_section (Dwfl_Module *mod, Elf *relocated, |
| 300 | Elf_Scn *relocscn, Elf_Scn *tscn, |
| 301 | bool partial) |
Roland McGrath | d2c5996 | 2005-08-10 22:13:57 +0000 | [diff] [blame] | 302 | internal_function; |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 303 | |
| 304 | /* Adjust *VALUE from section-relative to absolute. |
| 305 | MOD->dwfl->callbacks->section_address is called to determine the actual |
| 306 | address of a loaded section. */ |
Ulrich Drepper | b597dfa | 2007-10-16 05:21:27 +0000 | [diff] [blame] | 307 | extern Dwfl_Error __libdwfl_relocate_value (Dwfl_Module *mod, Elf *elf, |
| 308 | size_t *shstrndx_cache, |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 309 | Elf32_Word shndx, |
| 310 | GElf_Addr *value) |
| 311 | internal_function; |
| 312 | |
Roland McGrath | 994b489 | 2005-12-05 22:46:21 +0000 | [diff] [blame] | 313 | |
| 314 | /* Ensure that MOD->ebl is set up. */ |
| 315 | extern Dwfl_Error __libdwfl_module_getebl (Dwfl_Module *mod) internal_function; |
| 316 | |
Roland McGrath | 3c84db3 | 2009-06-24 17:41:40 -0700 | [diff] [blame] | 317 | /* Install a new Dwarf_CFI in *SLOT (MOD->eh_cfi or MOD->dwarf_cfi). */ |
| 318 | extern Dwarf_CFI *__libdwfl_set_cfi (Dwfl_Module *mod, Dwarf_CFI **slot, |
| 319 | Dwarf_CFI *cfi) |
| 320 | internal_function; |
| 321 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 322 | /* Iterate through all the CU's in the module. Start by passing a null |
| 323 | LASTCU, and then pass the last *CU returned. Success return with null |
| 324 | *CU no more CUs. */ |
| 325 | extern Dwfl_Error __libdwfl_nextcu (Dwfl_Module *mod, struct dwfl_cu *lastcu, |
| 326 | struct dwfl_cu **cu) internal_function; |
| 327 | |
| 328 | /* Find the CU by address. */ |
| 329 | extern Dwfl_Error __libdwfl_addrcu (Dwfl_Module *mod, Dwarf_Addr addr, |
| 330 | struct dwfl_cu **cu) internal_function; |
| 331 | |
| 332 | /* Ensure that CU->lines (and CU->cu->lines) is set up. */ |
| 333 | extern Dwfl_Error __libdwfl_cu_getsrclines (struct dwfl_cu *cu) |
Roland McGrath | 59ea7f3 | 2007-10-04 08:50:09 +0000 | [diff] [blame] | 334 | internal_function; |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 335 | |
Roland McGrath | 59ea7f3 | 2007-10-04 08:50:09 +0000 | [diff] [blame] | 336 | /* Look in ELF for an NT_GNU_BUILD_ID note. If SET is true, store it |
| 337 | in MOD and return its length. If SET is false, instead compare it |
| 338 | to that stored in MOD and return 2 if they match, 1 if they do not. |
| 339 | Returns -1 for errors, 0 if no note is found. */ |
| 340 | extern int __libdwfl_find_build_id (Dwfl_Module *mod, bool set, Elf *elf) |
| 341 | internal_function; |
| 342 | |
| 343 | /* Open a main or debuginfo file by its build ID, returns the fd. */ |
| 344 | extern int __libdwfl_open_by_build_id (Dwfl_Module *mod, bool debug, |
| 345 | char **file_name) internal_function; |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 346 | |
Ulrich Drepper | 18618fd | 2005-07-28 21:29:22 +0000 | [diff] [blame] | 347 | extern uint32_t __libdwfl_crc32 (uint32_t crc, unsigned char *buf, size_t len) |
Roland McGrath | 59ea7f3 | 2007-10-04 08:50:09 +0000 | [diff] [blame] | 348 | attribute_hidden; |
Ulrich Drepper | 18618fd | 2005-07-28 21:29:22 +0000 | [diff] [blame] | 349 | extern int __libdwfl_crc32_file (int fd, uint32_t *resp) attribute_hidden; |
| 350 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 351 | |
Ulrich Drepper | b597dfa | 2007-10-16 05:21:27 +0000 | [diff] [blame] | 352 | /* Meat of dwfl_report_elf, given elf_begin just called. |
| 353 | Consumes ELF on success, not on failure. */ |
| 354 | extern Dwfl_Module *__libdwfl_report_elf (Dwfl *dwfl, const char *name, |
| 355 | const char *file_name, int fd, |
Roland McGrath | 5453abf | 2009-02-10 17:33:49 -0800 | [diff] [blame] | 356 | Elf *elf, GElf_Addr base, bool sanity) |
Ulrich Drepper | b597dfa | 2007-10-16 05:21:27 +0000 | [diff] [blame] | 357 | internal_function; |
| 358 | |
| 359 | /* Meat of dwfl_report_offline. */ |
| 360 | extern Dwfl_Module *__libdwfl_report_offline (Dwfl *dwfl, const char *name, |
| 361 | const char *file_name, |
| 362 | int fd, bool closefd, |
| 363 | int (*predicate) (const char *, |
| 364 | const char *)) |
| 365 | internal_function; |
| 366 | |
Roland McGrath | bca4315 | 2009-01-05 23:59:32 -0800 | [diff] [blame] | 367 | /* Decompression wrappers: decompress whole file into memory. */ |
| 368 | extern Dwfl_Error __libdw_gunzip (int fd, off64_t start_offset, |
| 369 | void *mapped, size_t mapped_size, |
| 370 | void **whole, size_t *whole_size) |
| 371 | internal_function; |
Roland McGrath | 2416964 | 2009-08-26 02:26:34 -0700 | [diff] [blame] | 372 | extern Dwfl_Error __libdw_bunzip2 (int fd, off64_t start_offset, |
| 373 | void *mapped, size_t mapped_size, |
| 374 | void **whole, size_t *whole_size) |
| 375 | internal_function; |
| 376 | extern Dwfl_Error __libdw_unlzma (int fd, off64_t start_offset, |
| 377 | void *mapped, size_t mapped_size, |
| 378 | void **whole, size_t *whole_size) |
Roland McGrath | bca4315 | 2009-01-05 23:59:32 -0800 | [diff] [blame] | 379 | internal_function; |
| 380 | |
Roland McGrath | 6bb9071 | 2009-08-27 12:36:47 -0700 | [diff] [blame] | 381 | /* Skip the image header before a file image: updates *START_OFFSET. */ |
| 382 | extern Dwfl_Error __libdw_image_header (int fd, off64_t *start_offset, |
| 383 | void *mapped, size_t mapped_size) |
| 384 | internal_function; |
| 385 | |
Roland McGrath | bca4315 | 2009-01-05 23:59:32 -0800 | [diff] [blame] | 386 | /* Open Elf handle on *FDP. This handles decompression and checks |
| 387 | elf_kind. Succeed only for ELF_K_ELF, or also ELF_K_AR if ARCHIVE_OK. |
| 388 | Returns DWFL_E_NOERROR and sets *ELFP on success, resets *FDP to -1 if |
| 389 | it's no longer used. Resets *FDP on failure too iff CLOSE_ON_FAIL. */ |
| 390 | extern Dwfl_Error __libdw_open_file (int *fdp, Elf **elfp, |
| 391 | bool close_on_fail, bool archive_ok) |
| 392 | internal_function; |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 393 | |
Roland McGrath | b4d6f0f | 2008-08-25 22:55:17 +0000 | [diff] [blame] | 394 | /* These are working nicely for --core, but are not ready to be |
| 395 | exported interfaces quite yet. */ |
| 396 | |
| 397 | /* Type of callback function ... |
| 398 | */ |
| 399 | typedef bool Dwfl_Memory_Callback (Dwfl *dwfl, int segndx, |
| 400 | void **buffer, size_t *buffer_available, |
| 401 | GElf_Addr vaddr, size_t minread, void *arg); |
| 402 | |
| 403 | /* Type of callback function ... |
| 404 | */ |
| 405 | typedef bool Dwfl_Module_Callback (Dwfl_Module *mod, void **userdata, |
| 406 | const char *name, Dwarf_Addr base, |
| 407 | void **buffer, size_t *buffer_available, |
| 408 | GElf_Off cost, GElf_Off worthwhile, |
| 409 | GElf_Off whole, GElf_Off contiguous, |
| 410 | void *arg, Elf **elfp); |
| 411 | |
| 412 | /* ... |
| 413 | */ |
| 414 | extern int dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name, |
| 415 | Dwfl_Memory_Callback *memory_callback, |
| 416 | void *memory_callback_arg, |
| 417 | Dwfl_Module_Callback *read_eagerly, |
| 418 | void *read_eagerly_arg); |
| 419 | |
| 420 | /* Report a module for entry in the dynamic linker's struct link_map list. |
| 421 | For each link_map entry, if an existing module resides at its address, |
| 422 | this just modifies that module's name and suggested file name. If |
| 423 | no such module exists, this calls dwfl_report_elf on the l_name string. |
| 424 | |
| 425 | If AUXV is not null, it points to AUXV_SIZE bytes of auxiliary vector |
| 426 | data as contained in an NT_AUXV note or read from a /proc/pid/auxv |
| 427 | file. When this is available, it guides the search. If AUXV is null |
| 428 | or the memory it points to is not accessible, then this search can |
| 429 | only find where to begin if the correct executable file was |
| 430 | previously reported and preloaded as with dwfl_report_elf. |
| 431 | |
| 432 | Returns the number of modules found, or -1 for errors. */ |
| 433 | extern int dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size, |
| 434 | Dwfl_Memory_Callback *memory_callback, |
| 435 | void *memory_callback_arg); |
| 436 | |
Roland McGrath | bca4315 | 2009-01-05 23:59:32 -0800 | [diff] [blame] | 437 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 438 | /* Avoid PLT entries. */ |
| 439 | INTDECL (dwfl_begin) |
| 440 | INTDECL (dwfl_errmsg) |
Roland McGrath | ed431dd | 2010-05-06 00:52:51 -0700 | [diff] [blame] | 441 | INTDECL (dwfl_errno) |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 442 | INTDECL (dwfl_addrmodule) |
Roland McGrath | b4d6f0f | 2008-08-25 22:55:17 +0000 | [diff] [blame] | 443 | INTDECL (dwfl_addrsegment) |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 444 | INTDECL (dwfl_addrdwarf) |
| 445 | INTDECL (dwfl_addrdie) |
Roland McGrath | b4d6f0f | 2008-08-25 22:55:17 +0000 | [diff] [blame] | 446 | INTDECL (dwfl_core_file_report) |
| 447 | INTDECL (dwfl_getmodules) |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 448 | INTDECL (dwfl_module_addrdie) |
Roland McGrath | b4d6f0f | 2008-08-25 22:55:17 +0000 | [diff] [blame] | 449 | INTDECL (dwfl_module_address_section) |
Ulrich Drepper | 6258e74 | 2007-03-13 06:22:40 +0000 | [diff] [blame] | 450 | INTDECL (dwfl_module_addrsym) |
Roland McGrath | 59ea7f3 | 2007-10-04 08:50:09 +0000 | [diff] [blame] | 451 | INTDECL (dwfl_module_build_id) |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 452 | INTDECL (dwfl_module_getdwarf) |
| 453 | INTDECL (dwfl_module_getelf) |
Ulrich Drepper | e1812e1 | 2006-07-12 07:46:03 +0000 | [diff] [blame] | 454 | INTDECL (dwfl_module_getsym) |
| 455 | INTDECL (dwfl_module_getsymtab) |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 456 | INTDECL (dwfl_module_getsrc) |
Roland McGrath | 59ea7f3 | 2007-10-04 08:50:09 +0000 | [diff] [blame] | 457 | INTDECL (dwfl_module_report_build_id) |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 458 | INTDECL (dwfl_report_elf) |
| 459 | INTDECL (dwfl_report_begin) |
Ulrich Drepper | 6258e74 | 2007-03-13 06:22:40 +0000 | [diff] [blame] | 460 | INTDECL (dwfl_report_begin_add) |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 461 | INTDECL (dwfl_report_module) |
Roland McGrath | b4d6f0f | 2008-08-25 22:55:17 +0000 | [diff] [blame] | 462 | INTDECL (dwfl_report_segment) |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 463 | INTDECL (dwfl_report_offline) |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 464 | INTDECL (dwfl_report_end) |
Roland McGrath | 59ea7f3 | 2007-10-04 08:50:09 +0000 | [diff] [blame] | 465 | INTDECL (dwfl_build_id_find_elf) |
| 466 | INTDECL (dwfl_build_id_find_debuginfo) |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 467 | INTDECL (dwfl_standard_find_debuginfo) |
Roland McGrath | b4d6f0f | 2008-08-25 22:55:17 +0000 | [diff] [blame] | 468 | INTDECL (dwfl_link_map_report) |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 469 | INTDECL (dwfl_linux_kernel_find_elf) |
| 470 | INTDECL (dwfl_linux_kernel_module_section_address) |
| 471 | INTDECL (dwfl_linux_proc_report) |
Roland McGrath | 1656bc0 | 2005-12-23 01:49:50 +0000 | [diff] [blame] | 472 | INTDECL (dwfl_linux_proc_maps_report) |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 473 | INTDECL (dwfl_linux_proc_find_elf) |
| 474 | INTDECL (dwfl_linux_kernel_report_kernel) |
| 475 | INTDECL (dwfl_linux_kernel_report_modules) |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 476 | INTDECL (dwfl_linux_kernel_report_offline) |
| 477 | INTDECL (dwfl_offline_section_address) |
| 478 | INTDECL (dwfl_module_relocate_address) |
Roland McGrath | 3c84db3 | 2009-06-24 17:41:40 -0700 | [diff] [blame] | 479 | INTDECL (dwfl_module_dwarf_cfi) |
| 480 | INTDECL (dwfl_module_eh_cfi) |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 481 | |
| 482 | /* Leading arguments standard to callbacks passed a Dwfl_Module. */ |
| 483 | #define MODCB_ARGS(mod) (mod), &(mod)->userdata, (mod)->name, (mod)->low_addr |
| 484 | #define CBFAIL (errno ? DWFL_E (ERRNO, errno) : DWFL_E_CB); |
| 485 | |
| 486 | |
Roland McGrath | a1cee07 | 2006-08-15 01:37:23 +0000 | [diff] [blame] | 487 | /* The default used by dwfl_standard_find_debuginfo. */ |
| 488 | #define DEFAULT_DEBUGINFO_PATH ":.debug:/usr/lib/debug" |
| 489 | |
| 490 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 491 | #endif /* libdwflP.h */ |