1b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Internal definitions for libdwarf. 2daf278fda6d9bd329b517757f9ba2d74619f3be7Mark Wielaard Copyright (C) 2002-2011, 2013-2015 Red Hat, Inc. 3de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard This file is part of elfutils. 4b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Written by Ulrich Drepper <drepper@redhat.com>, 2002. 5b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 6de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard This file is free software; you can redistribute it and/or modify 7de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard it under the terms of either 8b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 9de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard * the GNU Lesser General Public License as published by the Free 10de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard Software Foundation; either version 3 of the License, or (at 11de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard your option) any later version 12de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard 13de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard or 14de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard 15de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard * the GNU General Public License as published by the Free 16de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard Software Foundation; either version 2 of the License, or (at 17de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard your option) any later version 18de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard 19de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard or both in parallel, as here. 20de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard 21de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard elfutils is distributed in the hope that it will be useful, but 22361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper WITHOUT ANY WARRANTY; without even the implied warranty of 23361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper General Public License for more details. 25361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper 26de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard You should have received copies of the GNU General Public License and 27de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard the GNU Lesser General Public License along with this program. If 28de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard not, see <http://www.gnu.org/licenses/>. */ 29b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 30b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#ifndef _LIBDWP_H 31b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define _LIBDWP_H 1 32b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 33b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <libintl.h> 34b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <stdbool.h> 35b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 36b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <libdw.h> 37c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone#include <dwarf.h> 38b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 39b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 40b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* gettext helper macros. */ 41b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define _(Str) dgettext ("elfutils", Str) 42b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 43b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 446724c90d02659f7466b67b357563042e403d154eRoland McGrath/* Known location expressions already decoded. */ 45b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct loc_s 46b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 47b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper void *addr; 486724c90d02659f7466b67b357563042e403d154eRoland McGrath Dwarf_Op *loc; 49b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper size_t nloc; 50b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper}; 51b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 52f0371041995308d197447019eb2ac9285c96477bRoland McGrath/* Known DW_OP_implicit_value blocks already decoded. 53f0371041995308d197447019eb2ac9285c96477bRoland McGrath This overlaps struct loc_s exactly, but only the 54f0371041995308d197447019eb2ac9285c96477bRoland McGrath first member really has to match. */ 55f0371041995308d197447019eb2ac9285c96477bRoland McGrathstruct loc_block_s 56f0371041995308d197447019eb2ac9285c96477bRoland McGrath{ 57f0371041995308d197447019eb2ac9285c96477bRoland McGrath void *addr; 58f0371041995308d197447019eb2ac9285c96477bRoland McGrath unsigned char *data; 59f0371041995308d197447019eb2ac9285c96477bRoland McGrath size_t length; 60f0371041995308d197447019eb2ac9285c96477bRoland McGrath}; 61f0371041995308d197447019eb2ac9285c96477bRoland McGrath 62fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata/* Already decoded .debug_line units. */ 63fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machatastruct files_lines_s 64fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata{ 65fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata Dwarf_Off debug_line_offset; 66fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata Dwarf_Files *files; 67fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata Dwarf_Lines *lines; 68fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata}; 69fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata 70b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Valid indeces for the section data. */ 71b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperenum 72b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 73b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper IDX_debug_info = 0, 74827d4d176b989c5d765c7f349edff6f994f8ea78Roland McGrath IDX_debug_types, 75b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper IDX_debug_abbrev, 76b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper IDX_debug_aranges, 77b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper IDX_debug_line, 78b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper IDX_debug_frame, 79b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper IDX_debug_loc, 80b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper IDX_debug_pubnames, 81b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper IDX_debug_str, 82b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper IDX_debug_macinfo, 83a0172d75311f36adb6db58000474d31f8a9cd553Mark Wielaard IDX_debug_macro, 84b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper IDX_debug_ranges, 85efa72a02de8a3bbbc43c8de659697df5d425ea7eFlorian Weimer IDX_gnu_debugaltlink, 86b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper IDX_last 87b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper }; 88b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 89b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 90b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Error values. */ 91b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperenum 92b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 93b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_NOERROR = 0, 94b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_UNKNOWN_ERROR, 95b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_INVALID_ACCESS, 96b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_NO_REGFILE, 97b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_IO_ERROR, 98b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_INVALID_ELF, 99b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_NO_DWARF, 100987e3d722d1d3879c51f4ed7ab1da03a75f5f38cJonathan Lebon DWARF_E_COMPRESSED_ERROR, 101b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_NOELF, 102b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_GETEHDR_ERROR, 103b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_NOMEM, 104b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_UNIMPL, 105b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_INVALID_CMD, 106b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_INVALID_VERSION, 107b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_INVALID_FILE, 108b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_NO_ENTRY, 109b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_INVALID_DWARF, 110b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_NO_STRING, 111b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_NO_ADDR, 112b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_NO_CONSTANT, 113b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_NO_REFERENCE, 114b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_INVALID_REFERENCE, 115b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_NO_DEBUG_LINE, 116b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_INVALID_DEBUG_LINE, 117b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_TOO_BIG, 118b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_VERSION, 119b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_INVALID_DIR_IDX, 120b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_ADDR_OUTOFRANGE, 121b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_NO_LOCLIST, 122b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_NO_BLOCK, 123b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_INVALID_LINE_IDX, 124b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_INVALID_ARANGE_IDX, 125b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_NO_MATCH, 126b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_NO_FLAG, 127b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_INVALID_OFFSET, 128b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DWARF_E_NO_DEBUG_RANGES, 1293c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath DWARF_E_INVALID_CFI, 130fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata DWARF_E_NO_ALT_DEBUGLINK, 131fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata DWARF_E_INVALID_OPCODE, 13271de1d2a8a3fffc83c707642a24f350d7217f83cPetr Machata DWARF_E_NOT_CUDIE, 133b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper}; 134b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 135b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1363e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath#include "dwarf_sig8_hash.h" 1373e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath 138b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* This is the structure representing the debugging state. */ 139b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct Dwarf 140b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 141b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* The underlying ELF file. */ 142b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Elf *elf; 143b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 144775375e3bd177cb19acb5020b6e0917551807276Mark Wielaard /* dwz alternate DWARF file. */ 145775375e3bd177cb19acb5020b6e0917551807276Mark Wielaard Dwarf *alt_dwarf; 146775375e3bd177cb19acb5020b6e0917551807276Mark Wielaard 147b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* The section data. */ 148b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Elf_Data *sectiondata[IDX_last]; 149b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 150b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* True if the file has a byte order different from the host. */ 151b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper bool other_byte_order; 152b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 153b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* If true, we allocated the ELF descriptor ourselves. */ 154b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper bool free_elf; 155b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 156b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Information for traversing the .debug_pubnames section. This is 157b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper an array and separately allocated with malloc. */ 158b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct pubnames_s 159b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 160b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Dwarf_Off cu_offset; 161b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Dwarf_Off set_start; 162b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned int cu_header_size; 163b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper int address_len; 164b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } *pubnames_sets; 165b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper size_t pubnames_nsets; 166b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 167b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Search tree for the CUs. */ 168b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper void *cu_tree; 169b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Dwarf_Off next_cu_offset; 170b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1712b1f09548b66c2c75d5be6f13cd9374adc95f8d8Roland McGrath /* Search tree and sig8 hash table for .debug_types type units. */ 1722b1f09548b66c2c75d5be6f13cd9374adc95f8d8Roland McGrath void *tu_tree; 1733e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath Dwarf_Off next_tu_offset; 1742b1f09548b66c2c75d5be6f13cd9374adc95f8d8Roland McGrath Dwarf_Sig8_Hash sig8_hash; 1753e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath 176fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata /* Search tree for .debug_macro operator tables. */ 177fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata void *macro_ops; 178fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata 179fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata /* Search tree for decoded .debug_line units. */ 180fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata void *files_lines; 181fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata 182b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Address ranges. */ 183b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Dwarf_Aranges *aranges; 184b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1853c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath /* Cached info from the CFI section. */ 1863c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath struct Dwarf_CFI_s *cfi; 1873c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath 1889202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaard /* Fake loc CU. Used when synthesizing attributes for Dwarf_Ops that 1899202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaard came from a location list entry in dwarf_getlocation_attr. */ 1909202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaard struct Dwarf_CU *fake_loc_cu; 1919202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaard 192b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Internal memory handling. This is basically a simplified 193b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper reimplementation of obstacks. Unfortunately the standard obstack 194b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper implementation is not usable in libraries. */ 195b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct libdw_memblock 196b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 197b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper size_t size; 198b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper size_t remaining; 199b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct libdw_memblock *prev; 200b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper char mem[0]; 201b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } *mem_tail; 202b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 203b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Default size of allocated memory blocks. */ 204b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper size_t mem_default_size; 205b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 206b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Registered OOM handler. */ 207b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Dwarf_OOM oom_handler; 208b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper}; 209b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 210b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 211b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Abbreviation representation. */ 212b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct Dwarf_Abbrev 213b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 2141f6d2010bb26b6bf5395a98651fce9a1a9141ac3Roland McGrath Dwarf_Off offset; 2151f6d2010bb26b6bf5395a98651fce9a1a9141ac3Roland McGrath unsigned char *attrp; 2161f6d2010bb26b6bf5395a98651fce9a1a9141ac3Roland McGrath unsigned int attrcnt; 217b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned int code; 218b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned int tag; 2191f6d2010bb26b6bf5395a98651fce9a1a9141ac3Roland McGrath bool has_children; 220b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper}; 221b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 222b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include "dwarf_abbrev_hash.h" 223b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 224b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 225b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Files in line information records. */ 226b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct Dwarf_Files_s 227b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 22843da9895c6d828ceae65a47f2337e8ef24eb97c1Roland McGrath unsigned int ndirs; 229b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned int nfiles; 230b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct Dwarf_Fileinfo_s 231b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 232b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper char *name; 233b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Dwarf_Word mtime; 234b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Dwarf_Word length; 235b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } info[0]; 23643da9895c6d828ceae65a47f2337e8ef24eb97c1Roland McGrath /* nfiles of those, followed by char *[ndirs]. */ 237b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper }; 238b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppertypedef struct Dwarf_Fileinfo_s Dwarf_Fileinfo; 239b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 240b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 241b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Representation of a row in the line table. */ 242b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 24303288f0df65115b75cf029825ecc9cf9158870a4Roland McGrathstruct Dwarf_Line_s 24403288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath{ 2456e1f4658619e0a6bdbf64d7678b82f4e97645633Roland McGrath Dwarf_Files *files; 2466e1f4658619e0a6bdbf64d7678b82f4e97645633Roland McGrath 24703288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath Dwarf_Addr addr; 24803288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath unsigned int file; 24903288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath int line; 25003288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath unsigned short int column; 25103288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath unsigned int is_stmt:1; 25203288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath unsigned int basic_block:1; 25303288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath unsigned int end_sequence:1; 25403288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath unsigned int prologue_end:1; 25503288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath unsigned int epilogue_begin:1; 256c70cf4e5e5a463b64673c4e80bcf60c938b437b4Roland McGrath /* The remaining bit fields are not flags, but hold values presumed to be 257c70cf4e5e5a463b64673c4e80bcf60c938b437b4Roland McGrath small. All the flags and other bit fields should add up to 48 bits 258c70cf4e5e5a463b64673c4e80bcf60c938b437b4Roland McGrath to give the whole struct a nice round size. */ 259c70cf4e5e5a463b64673c4e80bcf60c938b437b4Roland McGrath unsigned int op_index:8; 260c70cf4e5e5a463b64673c4e80bcf60c938b437b4Roland McGrath unsigned int isa:8; 261c70cf4e5e5a463b64673c4e80bcf60c938b437b4Roland McGrath unsigned int discriminator:24; 26203288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath}; 26303288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath 26403288f0df65115b75cf029825ecc9cf9158870a4Roland McGrathstruct Dwarf_Lines_s 26503288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath{ 26603288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath size_t nlines; 26703288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath struct Dwarf_Line_s info[0]; 26803288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath}; 269b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 270b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Representation of address ranges. */ 271b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct Dwarf_Aranges_s 272b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 273b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Dwarf *dbg; 274b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper size_t naranges; 275b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 276b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct Dwarf_Arange_s 277b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 278b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Dwarf_Addr addr; 279b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Dwarf_Word length; 280b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Dwarf_Off offset; 281b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } info[0]; 282b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper}; 283b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 284b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 285b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* CU representation. */ 286b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct Dwarf_CU 287b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 288b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Dwarf *dbg; 289b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Dwarf_Off start; 290b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Dwarf_Off end; 291b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper uint8_t address_size; 292b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper uint8_t offset_size; 293e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath uint16_t version; 294b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 2953e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath /* Zero if this is a normal CU. Nonzero if it is a type unit. */ 2963e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath size_t type_offset; 2973e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath uint64_t type_sig8; 2983e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath 299b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Hash table for the abbreviations. */ 300b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Dwarf_Abbrev_Hash abbrev_hash; 301b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Offset of the first abbreviation. */ 302b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper size_t orig_abbrev_offset; 303b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Offset past last read abbreviation. */ 304b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper size_t last_abbrev_offset; 305b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 306b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* The srcline information. */ 307b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Dwarf_Lines *lines; 308b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 309b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* The source file information. */ 310b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Dwarf_Files *files; 311b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 312b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Known location lists. */ 313b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper void *locs; 3148d200b5b728b7ee6150796e4baa07b54e1ac8cd2Josh Stone 3158d200b5b728b7ee6150796e4baa07b54e1ac8cd2Josh Stone /* Memory boundaries of this CU. */ 3168d200b5b728b7ee6150796e4baa07b54e1ac8cd2Josh Stone void *startp; 3178d200b5b728b7ee6150796e4baa07b54e1ac8cd2Josh Stone void *endp; 318b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper}; 319b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 32035f08c4d52d0ffd9f8aa50f47b84de5603842b1fUlrich Drepper/* Compute the offset of a CU's first DIE from its offset. This 32135f08c4d52d0ffd9f8aa50f47b84de5603842b1fUlrich Drepper is either: 32235f08c4d52d0ffd9f8aa50f47b84de5603842b1fUlrich Drepper LEN VER OFFSET ADDR 32335f08c4d52d0ffd9f8aa50f47b84de5603842b1fUlrich Drepper 4-bytes + 2-bytes + 4-bytes + 1-byte for 32-bit dwarf 32435f08c4d52d0ffd9f8aa50f47b84de5603842b1fUlrich Drepper 12-bytes + 2-bytes + 8-bytes + 1-byte for 64-bit dwarf 3253e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath or in .debug_types, SIGNATURE TYPE-OFFSET 3263e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath 4-bytes + 2-bytes + 4-bytes + 1-byte + 8-bytes + 4-bytes for 32-bit 3273e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath 12-bytes + 2-bytes + 8-bytes + 1-byte + 8-bytes + 8-bytes for 64-bit 328a969d8e19470157be1b8b2e1a693ac7702bf4273Ulrich Drepper 32935f08c4d52d0ffd9f8aa50f47b84de5603842b1fUlrich Drepper Note the trick in the computation. If the offset_size is 4 33035f08c4d52d0ffd9f8aa50f47b84de5603842b1fUlrich Drepper the '- 4' term changes the '3 *' into a '2 *'. If the 33135f08c4d52d0ffd9f8aa50f47b84de5603842b1fUlrich Drepper offset_size is 8 it accounts for the 4-byte escape value 33235f08c4d52d0ffd9f8aa50f47b84de5603842b1fUlrich Drepper used at the start of the length. */ 3333e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath#define DIE_OFFSET_FROM_CU_OFFSET(cu_offset, offset_size, type_unit) \ 3343e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath ((type_unit) ? ((cu_offset) + 4 * (offset_size) - 4 + 3 + 8) \ 3353e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath : ((cu_offset) + 3 * (offset_size) - 4 + 3)) 33635f08c4d52d0ffd9f8aa50f47b84de5603842b1fUlrich Drepper 3373e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath#define CUDIE(fromcu) \ 3386724c90d02659f7466b67b357563042e403d154eRoland McGrath ((Dwarf_Die) \ 3396724c90d02659f7466b67b357563042e403d154eRoland McGrath { \ 3406724c90d02659f7466b67b357563042e403d154eRoland McGrath .cu = (fromcu), \ 3419202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaard .addr = ((char *) fromcu->dbg->sectiondata[cu_sec_idx (fromcu)]->d_buf \ 3423e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath + DIE_OFFSET_FROM_CU_OFFSET ((fromcu)->start, \ 3433e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath (fromcu)->offset_size, \ 3443e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath (fromcu)->type_offset != 0)) \ 3453e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath }) \ 346b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 347b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 348fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata/* Prototype of a single .debug_macro operator. */ 349fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machatatypedef struct 350fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata{ 351fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata Dwarf_Word nforms; 352fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata unsigned char const *forms; 353fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata} Dwarf_Macro_Op_Proto; 354fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata 355fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata/* Prototype table. */ 356fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machatatypedef struct 357fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata{ 358fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata /* Offset of .debug_macro section. */ 359fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata Dwarf_Off offset; 360fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata 361fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata /* Offset of associated .debug_line section. */ 362fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata Dwarf_Off line_offset; 363fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata 364fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata /* The source file information. */ 365fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata Dwarf_Files *files; 366fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata 367fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata /* If this macro unit was opened through dwarf_getmacros or 368fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata dwarf_getmacros_die, this caches value of DW_AT_comp_dir, if 369fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata present. */ 370fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata const char *comp_dir; 371fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata 372fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata /* Header length. */ 373fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata Dwarf_Half header_len; 374fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata 375fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata uint16_t version; 376fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata bool is_64bit; 377fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata uint8_t sec_index; /* IDX_debug_macro or IDX_debug_macinfo. */ 378fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata 379fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata /* Shows where in TABLE each opcode is defined. Since opcode 0 is 380fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata never used, it stores index of opcode X in X-1'th element. The 381fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata value of 0xff means not stored at all. */ 382fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata unsigned char opcodes[255]; 383fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata 384fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata /* Individual opcode prototypes. */ 385fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata Dwarf_Macro_Op_Proto table[]; 386fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata} Dwarf_Macro_Op_Table; 387fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata 388b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct Dwarf_Macro_s 389b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 390fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata Dwarf_Macro_Op_Table *table; 391fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata Dwarf_Attribute *attributes; 392fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata uint8_t opcode; 393b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper}; 394b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 395fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machatastatic inline Dwarf_Word 396fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machatalibdw_macro_nforms (Dwarf_Macro *macro) 397fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata{ 398fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata return macro->table->table[macro->table->opcodes[macro->opcode - 1]].nforms; 399fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata} 400b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 401b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* We have to include the file at this point because the inline 402b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper functions access internals of the Dwarf structure. */ 403b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include "memory-access.h" 404b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 405b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 406b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Set error value. */ 407b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern void __libdw_seterrno (int value) internal_function; 408b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 409b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 410b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Memory handling, the easy parts. This macro does not do any locking. */ 411db1d54386fc38a30eff030517cbbfedf758fa32aUlrich Drepper#define libdw_alloc(dbg, type, tsize, cnt) \ 412b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ({ struct libdw_memblock *_tail = (dbg)->mem_tail; \ 413b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper size_t _required = (tsize) * (cnt); \ 414b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper type *_result = (type *) (_tail->mem + (_tail->size - _tail->remaining));\ 415b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper size_t _padding = ((__alignof (type) \ 416b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper - ((uintptr_t) _result & (__alignof (type) - 1))) \ 417b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper & (__alignof (type) - 1)); \ 418b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (unlikely (_tail->remaining < _required + _padding)) \ 419c373d850ec9ca342f4c71d5e287c8d8bf0723cd6Roland McGrath _result = (type *) __libdw_allocate (dbg, _required, __alignof (type));\ 420b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else \ 421b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { \ 422b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper _required += _padding; \ 423b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper _result = (type *) ((char *) _result + _padding); \ 424c373d850ec9ca342f4c71d5e287c8d8bf0723cd6Roland McGrath _tail->remaining -= _required; \ 425b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } \ 426b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper _result; }) 427b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 428b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define libdw_typed_alloc(dbg, type) \ 429b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper libdw_alloc (dbg, type, sizeof (type), 1) 430b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 431b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Callback to allocate more. */ 432c373d850ec9ca342f4c71d5e287c8d8bf0723cd6Roland McGrathextern void *__libdw_allocate (Dwarf *dbg, size_t minsize, size_t align) 433b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper __attribute__ ((__malloc__)) __nonnull_attribute__ (1); 434b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 435b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Default OOM handler. */ 436b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern void __libdw_oom (void) __attribute ((noreturn, visibility ("hidden"))); 437b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 4383e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath/* Allocate the internal data for a unit not seen before. */ 4393e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrathextern struct Dwarf_CU *__libdw_intern_next_unit (Dwarf *dbg, bool debug_types) 4403e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath __nonnull_attribute__ (1) internal_function; 4413e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath 442b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Find CU for given offset. */ 4432b1f09548b66c2c75d5be6f13cd9374adc95f8d8Roland McGrathextern struct Dwarf_CU *__libdw_findcu (Dwarf *dbg, Dwarf_Off offset, bool tu) 444b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper __nonnull_attribute__ (1) internal_function; 445b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 446b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone/* Get abbreviation with given code. */ 447b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Dwarf_Abbrev *__libdw_findabbrev (struct Dwarf_CU *cu, 448b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned int code) 449b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper __nonnull_attribute__ (1) internal_function; 450b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 451b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Get abbreviation at given offset. */ 452b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Dwarf_Abbrev *__libdw_getabbrev (Dwarf *dbg, struct Dwarf_CU *cu, 453b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Dwarf_Off offset, size_t *lengthp, 454b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Dwarf_Abbrev *result) 455b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper __nonnull_attribute__ (1) internal_function; 456b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 457b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone/* Get abbreviation of given DIE, and optionally set *READP to the DIE memory 458b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone just past the abbreviation code. */ 459b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stonestatic inline Dwarf_Abbrev * 460b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone__nonnull_attribute__ (1) 461b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone__libdw_dieabbrev (Dwarf_Die *die, const unsigned char **readp) 462b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone{ 463b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone /* Do we need to get the abbreviation, or need to read after the code? */ 464b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone if (die->abbrev == NULL || readp != NULL) 465b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone { 466b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone /* Get the abbreviation code. */ 467b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone unsigned int code; 468b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone const unsigned char *addr = die->addr; 4697a053473c7bedd22e3db39c444a4cd8f97eace25Mark Wielaard get_uleb128 (code, addr, die->cu->endp); 470b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone if (readp != NULL) 471b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone *readp = addr; 472b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone 473b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone /* Find the abbreviation. */ 474b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone if (die->abbrev == NULL) 475b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone die->abbrev = __libdw_findabbrev (die->cu, code); 476b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone } 477b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone return die->abbrev; 478b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone} 479b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone 480b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Helper functions for form handling. */ 4819202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaardextern size_t __libdw_form_val_compute_len (struct Dwarf_CU *cu, 482c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone unsigned int form, 4839202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaard const unsigned char *valp) 4849202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaard __nonnull_attribute__ (1, 3) internal_function; 485b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 486c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone/* Find the length of a form attribute. */ 487c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stonestatic inline size_t 4889202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaard__nonnull_attribute__ (1, 3) 4899202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaard__libdw_form_val_len (struct Dwarf_CU *cu, unsigned int form, 4909202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaard const unsigned char *valp) 491c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone{ 492c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone /* Small lookup table of forms with fixed lengths. Absent indexes are 493c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone initialized 0, so any truly desired 0 is set to 0x80 and masked. */ 494c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone static const uint8_t form_lengths[] = 495c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone { 496c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone [DW_FORM_flag_present] = 0x80, 497c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone [DW_FORM_data1] = 1, [DW_FORM_ref1] = 1, [DW_FORM_flag] = 1, 498c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone [DW_FORM_data2] = 2, [DW_FORM_ref2] = 2, 499c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone [DW_FORM_data4] = 4, [DW_FORM_ref4] = 4, 500c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone [DW_FORM_data8] = 8, [DW_FORM_ref8] = 8, [DW_FORM_ref_sig8] = 8, 501c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone }; 502c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone 503c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone /* Return immediately for forms with fixed lengths. */ 504c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone if (form < sizeof form_lengths / sizeof form_lengths[0]) 505c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone { 506c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone uint8_t len = form_lengths[form]; 507c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone if (len != 0) 508cb73b5a015606a02f952f7eddaba15327f6191faMark Wielaard { 5099202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaard const unsigned char *endp = cu->endp; 510cb73b5a015606a02f952f7eddaba15327f6191faMark Wielaard len &= 0x7f; /* Mask to allow 0x80 -> 0. */ 511cb73b5a015606a02f952f7eddaba15327f6191faMark Wielaard if (unlikely (len > (size_t) (endp - valp))) 512cb73b5a015606a02f952f7eddaba15327f6191faMark Wielaard { 513cb73b5a015606a02f952f7eddaba15327f6191faMark Wielaard __libdw_seterrno (DWARF_E_INVALID_DWARF); 514cb73b5a015606a02f952f7eddaba15327f6191faMark Wielaard return -1; 515cb73b5a015606a02f952f7eddaba15327f6191faMark Wielaard } 516cb73b5a015606a02f952f7eddaba15327f6191faMark Wielaard return len; 517cb73b5a015606a02f952f7eddaba15327f6191faMark Wielaard } 518c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone } 519c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone 520c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone /* Other forms require some computation. */ 5219202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaard return __libdw_form_val_compute_len (cu, form, valp); 522c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone} 523c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone 524e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath/* Helper function for DW_FORM_ref* handling. */ 525e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrathextern int __libdw_formref (Dwarf_Attribute *attr, Dwarf_Off *return_offset) 526e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath __nonnull_attribute__ (1, 2) internal_function; 527e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath 528e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath 529b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Helper function to locate attribute. */ 530b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern unsigned char *__libdw_find_attr (Dwarf_Die *die, 531b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned int search_name, 532b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned int *codep, 533b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned int *formp) 534b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper __nonnull_attribute__ (1) internal_function; 535b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 536b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Helper function to access integer attribute. */ 5376724c90d02659f7466b67b357563042e403d154eRoland McGrathextern int __libdw_attr_intval (Dwarf_Die *die, int *valp, int attval) 538b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper __nonnull_attribute__ (1, 2) internal_function; 539b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 5401ecb606f5af22838bf42b50dcc581d2b0f9191feRoland McGrath/* Helper function to walk scopes. */ 54171e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrathstruct Dwarf_Die_Chain 54271e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath{ 54371e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath Dwarf_Die die; 54471e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath struct Dwarf_Die_Chain *parent; 54571e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath bool prune; /* The PREVISIT function can set this. */ 54671e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath}; 54771e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrathextern int __libdw_visit_scopes (unsigned int depth, 54871e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath struct Dwarf_Die_Chain *root, 549daf278fda6d9bd329b517757f9ba2d74619f3be7Mark Wielaard struct Dwarf_Die_Chain *imports, 55071e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath int (*previsit) (unsigned int depth, 55171e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath struct Dwarf_Die_Chain *, 55271e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath void *arg), 55371e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath int (*postvisit) (unsigned int depth, 55471e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath struct Dwarf_Die_Chain *, 55571e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath void *arg), 5561ecb606f5af22838bf42b50dcc581d2b0f9191feRoland McGrath void *arg) 557daf278fda6d9bd329b517757f9ba2d74619f3be7Mark Wielaard __nonnull_attribute__ (2, 4) internal_function; 5581ecb606f5af22838bf42b50dcc581d2b0f9191feRoland McGrath 5593c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath/* Parse a DWARF Dwarf_Block into an array of Dwarf_Op's, 5603c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath and cache the result (via tsearch). */ 5613c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrathextern int __libdw_intern_expression (Dwarf *dbg, 5623c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath bool other_byte_order, 5633c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath unsigned int address_size, 564688f7fcdb395cefef6a098b5ac9ddd167bb5fc3dRoland McGrath unsigned int ref_size, 5653c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath void **cache, const Dwarf_Block *block, 5660ab97839da3c382ab8799ebdbf5eb0a79bf20bdcRoland McGrath bool cfap, bool valuep, 5673c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath Dwarf_Op **llbuf, size_t *listlen, 5683c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath int sec_index) 569688f7fcdb395cefef6a098b5ac9ddd167bb5fc3dRoland McGrath __nonnull_attribute__ (5, 6, 9, 10) internal_function; 5703c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath 571932585d2385c9d4e5686e4ddc9ba30c68172d7f3Roland McGrathextern Dwarf_Die *__libdw_offdie (Dwarf *dbg, Dwarf_Off offset, 572932585d2385c9d4e5686e4ddc9ba30c68172d7f3Roland McGrath Dwarf_Die *result, bool debug_types) 573932585d2385c9d4e5686e4ddc9ba30c68172d7f3Roland McGrath internal_function; 574932585d2385c9d4e5686e4ddc9ba30c68172d7f3Roland McGrath 5753c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath 576b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Return error code of last failing function call. This value is kept 577b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper separately for each thread. */ 578b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern int __dwarf_errno_internal (void); 579b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 580b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 58199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper/* Reader hooks. */ 58299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper 58399d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper/* Relocation hooks return -1 on error (in that case the error code 58499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper must already have been set), 0 if there is no relocation and 1 if a 58599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper relocation was present.*/ 58699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper 58799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepperstatic inline int 58899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper__libdw_relocate_address (Dwarf *dbg __attribute__ ((unused)), 58999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper int sec_index __attribute__ ((unused)), 59099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper const void *addr __attribute__ ((unused)), 59199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper int width __attribute__ ((unused)), 59299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper Dwarf_Addr *val __attribute__ ((unused))) 59399d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper{ 59499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper return 0; 59599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper} 59699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper 59799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepperstatic inline int 59899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper__libdw_relocate_offset (Dwarf *dbg __attribute__ ((unused)), 59999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper int sec_index __attribute__ ((unused)), 60099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper const void *addr __attribute__ ((unused)), 60199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper int width __attribute__ ((unused)), 60299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper Dwarf_Off *val __attribute__ ((unused))) 60399d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper{ 60499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper return 0; 60599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper} 60699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper 60799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepperstatic inline Elf_Data * 60899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper__libdw_checked_get_data (Dwarf *dbg, int sec_index) 60999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper{ 61099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper Elf_Data *data = dbg->sectiondata[sec_index]; 61199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper if (unlikely (data == NULL) 61299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper || unlikely (data->d_buf == NULL)) 61399d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper { 61499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper __libdw_seterrno (DWARF_E_INVALID_DWARF); 61599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper return NULL; 61699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper } 61799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper return data; 61899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper} 61999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper 62099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepperstatic inline int 62199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper__libdw_offset_in_section (Dwarf *dbg, int sec_index, 62299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper Dwarf_Off offset, size_t size) 62399d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper{ 62499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper Elf_Data *data = __libdw_checked_get_data (dbg, sec_index); 62599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper if (data == NULL) 62699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper return -1; 62799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper if (unlikely (offset > data->d_size) 62899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper || unlikely (data->d_size - offset < size)) 62999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper { 63099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper __libdw_seterrno (DWARF_E_INVALID_OFFSET); 63199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper return -1; 63299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper } 63399d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper 63499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper return 0; 63599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper} 63699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper 63799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepperstatic inline bool 63899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper__libdw_in_section (Dwarf *dbg, int sec_index, 63999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper const void *addr, size_t size) 64099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper{ 64199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper Elf_Data *data = __libdw_checked_get_data (dbg, sec_index); 64299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper if (data == NULL) 64399d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper return false; 64499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper if (unlikely (addr < data->d_buf) 64599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper || unlikely (data->d_size - (addr - data->d_buf) < size)) 64699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper { 64799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper __libdw_seterrno (DWARF_E_INVALID_OFFSET); 64899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper return false; 64999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper } 65099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper 65199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper return true; 65299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper} 65399d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper 65499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper#define READ_AND_RELOCATE(RELOC_HOOK, VAL) \ 65599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper ({ \ 65699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper if (!__libdw_in_section (dbg, sec_index, addr, width)) \ 65799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper return -1; \ 65899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper \ 65999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper const unsigned char *orig_addr = addr; \ 66099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper if (width == 4) \ 66199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper VAL = read_4ubyte_unaligned_inc (dbg, addr); \ 66299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper else \ 66399d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper VAL = read_8ubyte_unaligned_inc (dbg, addr); \ 66499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper \ 66599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper int status = RELOC_HOOK (dbg, sec_index, orig_addr, width, &VAL); \ 66699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper if (status < 0) \ 66799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper return status; \ 66899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper status > 0; \ 66999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper }) 67099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper 67199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepperstatic inline int 67299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper__libdw_read_address_inc (Dwarf *dbg, 67305c4e04640d173a4d1ce6e2f25a24060c21a67abRoland McGrath int sec_index, const unsigned char **addrp, 67499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper int width, Dwarf_Addr *ret) 67599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper{ 67605c4e04640d173a4d1ce6e2f25a24060c21a67abRoland McGrath const unsigned char *addr = *addrp; 67799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper READ_AND_RELOCATE (__libdw_relocate_address, (*ret)); 67899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper *addrp = addr; 67999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper return 0; 68099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper} 68199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper 68299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepperstatic inline int 68399d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper__libdw_read_address (Dwarf *dbg, 68499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper int sec_index, const unsigned char *addr, 68599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper int width, Dwarf_Addr *ret) 68699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper{ 68799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper READ_AND_RELOCATE (__libdw_relocate_address, (*ret)); 68899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper return 0; 68999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper} 69099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper 69199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepperstatic inline int 69299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper__libdw_read_offset_inc (Dwarf *dbg, 69305c4e04640d173a4d1ce6e2f25a24060c21a67abRoland McGrath int sec_index, const unsigned char **addrp, 69499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper int width, Dwarf_Off *ret, int sec_ret, 69599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper size_t size) 69699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper{ 69705c4e04640d173a4d1ce6e2f25a24060c21a67abRoland McGrath const unsigned char *addr = *addrp; 69899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper READ_AND_RELOCATE (__libdw_relocate_offset, (*ret)); 69999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper *addrp = addr; 70099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper return __libdw_offset_in_section (dbg, sec_ret, *ret, size); 70199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper} 70299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper 70399d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepperstatic inline int 704775375e3bd177cb19acb5020b6e0917551807276Mark Wielaard__libdw_read_offset (Dwarf *dbg, Dwarf *dbg_ret, 70599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper int sec_index, const unsigned char *addr, 70699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper int width, Dwarf_Off *ret, int sec_ret, 70799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper size_t size) 70899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper{ 70999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper READ_AND_RELOCATE (__libdw_relocate_offset, (*ret)); 710775375e3bd177cb19acb5020b6e0917551807276Mark Wielaard return __libdw_offset_in_section (dbg_ret, sec_ret, *ret, size); 71199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper} 71299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper 7133e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrathstatic inline size_t 7143e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrathcu_sec_idx (struct Dwarf_CU *cu) 7153e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath{ 7163e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath return cu->type_offset == 0 ? IDX_debug_info : IDX_debug_types; 7173e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath} 7183e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath 71971de1d2a8a3fffc83c707642a24f350d7217f83cPetr Machatastatic inline bool 72071de1d2a8a3fffc83c707642a24f350d7217f83cPetr Machatais_cudie (Dwarf_Die *cudie) 72171de1d2a8a3fffc83c707642a24f350d7217f83cPetr Machata{ 72271de1d2a8a3fffc83c707642a24f350d7217f83cPetr Machata return CUDIE (cudie->cu).addr == cudie->addr; 72371de1d2a8a3fffc83c707642a24f350d7217f83cPetr Machata} 72471de1d2a8a3fffc83c707642a24f350d7217f83cPetr Machata 72599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper/* Read up begin/end pair and increment read pointer. 72699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper - If it's normal range record, set up *BEGINP and *ENDP and return 0. 72799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper - If it's base address selection record, set up *BASEP and return 1. 72899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper - If it's end of rangelist, don't set anything and return 2 72999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper - If an error occurs, don't set anything and return <0. */ 73099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepperint __libdw_read_begin_end_pair_inc (Dwarf *dbg, int sec_index, 73199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper unsigned char **addr, int width, 73299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper Dwarf_Addr *beginp, Dwarf_Addr *endp, 73399d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper Dwarf_Addr *basep) 73499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper internal_function; 73599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper 73699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepperunsigned char * __libdw_formptr (Dwarf_Attribute *attr, int sec_index, 73799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper int err_nodata, unsigned char **endpp, 73899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper Dwarf_Off *offsetp) 73999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper internal_function; 74099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper 7413951f2ec0aaca021c77a2c7a464dcf43433261c3Mark Wielaard/* Fills in the given attribute to point at an empty location expression. */ 7429202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaardvoid __libdw_empty_loc_attr (Dwarf_Attribute *attr) 7433951f2ec0aaca021c77a2c7a464dcf43433261c3Mark Wielaard internal_function; 7443951f2ec0aaca021c77a2c7a464dcf43433261c3Mark Wielaard 745fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata/* Load .debug_line unit at DEBUG_LINE_OFFSET. COMP_DIR is a value of 746fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata DW_AT_comp_dir or NULL if that attribute is not available. Caches 747fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata the loaded unit and optionally set *LINESP and/or *FILESP (if not 748fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata NULL) with loaded information. Returns 0 for success or a negative 749fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata value for failure. */ 750fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machataint __libdw_getsrclines (Dwarf *dbg, Dwarf_Off debug_line_offset, 751fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata const char *comp_dir, unsigned address_size, 752fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata Dwarf_Lines **linesp, Dwarf_Files **filesp) 753fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata internal_function 754fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata __nonnull_attribute__ (1); 755fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata 756fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata/* Load and return value of DW_AT_comp_dir from CUDIE. */ 757fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machataconst char *__libdw_getcompdir (Dwarf_Die *cudie); 758fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata 75999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper 760b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Aliases to avoid PLTs. */ 761ebc5c885e696cdc4961916113c50e1396d8d3d48Roland McGrathINTDECL (dwarf_aggregate_size) 762b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_attr) 763b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_attr_integrate) 764775375e3bd177cb19acb5020b6e0917551807276Mark WielaardINTDECL (dwarf_begin) 765b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_begin_elf) 766b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_child) 767b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_dieoffset) 76871e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrathINTDECL (dwarf_diename) 7694959bf89d92b59ba72bea5786d7b3f9b5564f750Roland McGrathINTDECL (dwarf_end) 77007d4f2fc1cb53f170a71bc13617bbdd9cb1c3c60Roland McGrathINTDECL (dwarf_entrypc) 7714959bf89d92b59ba72bea5786d7b3f9b5564f750Roland McGrathINTDECL (dwarf_errmsg) 772b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_formaddr) 773b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_formblock) 774b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_formref_die) 775b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_formsdata) 776b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_formstring) 777b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_formudata) 77835e2a765c002374f1b88dc81ce154bed42f9b1d8Florian WeimerINTDECL (dwarf_getalt) 779b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_getarange_addr) 780b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_getarangeinfo) 781b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_getaranges) 782b2535b6a6be7717cdd41834d76e5cb48cb446b83Mark WielaardINTDECL (dwarf_getlocation_die) 783b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_getsrcfiles) 784b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_getsrclines) 785b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_hasattr) 786b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_haschildren) 787b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_haspc) 788b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_highpc) 789b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_lowpc) 790b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_nextcu) 7913e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrathINTDECL (dwarf_next_unit) 792b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_offdie) 7933a36e8a26c32103ec2f8edda8bf212d6883970a2Mark WielaardINTDECL (dwarf_peel_type) 79407d4f2fc1cb53f170a71bc13617bbdd9cb1c3c60Roland McGrathINTDECL (dwarf_ranges) 79535e2a765c002374f1b88dc81ce154bed42f9b1d8Florian WeimerINTDECL (dwarf_setalt) 796b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_siblingof) 797ebc5c885e696cdc4961916113c50e1396d8d3d48Roland McGrathINTDECL (dwarf_srclang) 798b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_tag) 799b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 800b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#endif /* libdwP.h */ 801