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