libdwP.h revision daf278fda6d9bd329b517757f9ba2d74619f3be7
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,
100b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_NOELF,
101b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_GETEHDR_ERROR,
102b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_NOMEM,
103b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_UNIMPL,
104b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_INVALID_CMD,
105b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_INVALID_VERSION,
106b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_INVALID_FILE,
107b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_NO_ENTRY,
108b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_INVALID_DWARF,
109b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_NO_STRING,
110b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_NO_ADDR,
111b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_NO_CONSTANT,
112b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_NO_REFERENCE,
113b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_INVALID_REFERENCE,
114b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_NO_DEBUG_LINE,
115b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_INVALID_DEBUG_LINE,
116b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_TOO_BIG,
117b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_VERSION,
118b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_INVALID_DIR_IDX,
119b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_ADDR_OUTOFRANGE,
120b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_NO_LOCLIST,
121b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_NO_BLOCK,
122b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_INVALID_LINE_IDX,
123b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_INVALID_ARANGE_IDX,
124b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_NO_MATCH,
125b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_NO_FLAG,
126b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_INVALID_OFFSET,
127b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  DWARF_E_NO_DEBUG_RANGES,
1283c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath  DWARF_E_INVALID_CFI,
129fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  DWARF_E_NO_ALT_DEBUGLINK,
130fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  DWARF_E_INVALID_OPCODE,
131b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper};
132b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
133b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
1343e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath#include "dwarf_sig8_hash.h"
1353e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath
136b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* This is the structure representing the debugging state.  */
137b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct Dwarf
138b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{
139b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* The underlying ELF file.  */
140b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Elf *elf;
141b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
142775375e3bd177cb19acb5020b6e0917551807276Mark Wielaard  /* dwz alternate DWARF file.  */
143775375e3bd177cb19acb5020b6e0917551807276Mark Wielaard  Dwarf *alt_dwarf;
144775375e3bd177cb19acb5020b6e0917551807276Mark Wielaard
145b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* The section data.  */
146b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Elf_Data *sectiondata[IDX_last];
147b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
148725aad5d2f8b78ed21a5e253fb38f9722c2c8b2dRoland McGrath#if USE_ZLIB
149725aad5d2f8b78ed21a5e253fb38f9722c2c8b2dRoland McGrath  /* The 1 << N bit is set if sectiondata[N] is malloc'd decompressed data.  */
150725aad5d2f8b78ed21a5e253fb38f9722c2c8b2dRoland McGrath  unsigned int sectiondata_gzip_mask:IDX_last;
151725aad5d2f8b78ed21a5e253fb38f9722c2c8b2dRoland McGrath#endif
152725aad5d2f8b78ed21a5e253fb38f9722c2c8b2dRoland McGrath
153b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* True if the file has a byte order different from the host.  */
154b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  bool other_byte_order;
155b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
156b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* If true, we allocated the ELF descriptor ourselves.  */
157b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  bool free_elf;
158b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
159b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* Information for traversing the .debug_pubnames section.  This is
160b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     an array and separately allocated with malloc.  */
161b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  struct pubnames_s
162b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  {
163b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    Dwarf_Off cu_offset;
164b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    Dwarf_Off set_start;
165b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    unsigned int cu_header_size;
166b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    int address_len;
167b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  } *pubnames_sets;
168b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  size_t pubnames_nsets;
169b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
170b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* Search tree for the CUs.  */
171b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  void *cu_tree;
172b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Dwarf_Off next_cu_offset;
173b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
1742b1f09548b66c2c75d5be6f13cd9374adc95f8d8Roland McGrath  /* Search tree and sig8 hash table for .debug_types type units.  */
1752b1f09548b66c2c75d5be6f13cd9374adc95f8d8Roland McGrath  void *tu_tree;
1763e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath  Dwarf_Off next_tu_offset;
1772b1f09548b66c2c75d5be6f13cd9374adc95f8d8Roland McGrath  Dwarf_Sig8_Hash sig8_hash;
1783e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath
179fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  /* Search tree for .debug_macro operator tables.  */
180fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  void *macro_ops;
181fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata
182fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  /* Search tree for decoded .debug_line units.  */
183fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  void *files_lines;
184fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata
185b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* Address ranges.  */
186b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Dwarf_Aranges *aranges;
187b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
1883c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath  /* Cached info from the CFI section.  */
1893c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath  struct Dwarf_CFI_s *cfi;
1903c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath
1919202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaard  /* Fake loc CU.  Used when synthesizing attributes for Dwarf_Ops that
1929202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaard     came from a location list entry in dwarf_getlocation_attr.  */
1939202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaard  struct Dwarf_CU *fake_loc_cu;
1949202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaard
195b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* Internal memory handling.  This is basically a simplified
196b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     reimplementation of obstacks.  Unfortunately the standard obstack
197b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     implementation is not usable in libraries.  */
198b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  struct libdw_memblock
199b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  {
200b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    size_t size;
201b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    size_t remaining;
202b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    struct libdw_memblock *prev;
203b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    char mem[0];
204b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  } *mem_tail;
205b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
206b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* Default size of allocated memory blocks.  */
207b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  size_t mem_default_size;
208b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
209b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* Registered OOM handler.  */
210b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Dwarf_OOM oom_handler;
211b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper};
212b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
213b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
214b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Abbreviation representation.  */
215b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct Dwarf_Abbrev
216b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{
2171f6d2010bb26b6bf5395a98651fce9a1a9141ac3Roland McGrath  Dwarf_Off offset;
2181f6d2010bb26b6bf5395a98651fce9a1a9141ac3Roland McGrath  unsigned char *attrp;
2191f6d2010bb26b6bf5395a98651fce9a1a9141ac3Roland McGrath  unsigned int attrcnt;
220b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  unsigned int code;
221b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  unsigned int tag;
2221f6d2010bb26b6bf5395a98651fce9a1a9141ac3Roland McGrath  bool has_children;
223b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper};
224b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
225b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include "dwarf_abbrev_hash.h"
226b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
227b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
228b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Files in line information records.  */
229b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct Dwarf_Files_s
230b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  {
23143da9895c6d828ceae65a47f2337e8ef24eb97c1Roland McGrath    unsigned int ndirs;
232b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    unsigned int nfiles;
233b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    struct Dwarf_Fileinfo_s
234b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    {
235b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      char *name;
236b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      Dwarf_Word mtime;
237b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper      Dwarf_Word length;
238b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    } info[0];
23943da9895c6d828ceae65a47f2337e8ef24eb97c1Roland McGrath    /* nfiles of those, followed by char *[ndirs].  */
240b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  };
241b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppertypedef struct Dwarf_Fileinfo_s Dwarf_Fileinfo;
242b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
243b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
244b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Representation of a row in the line table.  */
245b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
24603288f0df65115b75cf029825ecc9cf9158870a4Roland McGrathstruct Dwarf_Line_s
24703288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath{
2486e1f4658619e0a6bdbf64d7678b82f4e97645633Roland McGrath  Dwarf_Files *files;
2496e1f4658619e0a6bdbf64d7678b82f4e97645633Roland McGrath
25003288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath  Dwarf_Addr addr;
25103288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath  unsigned int file;
25203288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath  int line;
25303288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath  unsigned short int column;
25403288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath  unsigned int is_stmt:1;
25503288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath  unsigned int basic_block:1;
25603288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath  unsigned int end_sequence:1;
25703288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath  unsigned int prologue_end:1;
25803288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath  unsigned int epilogue_begin:1;
259c70cf4e5e5a463b64673c4e80bcf60c938b437b4Roland McGrath  /* The remaining bit fields are not flags, but hold values presumed to be
260c70cf4e5e5a463b64673c4e80bcf60c938b437b4Roland McGrath     small.  All the flags and other bit fields should add up to 48 bits
261c70cf4e5e5a463b64673c4e80bcf60c938b437b4Roland McGrath     to give the whole struct a nice round size.  */
262c70cf4e5e5a463b64673c4e80bcf60c938b437b4Roland McGrath  unsigned int op_index:8;
263c70cf4e5e5a463b64673c4e80bcf60c938b437b4Roland McGrath  unsigned int isa:8;
264c70cf4e5e5a463b64673c4e80bcf60c938b437b4Roland McGrath  unsigned int discriminator:24;
26503288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath};
26603288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath
26703288f0df65115b75cf029825ecc9cf9158870a4Roland McGrathstruct Dwarf_Lines_s
26803288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath{
26903288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath  size_t nlines;
27003288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath  struct Dwarf_Line_s info[0];
27103288f0df65115b75cf029825ecc9cf9158870a4Roland McGrath};
272b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
273b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Representation of address ranges.  */
274b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct Dwarf_Aranges_s
275b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{
276b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Dwarf *dbg;
277b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  size_t naranges;
278b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
279b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  struct Dwarf_Arange_s
280b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  {
281b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    Dwarf_Addr addr;
282b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    Dwarf_Word length;
283b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper    Dwarf_Off offset;
284b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  } info[0];
285b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper};
286b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
287b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
288b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* CU representation.  */
289b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct Dwarf_CU
290b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{
291b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Dwarf *dbg;
292b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Dwarf_Off start;
293b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Dwarf_Off end;
294b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  uint8_t address_size;
295b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  uint8_t offset_size;
296e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath  uint16_t version;
297b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
2983e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath  /* Zero if this is a normal CU.  Nonzero if it is a type unit.  */
2993e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath  size_t type_offset;
3003e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath  uint64_t type_sig8;
3013e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath
302b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* Hash table for the abbreviations.  */
303b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Dwarf_Abbrev_Hash abbrev_hash;
304b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* Offset of the first abbreviation.  */
305b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  size_t orig_abbrev_offset;
306b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* Offset past last read abbreviation.  */
307b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  size_t last_abbrev_offset;
308b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
309b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* The srcline information.  */
310b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Dwarf_Lines *lines;
311b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
312b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* The source file information.  */
313b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Dwarf_Files *files;
314b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
315b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* Known location lists.  */
316b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  void *locs;
3178d200b5b728b7ee6150796e4baa07b54e1ac8cd2Josh Stone
3188d200b5b728b7ee6150796e4baa07b54e1ac8cd2Josh Stone  /* Memory boundaries of this CU.  */
3198d200b5b728b7ee6150796e4baa07b54e1ac8cd2Josh Stone  void *startp;
3208d200b5b728b7ee6150796e4baa07b54e1ac8cd2Josh Stone  void *endp;
321b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper};
322b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
32335f08c4d52d0ffd9f8aa50f47b84de5603842b1fUlrich Drepper/* Compute the offset of a CU's first DIE from its offset.  This
32435f08c4d52d0ffd9f8aa50f47b84de5603842b1fUlrich Drepper   is either:
32535f08c4d52d0ffd9f8aa50f47b84de5603842b1fUlrich Drepper        LEN       VER     OFFSET    ADDR
32635f08c4d52d0ffd9f8aa50f47b84de5603842b1fUlrich Drepper      4-bytes + 2-bytes + 4-bytes + 1-byte  for 32-bit dwarf
32735f08c4d52d0ffd9f8aa50f47b84de5603842b1fUlrich Drepper     12-bytes + 2-bytes + 8-bytes + 1-byte  for 64-bit dwarf
3283e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath   or in .debug_types, 			     SIGNATURE TYPE-OFFSET
3293e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath      4-bytes + 2-bytes + 4-bytes + 1-byte + 8-bytes + 4-bytes  for 32-bit
3303e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath     12-bytes + 2-bytes + 8-bytes + 1-byte + 8-bytes + 8-bytes  for 64-bit
331a969d8e19470157be1b8b2e1a693ac7702bf4273Ulrich Drepper
33235f08c4d52d0ffd9f8aa50f47b84de5603842b1fUlrich Drepper   Note the trick in the computation.  If the offset_size is 4
33335f08c4d52d0ffd9f8aa50f47b84de5603842b1fUlrich Drepper   the '- 4' term changes the '3 *' into a '2 *'.  If the
33435f08c4d52d0ffd9f8aa50f47b84de5603842b1fUlrich Drepper   offset_size is 8 it accounts for the 4-byte escape value
33535f08c4d52d0ffd9f8aa50f47b84de5603842b1fUlrich Drepper   used at the start of the length.  */
3363e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath#define DIE_OFFSET_FROM_CU_OFFSET(cu_offset, offset_size, type_unit)	\
3373e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath  ((type_unit) ? ((cu_offset) + 4 * (offset_size) - 4 + 3 + 8)		\
3383e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath   : ((cu_offset) + 3 * (offset_size) - 4 + 3))
33935f08c4d52d0ffd9f8aa50f47b84de5603842b1fUlrich Drepper
3403e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath#define CUDIE(fromcu)							      \
3416724c90d02659f7466b67b357563042e403d154eRoland McGrath  ((Dwarf_Die)								      \
3426724c90d02659f7466b67b357563042e403d154eRoland McGrath   {									      \
3436724c90d02659f7466b67b357563042e403d154eRoland McGrath     .cu = (fromcu),							      \
3449202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaard     .addr = ((char *) fromcu->dbg->sectiondata[cu_sec_idx (fromcu)]->d_buf   \
3453e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath	      + DIE_OFFSET_FROM_CU_OFFSET ((fromcu)->start,		      \
3463e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath					   (fromcu)->offset_size,	      \
3473e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath					   (fromcu)->type_offset != 0))	      \
3483e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath   })									      \
349b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
350b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
351fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata/* Prototype of a single .debug_macro operator.  */
352fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machatatypedef struct
353fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata{
354fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  Dwarf_Word nforms;
355fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  unsigned char const *forms;
356fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata} Dwarf_Macro_Op_Proto;
357fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata
358fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata/* Prototype table.  */
359fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machatatypedef struct
360fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata{
361fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  /* Offset of .debug_macro section.  */
362fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  Dwarf_Off offset;
363fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata
364fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  /* Offset of associated .debug_line section.  */
365fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  Dwarf_Off line_offset;
366fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata
367fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  /* The source file information.  */
368fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  Dwarf_Files *files;
369fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata
370fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  /* If this macro unit was opened through dwarf_getmacros or
371fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata     dwarf_getmacros_die, this caches value of DW_AT_comp_dir, if
372fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata     present.  */
373fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  const char *comp_dir;
374fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata
375fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  /* Header length.  */
376fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  Dwarf_Half header_len;
377fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata
378fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  uint16_t version;
379fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  bool is_64bit;
380fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  uint8_t sec_index;	/* IDX_debug_macro or IDX_debug_macinfo.  */
381fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata
382fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  /* Shows where in TABLE each opcode is defined.  Since opcode 0 is
383fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata     never used, it stores index of opcode X in X-1'th element.  The
384fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata     value of 0xff means not stored at all.  */
385fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  unsigned char opcodes[255];
386fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata
387fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  /* Individual opcode prototypes.  */
388fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  Dwarf_Macro_Op_Proto table[];
389fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata} Dwarf_Macro_Op_Table;
390fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata
391b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct Dwarf_Macro_s
392b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{
393fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  Dwarf_Macro_Op_Table *table;
394fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  Dwarf_Attribute *attributes;
395fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  uint8_t opcode;
396b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper};
397b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
398fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machatastatic inline Dwarf_Word
399fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machatalibdw_macro_nforms (Dwarf_Macro *macro)
400fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata{
401fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  return macro->table->table[macro->table->opcodes[macro->opcode - 1]].nforms;
402fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata}
403b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
404b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* We have to include the file at this point because the inline
405b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   functions access internals of the Dwarf structure.  */
406b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include "memory-access.h"
407b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
408b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
409b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Set error value.  */
410b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern void __libdw_seterrno (int value) internal_function;
411b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
412b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
413b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Memory handling, the easy parts.  This macro does not do any locking.  */
414db1d54386fc38a30eff030517cbbfedf758fa32aUlrich Drepper#define libdw_alloc(dbg, type, tsize, cnt) \
415b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ({ struct libdw_memblock *_tail = (dbg)->mem_tail;			      \
416b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     size_t _required = (tsize) * (cnt);				      \
417b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     type *_result = (type *) (_tail->mem + (_tail->size - _tail->remaining));\
418b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     size_t _padding = ((__alignof (type)				      \
419b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper			 - ((uintptr_t) _result & (__alignof (type) - 1)))    \
420b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper			& (__alignof (type) - 1));			      \
421b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     if (unlikely (_tail->remaining < _required + _padding))		      \
422c373d850ec9ca342f4c71d5e287c8d8bf0723cd6Roland McGrath       _result = (type *) __libdw_allocate (dbg, _required, __alignof (type));\
423b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     else								      \
424b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper       {								      \
425b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	 _required += _padding;						      \
426b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper	 _result = (type *) ((char *) _result + _padding);		      \
427c373d850ec9ca342f4c71d5e287c8d8bf0723cd6Roland McGrath	 _tail->remaining -= _required;					      \
428b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper       }								      \
429b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     _result; })
430b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
431b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define libdw_typed_alloc(dbg, type) \
432b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  libdw_alloc (dbg, type, sizeof (type), 1)
433b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
434b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Callback to allocate more.  */
435c373d850ec9ca342f4c71d5e287c8d8bf0723cd6Roland McGrathextern void *__libdw_allocate (Dwarf *dbg, size_t minsize, size_t align)
436b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     __attribute__ ((__malloc__)) __nonnull_attribute__ (1);
437b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
438b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Default OOM handler.  */
439b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern void __libdw_oom (void) __attribute ((noreturn, visibility ("hidden")));
440b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
441725aad5d2f8b78ed21a5e253fb38f9722c2c8b2dRoland McGrath#if USE_ZLIB
442725aad5d2f8b78ed21a5e253fb38f9722c2c8b2dRoland McGrathextern void __libdw_free_zdata (Dwarf *dwarf) internal_function;
443725aad5d2f8b78ed21a5e253fb38f9722c2c8b2dRoland McGrath#else
444725aad5d2f8b78ed21a5e253fb38f9722c2c8b2dRoland McGrath# define __libdw_free_zdata(dwarf)	((void) (dwarf))
445725aad5d2f8b78ed21a5e253fb38f9722c2c8b2dRoland McGrath#endif
446725aad5d2f8b78ed21a5e253fb38f9722c2c8b2dRoland McGrath
4473e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath/* Allocate the internal data for a unit not seen before.  */
4483e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrathextern struct Dwarf_CU *__libdw_intern_next_unit (Dwarf *dbg, bool debug_types)
4493e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath     __nonnull_attribute__ (1) internal_function;
4503e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath
451b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Find CU for given offset.  */
4522b1f09548b66c2c75d5be6f13cd9374adc95f8d8Roland McGrathextern struct Dwarf_CU *__libdw_findcu (Dwarf *dbg, Dwarf_Off offset, bool tu)
453b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     __nonnull_attribute__ (1) internal_function;
454b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
455b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone/* Get abbreviation with given code.  */
456b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Dwarf_Abbrev *__libdw_findabbrev (struct Dwarf_CU *cu,
457b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper					 unsigned int code)
458b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     __nonnull_attribute__ (1) internal_function;
459b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
460b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Get abbreviation at given offset.  */
461b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Dwarf_Abbrev *__libdw_getabbrev (Dwarf *dbg, struct Dwarf_CU *cu,
462b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper					Dwarf_Off offset, size_t *lengthp,
463b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper					Dwarf_Abbrev *result)
464b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     __nonnull_attribute__ (1) internal_function;
465b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
466b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone/* Get abbreviation of given DIE, and optionally set *READP to the DIE memory
467b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone   just past the abbreviation code.  */
468b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stonestatic inline Dwarf_Abbrev *
469b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone__nonnull_attribute__ (1)
470b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone__libdw_dieabbrev (Dwarf_Die *die, const unsigned char **readp)
471b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone{
472b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone  /* Do we need to get the abbreviation, or need to read after the code?  */
473b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone  if (die->abbrev == NULL || readp != NULL)
474b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone    {
475b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone      /* Get the abbreviation code.  */
476b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone      unsigned int code;
477b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone      const unsigned char *addr = die->addr;
4787a053473c7bedd22e3db39c444a4cd8f97eace25Mark Wielaard      get_uleb128 (code, addr, die->cu->endp);
479b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone      if (readp != NULL)
480b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone	*readp = addr;
481b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone
482b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone      /* Find the abbreviation.  */
483b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone      if (die->abbrev == NULL)
484b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone	die->abbrev = __libdw_findabbrev (die->cu, code);
485b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone    }
486b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone  return die->abbrev;
487b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone}
488b849f813e6753ea60784175321d4bde78c0c2ad9Josh Stone
489b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Helper functions for form handling.  */
4909202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaardextern size_t __libdw_form_val_compute_len (struct Dwarf_CU *cu,
491c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone					    unsigned int form,
4929202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaard					    const unsigned char *valp)
4939202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaard     __nonnull_attribute__ (1, 3) internal_function;
494b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
495c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone/* Find the length of a form attribute.  */
496c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stonestatic inline size_t
4979202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaard__nonnull_attribute__ (1, 3)
4989202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaard__libdw_form_val_len (struct Dwarf_CU *cu, unsigned int form,
4999202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaard		      const unsigned char *valp)
500c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone{
501c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone  /* Small lookup table of forms with fixed lengths.  Absent indexes are
502c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone     initialized 0, so any truly desired 0 is set to 0x80 and masked.  */
503c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone  static const uint8_t form_lengths[] =
504c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone    {
505c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone      [DW_FORM_flag_present] = 0x80,
506c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone      [DW_FORM_data1] = 1, [DW_FORM_ref1] = 1, [DW_FORM_flag] = 1,
507c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone      [DW_FORM_data2] = 2, [DW_FORM_ref2] = 2,
508c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone      [DW_FORM_data4] = 4, [DW_FORM_ref4] = 4,
509c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone      [DW_FORM_data8] = 8, [DW_FORM_ref8] = 8, [DW_FORM_ref_sig8] = 8,
510c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone    };
511c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone
512c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone  /* Return immediately for forms with fixed lengths.  */
513c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone  if (form < sizeof form_lengths / sizeof form_lengths[0])
514c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone    {
515c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone      uint8_t len = form_lengths[form];
516c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone      if (len != 0)
517cb73b5a015606a02f952f7eddaba15327f6191faMark Wielaard	{
5189202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaard	  const unsigned char *endp = cu->endp;
519cb73b5a015606a02f952f7eddaba15327f6191faMark Wielaard	  len &= 0x7f; /* Mask to allow 0x80 -> 0.  */
520cb73b5a015606a02f952f7eddaba15327f6191faMark Wielaard	  if (unlikely (len > (size_t) (endp - valp)))
521cb73b5a015606a02f952f7eddaba15327f6191faMark Wielaard	    {
522cb73b5a015606a02f952f7eddaba15327f6191faMark Wielaard	      __libdw_seterrno (DWARF_E_INVALID_DWARF);
523cb73b5a015606a02f952f7eddaba15327f6191faMark Wielaard	      return -1;
524cb73b5a015606a02f952f7eddaba15327f6191faMark Wielaard	    }
525cb73b5a015606a02f952f7eddaba15327f6191faMark Wielaard	  return len;
526cb73b5a015606a02f952f7eddaba15327f6191faMark Wielaard	}
527c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone    }
528c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone
529c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone  /* Other forms require some computation.  */
5309202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaard  return __libdw_form_val_compute_len (cu, form, valp);
531c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone}
532c0d2a0b3a38bfb5164c1cf822d50e46cfad9c071Josh Stone
533e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath/* Helper function for DW_FORM_ref* handling.  */
534e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrathextern int __libdw_formref (Dwarf_Attribute *attr, Dwarf_Off *return_offset)
535e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath     __nonnull_attribute__ (1, 2) internal_function;
536e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath
537e4c22ea004c02a58f5db5eb53794275344c17958Roland McGrath
538b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Helper function to locate attribute.  */
539b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern unsigned char *__libdw_find_attr (Dwarf_Die *die,
540b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper					 unsigned int search_name,
541b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper					 unsigned int *codep,
542b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper					 unsigned int *formp)
543b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     __nonnull_attribute__ (1) internal_function;
544b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
545b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Helper function to access integer attribute.  */
5466724c90d02659f7466b67b357563042e403d154eRoland McGrathextern int __libdw_attr_intval (Dwarf_Die *die, int *valp, int attval)
547b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper     __nonnull_attribute__ (1, 2) internal_function;
548b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
5491ecb606f5af22838bf42b50dcc581d2b0f9191feRoland McGrath/* Helper function to walk scopes.  */
55071e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrathstruct Dwarf_Die_Chain
55171e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath{
55271e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath  Dwarf_Die die;
55371e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath  struct Dwarf_Die_Chain *parent;
55471e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath  bool prune;			/* The PREVISIT function can set this.  */
55571e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath};
55671e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrathextern int __libdw_visit_scopes (unsigned int depth,
55771e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath				 struct Dwarf_Die_Chain *root,
558daf278fda6d9bd329b517757f9ba2d74619f3be7Mark Wielaard				 struct Dwarf_Die_Chain *imports,
55971e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath				 int (*previsit) (unsigned int depth,
56071e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath						  struct Dwarf_Die_Chain *,
56171e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath						  void *arg),
56271e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath				 int (*postvisit) (unsigned int depth,
56371e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath						   struct Dwarf_Die_Chain *,
56471e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrath						   void *arg),
5651ecb606f5af22838bf42b50dcc581d2b0f9191feRoland McGrath				 void *arg)
566daf278fda6d9bd329b517757f9ba2d74619f3be7Mark Wielaard  __nonnull_attribute__ (2, 4) internal_function;
5671ecb606f5af22838bf42b50dcc581d2b0f9191feRoland McGrath
5683c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath/* Parse a DWARF Dwarf_Block into an array of Dwarf_Op's,
5693c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath   and cache the result (via tsearch).  */
5703c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrathextern int __libdw_intern_expression (Dwarf *dbg,
5713c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath				      bool other_byte_order,
5723c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath				      unsigned int address_size,
573688f7fcdb395cefef6a098b5ac9ddd167bb5fc3dRoland McGrath				      unsigned int ref_size,
5743c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath				      void **cache, const Dwarf_Block *block,
5750ab97839da3c382ab8799ebdbf5eb0a79bf20bdcRoland McGrath				      bool cfap, bool valuep,
5763c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath				      Dwarf_Op **llbuf, size_t *listlen,
5773c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath				      int sec_index)
578688f7fcdb395cefef6a098b5ac9ddd167bb5fc3dRoland McGrath  __nonnull_attribute__ (5, 6, 9, 10) internal_function;
5793c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath
580932585d2385c9d4e5686e4ddc9ba30c68172d7f3Roland McGrathextern Dwarf_Die *__libdw_offdie (Dwarf *dbg, Dwarf_Off offset,
581932585d2385c9d4e5686e4ddc9ba30c68172d7f3Roland McGrath				  Dwarf_Die *result, bool debug_types)
582932585d2385c9d4e5686e4ddc9ba30c68172d7f3Roland McGrath  internal_function;
583932585d2385c9d4e5686e4ddc9ba30c68172d7f3Roland McGrath
5843c84db3b4b610bf636c4363abb6d3dac5ae020f9Roland McGrath
585b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Return error code of last failing function call.  This value is kept
586b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   separately for each thread.  */
587b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern int __dwarf_errno_internal (void);
588b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
589b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
59099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper/* Reader hooks.  */
59199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper
59299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper/* Relocation hooks return -1 on error (in that case the error code
59399d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper   must already have been set), 0 if there is no relocation and 1 if a
59499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper   relocation was present.*/
59599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper
59699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepperstatic inline int
59799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper__libdw_relocate_address (Dwarf *dbg __attribute__ ((unused)),
59899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper			  int sec_index __attribute__ ((unused)),
59999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper			  const void *addr __attribute__ ((unused)),
60099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper			  int width __attribute__ ((unused)),
60199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper			  Dwarf_Addr *val __attribute__ ((unused)))
60299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper{
60399d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper  return 0;
60499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper}
60599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper
60699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepperstatic inline int
60799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper__libdw_relocate_offset (Dwarf *dbg __attribute__ ((unused)),
60899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper			 int sec_index __attribute__ ((unused)),
60999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper			 const void *addr __attribute__ ((unused)),
61099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper			 int width __attribute__ ((unused)),
61199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper			 Dwarf_Off *val __attribute__ ((unused)))
61299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper{
61399d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper  return 0;
61499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper}
61599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper
61699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepperstatic inline Elf_Data *
61799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper__libdw_checked_get_data (Dwarf *dbg, int sec_index)
61899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper{
61999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper  Elf_Data *data = dbg->sectiondata[sec_index];
62099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper  if (unlikely (data == NULL)
62199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper      || unlikely (data->d_buf == NULL))
62299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper    {
62399d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper      __libdw_seterrno (DWARF_E_INVALID_DWARF);
62499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper      return NULL;
62599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper    }
62699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper  return data;
62799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper}
62899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper
62999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepperstatic inline int
63099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper__libdw_offset_in_section (Dwarf *dbg, int sec_index,
63199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper			   Dwarf_Off offset, size_t size)
63299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper{
63399d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper  Elf_Data *data = __libdw_checked_get_data (dbg, sec_index);
63499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper  if (data == NULL)
63599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper    return -1;
63699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper  if (unlikely (offset > data->d_size)
63799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper      || unlikely (data->d_size - offset < size))
63899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper    {
63999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper      __libdw_seterrno (DWARF_E_INVALID_OFFSET);
64099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper      return -1;
64199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper    }
64299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper
64399d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper  return 0;
64499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper}
64599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper
64699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepperstatic inline bool
64799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper__libdw_in_section (Dwarf *dbg, int sec_index,
64899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper		    const void *addr, size_t size)
64999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper{
65099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper  Elf_Data *data = __libdw_checked_get_data (dbg, sec_index);
65199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper  if (data == NULL)
65299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper    return false;
65399d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper  if (unlikely (addr < data->d_buf)
65499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper      || unlikely (data->d_size - (addr - data->d_buf) < size))
65599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper    {
65699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper      __libdw_seterrno (DWARF_E_INVALID_OFFSET);
65799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper      return false;
65899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper    }
65999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper
66099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper  return true;
66199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper}
66299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper
66399d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper#define READ_AND_RELOCATE(RELOC_HOOK, VAL)				\
66499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper  ({									\
66599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper    if (!__libdw_in_section (dbg, sec_index, addr, width))		\
66699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper      return -1;							\
66799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper									\
66899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper    const unsigned char *orig_addr = addr;				\
66999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper    if (width == 4)							\
67099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper      VAL = read_4ubyte_unaligned_inc (dbg, addr);			\
67199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper    else								\
67299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper      VAL = read_8ubyte_unaligned_inc (dbg, addr);			\
67399d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper									\
67499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper    int status = RELOC_HOOK (dbg, sec_index, orig_addr, width, &VAL);	\
67599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper    if (status < 0)							\
67699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper      return status;							\
67799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper    status > 0;								\
67899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper   })
67999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper
68099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepperstatic inline int
68199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper__libdw_read_address_inc (Dwarf *dbg,
68205c4e04640d173a4d1ce6e2f25a24060c21a67abRoland McGrath			  int sec_index, const unsigned char **addrp,
68399d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper			  int width, Dwarf_Addr *ret)
68499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper{
68505c4e04640d173a4d1ce6e2f25a24060c21a67abRoland McGrath  const unsigned char *addr = *addrp;
68699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper  READ_AND_RELOCATE (__libdw_relocate_address, (*ret));
68799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper  *addrp = addr;
68899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper  return 0;
68999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper}
69099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper
69199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepperstatic inline int
69299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper__libdw_read_address (Dwarf *dbg,
69399d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper		      int sec_index, const unsigned char *addr,
69499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper		      int width, Dwarf_Addr *ret)
69599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper{
69699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper  READ_AND_RELOCATE (__libdw_relocate_address, (*ret));
69799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper  return 0;
69899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper}
69999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper
70099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepperstatic inline int
70199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper__libdw_read_offset_inc (Dwarf *dbg,
70205c4e04640d173a4d1ce6e2f25a24060c21a67abRoland McGrath			 int sec_index, const unsigned char **addrp,
70399d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper			 int width, Dwarf_Off *ret, int sec_ret,
70499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper			 size_t size)
70599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper{
70605c4e04640d173a4d1ce6e2f25a24060c21a67abRoland McGrath  const unsigned char *addr = *addrp;
70799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper  READ_AND_RELOCATE (__libdw_relocate_offset, (*ret));
70899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper  *addrp = addr;
70999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper  return __libdw_offset_in_section (dbg, sec_ret, *ret, size);
71099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper}
71199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper
71299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepperstatic inline int
713775375e3bd177cb19acb5020b6e0917551807276Mark Wielaard__libdw_read_offset (Dwarf *dbg, Dwarf *dbg_ret,
71499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper		     int sec_index, const unsigned char *addr,
71599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper		     int width, Dwarf_Off *ret, int sec_ret,
71699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper		     size_t size)
71799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper{
71899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper  READ_AND_RELOCATE (__libdw_relocate_offset, (*ret));
719775375e3bd177cb19acb5020b6e0917551807276Mark Wielaard  return __libdw_offset_in_section (dbg_ret, sec_ret, *ret, size);
72099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper}
72199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper
7223e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrathstatic inline size_t
7233e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrathcu_sec_idx (struct Dwarf_CU *cu)
7243e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath{
7253e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath  return cu->type_offset == 0 ? IDX_debug_info : IDX_debug_types;
7263e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath}
7273e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrath
72899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper/* Read up begin/end pair and increment read pointer.
72999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper    - If it's normal range record, set up *BEGINP and *ENDP and return 0.
73099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper    - If it's base address selection record, set up *BASEP and return 1.
73199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper    - If it's end of rangelist, don't set anything and return 2
73299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper    - If an error occurs, don't set anything and return <0.  */
73399d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepperint __libdw_read_begin_end_pair_inc (Dwarf *dbg, int sec_index,
73499d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper				     unsigned char **addr, int width,
73599d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper				     Dwarf_Addr *beginp, Dwarf_Addr *endp,
73699d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper				     Dwarf_Addr *basep)
73799d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper  internal_function;
73899d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper
73999d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepperunsigned char * __libdw_formptr (Dwarf_Attribute *attr, int sec_index,
74099d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper				 int err_nodata, unsigned char **endpp,
74199d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper				 Dwarf_Off *offsetp)
74299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper  internal_function;
74399d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper
7443951f2ec0aaca021c77a2c7a464dcf43433261c3Mark Wielaard/* Fills in the given attribute to point at an empty location expression.  */
7459202665816763fad8524dd78a664dbcaa157b8d4Mark Wielaardvoid __libdw_empty_loc_attr (Dwarf_Attribute *attr)
7463951f2ec0aaca021c77a2c7a464dcf43433261c3Mark Wielaard  internal_function;
7473951f2ec0aaca021c77a2c7a464dcf43433261c3Mark Wielaard
748fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata/* Load .debug_line unit at DEBUG_LINE_OFFSET.  COMP_DIR is a value of
749fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata   DW_AT_comp_dir or NULL if that attribute is not available.  Caches
750fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata   the loaded unit and optionally set *LINESP and/or *FILESP (if not
751fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata   NULL) with loaded information.  Returns 0 for success or a negative
752fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata   value for failure.  */
753fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machataint __libdw_getsrclines (Dwarf *dbg, Dwarf_Off debug_line_offset,
754fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata			 const char *comp_dir, unsigned address_size,
755fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata			 Dwarf_Lines **linesp, Dwarf_Files **filesp)
756fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  internal_function
757fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata  __nonnull_attribute__ (1);
758fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata
759fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata/* Load and return value of DW_AT_comp_dir from CUDIE.  */
760fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machataconst char *__libdw_getcompdir (Dwarf_Die *cudie);
761fb90bf3f84b5683bbc1f234ee05008ff26250e5cPetr Machata
76299d2372b25d1231d786b70278478c7a112f2b27cUlrich Drepper
763b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Aliases to avoid PLTs.  */
764ebc5c885e696cdc4961916113c50e1396d8d3d48Roland McGrathINTDECL (dwarf_aggregate_size)
765b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_attr)
766b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_attr_integrate)
767775375e3bd177cb19acb5020b6e0917551807276Mark WielaardINTDECL (dwarf_begin)
768b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_begin_elf)
769b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_child)
770b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_dieoffset)
77171e15a01742e5d5de9c6260d4526146be54e5a8aRoland McGrathINTDECL (dwarf_diename)
7724959bf89d92b59ba72bea5786d7b3f9b5564f750Roland McGrathINTDECL (dwarf_end)
77307d4f2fc1cb53f170a71bc13617bbdd9cb1c3c60Roland McGrathINTDECL (dwarf_entrypc)
7744959bf89d92b59ba72bea5786d7b3f9b5564f750Roland McGrathINTDECL (dwarf_errmsg)
775b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_formaddr)
776b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_formblock)
777b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_formref_die)
778b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_formsdata)
779b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_formstring)
780b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_formudata)
78135e2a765c002374f1b88dc81ce154bed42f9b1d8Florian WeimerINTDECL (dwarf_getalt)
782b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_getarange_addr)
783b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_getarangeinfo)
784b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_getaranges)
785b2535b6a6be7717cdd41834d76e5cb48cb446b83Mark WielaardINTDECL (dwarf_getlocation_die)
786b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_getsrcfiles)
787b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_getsrclines)
788b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_hasattr)
789b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_haschildren)
790b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_haspc)
791b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_highpc)
792b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_lowpc)
793b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_nextcu)
7943e0f7d1d1b817040cef82f41879f471ab59b663eRoland McGrathINTDECL (dwarf_next_unit)
795b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_offdie)
7963a36e8a26c32103ec2f8edda8bf212d6883970a2Mark WielaardINTDECL (dwarf_peel_type)
79707d4f2fc1cb53f170a71bc13617bbdd9cb1c3c60Roland McGrathINTDECL (dwarf_ranges)
79835e2a765c002374f1b88dc81ce154bed42f9b1d8Florian WeimerINTDECL (dwarf_setalt)
799b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_siblingof)
800ebc5c885e696cdc4961916113c50e1396d8d3d48Roland McGrathINTDECL (dwarf_srclang)
801b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperINTDECL (dwarf_tag)
802b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
803b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#endif	/* libdwP.h */
804