Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 1 | /* Interfaces for libdw. |
Mark Wielaard | 209f149 | 2014-08-15 13:08:24 +0200 | [diff] [blame] | 2 | Copyright (C) 2002-2010, 2013, 2014 Red Hat, Inc. |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 3 | This file is part of elfutils. |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 4 | |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 5 | This file is free software; you can redistribute it and/or modify |
| 6 | it under the terms of either |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 7 | |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 8 | * the GNU Lesser General Public License as published by the Free |
| 9 | Software Foundation; either version 3 of the License, or (at |
| 10 | your option) any later version |
| 11 | |
| 12 | or |
| 13 | |
| 14 | * the GNU General Public License as published by the Free |
| 15 | Software Foundation; either version 2 of the License, or (at |
| 16 | your option) any later version |
| 17 | |
| 18 | or both in parallel, as here. |
| 19 | |
| 20 | elfutils is distributed in the hope that it will be useful, but |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 21 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 23 | General Public License for more details. |
| 24 | |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 25 | You should have received copies of the GNU General Public License and |
| 26 | the GNU Lesser General Public License along with this program. If |
| 27 | not, see <http://www.gnu.org/licenses/>. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 28 | |
| 29 | #ifndef _LIBDW_H |
| 30 | #define _LIBDW_H 1 |
| 31 | |
| 32 | #include <gelf.h> |
| 33 | #include <stdbool.h> |
| 34 | #include <stddef.h> |
| 35 | |
| 36 | |
| 37 | #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) |
| 38 | # define __nonnull_attribute__(...) __attribute__ ((__nonnull__ (__VA_ARGS__))) |
Roland McGrath | e4c22ea | 2007-10-23 13:07:39 +0000 | [diff] [blame] | 39 | # define __deprecated_attribute__ __attribute__ ((__deprecated__)) |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 40 | #else |
| 41 | # define __nonnull_attribute__(args...) |
Roland McGrath | e4c22ea | 2007-10-23 13:07:39 +0000 | [diff] [blame] | 42 | # define __deprecated_attribute__ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 43 | #endif |
| 44 | |
Roland McGrath | e4c22ea | 2007-10-23 13:07:39 +0000 | [diff] [blame] | 45 | |
Roland McGrath | 87d4780 | 2007-07-16 22:23:37 +0000 | [diff] [blame] | 46 | #ifdef __GNUC_STDC_INLINE__ |
Ulrich Drepper | b597dfa | 2007-10-16 05:21:27 +0000 | [diff] [blame] | 47 | # define __libdw_extern_inline extern __inline __attribute__ ((__gnu_inline__)) |
Roland McGrath | 87d4780 | 2007-07-16 22:23:37 +0000 | [diff] [blame] | 48 | #else |
Ulrich Drepper | b597dfa | 2007-10-16 05:21:27 +0000 | [diff] [blame] | 49 | # define __libdw_extern_inline extern __inline |
Roland McGrath | 87d4780 | 2007-07-16 22:23:37 +0000 | [diff] [blame] | 50 | #endif |
| 51 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 52 | |
| 53 | /* Mode for the session. */ |
| 54 | typedef enum |
| 55 | { |
| 56 | DWARF_C_READ, /* Read .. */ |
| 57 | DWARF_C_RDWR, /* Read and write .. */ |
| 58 | DWARF_C_WRITE, /* Write .. */ |
| 59 | } |
| 60 | Dwarf_Cmd; |
| 61 | |
| 62 | |
| 63 | /* Callback results. */ |
| 64 | enum |
| 65 | { |
| 66 | DWARF_CB_OK = 0, |
| 67 | DWARF_CB_ABORT |
| 68 | }; |
| 69 | |
| 70 | |
| 71 | /* Error values. */ |
| 72 | enum |
| 73 | { |
| 74 | DW_TAG_invalid = 0 |
| 75 | #define DW_TAG_invalid DW_TAG_invalid |
| 76 | }; |
| 77 | |
| 78 | |
| 79 | /* Type for offset in DWARF file. */ |
| 80 | typedef GElf_Off Dwarf_Off; |
| 81 | |
| 82 | /* Type for address in DWARF file. */ |
| 83 | typedef GElf_Addr Dwarf_Addr; |
| 84 | |
| 85 | /* Integer types. Big enough to hold any numeric value. */ |
| 86 | typedef GElf_Xword Dwarf_Word; |
| 87 | typedef GElf_Sxword Dwarf_Sword; |
| 88 | /* For the times we know we do not need that much. */ |
| 89 | typedef GElf_Half Dwarf_Half; |
| 90 | |
| 91 | |
| 92 | /* DWARF abbreviation record. */ |
| 93 | typedef struct Dwarf_Abbrev Dwarf_Abbrev; |
| 94 | |
| 95 | /* Returned to show the last DIE has be returned. */ |
| 96 | #define DWARF_END_ABBREV ((Dwarf_Abbrev *) -1l) |
| 97 | |
| 98 | /* Source code line information for CU. */ |
| 99 | typedef struct Dwarf_Lines_s Dwarf_Lines; |
| 100 | |
| 101 | /* One source code line information. */ |
| 102 | typedef struct Dwarf_Line_s Dwarf_Line; |
| 103 | |
| 104 | /* Source file information. */ |
| 105 | typedef struct Dwarf_Files_s Dwarf_Files; |
| 106 | |
| 107 | /* One address range record. */ |
| 108 | typedef struct Dwarf_Arange_s Dwarf_Arange; |
| 109 | |
| 110 | /* Address ranges of a file. */ |
| 111 | typedef struct Dwarf_Aranges_s Dwarf_Aranges; |
| 112 | |
| 113 | /* CU representation. */ |
| 114 | struct Dwarf_CU; |
Mark Wielaard | 209f149 | 2014-08-15 13:08:24 +0200 | [diff] [blame] | 115 | typedef struct Dwarf_CU Dwarf_CU; |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 116 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 117 | /* Macro information. */ |
| 118 | typedef struct Dwarf_Macro_s Dwarf_Macro; |
| 119 | |
| 120 | /* Attribute representation. */ |
| 121 | typedef struct |
| 122 | { |
| 123 | unsigned int code; |
| 124 | unsigned int form; |
| 125 | unsigned char *valp; |
| 126 | struct Dwarf_CU *cu; |
| 127 | } Dwarf_Attribute; |
| 128 | |
| 129 | |
| 130 | /* Data block representation. */ |
| 131 | typedef struct |
| 132 | { |
| 133 | Dwarf_Word length; |
| 134 | unsigned char *data; |
| 135 | } Dwarf_Block; |
| 136 | |
| 137 | |
| 138 | /* DIE information. */ |
| 139 | typedef struct |
| 140 | { |
| 141 | /* The offset can be computed from the address. */ |
| 142 | void *addr; |
| 143 | struct Dwarf_CU *cu; |
| 144 | Dwarf_Abbrev *abbrev; |
| 145 | // XXX We'll see what other information will be needed. |
| 146 | long int padding__; |
| 147 | } Dwarf_Die; |
| 148 | |
| 149 | /* Returned to show the last DIE has be returned. */ |
| 150 | #define DWARF_END_DIE ((Dwarf_Die *) -1l) |
| 151 | |
| 152 | |
| 153 | /* Global symbol information. */ |
| 154 | typedef struct |
| 155 | { |
| 156 | Dwarf_Off cu_offset; |
| 157 | Dwarf_Off die_offset; |
| 158 | const char *name; |
| 159 | } Dwarf_Global; |
| 160 | |
| 161 | |
Roland McGrath | 6724c90 | 2005-10-28 07:07:19 +0000 | [diff] [blame] | 162 | /* One operation in a DWARF location expression. |
| 163 | A location expression is an array of these. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 164 | typedef struct |
| 165 | { |
| 166 | uint8_t atom; /* Operation */ |
| 167 | Dwarf_Word number; /* Operand */ |
| 168 | Dwarf_Word number2; /* Possible second operand */ |
| 169 | Dwarf_Word offset; /* Offset in location expression */ |
Roland McGrath | 6724c90 | 2005-10-28 07:07:19 +0000 | [diff] [blame] | 170 | } Dwarf_Op; |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 171 | |
| 172 | |
Roland McGrath | 3c84db3 | 2009-06-24 17:41:40 -0700 | [diff] [blame] | 173 | /* This describes one Common Information Entry read from a CFI section. |
| 174 | Pointers here point into the DATA->d_buf block passed to dwarf_next_cfi. */ |
| 175 | typedef struct |
| 176 | { |
| 177 | Dwarf_Off CIE_id; /* Always DW_CIE_ID_64 in Dwarf_CIE structures. */ |
| 178 | |
| 179 | /* Instruction stream describing initial state used by FDEs. If |
| 180 | we did not understand the whole augmentation string and it did |
| 181 | not use 'z', then there might be more augmentation data here |
| 182 | (and in FDEs) before the actual instructions. */ |
| 183 | const uint8_t *initial_instructions; |
| 184 | const uint8_t *initial_instructions_end; |
| 185 | |
| 186 | Dwarf_Word code_alignment_factor; |
| 187 | Dwarf_Sword data_alignment_factor; |
| 188 | Dwarf_Word return_address_register; |
| 189 | |
| 190 | const char *augmentation; /* Augmentation string. */ |
| 191 | |
| 192 | /* Augmentation data, might be NULL. The size is correct only if |
| 193 | we understood the augmentation string sufficiently. */ |
| 194 | const uint8_t *augmentation_data; |
| 195 | size_t augmentation_data_size; |
| 196 | size_t fde_augmentation_data_size; |
| 197 | } Dwarf_CIE; |
| 198 | |
| 199 | /* This describes one Frame Description Entry read from a CFI section. |
| 200 | Pointers here point into the DATA->d_buf block passed to dwarf_next_cfi. */ |
| 201 | typedef struct |
| 202 | { |
| 203 | /* Section offset of CIE this FDE refers to. This will never be |
| 204 | DW_CIE_ID_64 in an FDE. If this value is DW_CIE_ID_64, this is |
| 205 | actually a Dwarf_CIE structure. */ |
| 206 | Dwarf_Off CIE_pointer; |
| 207 | |
| 208 | /* We can't really decode anything further without looking up the CIE |
| 209 | and checking its augmentation string. Here follows the encoded |
| 210 | initial_location and address_range, then any augmentation data, |
| 211 | then the instruction stream. This FDE describes PC locations in |
| 212 | the byte range [initial_location, initial_location+address_range). |
| 213 | When the CIE augmentation string uses 'z', the augmentation data is |
| 214 | a DW_FORM_block (self-sized). Otherwise, when we understand the |
| 215 | augmentation string completely, fde_augmentation_data_size gives |
| 216 | the number of bytes of augmentation data before the instructions. */ |
| 217 | const uint8_t *start; |
| 218 | const uint8_t *end; |
| 219 | } Dwarf_FDE; |
| 220 | |
| 221 | /* Each entry in a CFI section is either a CIE described by Dwarf_CIE or |
| 222 | an FDE described by Dward_FDE. Check CIE_id to see which you have. */ |
| 223 | typedef union |
| 224 | { |
| 225 | Dwarf_Off CIE_id; /* Always DW_CIE_ID_64 in Dwarf_CIE structures. */ |
| 226 | Dwarf_CIE cie; |
| 227 | Dwarf_FDE fde; |
| 228 | } Dwarf_CFI_Entry; |
| 229 | |
Mark Wielaard | 08e71db | 2010-05-31 15:39:15 +0200 | [diff] [blame] | 230 | #define dwarf_cfi_cie_p(entry) ((entry)->cie.CIE_id == DW_CIE_ID_64) |
| 231 | |
Roland McGrath | 3c84db3 | 2009-06-24 17:41:40 -0700 | [diff] [blame] | 232 | /* Opaque type representing a frame state described by CFI. */ |
| 233 | typedef struct Dwarf_Frame_s Dwarf_Frame; |
| 234 | |
| 235 | /* Opaque type representing a CFI section found in a DWARF or ELF file. */ |
| 236 | typedef struct Dwarf_CFI_s Dwarf_CFI; |
| 237 | |
| 238 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 239 | /* Handle for debug sessions. */ |
| 240 | typedef struct Dwarf Dwarf; |
| 241 | |
| 242 | |
| 243 | /* Out-Of-Memory handler. */ |
| 244 | #if __GNUC__ < 4 |
| 245 | typedef void (*Dwarf_OOM) (void); |
| 246 | #else |
| 247 | typedef void (*__attribute__ ((noreturn)) Dwarf_OOM) (void); |
| 248 | #endif |
| 249 | |
| 250 | |
Ulrich Drepper | 3be7447 | 2006-05-27 18:15:40 +0000 | [diff] [blame] | 251 | #ifdef __cplusplus |
| 252 | extern "C" { |
| 253 | #endif |
| 254 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 255 | /* Create a handle for a new debug session. */ |
| 256 | extern Dwarf *dwarf_begin (int fildes, Dwarf_Cmd cmd); |
| 257 | |
| 258 | /* Create a handle for a new debug session for an ELF file. */ |
| 259 | extern Dwarf *dwarf_begin_elf (Elf *elf, Dwarf_Cmd cmd, Elf_Scn *scngrp); |
| 260 | |
| 261 | /* Retrieve ELF descriptor used for DWARF access. */ |
| 262 | extern Elf *dwarf_getelf (Dwarf *dwarf); |
| 263 | |
Mark Wielaard | 209f149 | 2014-08-15 13:08:24 +0200 | [diff] [blame] | 264 | /* Retieve DWARF descriptor used for a Dwarf_Die or Dwarf_Attribute. |
| 265 | A Dwarf_Die or a Dwarf_Attribute is associated with a particular |
| 266 | Dwarf_CU handle. This function returns the DWARF descriptor for |
| 267 | that Dwarf_CU. */ |
| 268 | extern Dwarf *dwarf_cu_getdwarf (Dwarf_CU *cu); |
| 269 | |
Florian Weimer | 35e2a76 | 2014-04-15 14:31:55 +0200 | [diff] [blame] | 270 | /* Retrieves the DWARF descriptor for debugaltlink data. Returns NULL |
| 271 | if no alternate debug data has been supplied. */ |
| 272 | extern Dwarf *dwarf_getalt (Dwarf *main); |
| 273 | |
| 274 | /* Provides the data referenced by the .gnu_debugaltlink section. The |
| 275 | caller should check that MAIN and ALT match (i.e., they have the |
| 276 | same build ID). It is the responsibility of the caller to ensure |
| 277 | that the data referenced by ALT stays valid while it is used by |
| 278 | MAIN, until dwarf_setalt is called on MAIN with a different |
| 279 | descriptor, or dwarf_end. */ |
| 280 | extern void dwarf_setalt (Dwarf *main, Dwarf *alt); |
| 281 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 282 | /* Release debugging handling context. */ |
| 283 | extern int dwarf_end (Dwarf *dwarf); |
| 284 | |
| 285 | |
| 286 | /* Get the data block for the .debug_info section. */ |
| 287 | extern Elf_Data *dwarf_getscn_info (Dwarf *dwarf); |
| 288 | |
Roland McGrath | 3e0f7d1 | 2010-06-15 23:10:35 -0700 | [diff] [blame] | 289 | /* Read the header for the DWARF CU. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 290 | extern int dwarf_nextcu (Dwarf *dwarf, Dwarf_Off off, Dwarf_Off *next_off, |
| 291 | size_t *header_sizep, Dwarf_Off *abbrev_offsetp, |
| 292 | uint8_t *address_sizep, uint8_t *offset_sizep) |
| 293 | __nonnull_attribute__ (3); |
| 294 | |
Roland McGrath | 3e0f7d1 | 2010-06-15 23:10:35 -0700 | [diff] [blame] | 295 | /* Read the header of a DWARF CU or type unit. If TYPE_SIGNATUREP is not |
| 296 | null, this reads a type unit from the .debug_types section; otherwise |
| 297 | this reads a CU from the .debug_info section. */ |
| 298 | extern int dwarf_next_unit (Dwarf *dwarf, Dwarf_Off off, Dwarf_Off *next_off, |
Roland McGrath | 2b1f095 | 2010-06-20 17:55:50 -0700 | [diff] [blame] | 299 | size_t *header_sizep, Dwarf_Half *versionp, |
Roland McGrath | 3e0f7d1 | 2010-06-15 23:10:35 -0700 | [diff] [blame] | 300 | Dwarf_Off *abbrev_offsetp, |
| 301 | uint8_t *address_sizep, uint8_t *offset_sizep, |
| 302 | uint64_t *type_signaturep, Dwarf_Off *type_offsetp) |
| 303 | __nonnull_attribute__ (3); |
| 304 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 305 | |
Roland McGrath | 3c84db3 | 2009-06-24 17:41:40 -0700 | [diff] [blame] | 306 | /* Decode one DWARF CFI entry (CIE or FDE) from the raw section data. |
| 307 | The E_IDENT from the originating ELF file indicates the address |
| 308 | size and byte order used in the CFI section contained in DATA; |
| 309 | EH_FRAME_P should be true for .eh_frame format and false for |
| 310 | .debug_frame format. OFFSET is the byte position in the section |
| 311 | to start at; on return *NEXT_OFFSET is filled in with the byte |
| 312 | position immediately after this entry. |
| 313 | |
| 314 | On success, returns 0 and fills in *ENTRY; use dwarf_cfi_cie_p to |
| 315 | see whether ENTRY->cie or ENTRY->fde is valid. |
| 316 | |
| 317 | On errors, returns -1. Some format errors will permit safely |
| 318 | skipping to the next CFI entry though the current one is unusable. |
| 319 | In that case, *NEXT_OFF will be updated before a -1 return. |
| 320 | |
| 321 | If there are no more CFI entries left in the section, |
| 322 | returns 1 and sets *NEXT_OFFSET to (Dwarf_Off) -1. */ |
| 323 | extern int dwarf_next_cfi (const unsigned char e_ident[], |
| 324 | Elf_Data *data, bool eh_frame_p, |
| 325 | Dwarf_Off offset, Dwarf_Off *next_offset, |
| 326 | Dwarf_CFI_Entry *entry) |
| 327 | __nonnull_attribute__ (1, 2, 5, 6); |
| 328 | |
| 329 | /* Use the CFI in the DWARF .debug_frame section. |
| 330 | Returns NULL if there is no such section (not an error). |
| 331 | The pointer returned can be used until dwarf_end is called on DWARF, |
| 332 | and must not be passed to dwarf_cfi_end. |
| 333 | Calling this more than once returns the same pointer. */ |
| 334 | extern Dwarf_CFI *dwarf_getcfi (Dwarf *dwarf); |
| 335 | |
| 336 | /* Use the CFI in the ELF file's exception-handling data. |
| 337 | Returns NULL if there is no such data. |
| 338 | The pointer returned can be used until elf_end is called on ELF, |
| 339 | and must be passed to dwarf_cfi_end before then. |
| 340 | Calling this more than once allocates independent data structures. */ |
| 341 | extern Dwarf_CFI *dwarf_getcfi_elf (Elf *elf); |
| 342 | |
| 343 | /* Release resources allocated by dwarf_getcfi_elf. */ |
| 344 | extern int dwarf_cfi_end (Dwarf_CFI *cache); |
| 345 | |
| 346 | |
Mark Wielaard | 0b72b65 | 2011-07-14 12:59:26 +0200 | [diff] [blame] | 347 | /* Return DIE at given offset in .debug_info section. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 348 | extern Dwarf_Die *dwarf_offdie (Dwarf *dbg, Dwarf_Off offset, |
| 349 | Dwarf_Die *result) __nonnull_attribute__ (3); |
| 350 | |
Roland McGrath | 2b1f095 | 2010-06-20 17:55:50 -0700 | [diff] [blame] | 351 | /* Return DIE at given offset in .debug_types section. */ |
| 352 | extern Dwarf_Die *dwarf_offdie_types (Dwarf *dbg, Dwarf_Off offset, |
| 353 | Dwarf_Die *result) |
| 354 | __nonnull_attribute__ (3); |
| 355 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 356 | /* Return offset of DIE. */ |
| 357 | extern Dwarf_Off dwarf_dieoffset (Dwarf_Die *die); |
| 358 | |
| 359 | /* Return offset of DIE in CU. */ |
| 360 | extern Dwarf_Off dwarf_cuoffset (Dwarf_Die *die); |
| 361 | |
Roland McGrath | 07d4f2f | 2005-10-28 06:56:24 +0000 | [diff] [blame] | 362 | /* Return CU DIE containing given DIE. */ |
| 363 | extern Dwarf_Die *dwarf_diecu (Dwarf_Die *die, Dwarf_Die *result, |
Roland McGrath | c373d85 | 2006-10-10 00:25:21 +0000 | [diff] [blame] | 364 | uint8_t *address_sizep, uint8_t *offset_sizep) |
| 365 | __nonnull_attribute__ (2); |
Roland McGrath | 07d4f2f | 2005-10-28 06:56:24 +0000 | [diff] [blame] | 366 | |
Mark Wielaard | f18f233 | 2014-08-15 16:03:21 +0200 | [diff] [blame] | 367 | /* Return the CU DIE and the header info associated with a Dwarf_Die |
| 368 | or Dwarf_Attribute. A Dwarf_Die or a Dwarf_Attribute is associated |
| 369 | with a particular Dwarf_CU handle. This function returns the CU or |
| 370 | type unit DIE and header information for that Dwarf_CU. The |
| 371 | returned DIE is either a compile_unit, partial_unit or type_unit. |
| 372 | If it is a type_unit, then the type signature and type offset are |
| 373 | also provided, otherwise type_offset will be set to zero. See also |
| 374 | dwarf_diecu and dwarf_next_unit. */ |
| 375 | extern Dwarf_Die *dwarf_cu_die (Dwarf_CU *cu, Dwarf_Die *result, |
| 376 | Dwarf_Half *versionp, |
| 377 | Dwarf_Off *abbrev_offsetp, |
| 378 | uint8_t *address_sizep, |
| 379 | uint8_t *offset_sizep, |
| 380 | uint64_t *type_signaturep, |
| 381 | Dwarf_Off *type_offsetp) |
| 382 | __nonnull_attribute__ (2); |
| 383 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 384 | /* Return CU DIE containing given address. */ |
| 385 | extern Dwarf_Die *dwarf_addrdie (Dwarf *dbg, Dwarf_Addr addr, |
| 386 | Dwarf_Die *result) __nonnull_attribute__ (3); |
| 387 | |
| 388 | /* Return child of current DIE. */ |
| 389 | extern int dwarf_child (Dwarf_Die *die, Dwarf_Die *result) |
Roland McGrath | c373d85 | 2006-10-10 00:25:21 +0000 | [diff] [blame] | 390 | __nonnull_attribute__ (2); |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 391 | |
Ulrich Drepper | 35f08c4 | 2008-01-18 19:59:08 +0000 | [diff] [blame] | 392 | /* Locates the first sibling of DIE and places it in RESULT. |
| 393 | Returns 0 if a sibling was found, -1 if something went wrong. |
| 394 | Returns 1 if no sibling could be found and, if RESULT is not |
| 395 | the same as DIE, it sets RESULT->addr to the address of the |
| 396 | (non-sibling) DIE that follows this one, or NULL if this DIE |
Roland McGrath | ebc5c88 | 2010-01-05 22:53:31 -0800 | [diff] [blame] | 397 | was the last one in the compilation unit. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 398 | extern int dwarf_siblingof (Dwarf_Die *die, Dwarf_Die *result) |
| 399 | __nonnull_attribute__ (2); |
| 400 | |
Mark Wielaard | 3a36e8a | 2014-10-06 22:00:16 +0200 | [diff] [blame] | 401 | /* For type aliases and qualifier type DIEs follow the DW_AT_type |
| 402 | attribute (recursively) and return the underlying type Dwarf_Die. |
| 403 | Returns 0 when RESULT contains a Dwarf_Die (possibly equal to the |
| 404 | given DIE) that isn't a type alias or qualifier type. Returns 1 |
| 405 | when RESULT contains a type alias or qualifier Dwarf_Die that |
| 406 | couldn't be peeled further (it doesn't have a DW_TAG_type |
| 407 | attribute). Returns -1 when an error occured. |
| 408 | |
| 409 | The current DWARF specification defines one type alias tag |
| 410 | (DW_TAG_typedef) and three qualifier type tags (DW_TAG_const_type, |
| 411 | DW_TAG_volatile_type, DW_TAG_restrict_type). A future version of |
| 412 | this function might peel other alias or qualifier type tags if a |
| 413 | future DWARF version or GNU extension defines other type aliases or |
| 414 | qualifier type tags that don't modify or change the structural |
| 415 | layout of the underlying type. */ |
| 416 | extern int dwarf_peel_type (Dwarf_Die *die, Dwarf_Die *result) |
| 417 | __nonnull_attribute__ (2); |
| 418 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 419 | /* Check whether the DIE has children. */ |
Ulrich Drepper | 4f3d2a2 | 2006-05-22 01:30:56 +0000 | [diff] [blame] | 420 | extern int dwarf_haschildren (Dwarf_Die *die) __nonnull_attribute__ (1); |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 421 | |
Ulrich Drepper | 35f08c4 | 2008-01-18 19:59:08 +0000 | [diff] [blame] | 422 | /* Walks the attributes of DIE, starting at the one OFFSET bytes in, |
| 423 | calling the CALLBACK function for each one. Stops if the callback |
| 424 | function ever returns a value other than DWARF_CB_OK and returns the |
| 425 | offset of the offending attribute. If the end of the attributes |
| 426 | is reached 1 is returned. If something goes wrong -1 is returned and |
| 427 | the dwarf error number is set. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 428 | extern ptrdiff_t dwarf_getattrs (Dwarf_Die *die, |
| 429 | int (*callback) (Dwarf_Attribute *, void *), |
Ulrich Drepper | 4f3d2a2 | 2006-05-22 01:30:56 +0000 | [diff] [blame] | 430 | void *arg, ptrdiff_t offset) |
| 431 | __nonnull_attribute__ (2); |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 432 | |
| 433 | /* Return tag of given DIE. */ |
Ulrich Drepper | 4f3d2a2 | 2006-05-22 01:30:56 +0000 | [diff] [blame] | 434 | extern int dwarf_tag (Dwarf_Die *die) __nonnull_attribute__ (1); |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 435 | |
| 436 | |
| 437 | /* Return specific attribute of DIE. */ |
| 438 | extern Dwarf_Attribute *dwarf_attr (Dwarf_Die *die, unsigned int search_name, |
| 439 | Dwarf_Attribute *result) |
| 440 | __nonnull_attribute__ (3); |
| 441 | |
| 442 | /* Check whether given DIE has specific attribute. */ |
| 443 | extern int dwarf_hasattr (Dwarf_Die *die, unsigned int search_name); |
| 444 | |
| 445 | /* These are the same as dwarf_attr and dwarf_hasattr, respectively, |
| 446 | but they resolve an indirect attribute through DW_AT_abstract_origin. */ |
| 447 | extern Dwarf_Attribute *dwarf_attr_integrate (Dwarf_Die *die, |
| 448 | unsigned int search_name, |
| 449 | Dwarf_Attribute *result) |
| 450 | __nonnull_attribute__ (3); |
| 451 | extern int dwarf_hasattr_integrate (Dwarf_Die *die, unsigned int search_name); |
| 452 | |
| 453 | |
| 454 | |
| 455 | |
| 456 | /* Check whether given attribute has specific form. */ |
| 457 | extern int dwarf_hasform (Dwarf_Attribute *attr, unsigned int search_form); |
| 458 | |
| 459 | /* Return attribute code of given attribute. */ |
| 460 | extern unsigned int dwarf_whatattr (Dwarf_Attribute *attr); |
| 461 | |
| 462 | /* Return form code of given attribute. */ |
| 463 | extern unsigned int dwarf_whatform (Dwarf_Attribute *attr); |
| 464 | |
| 465 | |
| 466 | /* Return string associated with given attribute. */ |
| 467 | extern const char *dwarf_formstring (Dwarf_Attribute *attrp); |
| 468 | |
| 469 | /* Return unsigned constant represented by attribute. */ |
| 470 | extern int dwarf_formudata (Dwarf_Attribute *attr, Dwarf_Word *return_uval) |
| 471 | __nonnull_attribute__ (2); |
| 472 | |
| 473 | /* Return signed constant represented by attribute. */ |
| 474 | extern int dwarf_formsdata (Dwarf_Attribute *attr, Dwarf_Sword *return_uval) |
| 475 | __nonnull_attribute__ (2); |
| 476 | |
| 477 | /* Return address represented by attribute. */ |
| 478 | extern int dwarf_formaddr (Dwarf_Attribute *attr, Dwarf_Addr *return_addr) |
| 479 | __nonnull_attribute__ (2); |
| 480 | |
Roland McGrath | e4c22ea | 2007-10-23 13:07:39 +0000 | [diff] [blame] | 481 | /* This function is deprecated. Always use dwarf_formref_die instead. |
| 482 | Return reference offset represented by attribute. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 483 | extern int dwarf_formref (Dwarf_Attribute *attr, Dwarf_Off *return_offset) |
Roland McGrath | e4c22ea | 2007-10-23 13:07:39 +0000 | [diff] [blame] | 484 | __nonnull_attribute__ (2) __deprecated_attribute__; |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 485 | |
| 486 | /* Look up the DIE in a reference-form attribute. */ |
| 487 | extern Dwarf_Die *dwarf_formref_die (Dwarf_Attribute *attr, Dwarf_Die *die_mem) |
| 488 | __nonnull_attribute__ (2); |
| 489 | |
| 490 | /* Return block represented by attribute. */ |
| 491 | extern int dwarf_formblock (Dwarf_Attribute *attr, Dwarf_Block *return_block) |
| 492 | __nonnull_attribute__ (2); |
| 493 | |
| 494 | /* Return flag represented by attribute. */ |
| 495 | extern int dwarf_formflag (Dwarf_Attribute *attr, bool *return_bool) |
| 496 | __nonnull_attribute__ (2); |
| 497 | |
| 498 | |
| 499 | /* Simplified attribute value access functions. */ |
| 500 | |
| 501 | /* Return string in name attribute of DIE. */ |
| 502 | extern const char *dwarf_diename (Dwarf_Die *die); |
| 503 | |
| 504 | /* Return high PC attribute of DIE. */ |
| 505 | extern int dwarf_highpc (Dwarf_Die *die, Dwarf_Addr *return_addr) |
| 506 | __nonnull_attribute__ (2); |
| 507 | |
| 508 | /* Return low PC attribute of DIE. */ |
| 509 | extern int dwarf_lowpc (Dwarf_Die *die, Dwarf_Addr *return_addr) |
| 510 | __nonnull_attribute__ (2); |
| 511 | |
Roland McGrath | 07d4f2f | 2005-10-28 06:56:24 +0000 | [diff] [blame] | 512 | /* Return entry_pc or low_pc attribute of DIE. */ |
| 513 | extern int dwarf_entrypc (Dwarf_Die *die, Dwarf_Addr *return_addr) |
| 514 | __nonnull_attribute__ (2); |
| 515 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 516 | /* Return 1 if DIE's lowpc/highpc or ranges attributes match the PC address, |
| 517 | 0 if not, or -1 for errors. */ |
| 518 | extern int dwarf_haspc (Dwarf_Die *die, Dwarf_Addr pc); |
| 519 | |
Roland McGrath | 07d4f2f | 2005-10-28 06:56:24 +0000 | [diff] [blame] | 520 | /* Enumerate the PC address ranges covered by this DIE, covering all |
| 521 | addresses where dwarf_haspc returns true. In the first call OFFSET |
| 522 | should be zero and *BASEP need not be initialized. Returns -1 for |
| 523 | errors, zero when there are no more address ranges to report, or a |
| 524 | nonzero OFFSET value to pass to the next call. Each subsequent call |
| 525 | must preserve *BASEP from the prior call. Successful calls fill in |
| 526 | *STARTP and *ENDP with a contiguous address range. */ |
| 527 | extern ptrdiff_t dwarf_ranges (Dwarf_Die *die, |
| 528 | ptrdiff_t offset, Dwarf_Addr *basep, |
| 529 | Dwarf_Addr *startp, Dwarf_Addr *endp); |
| 530 | |
| 531 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 532 | /* Return byte size attribute of DIE. */ |
| 533 | extern int dwarf_bytesize (Dwarf_Die *die); |
| 534 | |
| 535 | /* Return bit size attribute of DIE. */ |
| 536 | extern int dwarf_bitsize (Dwarf_Die *die); |
| 537 | |
| 538 | /* Return bit offset attribute of DIE. */ |
| 539 | extern int dwarf_bitoffset (Dwarf_Die *die); |
| 540 | |
| 541 | /* Return array order attribute of DIE. */ |
| 542 | extern int dwarf_arrayorder (Dwarf_Die *die); |
| 543 | |
| 544 | /* Return source language attribute of DIE. */ |
| 545 | extern int dwarf_srclang (Dwarf_Die *die); |
| 546 | |
| 547 | |
| 548 | /* Get abbreviation at given offset for given DIE. */ |
| 549 | extern Dwarf_Abbrev *dwarf_getabbrev (Dwarf_Die *die, Dwarf_Off offset, |
| 550 | size_t *lengthp); |
| 551 | |
| 552 | /* Get abbreviation at given offset in .debug_abbrev section. */ |
| 553 | extern int dwarf_offabbrev (Dwarf *dbg, Dwarf_Off offset, size_t *lengthp, |
| 554 | Dwarf_Abbrev *abbrevp) |
| 555 | __nonnull_attribute__ (4); |
| 556 | |
| 557 | /* Get abbreviation code. */ |
| 558 | extern unsigned int dwarf_getabbrevcode (Dwarf_Abbrev *abbrev); |
| 559 | |
| 560 | /* Get abbreviation tag. */ |
| 561 | extern unsigned int dwarf_getabbrevtag (Dwarf_Abbrev *abbrev); |
| 562 | |
| 563 | /* Return true if abbreviation is children flag set. */ |
| 564 | extern int dwarf_abbrevhaschildren (Dwarf_Abbrev *abbrev); |
| 565 | |
| 566 | /* Get number of attributes of abbreviation. */ |
| 567 | extern int dwarf_getattrcnt (Dwarf_Abbrev *abbrev, size_t *attrcntp) |
| 568 | __nonnull_attribute__ (2); |
| 569 | |
| 570 | /* Get specific attribute of abbreviation. */ |
| 571 | extern int dwarf_getabbrevattr (Dwarf_Abbrev *abbrev, size_t idx, |
| 572 | unsigned int *namep, unsigned int *formp, |
| 573 | Dwarf_Off *offset); |
| 574 | |
| 575 | |
| 576 | /* Get string from-debug_str section. */ |
| 577 | extern const char *dwarf_getstring (Dwarf *dbg, Dwarf_Off offset, |
| 578 | size_t *lenp); |
| 579 | |
| 580 | |
| 581 | /* Get public symbol information. */ |
| 582 | extern ptrdiff_t dwarf_getpubnames (Dwarf *dbg, |
| 583 | int (*callback) (Dwarf *, Dwarf_Global *, |
| 584 | void *), |
| 585 | void *arg, ptrdiff_t offset) |
| 586 | __nonnull_attribute__ (2); |
| 587 | |
| 588 | |
| 589 | /* Get source file information for CU. */ |
| 590 | extern int dwarf_getsrclines (Dwarf_Die *cudie, Dwarf_Lines **lines, |
| 591 | size_t *nlines) __nonnull_attribute__ (2, 3); |
| 592 | |
| 593 | /* Return one of the source lines of the CU. */ |
| 594 | extern Dwarf_Line *dwarf_onesrcline (Dwarf_Lines *lines, size_t idx); |
| 595 | |
| 596 | /* Get the file source files used in the CU. */ |
| 597 | extern int dwarf_getsrcfiles (Dwarf_Die *cudie, Dwarf_Files **files, |
| 598 | size_t *nfiles) |
| 599 | __nonnull_attribute__ (2); |
| 600 | |
| 601 | |
| 602 | /* Get source for address in CU. */ |
| 603 | extern Dwarf_Line *dwarf_getsrc_die (Dwarf_Die *cudie, Dwarf_Addr addr); |
| 604 | |
| 605 | /* Get source for file and line number. */ |
| 606 | extern int dwarf_getsrc_file (Dwarf *dbg, const char *fname, int line, int col, |
| 607 | Dwarf_Line ***srcsp, size_t *nsrcs) |
| 608 | __nonnull_attribute__ (2, 5, 6); |
| 609 | |
| 610 | |
| 611 | /* Return line address. */ |
| 612 | extern int dwarf_lineaddr (Dwarf_Line *line, Dwarf_Addr *addrp); |
| 613 | |
Roland McGrath | c70cf4e | 2010-06-18 17:01:05 -0700 | [diff] [blame] | 614 | /* Return line VLIW operation index. */ |
| 615 | extern int dwarf_lineop_index (Dwarf_Line *line, unsigned int *op_indexp); |
| 616 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 617 | /* Return line number. */ |
| 618 | extern int dwarf_lineno (Dwarf_Line *line, int *linep) |
| 619 | __nonnull_attribute__ (2); |
| 620 | |
| 621 | /* Return column in line. */ |
| 622 | extern int dwarf_linecol (Dwarf_Line *line, int *colp) |
| 623 | __nonnull_attribute__ (2); |
| 624 | |
| 625 | /* Return true if record is for beginning of a statement. */ |
| 626 | extern int dwarf_linebeginstatement (Dwarf_Line *line, bool *flagp) |
| 627 | __nonnull_attribute__ (2); |
| 628 | |
| 629 | /* Return true if record is for end of sequence. */ |
| 630 | extern int dwarf_lineendsequence (Dwarf_Line *line, bool *flagp) |
| 631 | __nonnull_attribute__ (2); |
| 632 | |
| 633 | /* Return true if record is for beginning of a basic block. */ |
| 634 | extern int dwarf_lineblock (Dwarf_Line *line, bool *flagp) |
| 635 | __nonnull_attribute__ (2); |
| 636 | |
| 637 | /* Return true if record is for end of prologue. */ |
| 638 | extern int dwarf_lineprologueend (Dwarf_Line *line, bool *flagp) |
| 639 | __nonnull_attribute__ (2); |
| 640 | |
| 641 | /* Return true if record is for beginning of epilogue. */ |
| 642 | extern int dwarf_lineepiloguebegin (Dwarf_Line *line, bool *flagp) |
| 643 | __nonnull_attribute__ (2); |
| 644 | |
Roland McGrath | c70cf4e | 2010-06-18 17:01:05 -0700 | [diff] [blame] | 645 | /* Return instruction-set architecture in this record. */ |
| 646 | extern int dwarf_lineisa (Dwarf_Line *line, unsigned int *isap) |
| 647 | __nonnull_attribute__ (2); |
| 648 | |
| 649 | /* Return code path discriminator in this record. */ |
| 650 | extern int dwarf_linediscriminator (Dwarf_Line *line, unsigned int *discp) |
| 651 | __nonnull_attribute__ (2); |
| 652 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 653 | |
| 654 | /* Find line information for address. */ |
| 655 | extern const char *dwarf_linesrc (Dwarf_Line *line, |
| 656 | Dwarf_Word *mtime, Dwarf_Word *length); |
| 657 | |
| 658 | /* Return file information. */ |
| 659 | extern const char *dwarf_filesrc (Dwarf_Files *file, size_t idx, |
| 660 | Dwarf_Word *mtime, Dwarf_Word *length); |
| 661 | |
Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 662 | /* Return the directory list used in the file information extracted. |
| 663 | (*RESULT)[0] is the CU's DW_AT_comp_dir value, and may be null. |
| 664 | (*RESULT)[0..*NDIRS-1] are the compile-time include directory path |
| 665 | encoded by the compiler. */ |
| 666 | extern int dwarf_getsrcdirs (Dwarf_Files *files, |
| 667 | const char *const **result, size_t *ndirs) |
| 668 | __nonnull_attribute__ (2, 3); |
| 669 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 670 | |
Roland McGrath | 6724c90 | 2005-10-28 07:07:19 +0000 | [diff] [blame] | 671 | /* Return location expression, decoded as a list of operations. */ |
| 672 | extern int dwarf_getlocation (Dwarf_Attribute *attr, Dwarf_Op **expr, |
| 673 | size_t *exprlen) __nonnull_attribute__ (2, 3); |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 674 | |
Roland McGrath | 6724c90 | 2005-10-28 07:07:19 +0000 | [diff] [blame] | 675 | /* Return location expressions. If the attribute uses a location list, |
| 676 | ADDRESS selects the relevant location expressions from the list. |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 677 | There can be multiple matches, resulting in multiple expressions to |
Roland McGrath | 6724c90 | 2005-10-28 07:07:19 +0000 | [diff] [blame] | 678 | return. EXPRS and EXPRLENS are parallel arrays of NLOCS slots to |
| 679 | fill in. Returns the number of locations filled in, or -1 for |
| 680 | errors. If EXPRS is a null pointer, stores nothing and returns the |
| 681 | total number of locations. A return value of zero means that the |
| 682 | location list indicated no value is accessible. */ |
| 683 | extern int dwarf_getlocation_addr (Dwarf_Attribute *attr, Dwarf_Addr address, |
| 684 | Dwarf_Op **exprs, size_t *exprlens, |
| 685 | size_t nlocs); |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 686 | |
Mark Wielaard | 66eaae9 | 2013-08-23 16:12:37 +0200 | [diff] [blame] | 687 | /* Enumerate the locations ranges and descriptions covered by the |
| 688 | given attribute. In the first call OFFSET should be zero and |
| 689 | *BASEP need not be initialized. Returns -1 for errors, zero when |
| 690 | there are no more locations to report, or a nonzero OFFSET |
| 691 | value to pass to the next call. Each subsequent call must preserve |
| 692 | *BASEP from the prior call. Successful calls fill in *STARTP and |
| 693 | *ENDP with a contiguous address range and *EXPR with a pointer to |
| 694 | an array of operations with length *EXPRLEN. If the attribute |
| 695 | describes a single location description and not a location list the |
| 696 | first call (with OFFSET zero) will return the location description |
| 697 | in *EXPR with *STARTP set to zero and *ENDP set to minus one. */ |
| 698 | extern ptrdiff_t dwarf_getlocations (Dwarf_Attribute *attr, |
| 699 | ptrdiff_t offset, Dwarf_Addr *basep, |
| 700 | Dwarf_Addr *startp, Dwarf_Addr *endp, |
| 701 | Dwarf_Op **expr, size_t *exprlen); |
| 702 | |
Roland McGrath | f037104 | 2009-09-10 12:39:09 -0700 | [diff] [blame] | 703 | /* Return the block associated with a DW_OP_implicit_value operation. |
| 704 | The OP pointer must point into an expression that dwarf_getlocation |
| 705 | or dwarf_getlocation_addr has returned given the same ATTR. */ |
| 706 | extern int dwarf_getlocation_implicit_value (Dwarf_Attribute *attr, |
Roland McGrath | 7e0aecd | 2009-09-17 15:02:34 -0700 | [diff] [blame] | 707 | const Dwarf_Op *op, |
Roland McGrath | f037104 | 2009-09-10 12:39:09 -0700 | [diff] [blame] | 708 | Dwarf_Block *return_block) |
| 709 | __nonnull_attribute__ (2, 3); |
| 710 | |
Roland McGrath | 932585d | 2010-05-08 04:01:14 -0700 | [diff] [blame] | 711 | /* Return the attribute indicated by a DW_OP_GNU_implicit_pointer operation. |
| 712 | The OP pointer must point into an expression that dwarf_getlocation |
| 713 | or dwarf_getlocation_addr has returned given the same ATTR. |
| 714 | The result is the DW_AT_location or DW_AT_const_value attribute |
| 715 | of the OP->number DIE. */ |
| 716 | extern int dwarf_getlocation_implicit_pointer (Dwarf_Attribute *attr, |
| 717 | const Dwarf_Op *op, |
| 718 | Dwarf_Attribute *result) |
| 719 | __nonnull_attribute__ (2, 3); |
| 720 | |
Mark Wielaard | b2535b6 | 2013-08-30 23:55:12 +0200 | [diff] [blame] | 721 | /* Return the DIE associated with an operation such as |
| 722 | DW_OP_GNU_implicit_pointer, DW_OP_GNU_parameter_ref, DW_OP_GNU_convert, |
| 723 | DW_OP_GNU_reinterpret, DW_OP_GNU_const_type, DW_OP_GNU_regval_type or |
| 724 | DW_OP_GNU_deref_type. The OP pointer must point into an expression that |
| 725 | dwarf_getlocation or dwarf_getlocation_addr has returned given the same |
| 726 | ATTR. The RESULT is a DIE that expresses a type or value needed by the |
| 727 | given OP. */ |
| 728 | extern int dwarf_getlocation_die (Dwarf_Attribute *attr, |
| 729 | const Dwarf_Op *op, |
| 730 | Dwarf_Die *result) |
| 731 | __nonnull_attribute__ (2, 3); |
| 732 | |
| 733 | /* Return the attribute expressing a value associated with an operation such |
| 734 | as DW_OP_implicit_value, DW_OP_GNU_entry_value or DW_OP_GNU_const_type. |
| 735 | The OP pointer must point into an expression that dwarf_getlocation |
| 736 | or dwarf_getlocation_addr has returned given the same ATTR. |
| 737 | The RESULT is a value expressed by an attribute such as DW_AT_location |
| 738 | or DW_AT_const_value. */ |
| 739 | extern int dwarf_getlocation_attr (Dwarf_Attribute *attr, |
| 740 | const Dwarf_Op *op, |
| 741 | Dwarf_Attribute *result) |
| 742 | __nonnull_attribute__ (2, 3); |
| 743 | |
Roland McGrath | f037104 | 2009-09-10 12:39:09 -0700 | [diff] [blame] | 744 | |
Roland McGrath | ebc5c88 | 2010-01-05 22:53:31 -0800 | [diff] [blame] | 745 | /* Compute the byte-size of a type DIE according to DWARF rules. |
| 746 | For most types, this is just DW_AT_byte_size. |
| 747 | For DW_TAG_array_type it can apply much more complex rules. */ |
| 748 | extern int dwarf_aggregate_size (Dwarf_Die *die, Dwarf_Word *size); |
| 749 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 750 | |
| 751 | /* Return scope DIEs containing PC address. |
| 752 | Sets *SCOPES to a malloc'd array of Dwarf_Die structures, |
| 753 | and returns the number of elements in the array. |
| 754 | (*SCOPES)[0] is the DIE for the innermost scope containing PC, |
| 755 | (*SCOPES)[1] is the DIE for the scope containing that scope, and so on. |
| 756 | Returns -1 for errors or 0 if no scopes match PC. */ |
| 757 | extern int dwarf_getscopes (Dwarf_Die *cudie, Dwarf_Addr pc, |
| 758 | Dwarf_Die **scopes); |
| 759 | |
Roland McGrath | 71e15a0 | 2005-08-27 10:33:26 +0000 | [diff] [blame] | 760 | /* Return scope DIEs containing the given DIE. |
| 761 | Sets *SCOPES to a malloc'd array of Dwarf_Die structures, |
| 762 | and returns the number of elements in the array. |
| 763 | (*SCOPES)[0] is a copy of DIE. |
| 764 | (*SCOPES)[1] is the DIE for the scope containing that scope, and so on. |
| 765 | Returns -1 for errors or 0 if DIE is not found in any scope entry. */ |
| 766 | extern int dwarf_getscopes_die (Dwarf_Die *die, Dwarf_Die **scopes); |
| 767 | |
| 768 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 769 | /* Search SCOPES[0..NSCOPES-1] for a variable called NAME. |
| 770 | Ignore the first SKIP_SHADOWS scopes that match the name. |
| 771 | If MATCH_FILE is not null, accept only declaration in that source file; |
| 772 | if MATCH_LINENO or MATCH_LINECOL are also nonzero, accept only declaration |
| 773 | at that line and column. |
| 774 | |
| 775 | If successful, fill in *RESULT with the DIE of the variable found, |
| 776 | and return N where SCOPES[N] is the scope defining the variable. |
| 777 | Return -1 for errors or -2 for no matching variable found. */ |
| 778 | extern int dwarf_getscopevar (Dwarf_Die *scopes, int nscopes, |
| 779 | const char *name, int skip_shadows, |
| 780 | const char *match_file, |
| 781 | int match_lineno, int match_linecol, |
| 782 | Dwarf_Die *result); |
| 783 | |
| 784 | |
| 785 | |
| 786 | /* Return list address ranges. */ |
| 787 | extern int dwarf_getaranges (Dwarf *dbg, Dwarf_Aranges **aranges, |
| 788 | size_t *naranges) |
| 789 | __nonnull_attribute__ (2); |
| 790 | |
| 791 | /* Return one of the address range entries. */ |
| 792 | extern Dwarf_Arange *dwarf_onearange (Dwarf_Aranges *aranges, size_t idx); |
| 793 | |
| 794 | /* Return information in address range record. */ |
| 795 | extern int dwarf_getarangeinfo (Dwarf_Arange *arange, Dwarf_Addr *addrp, |
| 796 | Dwarf_Word *lengthp, Dwarf_Off *offsetp); |
| 797 | |
| 798 | /* Get address range which includes given address. */ |
| 799 | extern Dwarf_Arange *dwarf_getarange_addr (Dwarf_Aranges *aranges, |
| 800 | Dwarf_Addr addr); |
| 801 | |
| 802 | |
| 803 | |
Mark Wielaard | 1b734df | 2013-09-20 09:50:42 -0400 | [diff] [blame] | 804 | /* Get functions in CUDIE. The given callback will be called for all |
| 805 | defining DW_TAG_subprograms in the CU DIE tree. If the callback |
| 806 | returns DWARF_CB_ABORT the return value can be used as offset argument |
| 807 | to resume the function to find all remaining functions (this is not |
| 808 | really recommended, since it needs to rewalk the CU DIE tree first till |
| 809 | that offset is found again). If the callback returns DWARF_CB_OK |
| 810 | dwarf_getfuncs will not return but keep calling the callback for each |
| 811 | function DIE it finds. Pass zero for offset on the first call to walk |
| 812 | the full CU DIE tree. If no more functions can be found and the callback |
| 813 | returned DWARF_CB_OK then the function returns zero. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 814 | extern ptrdiff_t dwarf_getfuncs (Dwarf_Die *cudie, |
Roland McGrath | 6724c90 | 2005-10-28 07:07:19 +0000 | [diff] [blame] | 815 | int (*callback) (Dwarf_Die *, void *), |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 816 | void *arg, ptrdiff_t offset); |
| 817 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 818 | |
Roland McGrath | 6724c90 | 2005-10-28 07:07:19 +0000 | [diff] [blame] | 819 | /* Return file name containing definition of the given declaration. */ |
| 820 | extern const char *dwarf_decl_file (Dwarf_Die *decl); |
| 821 | |
| 822 | /* Get line number of beginning of given declaration. */ |
| 823 | extern int dwarf_decl_line (Dwarf_Die *decl, int *linep) |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 824 | __nonnull_attribute__ (2); |
| 825 | |
Roland McGrath | 6724c90 | 2005-10-28 07:07:19 +0000 | [diff] [blame] | 826 | /* Get column number of beginning of given declaration. */ |
| 827 | extern int dwarf_decl_column (Dwarf_Die *decl, int *colp) |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 828 | __nonnull_attribute__ (2); |
| 829 | |
Roland McGrath | 1ecb606 | 2005-08-15 09:53:04 +0000 | [diff] [blame] | 830 | |
| 831 | /* Return nonzero if given function is an abstract inline definition. */ |
Roland McGrath | 6724c90 | 2005-10-28 07:07:19 +0000 | [diff] [blame] | 832 | extern int dwarf_func_inline (Dwarf_Die *func); |
Roland McGrath | 1ecb606 | 2005-08-15 09:53:04 +0000 | [diff] [blame] | 833 | |
| 834 | /* Find each concrete inlined instance of the abstract inline definition. */ |
Roland McGrath | 6724c90 | 2005-10-28 07:07:19 +0000 | [diff] [blame] | 835 | extern int dwarf_func_inline_instances (Dwarf_Die *func, |
Roland McGrath | 1ecb606 | 2005-08-15 09:53:04 +0000 | [diff] [blame] | 836 | int (*callback) (Dwarf_Die *, void *), |
| 837 | void *arg); |
| 838 | |
| 839 | |
Roland McGrath | 07d4f2f | 2005-10-28 06:56:24 +0000 | [diff] [blame] | 840 | /* Find the appropriate PC location or locations for function entry |
| 841 | breakpoints for the given DW_TAG_subprogram DIE. Returns -1 for errors. |
| 842 | On success, returns the number of breakpoint locations (never zero) |
| 843 | and sets *BKPTS to a malloc'd vector of addresses. */ |
| 844 | extern int dwarf_entry_breakpoints (Dwarf_Die *die, Dwarf_Addr **bkpts); |
| 845 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 846 | |
Petr Machata | fb90bf3 | 2014-10-17 02:47:03 +0200 | [diff] [blame] | 847 | /* Iterate through the macro unit referenced by CUDIE and call |
| 848 | CALLBACK for each macro information entry. Keeps iterating while |
| 849 | CALLBACK returns DWARF_CB_OK. If the callback returns |
| 850 | DWARF_CB_ABORT, it stops iterating and returns a continuation |
| 851 | token, which can be used to restart the iteration at the point |
| 852 | where it ended. A TOKEN of 0 starts the iteration. Returns -1 for |
| 853 | errors or 0 if there are no more macro entries. |
| 854 | |
| 855 | Note that the Dwarf_Macro pointer passed to the callback is only |
| 856 | valid for the duration of the callback invocation. |
| 857 | |
| 858 | Note that this interface will refuse to serve opcode 0xff from |
| 859 | .debug_macro sections. Such opcode is considered invalid and will |
| 860 | cause dwarf_getmacros to return with error. Note that this should |
| 861 | be no limitation as of now, as DW_MACRO_GNU_* domain doesn't |
| 862 | allocate 0xff. It is however a theoretical possibility with future |
| 863 | Dwarf standards. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 864 | extern ptrdiff_t dwarf_getmacros (Dwarf_Die *cudie, |
| 865 | int (*callback) (Dwarf_Macro *, void *), |
Petr Machata | fb90bf3 | 2014-10-17 02:47:03 +0200 | [diff] [blame] | 866 | void *arg, ptrdiff_t token) |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 867 | __nonnull_attribute__ (2); |
| 868 | |
Petr Machata | fb90bf3 | 2014-10-17 02:47:03 +0200 | [diff] [blame] | 869 | /* This is similar in operation to dwarf_getmacros, but selects the |
| 870 | unit to iterate through by offset instead of by CU, and always |
| 871 | iterates .debug_macro. This can be used for handling |
| 872 | DW_MACRO_GNU_transparent_include's or similar opcodes. |
| 873 | |
| 874 | It is not appropriate to obtain macro unit offset by hand from a CU |
| 875 | DIE and then request iteration through this interface. The reason |
| 876 | for this is that if a dwarf_macro_getsrcfiles is later called, |
| 877 | there would be no way to figure out what DW_AT_comp_dir was present |
| 878 | on the CU DIE, and file names referenced in either the macro unit |
| 879 | itself, or the .debug_line unit that it references, might be wrong. |
| 880 | Use dwarf_getmacro. */ |
| 881 | extern ptrdiff_t dwarf_getmacros_off (Dwarf *dbg, Dwarf_Off macoff, |
| 882 | int (*callback) (Dwarf_Macro *, void *), |
| 883 | void *arg, ptrdiff_t token) |
| 884 | __nonnull_attribute__ (3); |
| 885 | |
| 886 | /* Get the source files used by the macro entry. You shouldn't assume |
| 887 | that Dwarf_Files references will remain valid after MACRO becomes |
| 888 | invalid. (Which is to say it's only valid within the |
| 889 | dwarf_getmacros* callback.) Returns 0 for success or a negative |
| 890 | value in case of an error. */ |
| 891 | extern int dwarf_macro_getsrcfiles (Dwarf *dbg, Dwarf_Macro *macro, |
| 892 | Dwarf_Files **files, size_t *nfiles) |
| 893 | __nonnull_attribute__ (2, 3, 4); |
| 894 | |
| 895 | /* Return macro opcode. That's a constant that can be either from |
| 896 | DW_MACINFO_* domain or DW_MACRO_GNU_* domain. The two domains have |
| 897 | compatible values, so it's OK to use either of them for |
| 898 | comparisons. The only differences is 0xff, which currently is |
| 899 | never served from .debug_macro, and can thus be safely assumed to |
| 900 | mean DW_MACINFO_vendor_ext. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 901 | extern int dwarf_macro_opcode (Dwarf_Macro *macro, unsigned int *opcodep) |
| 902 | __nonnull_attribute__ (2); |
| 903 | |
Petr Machata | fb90bf3 | 2014-10-17 02:47:03 +0200 | [diff] [blame] | 904 | /* Get number of parameters of MACRO and store it to *PARAMCNTP. */ |
| 905 | extern int dwarf_macro_getparamcnt (Dwarf_Macro *macro, size_t *paramcntp); |
| 906 | |
| 907 | /* Get IDX-th parameter of MACRO (numbered from zero), and stores it |
| 908 | to *ATTRIBUTE. Returns 0 on success or -1 for errors. |
| 909 | |
| 910 | After a successful call, you can query ATTRIBUTE by dwarf_whatform |
| 911 | to determine which of the dwarf_formX calls to make to get actual |
| 912 | value out of ATTRIBUTE. Note that calling dwarf_whatattr is not |
| 913 | meaningful for pseudo-attributes formed this way. */ |
| 914 | extern int dwarf_macro_param (Dwarf_Macro *macro, size_t idx, |
| 915 | Dwarf_Attribute *attribute); |
| 916 | |
| 917 | /* Return macro parameter with index 0. This will return -1 if the |
| 918 | parameter is not an integral value. Use dwarf_macro_param for more |
| 919 | general access. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 920 | extern int dwarf_macro_param1 (Dwarf_Macro *macro, Dwarf_Word *paramp) |
| 921 | __nonnull_attribute__ (2); |
| 922 | |
Petr Machata | fb90bf3 | 2014-10-17 02:47:03 +0200 | [diff] [blame] | 923 | /* Return macro parameter with index 1. This will return -1 if the |
| 924 | parameter is not an integral or string value. Use |
| 925 | dwarf_macro_param for more general access. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 926 | extern int dwarf_macro_param2 (Dwarf_Macro *macro, Dwarf_Word *paramp, |
| 927 | const char **strp); |
| 928 | |
Roland McGrath | 3c84db3 | 2009-06-24 17:41:40 -0700 | [diff] [blame] | 929 | /* Compute what's known about a call frame when the PC is at ADDRESS. |
| 930 | Returns 0 for success or -1 for errors. |
| 931 | On success, *FRAME is a malloc'd pointer. */ |
| 932 | extern int dwarf_cfi_addrframe (Dwarf_CFI *cache, |
| 933 | Dwarf_Addr address, Dwarf_Frame **frame) |
| 934 | __nonnull_attribute__ (3); |
| 935 | |
| 936 | /* Return the DWARF register number used in FRAME to denote |
| 937 | the return address in FRAME's caller frame. The remaining |
| 938 | arguments can be non-null to fill in more information. |
| 939 | |
| 940 | Fill [*START, *END) with the PC range to which FRAME's information applies. |
| 941 | Fill in *SIGNALP to indicate whether this is a signal-handling frame. |
| 942 | If true, this is the implicit call frame that calls a signal handler. |
| 943 | This frame's "caller" is actually the interrupted state, not a call; |
| 944 | its return address is an exact PC, not a PC after a call instruction. */ |
| 945 | extern int dwarf_frame_info (Dwarf_Frame *frame, |
| 946 | Dwarf_Addr *start, Dwarf_Addr *end, bool *signalp); |
| 947 | |
Roland McGrath | af80014 | 2009-07-22 13:55:50 -0700 | [diff] [blame] | 948 | /* Return a DWARF expression that yields the Canonical Frame Address at |
| 949 | this frame state. Returns -1 for errors, or zero for success, with |
| 950 | *NOPS set to the number of operations stored at *OPS. That pointer |
| 951 | can be used only as long as FRAME is alive and unchanged. *NOPS is |
| 952 | zero if the CFA cannot be determined here. Note that if nonempty, |
| 953 | *OPS is a DWARF expression, not a location description--append |
| 954 | DW_OP_stack_value to a get a location description for the CFA. */ |
| 955 | extern int dwarf_frame_cfa (Dwarf_Frame *frame, Dwarf_Op **ops, size_t *nops) |
Roland McGrath | 3c84db3 | 2009-06-24 17:41:40 -0700 | [diff] [blame] | 956 | __nonnull_attribute__ (2); |
| 957 | |
Roland McGrath | af80014 | 2009-07-22 13:55:50 -0700 | [diff] [blame] | 958 | /* Deliver a DWARF location description that yields the location or |
| 959 | value of DWARF register number REGNO in the state described by FRAME. |
Roland McGrath | 3c84db3 | 2009-06-24 17:41:40 -0700 | [diff] [blame] | 960 | |
Roland McGrath | af80014 | 2009-07-22 13:55:50 -0700 | [diff] [blame] | 961 | Returns -1 for errors or zero for success, setting *NOPS to the |
| 962 | number of operations in the array stored at *OPS. Note the last |
| 963 | operation is DW_OP_stack_value if there is no mutable location but |
| 964 | only a computable value. |
Roland McGrath | 3c84db3 | 2009-06-24 17:41:40 -0700 | [diff] [blame] | 965 | |
Roland McGrath | af80014 | 2009-07-22 13:55:50 -0700 | [diff] [blame] | 966 | *NOPS zero with *OPS set to OPS_MEM means CFI says the caller's |
| 967 | REGNO is "undefined", i.e. it's call-clobbered and cannot be recovered. |
Roland McGrath | 3c84db3 | 2009-06-24 17:41:40 -0700 | [diff] [blame] | 968 | |
Roland McGrath | af80014 | 2009-07-22 13:55:50 -0700 | [diff] [blame] | 969 | *NOPS zero with *OPS set to a null pointer means CFI says the |
| 970 | caller's REGNO is "same_value", i.e. this frame did not change it; |
| 971 | ask the caller frame where to find it. |
Roland McGrath | 3c84db3 | 2009-06-24 17:41:40 -0700 | [diff] [blame] | 972 | |
| 973 | For common simple expressions *OPS is OPS_MEM. For arbitrary DWARF |
| 974 | expressions in the CFI, *OPS is an internal pointer that can be used as |
| 975 | long as the Dwarf_CFI used to create FRAME remains alive. */ |
| 976 | extern int dwarf_frame_register (Dwarf_Frame *frame, int regno, |
Roland McGrath | af80014 | 2009-07-22 13:55:50 -0700 | [diff] [blame] | 977 | Dwarf_Op ops_mem[3], |
Roland McGrath | 3c84db3 | 2009-06-24 17:41:40 -0700 | [diff] [blame] | 978 | Dwarf_Op **ops, size_t *nops) |
| 979 | __nonnull_attribute__ (3, 4, 5); |
| 980 | |
| 981 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 982 | /* Return error code of last failing function call. This value is kept |
| 983 | separately for each thread. */ |
| 984 | extern int dwarf_errno (void); |
| 985 | |
| 986 | /* Return error string for ERROR. If ERROR is zero, return error string |
| 987 | for most recent error or NULL is none occurred. If ERROR is -1 the |
| 988 | behaviour is similar to the last case except that not NULL but a legal |
| 989 | string is returned. */ |
| 990 | extern const char *dwarf_errmsg (int err); |
| 991 | |
| 992 | |
| 993 | /* Register new Out-Of-Memory handler. The old handler is returned. */ |
| 994 | extern Dwarf_OOM dwarf_new_oom_handler (Dwarf *dbg, Dwarf_OOM handler); |
| 995 | |
| 996 | |
| 997 | /* Inline optimizations. */ |
| 998 | #ifdef __OPTIMIZE__ |
| 999 | /* Return attribute code of given attribute. */ |
Ulrich Drepper | b597dfa | 2007-10-16 05:21:27 +0000 | [diff] [blame] | 1000 | __libdw_extern_inline unsigned int |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 1001 | dwarf_whatattr (Dwarf_Attribute *attr) |
| 1002 | { |
| 1003 | return attr == NULL ? 0 : attr->code; |
| 1004 | } |
| 1005 | |
| 1006 | /* Return attribute code of given attribute. */ |
Ulrich Drepper | b597dfa | 2007-10-16 05:21:27 +0000 | [diff] [blame] | 1007 | __libdw_extern_inline unsigned int |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 1008 | dwarf_whatform (Dwarf_Attribute *attr) |
| 1009 | { |
| 1010 | return attr == NULL ? 0 : attr->form; |
| 1011 | } |
| 1012 | #endif /* Optimize. */ |
| 1013 | |
Ulrich Drepper | 3be7447 | 2006-05-27 18:15:40 +0000 | [diff] [blame] | 1014 | #ifdef __cplusplus |
| 1015 | } |
| 1016 | #endif |
| 1017 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 1018 | #endif /* libdw.h */ |