libdwflP.h revision 744fc6f97f1c32fbab0f2a124bfa053e88fc3697
1b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Internal definitions for libdwfl. 2d5784afaf49cd59b9286e766cd9b1cf00cb43553Jan Kratochvil Copyright (C) 2005-2012 Red Hat, Inc. 3de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard This file is part of elfutils. 4b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 5de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard This file is free software; you can redistribute it and/or modify 6de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard it under the terms of either 7b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 8de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard * the GNU Lesser General Public License as published by the Free 9de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard Software Foundation; either version 3 of the License, or (at 10de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard your option) any later version 11de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard 12de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard or 13de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard 14de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard * the GNU General Public License as published by the Free 15de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard Software Foundation; either version 2 of the License, or (at 16de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard your option) any later version 17de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard 18de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard or both in parallel, as here. 19de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard 20de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard elfutils is distributed in the hope that it will be useful, but 21361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper WITHOUT ANY WARRANTY; without even the implied warranty of 22361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper General Public License for more details. 24361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper 25de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard You should have received copies of the GNU General Public License and 26de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard the GNU Lesser General Public License along with this program. If 27de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard not, see <http://www.gnu.org/licenses/>. */ 28b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 29b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#ifndef _LIBDWFLP_H 30b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define _LIBDWFLP_H 1 31b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 3255d34a5ac854be02fa10186182bc22685923c703Roland McGrath#ifndef PACKAGE_NAME 33b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper# include <config.h> 34b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#endif 35b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <libdwfl.h> 36b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <libebl.h> 37b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <assert.h> 38b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <errno.h> 39b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <stdbool.h> 40b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <stdlib.h> 41b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <string.h> 42b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 434959bf89d92b59ba72bea5786d7b3f9b5564f750Roland McGrath#include "../libdw/libdwP.h" /* We need its INTDECLs. */ 444959bf89d92b59ba72bea5786d7b3f9b5564f750Roland McGrath 45b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* gettext helper macros. */ 46b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define _(Str) dgettext ("elfutils", Str) 47b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 48b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define DWFL_ERRORS \ 49b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWFL_ERROR (NOERROR, N_("no error")) \ 50b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWFL_ERROR (UNKNOWN_ERROR, N_("unknown error")) \ 51b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWFL_ERROR (NOMEM, N_("out of memory")) \ 52b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWFL_ERROR (ERRNO, N_("See errno")) \ 53b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWFL_ERROR (LIBELF, N_("See elf_errno")) \ 54b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWFL_ERROR (LIBDW, N_("See dwarf_errno")) \ 55b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWFL_ERROR (LIBEBL, N_("See ebl_errno (XXX missing)")) \ 56bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath DWFL_ERROR (ZLIB, N_("gzip decompression failed")) \ 57bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath DWFL_ERROR (BZLIB, N_("bzip2 decompression failed")) \ 58241696467caa087278576291cb3b89693668df0bRoland McGrath DWFL_ERROR (LZMA, N_("LZMA decompression failed")) \ 5907d4f2fc1cb53f170a71bc13617bbdd9cb1c3c60Roland McGrath DWFL_ERROR (UNKNOWN_MACHINE, N_("no support library found for machine")) \ 60b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWFL_ERROR (NOREL, N_("Callbacks missing for ET_REL file")) \ 61b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWFL_ERROR (BADRELTYPE, N_("Unsupported relocation type")) \ 62b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWFL_ERROR (BADRELOFF, N_("r_offset is bogus")) \ 63b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWFL_ERROR (BADSTROFF, N_("offset out of range")) \ 64b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWFL_ERROR (RELUNDEF, N_("relocation refers to undefined symbol")) \ 65b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWFL_ERROR (CB, N_("Callback returned failure")) \ 66b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWFL_ERROR (NO_DWARF, N_("No DWARF information found")) \ 67b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWFL_ERROR (NO_SYMTAB, N_("No symbol table found")) \ 68b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWFL_ERROR (NO_PHDR, N_("No ELF program headers")) \ 69b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWFL_ERROR (OVERLAP, N_("address range overlaps an existing module")) \ 70b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWFL_ERROR (ADDR_OUTOFRANGE, N_("address out of range")) \ 71b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWFL_ERROR (NO_MATCH, N_("no matching address range")) \ 72b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWFL_ERROR (TRUNCATED, N_("image truncated")) \ 7359ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath DWFL_ERROR (ALREADY_ELF, N_("ELF file opened")) \ 74e47ab76f02c2a4f4d802ec298969ba67956435feRoland McGrath DWFL_ERROR (BADELF, N_("not a valid ELF file")) \ 75ed431ddb74331f24add8c6d932ebed129c4385d8Roland McGrath DWFL_ERROR (WEIRD_TYPE, N_("cannot handle DWARF type description")) \ 765ad466d544bdca479626d07d65288b2cc2638b4aRoland McGrath DWFL_ERROR (WRONG_ID_ELF, N_("ELF file does not match build ID")) \ 775ad466d544bdca479626d07d65288b2cc2638b4aRoland McGrath DWFL_ERROR (BAD_PRELINK, N_("corrupt .gnu.prelink_undo section data")) 78b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 79b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define DWFL_ERROR(name, text) DWFL_E_##name, 80b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppertypedef enum { DWFL_ERRORS DWFL_E_NUM } Dwfl_Error; 81b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#undef DWFL_ERROR 82b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 83b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define OTHER_ERROR(name) ((unsigned int) DWFL_E_##name << 16) 84b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define DWFL_E(name, errno) (OTHER_ERROR (name) | (errno)) 85b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 86d11f9cbecac4a5ac3848a68597028d1924f3ff6bRoland McGrathextern int __libdwfl_canon_error (Dwfl_Error) internal_function; 87d11f9cbecac4a5ac3848a68597028d1924f3ff6bRoland McGrathextern void __libdwfl_seterrno (Dwfl_Error) internal_function; 88b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 89b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct Dwfl 90b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 91b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper const Dwfl_Callbacks *callbacks; 92b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 93b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Dwfl_Module *modulelist; /* List in order used by full traversals. */ 94b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 95d17fac7e89666b47811581b10b5ca0d253a3a82dRoland McGrath GElf_Addr offline_next_address; 96b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath 97b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath GElf_Addr segment_align; /* Smallest granularity of segments. */ 98b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath 99b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath /* Binary search table in three parallel malloc'd arrays. */ 100b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath size_t lookup_elts; /* Elements in use. */ 101b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath size_t lookup_alloc; /* Elements allococated. */ 102b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath GElf_Addr *lookup_addr; /* Start address of segment. */ 103b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath Dwfl_Module **lookup_module; /* Module associated with segment, or null. */ 104b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath int *lookup_segndx; /* User segment index, or -1. */ 105b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath 106b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath /* Cache from last dwfl_report_segment call. */ 107b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath const void *lookup_tail_ident; 108b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath GElf_Off lookup_tail_vaddr; 109b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath GElf_Off lookup_tail_offset; 110b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath int lookup_tail_ndx; 111d5784afaf49cd59b9286e766cd9b1cf00cb43553Jan Kratochvil 112d5784afaf49cd59b9286e766cd9b1cf00cb43553Jan Kratochvil char *executable_for_core; /* --executable if --core was specified. */ 113b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper}; 114b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 115d17fac7e89666b47811581b10b5ca0d253a3a82dRoland McGrath#define OFFLINE_REDZONE 0x10000 116d17fac7e89666b47811581b10b5ca0d253a3a82dRoland McGrath 117b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct dwfl_file 118b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 119b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper char *name; 120b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper int fd; 12159ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath bool valid; /* The build ID note has been matched. */ 122e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath bool relocated; /* Partial relocation of all sections done. */ 123b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 124b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Elf *elf; 1251743d7f010bead5e869d097e23ce840583913381Roland McGrath 1261743d7f010bead5e869d097e23ce840583913381Roland McGrath /* This is the lowest p_vaddr in this ELF file, aligned to p_align. 1271743d7f010bead5e869d097e23ce840583913381Roland McGrath For a file without phdrs, this is zero. */ 1281743d7f010bead5e869d097e23ce840583913381Roland McGrath GElf_Addr vaddr; 1291743d7f010bead5e869d097e23ce840583913381Roland McGrath 1301743d7f010bead5e869d097e23ce840583913381Roland McGrath /* This is an address chosen for synchronization between the main file 1312c7d0ddfb8a08b8c450d0d3a5e297ec5d624661dRoland McGrath and the debug file. See dwfl_module_getdwarf.c for how it's chosen. */ 1321743d7f010bead5e869d097e23ce840583913381Roland McGrath GElf_Addr address_sync; 133b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper}; 134b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 135b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct Dwfl_Module 136b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 137b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Dwfl *dwfl; 138d17fac7e89666b47811581b10b5ca0d253a3a82dRoland McGrath struct Dwfl_Module *next; /* Link on Dwfl.modulelist. */ 139b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 140b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper void *userdata; 141b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 142b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper char *name; /* Iterator name for this module. */ 143b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper GElf_Addr low_addr, high_addr; 144b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1455083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard struct dwfl_file main, debug, aux_sym; 1461743d7f010bead5e869d097e23ce840583913381Roland McGrath GElf_Addr main_bias; 147b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Ebl *ebl; 148d17fac7e89666b47811581b10b5ca0d253a3a82dRoland McGrath GElf_Half e_type; /* GElf_Ehdr.e_type cache. */ 149b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Dwfl_Error elferr; /* Previous failure to open main file. */ 150b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 151d17fac7e89666b47811581b10b5ca0d253a3a82dRoland McGrath struct dwfl_relocation *reloc_info; /* Relocatable sections. */ 152d17fac7e89666b47811581b10b5ca0d253a3a82dRoland McGrath 153b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct dwfl_file *symfile; /* Either main or debug. */ 154b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Elf_Data *symdata; /* Data in the ELF symbol table section. */ 1555083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard Elf_Data *aux_symdata; /* Data in the auxiliary ELF symbol table. */ 156b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper size_t syments; /* sh_size / sh_entsize of that section. */ 1575083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard size_t aux_syments; /* sh_size / sh_entsize of aux_sym section. */ 158ef431cd30b8a1a6b12a8783516fc95da88a9a636Mark Wielaard int first_global; /* Index of first global symbol of table. */ 1595083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard int aux_first_global; /* Index of first global of aux_sym table. */ 160e1812e1d90090450e3d93be56a487e2f11affcedUlrich Drepper Elf_Data *symstrdata; /* Data for its string table. */ 1615083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard Elf_Data *aux_symstrdata; /* Data for aux_sym string table. */ 162b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Elf_Data *symxndxdata; /* Data in the extended section index table. */ 1635083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard Elf_Data *aux_symxndxdata; /* Data in the extended auxiliary table. */ 164b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 165b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Dwarf *dw; /* libdw handle for its debugging info. */ 166fe8b42e6131b74829fe31d15f31349cade566a59Roland McGrath 167fe8b42e6131b74829fe31d15f31349cade566a59Roland McGrath Dwfl_Error symerr; /* Previous failure to load symbols. */ 168fe8b42e6131b74829fe31d15f31349cade566a59Roland McGrath Dwfl_Error dwerr; /* Previous failure to load DWARF. */ 169b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 170b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Known CU's in this module. */ 171b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct dwfl_cu *first_cu, **cu; 172b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 173b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper void *lazy_cu_root; /* Table indexed by Dwarf_Off of CU. */ 174b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 175b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct dwfl_arange *aranges; /* Mapping of addresses in module to CUs. */ 176fe8b42e6131b74829fe31d15f31349cade566a59Roland McGrath 177fe8b42e6131b74829fe31d15f31349cade566a59Roland McGrath void *build_id_bits; /* malloc'd copy of build ID bits. */ 178fe8b42e6131b74829fe31d15f31349cade566a59Roland McGrath GElf_Addr build_id_vaddr; /* Address where they reside, 0 if unknown. */ 179fe8b42e6131b74829fe31d15f31349cade566a59Roland McGrath int build_id_len; /* -1 for prior failure, 0 if unset. */ 180fe8b42e6131b74829fe31d15f31349cade566a59Roland McGrath 181fe8b42e6131b74829fe31d15f31349cade566a59Roland McGrath unsigned int ncu; 182fe8b42e6131b74829fe31d15f31349cade566a59Roland McGrath unsigned int lazycu; /* Possible users, deleted when none left. */ 183b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned int naranges; 184b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1853c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath Dwarf_CFI *dwarf_cfi; /* Cached DWARF CFI for this module. */ 1863c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath Dwarf_CFI *eh_cfi; /* Cached EH CFI for this module. */ 1873c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath 188b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath int segment; /* Index of first segment table entry. */ 189b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper bool gc; /* Mark/sweep flag. */ 190b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper}; 191b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 192b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 193b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 194b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Information cached about each CU in Dwfl_Module.dw. */ 195b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct dwfl_cu 196b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 197b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* This caches libdw information about the CU. It's also the 198b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper address passed back to users, so we take advantage of the 199b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper fact that it's placed first to cast back. */ 200b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Dwarf_Die die; 201b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 202b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Dwfl_Module *mod; /* Pointer back to containing module. */ 203b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 204b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct dwfl_cu *next; /* CU immediately following in the file. */ 205b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 206b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct Dwfl_Lines *lines; 207b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper}; 208b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 209b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct Dwfl_Lines 210b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 211b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct dwfl_cu *cu; 212b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 213b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* This is what the opaque Dwfl_Line * pointers we pass to users are. 214b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper We need to recover pointers to our struct dwfl_cu and a record in 215b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper libdw's Dwarf_Line table. To minimize the memory used in addition 216b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper to libdw's Dwarf_Lines buffer, we just point to our own index in 217b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper this table, and have one pointer back to the CU. The indices here 218b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper match those in libdw's Dwarf_CU.lines->info table. */ 219b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct Dwfl_Line 220b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 221b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned int idx; /* My index in the dwfl_cu.lines table. */ 222b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } idx[0]; 223b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper}; 224b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 225b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic inline struct dwfl_cu * 226e1812e1d90090450e3d93be56a487e2f11affcedUlrich Drepperdwfl_linecu_inline (const Dwfl_Line *line) 227b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 228b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper const struct Dwfl_Lines *lines = ((const void *) line 229b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper - offsetof (struct Dwfl_Lines, 230b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper idx[line->idx])); 231b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper return lines->cu; 232b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 233e1812e1d90090450e3d93be56a487e2f11affcedUlrich Drepper#define dwfl_linecu dwfl_linecu_inline 234b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 2351743d7f010bead5e869d097e23ce840583913381Roland McGrathstatic inline GElf_Addr 2361743d7f010bead5e869d097e23ce840583913381Roland McGrathdwfl_adjusted_address (Dwfl_Module *mod, GElf_Addr addr) 2371743d7f010bead5e869d097e23ce840583913381Roland McGrath{ 2381743d7f010bead5e869d097e23ce840583913381Roland McGrath return addr + mod->main_bias; 2391743d7f010bead5e869d097e23ce840583913381Roland McGrath} 2401743d7f010bead5e869d097e23ce840583913381Roland McGrath 2411743d7f010bead5e869d097e23ce840583913381Roland McGrathstatic inline GElf_Addr 2421743d7f010bead5e869d097e23ce840583913381Roland McGrathdwfl_deadjust_address (Dwfl_Module *mod, GElf_Addr addr) 2431743d7f010bead5e869d097e23ce840583913381Roland McGrath{ 2441743d7f010bead5e869d097e23ce840583913381Roland McGrath return addr - mod->main_bias; 2451743d7f010bead5e869d097e23ce840583913381Roland McGrath} 2461743d7f010bead5e869d097e23ce840583913381Roland McGrath 2471743d7f010bead5e869d097e23ce840583913381Roland McGrathstatic inline Dwarf_Addr 2481743d7f010bead5e869d097e23ce840583913381Roland McGrathdwfl_adjusted_dwarf_addr (Dwfl_Module *mod, Dwarf_Addr addr) 2491743d7f010bead5e869d097e23ce840583913381Roland McGrath{ 2501743d7f010bead5e869d097e23ce840583913381Roland McGrath return dwfl_adjusted_address (mod, (addr 2511743d7f010bead5e869d097e23ce840583913381Roland McGrath - mod->debug.address_sync 2521743d7f010bead5e869d097e23ce840583913381Roland McGrath + mod->main.address_sync)); 2531743d7f010bead5e869d097e23ce840583913381Roland McGrath} 2541743d7f010bead5e869d097e23ce840583913381Roland McGrath 2551743d7f010bead5e869d097e23ce840583913381Roland McGrathstatic inline Dwarf_Addr 2561743d7f010bead5e869d097e23ce840583913381Roland McGrathdwfl_deadjust_dwarf_addr (Dwfl_Module *mod, Dwarf_Addr addr) 2571743d7f010bead5e869d097e23ce840583913381Roland McGrath{ 2581743d7f010bead5e869d097e23ce840583913381Roland McGrath return (dwfl_deadjust_address (mod, addr) 2591743d7f010bead5e869d097e23ce840583913381Roland McGrath - mod->main.address_sync 2601743d7f010bead5e869d097e23ce840583913381Roland McGrath + mod->debug.address_sync); 2611743d7f010bead5e869d097e23ce840583913381Roland McGrath} 2621743d7f010bead5e869d097e23ce840583913381Roland McGrath 2635083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaardstatic inline Dwarf_Addr 2645083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaarddwfl_adjusted_aux_sym_addr (Dwfl_Module *mod, Dwarf_Addr addr) 2655083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard{ 2665083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard return dwfl_adjusted_address (mod, (addr 2675083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard - mod->aux_sym.address_sync 2685083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard + mod->main.address_sync)); 2695083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard} 2705083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard 2715083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaardstatic inline Dwarf_Addr 2725083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaarddwfl_deadjust_aux_sym_addr (Dwfl_Module *mod, Dwarf_Addr addr) 2735083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard{ 2745083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard return (dwfl_deadjust_address (mod, addr) 2755083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard - mod->main.address_sync 2765083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard + mod->aux_sym.address_sync); 2775083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard} 2785083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard 2791743d7f010bead5e869d097e23ce840583913381Roland McGrathstatic inline GElf_Addr 2805083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaarddwfl_adjusted_st_value (Dwfl_Module *mod, struct dwfl_file *symfile, 2815083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard GElf_Addr addr) 2821743d7f010bead5e869d097e23ce840583913381Roland McGrath{ 2835083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard if (symfile == &mod->main) 2841743d7f010bead5e869d097e23ce840583913381Roland McGrath return dwfl_adjusted_address (mod, addr); 2855083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard if (symfile == &mod->debug) 2865083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard return dwfl_adjusted_dwarf_addr (mod, addr); 2875083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard return dwfl_adjusted_aux_sym_addr (mod, addr); 2881743d7f010bead5e869d097e23ce840583913381Roland McGrath} 2891743d7f010bead5e869d097e23ce840583913381Roland McGrath 2901743d7f010bead5e869d097e23ce840583913381Roland McGrathstatic inline GElf_Addr 2915083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaarddwfl_deadjust_st_value (Dwfl_Module *mod, struct dwfl_file *symfile, 2925083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard GElf_Addr addr) 2931743d7f010bead5e869d097e23ce840583913381Roland McGrath{ 2945083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard if (symfile == &mod->main) 2951743d7f010bead5e869d097e23ce840583913381Roland McGrath return dwfl_deadjust_address (mod, addr); 2965083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard if (symfile == &mod->debug) 2975083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard return dwfl_deadjust_dwarf_addr (mod, addr); 2985083a70d3b64946fa47ea5766943a15a3ecc6891Mark Wielaard return dwfl_deadjust_aux_sym_addr (mod, addr); 2991743d7f010bead5e869d097e23ce840583913381Roland McGrath} 3001743d7f010bead5e869d097e23ce840583913381Roland McGrath 301b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* This describes a contiguous address range that lies in a single CU. 302b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper We condense runs of Dwarf_Arange entries for the same CU into this. */ 303b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct dwfl_arange 304b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 305b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct dwfl_cu *cu; 306b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper size_t arange; /* Index in Dwarf_Aranges. */ 307b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper}; 308b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 309b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 310b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 311b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern void __libdwfl_module_free (Dwfl_Module *mod) internal_function; 312b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 313a605a3c8f354895f4cca56aca8f8aa468b506fdfRoland McGrath/* Find the main ELF file, update MOD->elferr and/or MOD->main.elf. */ 314a605a3c8f354895f4cca56aca8f8aa468b506fdfRoland McGrathextern void __libdwfl_getelf (Dwfl_Module *mod) internal_function; 315b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 316b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Process relocations in debugging sections in an ET_REL file. 317e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath FILE must be opened with ELF_C_READ_MMAP_PRIVATE or ELF_C_READ, 318b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper to make it possible to relocate the data in place (or ELF_C_RDWR or 319b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_C_RDWR_MMAP if you intend to modify the Elf file on disk). After 320e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath this, dwarf_begin_elf on FILE will read the relocated data. 321e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath 322e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath When DEBUG is false, apply partial relocation to all sections. */ 323e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrathextern Dwfl_Error __libdwfl_relocate (Dwfl_Module *mod, Elf *file, bool debug) 324e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath internal_function; 325e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath 326e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath/* Process (simple) relocations in arbitrary section TSCN of an ET_REL file. 327e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath RELOCSCN is SHT_REL or SHT_RELA and TSCN is its sh_info target section. */ 328e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrathextern Dwfl_Error __libdwfl_relocate_section (Dwfl_Module *mod, Elf *relocated, 329e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath Elf_Scn *relocscn, Elf_Scn *tscn, 330e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath bool partial) 331d2c5996f70844ae7816034b56e769ce163251718Roland McGrath internal_function; 332b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 333b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Adjust *VALUE from section-relative to absolute. 334b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper MOD->dwfl->callbacks->section_address is called to determine the actual 335b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper address of a loaded section. */ 336b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepperextern Dwfl_Error __libdwfl_relocate_value (Dwfl_Module *mod, Elf *elf, 337b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepper size_t *shstrndx_cache, 338b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Elf32_Word shndx, 339b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper GElf_Addr *value) 340b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper internal_function; 341b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 342994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath 343994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath/* Ensure that MOD->ebl is set up. */ 344994b4899278199fc4d307780dac0ea50b238bc74Roland McGrathextern Dwfl_Error __libdwfl_module_getebl (Dwfl_Module *mod) internal_function; 345994b4899278199fc4d307780dac0ea50b238bc74Roland McGrath 3463c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath/* Install a new Dwarf_CFI in *SLOT (MOD->eh_cfi or MOD->dwarf_cfi). */ 3473c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrathextern Dwarf_CFI *__libdwfl_set_cfi (Dwfl_Module *mod, Dwarf_CFI **slot, 3483c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath Dwarf_CFI *cfi) 3493c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath internal_function; 3503c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath 351b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Iterate through all the CU's in the module. Start by passing a null 352b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper LASTCU, and then pass the last *CU returned. Success return with null 353b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper *CU no more CUs. */ 354b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Dwfl_Error __libdwfl_nextcu (Dwfl_Module *mod, struct dwfl_cu *lastcu, 355b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct dwfl_cu **cu) internal_function; 356b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 357b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Find the CU by address. */ 358b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Dwfl_Error __libdwfl_addrcu (Dwfl_Module *mod, Dwarf_Addr addr, 359b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct dwfl_cu **cu) internal_function; 360b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 361b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Ensure that CU->lines (and CU->cu->lines) is set up. */ 362b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Dwfl_Error __libdwfl_cu_getsrclines (struct dwfl_cu *cu) 36359ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath internal_function; 36459ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath 3658ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil/* Look in ELF for an NT_GNU_BUILD_ID note. Store it to BUILD_ID_BITS, 3668ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil its vaddr in ELF to BUILD_ID_VADDR (it is unrelocated, even if MOD is not 3678ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil NULL) and store length to BUILD_ID_LEN. Returns -1 for errors, 1 if it was 3688ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil stored and 0 if no note is found. MOD may be NULL, MOD must be non-NULL 3698ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil only if ELF is ET_REL. */ 3708ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvilextern int __libdwfl_find_elf_build_id (Dwfl_Module *mod, Elf *elf, 3718ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil const void **build_id_bits, 3728ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil GElf_Addr *build_id_elfaddr, 3738af254a19665c3baf6074a36ba2618413b80d169Jan Kratochvil int *build_id_len) 3748af254a19665c3baf6074a36ba2618413b80d169Jan Kratochvil internal_function; 3758ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil 37659ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath/* Look in ELF for an NT_GNU_BUILD_ID note. If SET is true, store it 37759ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath in MOD and return its length. If SET is false, instead compare it 37859ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath to that stored in MOD and return 2 if they match, 1 if they do not. 37959ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath Returns -1 for errors, 0 if no note is found. */ 38059ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrathextern int __libdwfl_find_build_id (Dwfl_Module *mod, bool set, Elf *elf) 38159ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath internal_function; 382b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 38359ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath/* Open a main or debuginfo file by its build ID, returns the fd. */ 38459ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrathextern int __libdwfl_open_by_build_id (Dwfl_Module *mod, bool debug, 38559ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath char **file_name) internal_function; 386b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 38718618fd74777576cc20dce341bb71be327f9ed48Ulrich Drepperextern uint32_t __libdwfl_crc32 (uint32_t crc, unsigned char *buf, size_t len) 38859ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath attribute_hidden; 38918618fd74777576cc20dce341bb71be327f9ed48Ulrich Drepperextern int __libdwfl_crc32_file (int fd, uint32_t *resp) attribute_hidden; 39018618fd74777576cc20dce341bb71be327f9ed48Ulrich Drepper 391b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 392596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil/* Given ELF and some parameters return TRUE if the *P return value parameters 393596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil have been successfully filled in. Any of the *P parameters can be NULL. */ 394596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvilextern bool __libdwfl_elf_address_range (Elf *elf, GElf_Addr base, 395596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil bool add_p_vaddr, bool sanity, 396596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil GElf_Addr *vaddrp, 397596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil GElf_Addr *address_syncp, 398596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil GElf_Addr *startp, GElf_Addr *endp, 399744fc6f97f1c32fbab0f2a124bfa053e88fc3697Jan Kratochvil GElf_Addr *biasp, GElf_Half *e_typep) 400596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil internal_function; 401596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil 402b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepper/* Meat of dwfl_report_elf, given elf_begin just called. 403b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepper Consumes ELF on success, not on failure. */ 404b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepperextern Dwfl_Module *__libdwfl_report_elf (Dwfl *dwfl, const char *name, 405b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepper const char *file_name, int fd, 406904aec2c2f62b729a536c2259274fdd440b0d923Jan Kratochvil Elf *elf, GElf_Addr base, 407904aec2c2f62b729a536c2259274fdd440b0d923Jan Kratochvil bool add_p_vaddr, bool sanity) 408b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepper internal_function; 409b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepper 410b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepper/* Meat of dwfl_report_offline. */ 411b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepperextern Dwfl_Module *__libdwfl_report_offline (Dwfl *dwfl, const char *name, 412b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepper const char *file_name, 413b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepper int fd, bool closefd, 414b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepper int (*predicate) (const char *, 415b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepper const char *)) 416b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepper internal_function; 417b597dfad924980dede10d7c19d87900b6172e599Ulrich Drepper 418bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath/* Decompression wrappers: decompress whole file into memory. */ 419bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrathextern Dwfl_Error __libdw_gunzip (int fd, off64_t start_offset, 420bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath void *mapped, size_t mapped_size, 421bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath void **whole, size_t *whole_size) 422bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath internal_function; 423241696467caa087278576291cb3b89693668df0bRoland McGrathextern Dwfl_Error __libdw_bunzip2 (int fd, off64_t start_offset, 424241696467caa087278576291cb3b89693668df0bRoland McGrath void *mapped, size_t mapped_size, 425241696467caa087278576291cb3b89693668df0bRoland McGrath void **whole, size_t *whole_size) 426241696467caa087278576291cb3b89693668df0bRoland McGrath internal_function; 427241696467caa087278576291cb3b89693668df0bRoland McGrathextern Dwfl_Error __libdw_unlzma (int fd, off64_t start_offset, 428241696467caa087278576291cb3b89693668df0bRoland McGrath void *mapped, size_t mapped_size, 429241696467caa087278576291cb3b89693668df0bRoland McGrath void **whole, size_t *whole_size) 430bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath internal_function; 4316bb90710916169e242ce39b12831c5a22a57fcd4Roland McGrath 4326bb90710916169e242ce39b12831c5a22a57fcd4Roland McGrath/* Skip the image header before a file image: updates *START_OFFSET. */ 4336bb90710916169e242ce39b12831c5a22a57fcd4Roland McGrathextern Dwfl_Error __libdw_image_header (int fd, off64_t *start_offset, 4346bb90710916169e242ce39b12831c5a22a57fcd4Roland McGrath void *mapped, size_t mapped_size) 4356bb90710916169e242ce39b12831c5a22a57fcd4Roland McGrath internal_function; 436bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath 437bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath/* Open Elf handle on *FDP. This handles decompression and checks 438bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath elf_kind. Succeed only for ELF_K_ELF, or also ELF_K_AR if ARCHIVE_OK. 439bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath Returns DWFL_E_NOERROR and sets *ELFP on success, resets *FDP to -1 if 440bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath it's no longer used. Resets *FDP on failure too iff CLOSE_ON_FAIL. */ 441bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrathextern Dwfl_Error __libdw_open_file (int *fdp, Elf **elfp, 442bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath bool close_on_fail, bool archive_ok) 443bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath internal_function; 444b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 445b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath/* These are working nicely for --core, but are not ready to be 446b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath exported interfaces quite yet. */ 447b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath 448b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath/* Type of callback function ... 449b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath */ 450b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrathtypedef bool Dwfl_Memory_Callback (Dwfl *dwfl, int segndx, 451b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath void **buffer, size_t *buffer_available, 452b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath GElf_Addr vaddr, size_t minread, void *arg); 453b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath 454b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath/* Type of callback function ... 455b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath */ 456b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrathtypedef bool Dwfl_Module_Callback (Dwfl_Module *mod, void **userdata, 457b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath const char *name, Dwarf_Addr base, 458b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath void **buffer, size_t *buffer_available, 459b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath GElf_Off cost, GElf_Off worthwhile, 460b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath GElf_Off whole, GElf_Off contiguous, 461b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath void *arg, Elf **elfp); 462b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath 4638ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil/* One shared library (or executable) info from DT_DEBUG link map. */ 4648ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvilstruct r_debug_info_module 4658ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil{ 4668ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil struct r_debug_info_module *next; 467596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil /* FD is -1 iff ELF is NULL. */ 468596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil int fd; 469596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil Elf *elf; 470596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil GElf_Addr l_addr, l_ld; 471596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil /* START and END are both zero if not valid. */ 472596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil GElf_Addr start, end; 473596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil bool disk_file_has_build_id; 4748ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil char name[0]; 4758ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil}; 4768ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil 4778ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil/* Information gathered from DT_DEBUG by dwfl_link_map_report hinted to 4788ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil dwfl_segment_report_module. */ 4798ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvilstruct r_debug_info 4808ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil{ 4818ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil struct r_debug_info_module *module; 4828ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil}; 4838ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil 484b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath/* ... 485b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath */ 486b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrathextern int dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name, 487b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath Dwfl_Memory_Callback *memory_callback, 488b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath void *memory_callback_arg, 489b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath Dwfl_Module_Callback *read_eagerly, 4908ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil void *read_eagerly_arg, 4918ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil const struct r_debug_info *r_debug_info); 492b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath 493b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath/* Report a module for entry in the dynamic linker's struct link_map list. 494b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath For each link_map entry, if an existing module resides at its address, 495b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath this just modifies that module's name and suggested file name. If 496b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath no such module exists, this calls dwfl_report_elf on the l_name string. 497b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath 498b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath If AUXV is not null, it points to AUXV_SIZE bytes of auxiliary vector 499b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath data as contained in an NT_AUXV note or read from a /proc/pid/auxv 500b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath file. When this is available, it guides the search. If AUXV is null 501b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath or the memory it points to is not accessible, then this search can 502b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath only find where to begin if the correct executable file was 503b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath previously reported and preloaded as with dwfl_report_elf. 504b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath 5058ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil Fill in R_DEBUG_INFO if it is not NULL. It should be cleared by the 5068ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil caller, this function does not touch fields it does not need to modify. 507596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil If R_DEBUG_INFO is not NULL then no modules get added to DWFL, caller 508596d430f23f85f3cd019bd0ac560ecd5371fc7e0Jan Kratochvil has to add them from filled in R_DEBUG_INFO. 5098ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil 510b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath Returns the number of modules found, or -1 for errors. */ 511b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrathextern int dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size, 512b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath Dwfl_Memory_Callback *memory_callback, 5138ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil void *memory_callback_arg, 5148ff862960efb648cdff647d7fad1be5acffe9b11Jan Kratochvil struct r_debug_info *r_debug_info); 515b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrath 516bca43152aa0bcb31b9442c407bf2b86379761c50Roland McGrath 517b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Avoid PLT entries. */ 518b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_begin) 519b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_errmsg) 520ed431ddb74331f24add8c6d932ebed129c4385d8Roland McGrathINTDECL (dwfl_errno) 521b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_addrmodule) 522b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrathINTDECL (dwfl_addrsegment) 523b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_addrdwarf) 524b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_addrdie) 525b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrathINTDECL (dwfl_core_file_report) 526b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrathINTDECL (dwfl_getmodules) 527b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_module_addrdie) 528b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrathINTDECL (dwfl_module_address_section) 5296258e7486eb3eed6e50005946795c5fbf73aa106Ulrich DrepperINTDECL (dwfl_module_addrsym) 53059ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrathINTDECL (dwfl_module_build_id) 531b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_module_getdwarf) 532b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_module_getelf) 533e1812e1d90090450e3d93be56a487e2f11affcedUlrich DrepperINTDECL (dwfl_module_getsym) 534e1812e1d90090450e3d93be56a487e2f11affcedUlrich DrepperINTDECL (dwfl_module_getsymtab) 535b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_module_getsrc) 53659ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrathINTDECL (dwfl_module_report_build_id) 537b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_report_elf) 538b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_report_begin) 5396258e7486eb3eed6e50005946795c5fbf73aa106Ulrich DrepperINTDECL (dwfl_report_begin_add) 540b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_report_module) 541b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrathINTDECL (dwfl_report_segment) 542d17fac7e89666b47811581b10b5ca0d253a3a82dRoland McGrathINTDECL (dwfl_report_offline) 543b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_report_end) 54459ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrathINTDECL (dwfl_build_id_find_elf) 54559ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrathINTDECL (dwfl_build_id_find_debuginfo) 546b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_standard_find_debuginfo) 547b4d6f0f8064f2b706ea9035ef0393d8299671390Roland McGrathINTDECL (dwfl_link_map_report) 548b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_linux_kernel_find_elf) 549b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_linux_kernel_module_section_address) 550b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_linux_proc_report) 5511656bc00ae97fa16a941a8cefacc4e01488d0e8aRoland McGrathINTDECL (dwfl_linux_proc_maps_report) 552b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_linux_proc_find_elf) 553b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_linux_kernel_report_kernel) 554b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwfl_linux_kernel_report_modules) 555d17fac7e89666b47811581b10b5ca0d253a3a82dRoland McGrathINTDECL (dwfl_linux_kernel_report_offline) 556d17fac7e89666b47811581b10b5ca0d253a3a82dRoland McGrathINTDECL (dwfl_offline_section_address) 557d17fac7e89666b47811581b10b5ca0d253a3a82dRoland McGrathINTDECL (dwfl_module_relocate_address) 5583c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrathINTDECL (dwfl_module_dwarf_cfi) 5593c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrathINTDECL (dwfl_module_eh_cfi) 560b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 561b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Leading arguments standard to callbacks passed a Dwfl_Module. */ 562b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define MODCB_ARGS(mod) (mod), &(mod)->userdata, (mod)->name, (mod)->low_addr 563b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define CBFAIL (errno ? DWFL_E (ERRNO, errno) : DWFL_E_CB); 564b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 565b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 566a1cee0760dceaeca52aff9498b144978537d5a16Roland McGrath/* The default used by dwfl_standard_find_debuginfo. */ 567a1cee0760dceaeca52aff9498b144978537d5a16Roland McGrath#define DEFAULT_DEBUGINFO_PATH ":.debug:/usr/lib/debug" 568a1cee0760dceaeca52aff9498b144978537d5a16Roland McGrath 569a1cee0760dceaeca52aff9498b144978537d5a16Roland McGrath 570b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#endif /* libdwflP.h */ 571