Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 1 | /* Internal definitions for libdwarf. |
Roland McGrath | c5acb30 | 2009-01-28 18:28:52 -0800 | [diff] [blame] | 2 | Copyright (C) 2002-2009 Red Hat, Inc. |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 3 | This file is part of Red Hat elfutils. |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 4 | Written by Ulrich Drepper <drepper@redhat.com>, 2002. |
| 5 | |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 6 | Red Hat elfutils is free software; you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by the |
| 8 | Free Software Foundation; version 2 of the License. |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 9 | |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 10 | Red Hat elfutils is distributed in the hope that it will be useful, but |
| 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License along |
| 16 | with Red Hat elfutils; if not, write to the Free Software Foundation, |
Ulrich Drepper | 1e9ef50 | 2006-04-04 22:29:06 +0000 | [diff] [blame] | 17 | Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA. |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 18 | |
| 19 | In addition, as a special exception, Red Hat, Inc. gives You the |
| 20 | additional right to link the code of Red Hat elfutils with code licensed |
| 21 | under any Open Source Initiative certified open source license |
| 22 | (http://www.opensource.org/licenses/index.php) which requires the |
| 23 | distribution of source code with any binary distribution and to |
| 24 | distribute linked combinations of the two. Non-GPL Code permitted under |
| 25 | this exception must only link to the code of Red Hat elfutils through |
| 26 | those well defined interfaces identified in the file named EXCEPTION |
| 27 | found in the source code files (the "Approved Interfaces"). The files |
| 28 | of Non-GPL Code may instantiate templates or use macros or inline |
| 29 | functions from the Approved Interfaces without causing the resulting |
| 30 | work to be covered by the GNU General Public License. Only Red Hat, |
| 31 | Inc. may make changes or additions to the list of Approved Interfaces. |
| 32 | Red Hat's grant of this exception is conditioned upon your not adding |
| 33 | any new exceptions. If you wish to add a new Approved Interface or |
| 34 | exception, please contact Red Hat. You must obey the GNU General Public |
| 35 | License in all respects for all of the Red Hat elfutils code and other |
| 36 | code used in conjunction with Red Hat elfutils except the Non-GPL Code |
| 37 | covered by this exception. If you modify this file, you may extend this |
| 38 | exception to your version of the file, but you are not obligated to do |
| 39 | so. If you do not wish to provide this exception without modification, |
| 40 | you must delete this exception statement from your version and license |
| 41 | this file solely under the GPL without exception. |
| 42 | |
| 43 | Red Hat elfutils is an included package of the Open Invention Network. |
| 44 | An included package of the Open Invention Network is a package for which |
| 45 | Open Invention Network licensees cross-license their patents. No patent |
| 46 | license is granted, either expressly or impliedly, by designation as an |
| 47 | included package. Should you wish to participate in the Open Invention |
| 48 | Network licensing program, please visit www.openinventionnetwork.com |
| 49 | <http://www.openinventionnetwork.com>. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 50 | |
| 51 | #ifndef _LIBDWP_H |
| 52 | #define _LIBDWP_H 1 |
| 53 | |
| 54 | #include <libintl.h> |
| 55 | #include <stdbool.h> |
| 56 | |
| 57 | #include <libdw.h> |
| 58 | |
| 59 | |
| 60 | /* gettext helper macros. */ |
| 61 | #define _(Str) dgettext ("elfutils", Str) |
| 62 | |
| 63 | |
| 64 | /* Version of the DWARF specification we support. */ |
Ulrich Drepper | 35f08c4 | 2008-01-18 19:59:08 +0000 | [diff] [blame] | 65 | #define DWARF_VERSION 3 |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 66 | |
| 67 | /* Version of the CIE format. */ |
| 68 | #define CIE_VERSION 1 |
| 69 | |
| 70 | |
Roland McGrath | 6724c90 | 2005-10-28 07:07:19 +0000 | [diff] [blame] | 71 | /* Known location expressions already decoded. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 72 | struct loc_s |
| 73 | { |
| 74 | void *addr; |
Roland McGrath | 6724c90 | 2005-10-28 07:07:19 +0000 | [diff] [blame] | 75 | Dwarf_Op *loc; |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 76 | size_t nloc; |
| 77 | }; |
| 78 | |
Roland McGrath | f037104 | 2009-09-10 12:39:09 -0700 | [diff] [blame^] | 79 | /* Known DW_OP_implicit_value blocks already decoded. |
| 80 | This overlaps struct loc_s exactly, but only the |
| 81 | first member really has to match. */ |
| 82 | struct loc_block_s |
| 83 | { |
| 84 | void *addr; |
| 85 | unsigned char *data; |
| 86 | size_t length; |
| 87 | }; |
| 88 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 89 | /* Valid indeces for the section data. */ |
| 90 | enum |
| 91 | { |
| 92 | IDX_debug_info = 0, |
| 93 | IDX_debug_abbrev, |
| 94 | IDX_debug_aranges, |
| 95 | IDX_debug_line, |
| 96 | IDX_debug_frame, |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 97 | IDX_debug_loc, |
| 98 | IDX_debug_pubnames, |
| 99 | IDX_debug_str, |
| 100 | IDX_debug_funcnames, |
| 101 | IDX_debug_typenames, |
| 102 | IDX_debug_varnames, |
| 103 | IDX_debug_weaknames, |
| 104 | IDX_debug_macinfo, |
| 105 | IDX_debug_ranges, |
| 106 | IDX_last |
| 107 | }; |
| 108 | |
| 109 | |
| 110 | /* Error values. */ |
| 111 | enum |
| 112 | { |
| 113 | DWARF_E_NOERROR = 0, |
| 114 | DWARF_E_UNKNOWN_ERROR, |
| 115 | DWARF_E_INVALID_ACCESS, |
| 116 | DWARF_E_NO_REGFILE, |
| 117 | DWARF_E_IO_ERROR, |
| 118 | DWARF_E_INVALID_ELF, |
| 119 | DWARF_E_NO_DWARF, |
| 120 | DWARF_E_NOELF, |
| 121 | DWARF_E_GETEHDR_ERROR, |
| 122 | DWARF_E_NOMEM, |
| 123 | DWARF_E_UNIMPL, |
| 124 | DWARF_E_INVALID_CMD, |
| 125 | DWARF_E_INVALID_VERSION, |
| 126 | DWARF_E_INVALID_FILE, |
| 127 | DWARF_E_NO_ENTRY, |
| 128 | DWARF_E_INVALID_DWARF, |
| 129 | DWARF_E_NO_STRING, |
| 130 | DWARF_E_NO_ADDR, |
| 131 | DWARF_E_NO_CONSTANT, |
| 132 | DWARF_E_NO_REFERENCE, |
| 133 | DWARF_E_INVALID_REFERENCE, |
| 134 | DWARF_E_NO_DEBUG_LINE, |
| 135 | DWARF_E_INVALID_DEBUG_LINE, |
| 136 | DWARF_E_TOO_BIG, |
| 137 | DWARF_E_VERSION, |
| 138 | DWARF_E_INVALID_DIR_IDX, |
| 139 | DWARF_E_ADDR_OUTOFRANGE, |
| 140 | DWARF_E_NO_LOCLIST, |
| 141 | DWARF_E_NO_BLOCK, |
| 142 | DWARF_E_INVALID_LINE_IDX, |
| 143 | DWARF_E_INVALID_ARANGE_IDX, |
| 144 | DWARF_E_NO_MATCH, |
| 145 | DWARF_E_NO_FLAG, |
| 146 | DWARF_E_INVALID_OFFSET, |
| 147 | DWARF_E_NO_DEBUG_RANGES, |
Roland McGrath | 3c84db3 | 2009-06-24 17:41:40 -0700 | [diff] [blame] | 148 | DWARF_E_INVALID_CFI, |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | |
| 152 | /* This is the structure representing the debugging state. */ |
| 153 | struct Dwarf |
| 154 | { |
| 155 | /* The underlying ELF file. */ |
| 156 | Elf *elf; |
| 157 | |
| 158 | /* The section data. */ |
| 159 | Elf_Data *sectiondata[IDX_last]; |
| 160 | |
| 161 | /* True if the file has a byte order different from the host. */ |
| 162 | bool other_byte_order; |
| 163 | |
| 164 | /* If true, we allocated the ELF descriptor ourselves. */ |
| 165 | bool free_elf; |
| 166 | |
| 167 | /* Information for traversing the .debug_pubnames section. This is |
| 168 | an array and separately allocated with malloc. */ |
| 169 | struct pubnames_s |
| 170 | { |
| 171 | Dwarf_Off cu_offset; |
| 172 | Dwarf_Off set_start; |
| 173 | unsigned int cu_header_size; |
| 174 | int address_len; |
| 175 | } *pubnames_sets; |
| 176 | size_t pubnames_nsets; |
| 177 | |
| 178 | /* Search tree for the CUs. */ |
| 179 | void *cu_tree; |
| 180 | Dwarf_Off next_cu_offset; |
| 181 | |
| 182 | /* Address ranges. */ |
| 183 | Dwarf_Aranges *aranges; |
| 184 | |
Roland McGrath | 3c84db3 | 2009-06-24 17:41:40 -0700 | [diff] [blame] | 185 | /* Cached info from the CFI section. */ |
| 186 | struct Dwarf_CFI_s *cfi; |
| 187 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 188 | /* Internal memory handling. This is basically a simplified |
| 189 | reimplementation of obstacks. Unfortunately the standard obstack |
| 190 | implementation is not usable in libraries. */ |
| 191 | struct libdw_memblock |
| 192 | { |
| 193 | size_t size; |
| 194 | size_t remaining; |
| 195 | struct libdw_memblock *prev; |
| 196 | char mem[0]; |
| 197 | } *mem_tail; |
| 198 | |
| 199 | /* Default size of allocated memory blocks. */ |
| 200 | size_t mem_default_size; |
| 201 | |
| 202 | /* Registered OOM handler. */ |
| 203 | Dwarf_OOM oom_handler; |
| 204 | }; |
| 205 | |
| 206 | |
| 207 | /* Abbreviation representation. */ |
| 208 | struct Dwarf_Abbrev |
| 209 | { |
Roland McGrath | 1f6d201 | 2008-12-31 00:21:04 -0800 | [diff] [blame] | 210 | Dwarf_Off offset; |
| 211 | unsigned char *attrp; |
| 212 | unsigned int attrcnt; |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 213 | unsigned int code; |
| 214 | unsigned int tag; |
Roland McGrath | 1f6d201 | 2008-12-31 00:21:04 -0800 | [diff] [blame] | 215 | bool has_children; |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 216 | }; |
| 217 | |
| 218 | #include "dwarf_abbrev_hash.h" |
| 219 | |
| 220 | |
| 221 | /* Files in line information records. */ |
| 222 | struct Dwarf_Files_s |
| 223 | { |
Roland McGrath | c5acb30 | 2009-01-28 18:28:52 -0800 | [diff] [blame] | 224 | struct Dwarf_CU *cu; |
Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 225 | unsigned int ndirs; |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 226 | unsigned int nfiles; |
| 227 | struct Dwarf_Fileinfo_s |
| 228 | { |
| 229 | char *name; |
| 230 | Dwarf_Word mtime; |
| 231 | Dwarf_Word length; |
| 232 | } info[0]; |
Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 233 | /* nfiles of those, followed by char *[ndirs]. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 234 | }; |
| 235 | typedef struct Dwarf_Fileinfo_s Dwarf_Fileinfo; |
| 236 | |
| 237 | |
| 238 | /* Representation of a row in the line table. */ |
Roland McGrath | 03288f0 | 2009-01-28 22:00:54 -0800 | [diff] [blame] | 239 | |
| 240 | struct Dwarf_Line_s |
| 241 | { |
Roland McGrath | 6e1f465 | 2009-07-08 14:48:34 -0700 | [diff] [blame] | 242 | Dwarf_Files *files; |
| 243 | |
Roland McGrath | 03288f0 | 2009-01-28 22:00:54 -0800 | [diff] [blame] | 244 | Dwarf_Addr addr; |
| 245 | unsigned int file; |
| 246 | int line; |
| 247 | unsigned short int column; |
| 248 | unsigned int is_stmt:1; |
| 249 | unsigned int basic_block:1; |
| 250 | unsigned int end_sequence:1; |
| 251 | unsigned int prologue_end:1; |
| 252 | unsigned int epilogue_begin:1; |
Roland McGrath | 03288f0 | 2009-01-28 22:00:54 -0800 | [diff] [blame] | 253 | }; |
| 254 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 255 | struct Dwarf_Lines_s |
Roland McGrath | 03288f0 | 2009-01-28 22:00:54 -0800 | [diff] [blame] | 256 | { |
| 257 | size_t nlines; |
| 258 | struct Dwarf_Line_s info[0]; |
| 259 | }; |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 260 | |
| 261 | /* Representation of address ranges. */ |
| 262 | struct Dwarf_Aranges_s |
| 263 | { |
| 264 | Dwarf *dbg; |
| 265 | size_t naranges; |
| 266 | |
| 267 | struct Dwarf_Arange_s |
| 268 | { |
| 269 | Dwarf_Addr addr; |
| 270 | Dwarf_Word length; |
| 271 | Dwarf_Off offset; |
| 272 | } info[0]; |
| 273 | }; |
| 274 | |
| 275 | |
| 276 | /* CU representation. */ |
| 277 | struct Dwarf_CU |
| 278 | { |
| 279 | Dwarf *dbg; |
| 280 | Dwarf_Off start; |
| 281 | Dwarf_Off end; |
| 282 | uint8_t address_size; |
| 283 | uint8_t offset_size; |
Roland McGrath | e4c22ea | 2007-10-23 13:07:39 +0000 | [diff] [blame] | 284 | uint16_t version; |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 285 | |
| 286 | /* Hash table for the abbreviations. */ |
| 287 | Dwarf_Abbrev_Hash abbrev_hash; |
| 288 | /* Offset of the first abbreviation. */ |
| 289 | size_t orig_abbrev_offset; |
| 290 | /* Offset past last read abbreviation. */ |
| 291 | size_t last_abbrev_offset; |
| 292 | |
| 293 | /* The srcline information. */ |
| 294 | Dwarf_Lines *lines; |
| 295 | |
| 296 | /* The source file information. */ |
| 297 | Dwarf_Files *files; |
| 298 | |
| 299 | /* Known location lists. */ |
| 300 | void *locs; |
| 301 | }; |
| 302 | |
Ulrich Drepper | 35f08c4 | 2008-01-18 19:59:08 +0000 | [diff] [blame] | 303 | /* Compute the offset of a CU's first DIE from its offset. This |
| 304 | is either: |
| 305 | LEN VER OFFSET ADDR |
| 306 | 4-bytes + 2-bytes + 4-bytes + 1-byte for 32-bit dwarf |
| 307 | 12-bytes + 2-bytes + 8-bytes + 1-byte for 64-bit dwarf |
Ulrich Drepper | a969d8e | 2008-01-22 06:15:00 +0000 | [diff] [blame] | 308 | |
Ulrich Drepper | 35f08c4 | 2008-01-18 19:59:08 +0000 | [diff] [blame] | 309 | Note the trick in the computation. If the offset_size is 4 |
| 310 | the '- 4' term changes the '3 *' into a '2 *'. If the |
| 311 | offset_size is 8 it accounts for the 4-byte escape value |
| 312 | used at the start of the length. */ |
| 313 | #define DIE_OFFSET_FROM_CU_OFFSET(cu_offset, offset_size) \ |
| 314 | ((cu_offset) + 3 * (offset_size) - 4 + 3) |
| 315 | |
Ulrich Drepper | db1d543 | 2006-10-10 15:34:34 +0000 | [diff] [blame] | 316 | #define CUDIE(fromcu) \ |
Roland McGrath | 6724c90 | 2005-10-28 07:07:19 +0000 | [diff] [blame] | 317 | ((Dwarf_Die) \ |
| 318 | { \ |
| 319 | .cu = (fromcu), \ |
| 320 | .addr = ((char *) (fromcu)->dbg->sectiondata[IDX_debug_info]->d_buf \ |
| 321 | + (fromcu)->start + 3 * (fromcu)->offset_size - 4 + 3), \ |
| 322 | }) |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 323 | |
| 324 | |
| 325 | /* Macro information. */ |
| 326 | struct Dwarf_Macro_s |
| 327 | { |
| 328 | unsigned int opcode; |
| 329 | Dwarf_Word param1; |
| 330 | union |
| 331 | { |
| 332 | Dwarf_Word u; |
| 333 | const char *s; |
| 334 | } param2; |
| 335 | }; |
| 336 | |
| 337 | |
| 338 | /* We have to include the file at this point because the inline |
| 339 | functions access internals of the Dwarf structure. */ |
| 340 | #include "memory-access.h" |
| 341 | |
| 342 | |
| 343 | /* Set error value. */ |
| 344 | extern void __libdw_seterrno (int value) internal_function; |
| 345 | |
| 346 | |
| 347 | /* Memory handling, the easy parts. This macro does not do any locking. */ |
Ulrich Drepper | db1d543 | 2006-10-10 15:34:34 +0000 | [diff] [blame] | 348 | #define libdw_alloc(dbg, type, tsize, cnt) \ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 349 | ({ struct libdw_memblock *_tail = (dbg)->mem_tail; \ |
| 350 | size_t _required = (tsize) * (cnt); \ |
| 351 | type *_result = (type *) (_tail->mem + (_tail->size - _tail->remaining));\ |
| 352 | size_t _padding = ((__alignof (type) \ |
| 353 | - ((uintptr_t) _result & (__alignof (type) - 1))) \ |
| 354 | & (__alignof (type) - 1)); \ |
| 355 | if (unlikely (_tail->remaining < _required + _padding)) \ |
Roland McGrath | c373d85 | 2006-10-10 00:25:21 +0000 | [diff] [blame] | 356 | _result = (type *) __libdw_allocate (dbg, _required, __alignof (type));\ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 357 | else \ |
| 358 | { \ |
| 359 | _required += _padding; \ |
| 360 | _result = (type *) ((char *) _result + _padding); \ |
Roland McGrath | c373d85 | 2006-10-10 00:25:21 +0000 | [diff] [blame] | 361 | _tail->remaining -= _required; \ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 362 | } \ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 363 | _result; }) |
| 364 | |
| 365 | #define libdw_typed_alloc(dbg, type) \ |
| 366 | libdw_alloc (dbg, type, sizeof (type), 1) |
| 367 | |
| 368 | /* Callback to allocate more. */ |
Roland McGrath | c373d85 | 2006-10-10 00:25:21 +0000 | [diff] [blame] | 369 | extern void *__libdw_allocate (Dwarf *dbg, size_t minsize, size_t align) |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 370 | __attribute__ ((__malloc__)) __nonnull_attribute__ (1); |
| 371 | |
| 372 | /* Default OOM handler. */ |
| 373 | extern void __libdw_oom (void) __attribute ((noreturn, visibility ("hidden"))); |
| 374 | |
| 375 | /* Find CU for given offset. */ |
| 376 | extern struct Dwarf_CU *__libdw_findcu (Dwarf *dbg, Dwarf_Off offset) |
| 377 | __nonnull_attribute__ (1) internal_function; |
| 378 | |
| 379 | /* Return tag of given DIE. */ |
| 380 | extern Dwarf_Abbrev *__libdw_findabbrev (struct Dwarf_CU *cu, |
| 381 | unsigned int code) |
| 382 | __nonnull_attribute__ (1) internal_function; |
| 383 | |
| 384 | /* Get abbreviation at given offset. */ |
| 385 | extern Dwarf_Abbrev *__libdw_getabbrev (Dwarf *dbg, struct Dwarf_CU *cu, |
| 386 | Dwarf_Off offset, size_t *lengthp, |
| 387 | Dwarf_Abbrev *result) |
| 388 | __nonnull_attribute__ (1) internal_function; |
| 389 | |
| 390 | /* Helper functions for form handling. */ |
| 391 | extern size_t __libdw_form_val_len (Dwarf *dbg, struct Dwarf_CU *cu, |
| 392 | unsigned int form, |
| 393 | const unsigned char *valp) |
| 394 | __nonnull_attribute__ (1, 2, 4) internal_function; |
| 395 | |
Roland McGrath | e4c22ea | 2007-10-23 13:07:39 +0000 | [diff] [blame] | 396 | /* Helper function for DW_FORM_ref* handling. */ |
| 397 | extern int __libdw_formref (Dwarf_Attribute *attr, Dwarf_Off *return_offset) |
| 398 | __nonnull_attribute__ (1, 2) internal_function; |
| 399 | |
| 400 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 401 | /* Helper function to locate attribute. */ |
| 402 | extern unsigned char *__libdw_find_attr (Dwarf_Die *die, |
| 403 | unsigned int search_name, |
| 404 | unsigned int *codep, |
| 405 | unsigned int *formp) |
| 406 | __nonnull_attribute__ (1) internal_function; |
| 407 | |
| 408 | /* Helper function to access integer attribute. */ |
Roland McGrath | 6724c90 | 2005-10-28 07:07:19 +0000 | [diff] [blame] | 409 | extern int __libdw_attr_intval (Dwarf_Die *die, int *valp, int attval) |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 410 | __nonnull_attribute__ (1, 2) internal_function; |
| 411 | |
Roland McGrath | 1ecb606 | 2005-08-15 09:53:04 +0000 | [diff] [blame] | 412 | /* Helper function to walk scopes. */ |
Roland McGrath | 71e15a0 | 2005-08-27 10:33:26 +0000 | [diff] [blame] | 413 | struct Dwarf_Die_Chain |
| 414 | { |
| 415 | Dwarf_Die die; |
| 416 | struct Dwarf_Die_Chain *parent; |
| 417 | bool prune; /* The PREVISIT function can set this. */ |
| 418 | }; |
| 419 | extern int __libdw_visit_scopes (unsigned int depth, |
| 420 | struct Dwarf_Die_Chain *root, |
| 421 | int (*previsit) (unsigned int depth, |
| 422 | struct Dwarf_Die_Chain *, |
| 423 | void *arg), |
| 424 | int (*postvisit) (unsigned int depth, |
| 425 | struct Dwarf_Die_Chain *, |
| 426 | void *arg), |
Roland McGrath | 1ecb606 | 2005-08-15 09:53:04 +0000 | [diff] [blame] | 427 | void *arg) |
| 428 | __nonnull_attribute__ (2, 3) internal_function; |
| 429 | |
Roland McGrath | 3c84db3 | 2009-06-24 17:41:40 -0700 | [diff] [blame] | 430 | /* Parse a DWARF Dwarf_Block into an array of Dwarf_Op's, |
| 431 | and cache the result (via tsearch). */ |
| 432 | extern int __libdw_intern_expression (Dwarf *dbg, |
| 433 | bool other_byte_order, |
| 434 | unsigned int address_size, |
| 435 | void **cache, const Dwarf_Block *block, |
Roland McGrath | af80014 | 2009-07-22 13:55:50 -0700 | [diff] [blame] | 436 | bool valuep, |
Roland McGrath | 3c84db3 | 2009-06-24 17:41:40 -0700 | [diff] [blame] | 437 | Dwarf_Op **llbuf, size_t *listlen, |
| 438 | int sec_index) |
Roland McGrath | af80014 | 2009-07-22 13:55:50 -0700 | [diff] [blame] | 439 | __nonnull_attribute__ (4, 5, 7, 8) internal_function; |
Roland McGrath | 3c84db3 | 2009-06-24 17:41:40 -0700 | [diff] [blame] | 440 | |
| 441 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 442 | /* Return error code of last failing function call. This value is kept |
| 443 | separately for each thread. */ |
| 444 | extern int __dwarf_errno_internal (void); |
| 445 | |
| 446 | |
Ulrich Drepper | 99d2372 | 2009-06-14 20:19:45 -0700 | [diff] [blame] | 447 | /* Reader hooks. */ |
| 448 | |
| 449 | /* Relocation hooks return -1 on error (in that case the error code |
| 450 | must already have been set), 0 if there is no relocation and 1 if a |
| 451 | relocation was present.*/ |
| 452 | |
| 453 | static inline int |
| 454 | __libdw_relocate_address (Dwarf *dbg __attribute__ ((unused)), |
| 455 | int sec_index __attribute__ ((unused)), |
| 456 | const void *addr __attribute__ ((unused)), |
| 457 | int width __attribute__ ((unused)), |
| 458 | Dwarf_Addr *val __attribute__ ((unused))) |
| 459 | { |
| 460 | return 0; |
| 461 | } |
| 462 | |
| 463 | static inline int |
| 464 | __libdw_relocate_offset (Dwarf *dbg __attribute__ ((unused)), |
| 465 | int sec_index __attribute__ ((unused)), |
| 466 | const void *addr __attribute__ ((unused)), |
| 467 | int width __attribute__ ((unused)), |
| 468 | Dwarf_Off *val __attribute__ ((unused))) |
| 469 | { |
| 470 | return 0; |
| 471 | } |
| 472 | |
| 473 | static inline Elf_Data * |
| 474 | __libdw_checked_get_data (Dwarf *dbg, int sec_index) |
| 475 | { |
| 476 | Elf_Data *data = dbg->sectiondata[sec_index]; |
| 477 | if (unlikely (data == NULL) |
| 478 | || unlikely (data->d_buf == NULL)) |
| 479 | { |
| 480 | __libdw_seterrno (DWARF_E_INVALID_DWARF); |
| 481 | return NULL; |
| 482 | } |
| 483 | return data; |
| 484 | } |
| 485 | |
| 486 | static inline int |
| 487 | __libdw_offset_in_section (Dwarf *dbg, int sec_index, |
| 488 | Dwarf_Off offset, size_t size) |
| 489 | { |
| 490 | Elf_Data *data = __libdw_checked_get_data (dbg, sec_index); |
| 491 | if (data == NULL) |
| 492 | return -1; |
| 493 | if (unlikely (offset > data->d_size) |
| 494 | || unlikely (data->d_size - offset < size)) |
| 495 | { |
| 496 | __libdw_seterrno (DWARF_E_INVALID_OFFSET); |
| 497 | return -1; |
| 498 | } |
| 499 | |
| 500 | return 0; |
| 501 | } |
| 502 | |
| 503 | static inline bool |
| 504 | __libdw_in_section (Dwarf *dbg, int sec_index, |
| 505 | const void *addr, size_t size) |
| 506 | { |
| 507 | Elf_Data *data = __libdw_checked_get_data (dbg, sec_index); |
| 508 | if (data == NULL) |
| 509 | return false; |
| 510 | if (unlikely (addr < data->d_buf) |
| 511 | || unlikely (data->d_size - (addr - data->d_buf) < size)) |
| 512 | { |
| 513 | __libdw_seterrno (DWARF_E_INVALID_OFFSET); |
| 514 | return false; |
| 515 | } |
| 516 | |
| 517 | return true; |
| 518 | } |
| 519 | |
| 520 | #define READ_AND_RELOCATE(RELOC_HOOK, VAL) \ |
| 521 | ({ \ |
| 522 | if (!__libdw_in_section (dbg, sec_index, addr, width)) \ |
| 523 | return -1; \ |
| 524 | \ |
| 525 | const unsigned char *orig_addr = addr; \ |
| 526 | if (width == 4) \ |
| 527 | VAL = read_4ubyte_unaligned_inc (dbg, addr); \ |
| 528 | else \ |
| 529 | VAL = read_8ubyte_unaligned_inc (dbg, addr); \ |
| 530 | \ |
| 531 | int status = RELOC_HOOK (dbg, sec_index, orig_addr, width, &VAL); \ |
| 532 | if (status < 0) \ |
| 533 | return status; \ |
| 534 | status > 0; \ |
| 535 | }) |
| 536 | |
| 537 | static inline int |
| 538 | __libdw_read_address_inc (Dwarf *dbg, |
Roland McGrath | 05c4e04 | 2009-06-18 13:56:02 -0700 | [diff] [blame] | 539 | int sec_index, const unsigned char **addrp, |
Ulrich Drepper | 99d2372 | 2009-06-14 20:19:45 -0700 | [diff] [blame] | 540 | int width, Dwarf_Addr *ret) |
| 541 | { |
Roland McGrath | 05c4e04 | 2009-06-18 13:56:02 -0700 | [diff] [blame] | 542 | const unsigned char *addr = *addrp; |
Ulrich Drepper | 99d2372 | 2009-06-14 20:19:45 -0700 | [diff] [blame] | 543 | READ_AND_RELOCATE (__libdw_relocate_address, (*ret)); |
| 544 | *addrp = addr; |
| 545 | return 0; |
| 546 | } |
| 547 | |
| 548 | static inline int |
| 549 | __libdw_read_address (Dwarf *dbg, |
| 550 | int sec_index, const unsigned char *addr, |
| 551 | int width, Dwarf_Addr *ret) |
| 552 | { |
| 553 | READ_AND_RELOCATE (__libdw_relocate_address, (*ret)); |
| 554 | return 0; |
| 555 | } |
| 556 | |
| 557 | static inline int |
| 558 | __libdw_read_offset_inc (Dwarf *dbg, |
Roland McGrath | 05c4e04 | 2009-06-18 13:56:02 -0700 | [diff] [blame] | 559 | int sec_index, const unsigned char **addrp, |
Ulrich Drepper | 99d2372 | 2009-06-14 20:19:45 -0700 | [diff] [blame] | 560 | int width, Dwarf_Off *ret, int sec_ret, |
| 561 | size_t size) |
| 562 | { |
Roland McGrath | 05c4e04 | 2009-06-18 13:56:02 -0700 | [diff] [blame] | 563 | const unsigned char *addr = *addrp; |
Ulrich Drepper | 99d2372 | 2009-06-14 20:19:45 -0700 | [diff] [blame] | 564 | READ_AND_RELOCATE (__libdw_relocate_offset, (*ret)); |
| 565 | *addrp = addr; |
| 566 | return __libdw_offset_in_section (dbg, sec_ret, *ret, size); |
| 567 | } |
| 568 | |
| 569 | static inline int |
| 570 | __libdw_read_offset (Dwarf *dbg, |
| 571 | int sec_index, const unsigned char *addr, |
| 572 | int width, Dwarf_Off *ret, int sec_ret, |
| 573 | size_t size) |
| 574 | { |
| 575 | READ_AND_RELOCATE (__libdw_relocate_offset, (*ret)); |
| 576 | return __libdw_offset_in_section (dbg, sec_ret, *ret, size); |
| 577 | } |
| 578 | |
| 579 | /* Read up begin/end pair and increment read pointer. |
| 580 | - If it's normal range record, set up *BEGINP and *ENDP and return 0. |
| 581 | - If it's base address selection record, set up *BASEP and return 1. |
| 582 | - If it's end of rangelist, don't set anything and return 2 |
| 583 | - If an error occurs, don't set anything and return <0. */ |
| 584 | int __libdw_read_begin_end_pair_inc (Dwarf *dbg, int sec_index, |
| 585 | unsigned char **addr, int width, |
| 586 | Dwarf_Addr *beginp, Dwarf_Addr *endp, |
| 587 | Dwarf_Addr *basep) |
| 588 | internal_function; |
| 589 | |
| 590 | unsigned char * __libdw_formptr (Dwarf_Attribute *attr, int sec_index, |
| 591 | int err_nodata, unsigned char **endpp, |
| 592 | Dwarf_Off *offsetp) |
| 593 | internal_function; |
| 594 | |
| 595 | |
| 596 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 597 | /* Aliases to avoid PLTs. */ |
| 598 | INTDECL (dwarf_attr) |
| 599 | INTDECL (dwarf_attr_integrate) |
| 600 | INTDECL (dwarf_begin_elf) |
| 601 | INTDECL (dwarf_child) |
| 602 | INTDECL (dwarf_dieoffset) |
Roland McGrath | 71e15a0 | 2005-08-27 10:33:26 +0000 | [diff] [blame] | 603 | INTDECL (dwarf_diename) |
Roland McGrath | 4959bf8 | 2005-08-09 10:31:08 +0000 | [diff] [blame] | 604 | INTDECL (dwarf_end) |
Roland McGrath | 07d4f2f | 2005-10-28 06:56:24 +0000 | [diff] [blame] | 605 | INTDECL (dwarf_entrypc) |
Roland McGrath | 4959bf8 | 2005-08-09 10:31:08 +0000 | [diff] [blame] | 606 | INTDECL (dwarf_errmsg) |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 607 | INTDECL (dwarf_formaddr) |
| 608 | INTDECL (dwarf_formblock) |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 609 | INTDECL (dwarf_formref_die) |
| 610 | INTDECL (dwarf_formsdata) |
| 611 | INTDECL (dwarf_formstring) |
| 612 | INTDECL (dwarf_formudata) |
| 613 | INTDECL (dwarf_getarange_addr) |
| 614 | INTDECL (dwarf_getarangeinfo) |
| 615 | INTDECL (dwarf_getaranges) |
| 616 | INTDECL (dwarf_getsrcfiles) |
| 617 | INTDECL (dwarf_getsrclines) |
| 618 | INTDECL (dwarf_hasattr) |
| 619 | INTDECL (dwarf_haschildren) |
| 620 | INTDECL (dwarf_haspc) |
| 621 | INTDECL (dwarf_highpc) |
| 622 | INTDECL (dwarf_lowpc) |
| 623 | INTDECL (dwarf_nextcu) |
| 624 | INTDECL (dwarf_offdie) |
Roland McGrath | 07d4f2f | 2005-10-28 06:56:24 +0000 | [diff] [blame] | 625 | INTDECL (dwarf_ranges) |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 626 | INTDECL (dwarf_siblingof) |
| 627 | INTDECL (dwarf_tag) |
| 628 | |
| 629 | #endif /* libdwP.h */ |