Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:14:37

0001 /* Interfaces for libdw.
0002    Copyright (C) 2002-2010, 2013, 2014, 2016, 2018 Red Hat, Inc.
0003    This file is part of elfutils.
0004 
0005    This file is free software; you can redistribute it and/or modify
0006    it under the terms of either
0007 
0008      * the GNU Lesser General Public License as published by the Free
0009        Software Foundation; either version 3 of the License, or (at
0010        your option) any later version
0011 
0012    or
0013 
0014      * the GNU General Public License as published by the Free
0015        Software Foundation; either version 2 of the License, or (at
0016        your option) any later version
0017 
0018    or both in parallel, as here.
0019 
0020    elfutils is distributed in the hope that it will be useful, but
0021    WITHOUT ANY WARRANTY; without even the implied warranty of
0022    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0023    General Public License for more details.
0024 
0025    You should have received copies of the GNU General Public License and
0026    the GNU Lesser General Public License along with this program.  If
0027    not, see <http://www.gnu.org/licenses/>.  */
0028 
0029 #ifndef _LIBDW_H
0030 #define _LIBDW_H    1
0031 
0032 #include <gelf.h>
0033 #include <stdbool.h>
0034 #include <stddef.h>
0035 #include <stdint.h>
0036 
0037 /* Mode for the session.  */
0038 typedef enum
0039   {
0040     DWARF_C_READ,       /* Read .. */
0041     DWARF_C_RDWR,       /* Read and write .. */
0042     DWARF_C_WRITE,      /* Write .. */
0043   }
0044 Dwarf_Cmd;
0045 
0046 
0047 /* Callback results.  */
0048 enum
0049 {
0050   DWARF_CB_OK = 0,
0051   DWARF_CB_ABORT
0052 };
0053 
0054 
0055 /* Error values.  */
0056 enum
0057   {
0058     DW_TAG_invalid = 0
0059 #define DW_TAG_invalid  DW_TAG_invalid
0060   };
0061 
0062 
0063 /* Type for offset in DWARF file.  */
0064 typedef GElf_Off Dwarf_Off;
0065 
0066 /* Type for address in DWARF file.  */
0067 typedef GElf_Addr Dwarf_Addr;
0068 
0069 /* Integer types.  Big enough to hold any numeric value.  */
0070 typedef GElf_Xword Dwarf_Word;
0071 typedef GElf_Sxword Dwarf_Sword;
0072 /* For the times we know we do not need that much.  */
0073 typedef GElf_Half Dwarf_Half;
0074 
0075 
0076 /* DWARF abbreviation record.  */
0077 typedef struct Dwarf_Abbrev Dwarf_Abbrev;
0078 
0079 /* Returned to show the last DIE has be returned.  */
0080 #define DWARF_END_ABBREV ((Dwarf_Abbrev *) -1l)
0081 
0082 /* Source code line information for CU.  */
0083 typedef struct Dwarf_Lines_s Dwarf_Lines;
0084 
0085 /* One source code line information.  */
0086 typedef struct Dwarf_Line_s Dwarf_Line;
0087 
0088 /* Source file information.  */
0089 typedef struct Dwarf_Files_s Dwarf_Files;
0090 
0091 /* One address range record.  */
0092 typedef struct Dwarf_Arange_s Dwarf_Arange;
0093 
0094 /* Address ranges of a file.  */
0095 typedef struct Dwarf_Aranges_s Dwarf_Aranges;
0096 
0097 /* CU representation.  */
0098 struct Dwarf_CU;
0099 typedef struct Dwarf_CU Dwarf_CU;
0100 
0101 /* Macro information.  */
0102 typedef struct Dwarf_Macro_s Dwarf_Macro;
0103 
0104 /* Attribute representation.  */
0105 typedef struct
0106 {
0107   unsigned int code;
0108   unsigned int form;
0109   unsigned char *valp;
0110   struct Dwarf_CU *cu;
0111 } Dwarf_Attribute;
0112 
0113 
0114 /* Data block representation.  */
0115 typedef struct
0116 {
0117   Dwarf_Word length;
0118   unsigned char *data;
0119 } Dwarf_Block;
0120 
0121 
0122 /* DIE information.  */
0123 typedef struct
0124 {
0125   /* The offset can be computed from the address.  */
0126   void *addr;
0127   struct Dwarf_CU *cu;
0128   Dwarf_Abbrev *abbrev;
0129   // XXX We'll see what other information will be needed.
0130   long int padding__;
0131 } Dwarf_Die;
0132 
0133 /* Returned to show the last DIE has be returned.  */
0134 #define DWARF_END_DIE ((Dwarf_Die *) -1l)
0135 
0136 
0137 /* Global symbol information.  */
0138 typedef struct
0139 {
0140   Dwarf_Off cu_offset;
0141   Dwarf_Off die_offset;
0142   const char *name;
0143 } Dwarf_Global;
0144 
0145 
0146 /* One operation in a DWARF location expression.
0147    A location expression is an array of these.  */
0148 typedef struct
0149 {
0150   uint8_t atom;         /* Operation */
0151   Dwarf_Word number;        /* Operand */
0152   Dwarf_Word number2;       /* Possible second operand */
0153   Dwarf_Word offset;        /* Offset in location expression */
0154 } Dwarf_Op;
0155 
0156 
0157 /* This describes one Common Information Entry read from a CFI section.
0158    Pointers here point into the DATA->d_buf block passed to dwarf_next_cfi.  */
0159 typedef struct
0160 {
0161   Dwarf_Off CIE_id;  /* Always DW_CIE_ID_64 in Dwarf_CIE structures.  */
0162 
0163   /* Instruction stream describing initial state used by FDEs.  If
0164      we did not understand the whole augmentation string and it did
0165      not use 'z', then there might be more augmentation data here
0166      (and in FDEs) before the actual instructions.  */
0167   const uint8_t *initial_instructions;
0168   const uint8_t *initial_instructions_end;
0169 
0170   Dwarf_Word code_alignment_factor;
0171   Dwarf_Sword data_alignment_factor;
0172   Dwarf_Word return_address_register;
0173 
0174   const char *augmentation; /* Augmentation string.  */
0175 
0176   /* Augmentation data, might be NULL.  The size is correct only if
0177      we understood the augmentation string sufficiently.  */
0178   const uint8_t *augmentation_data;
0179   size_t augmentation_data_size;
0180   size_t fde_augmentation_data_size;
0181 } Dwarf_CIE;
0182 
0183 /* This describes one Frame Description Entry read from a CFI section.
0184    Pointers here point into the DATA->d_buf block passed to dwarf_next_cfi.  */
0185 typedef struct
0186 {
0187   /* Section offset of CIE this FDE refers to.  This will never be
0188      DW_CIE_ID_64 in an FDE.  If this value is DW_CIE_ID_64, this is
0189      actually a Dwarf_CIE structure.  */
0190   Dwarf_Off CIE_pointer;
0191 
0192   /* We can't really decode anything further without looking up the CIE
0193      and checking its augmentation string.  Here follows the encoded
0194      initial_location and address_range, then any augmentation data,
0195      then the instruction stream.  This FDE describes PC locations in
0196      the byte range [initial_location, initial_location+address_range).
0197      When the CIE augmentation string uses 'z', the augmentation data is
0198      a DW_FORM_block (self-sized).  Otherwise, when we understand the
0199      augmentation string completely, fde_augmentation_data_size gives
0200      the number of bytes of augmentation data before the instructions.  */
0201   const uint8_t *start;
0202   const uint8_t *end;
0203 } Dwarf_FDE;
0204 
0205 /* Each entry in a CFI section is either a CIE described by Dwarf_CIE or
0206    an FDE described by Dward_FDE.  Check CIE_id to see which you have.  */
0207 typedef union
0208 {
0209   Dwarf_Off CIE_id;  /* Always DW_CIE_ID_64 in Dwarf_CIE structures.  */
0210   Dwarf_CIE cie;
0211   Dwarf_FDE fde;
0212 } Dwarf_CFI_Entry;
0213 
0214 /* Same as DW_CIE_ID_64 from dwarf.h to keep libdw.h independent.  */
0215 #define LIBDW_CIE_ID 0xffffffffffffffffULL
0216 #define dwarf_cfi_cie_p(entry)  ((entry)->cie.CIE_id == LIBDW_CIE_ID)
0217 
0218 /* Opaque type representing a frame state described by CFI.  */
0219 typedef struct Dwarf_Frame_s Dwarf_Frame;
0220 
0221 /* Opaque type representing a CFI section found in a DWARF or ELF file.  */
0222 typedef struct Dwarf_CFI_s Dwarf_CFI;
0223 
0224 
0225 /* Handle for debug sessions.  */
0226 typedef struct Dwarf Dwarf;
0227 
0228 
0229 /* Out-Of-Memory handler.  */
0230 typedef void (*__noreturn_attribute__ Dwarf_OOM) (void);
0231 
0232 
0233 #ifdef __cplusplus
0234 extern "C" {
0235 #endif
0236 
0237 /* Create a handle for a new debug session.  */
0238 extern Dwarf *dwarf_begin (int fildes, Dwarf_Cmd cmd);
0239 
0240 /* Create a handle for a new debug session for an ELF file.  */
0241 extern Dwarf *dwarf_begin_elf (Elf *elf, Dwarf_Cmd cmd, Elf_Scn *scngrp);
0242 
0243 /* Retrieve ELF descriptor used for DWARF access.  */
0244 extern Elf *dwarf_getelf (Dwarf *dwarf);
0245 
0246 /* Retrieve DWARF descriptor used for a Dwarf_Die or Dwarf_Attribute.
0247    A Dwarf_Die or a Dwarf_Attribute is associated with a particular
0248    Dwarf_CU handle.  This function returns the DWARF descriptor for
0249    that Dwarf_CU.  */
0250 extern Dwarf *dwarf_cu_getdwarf (Dwarf_CU *cu);
0251 
0252 /* Retrieves the DWARF descriptor for debugaltlink data.  Returns NULL
0253    if no alternate debug data has been supplied yet.  libdw will try
0254    to set the alt file on first use of an alt FORM if not yet explicitly
0255    provided by dwarf_setalt.  */
0256 extern Dwarf *dwarf_getalt (Dwarf *main);
0257 
0258 /* Provides the data referenced by the .gnu_debugaltlink section.  The
0259    caller should check that MAIN and ALT match (i.e., they have the
0260    same build ID).  It is the responsibility of the caller to ensure
0261    that the data referenced by ALT stays valid while it is used by
0262    MAIN, until dwarf_setalt is called on MAIN with a different
0263    descriptor, or dwarf_end.  Must be called before inspecting DIEs
0264    that might have alt FORMs.  Otherwise libdw will try to set the
0265    alt file itself on first use.  */
0266 extern void dwarf_setalt (Dwarf *main, Dwarf *alt);
0267 
0268 /* Release debugging handling context.  */
0269 extern int dwarf_end (Dwarf *dwarf);
0270 
0271 
0272 /* Read the header for the DWARF CU.  */
0273 extern int dwarf_nextcu (Dwarf *dwarf, Dwarf_Off off, Dwarf_Off *next_off,
0274              size_t *header_sizep, Dwarf_Off *abbrev_offsetp,
0275              uint8_t *address_sizep, uint8_t *offset_sizep)
0276      __nonnull_attribute__ (3);
0277 
0278 /* Read the header of a DWARF CU or type unit.  If TYPE_SIGNATUREP is not
0279    null, this reads a type unit from the .debug_types section; otherwise
0280    this reads a CU from the .debug_info section.  */
0281 extern int dwarf_next_unit (Dwarf *dwarf, Dwarf_Off off, Dwarf_Off *next_off,
0282                 size_t *header_sizep, Dwarf_Half *versionp,
0283                 Dwarf_Off *abbrev_offsetp,
0284                 uint8_t *address_sizep, uint8_t *offset_sizep,
0285                 uint64_t *type_signaturep, Dwarf_Off *type_offsetp)
0286      __nonnull_attribute__ (3);
0287 
0288 
0289 /* Gets the next Dwarf_CU (unit), version, unit type and if available
0290    the CU DIE and sub (type) DIE of the unit.  Returns 0 on success,
0291    -1 on error or 1 if there are no more units.  To start iterating
0292    provide NULL for CU.  If version < 5 the unit type is set from the
0293    CU DIE if available (DW_UT_compile for DW_TAG_compile_unit,
0294    DW_UT_type for DW_TAG_type_unit or DW_UT_partial for
0295    DW_TAG_partial_unit), otherwise it is set to zero.  If unavailable
0296    (the version or unit type is unknown) the CU DIE is cleared.
0297    Likewise if the sub DIE isn't isn't available (the unit type is not
0298    DW_UT_type or DW_UT_split_type) the sub DIE tag is cleared.  */
0299 extern int dwarf_get_units (Dwarf *dwarf, Dwarf_CU *cu, Dwarf_CU **next_cu,
0300                 Dwarf_Half *version, uint8_t *unit_type,
0301                 Dwarf_Die *cudie, Dwarf_Die *subdie)
0302      __nonnull_attribute__ (3);
0303 
0304 /* Provides information and DIEs associated with the given Dwarf_CU
0305    unit.  Returns -1 on error, zero on success. Arguments not needed
0306    may be NULL.  If they are NULL and aren't known yet, they won't be
0307    looked up.  If the subdie doesn't exist for this unit_type it will
0308    be cleared.  If there is no unit_id for this unit type it will be
0309    set to zero.  */
0310 extern int dwarf_cu_info (Dwarf_CU *cu,
0311               Dwarf_Half *version, uint8_t *unit_type,
0312               Dwarf_Die *cudie, Dwarf_Die *subdie,
0313               uint64_t *unit_id,
0314               uint8_t *address_size, uint8_t *offset_size);
0315 
0316 /* Decode one DWARF CFI entry (CIE or FDE) from the raw section data.
0317    The E_IDENT from the originating ELF file indicates the address
0318    size and byte order used in the CFI section contained in DATA;
0319    EH_FRAME_P should be true for .eh_frame format and false for
0320    .debug_frame format.  OFFSET is the byte position in the section
0321    to start at; on return *NEXT_OFFSET is filled in with the byte
0322    position immediately after this entry.
0323 
0324    On success, returns 0 and fills in *ENTRY; use dwarf_cfi_cie_p to
0325    see whether ENTRY->cie or ENTRY->fde is valid.
0326 
0327    On errors, returns -1.  Some format errors will permit safely
0328    skipping to the next CFI entry though the current one is unusable.
0329    In that case, *NEXT_OFF will be updated before a -1 return.
0330 
0331    If there are no more CFI entries left in the section,
0332    returns 1 and sets *NEXT_OFFSET to (Dwarf_Off) -1.  */
0333 extern int dwarf_next_cfi (const unsigned char e_ident[],
0334                Elf_Data *data, bool eh_frame_p,
0335                Dwarf_Off offset, Dwarf_Off *next_offset,
0336                Dwarf_CFI_Entry *entry)
0337   __nonnull_attribute__ (1, 2, 5, 6);
0338 
0339 /* Use the CFI in the DWARF .debug_frame section.
0340    Returns NULL if there is no such section (not an error).
0341    The pointer returned can be used until dwarf_end is called on DWARF,
0342    and must not be passed to dwarf_cfi_end.
0343    Calling this more than once returns the same pointer.  */
0344 extern Dwarf_CFI *dwarf_getcfi (Dwarf *dwarf);
0345 
0346 /* Use the CFI in the ELF file's exception-handling data.
0347    Returns NULL if there is no such data.
0348    The pointer returned can be used until elf_end is called on ELF,
0349    and must be passed to dwarf_cfi_end before then.
0350    Calling this more than once allocates independent data structures.  */
0351 extern Dwarf_CFI *dwarf_getcfi_elf (Elf *elf);
0352 
0353 /* Release resources allocated by dwarf_getcfi_elf.  */
0354 extern int dwarf_cfi_end (Dwarf_CFI *cache);
0355 
0356 
0357 /* Return DIE at given offset in .debug_info section.  */
0358 extern Dwarf_Die *dwarf_offdie (Dwarf *dbg, Dwarf_Off offset,
0359                 Dwarf_Die *result) __nonnull_attribute__ (3);
0360 
0361 /* Return DIE at given offset in .debug_types section.  */
0362 extern Dwarf_Die *dwarf_offdie_types (Dwarf *dbg, Dwarf_Off offset,
0363                       Dwarf_Die *result)
0364      __nonnull_attribute__ (3);
0365 
0366 /* Return offset of DIE.  */
0367 extern Dwarf_Off dwarf_dieoffset (Dwarf_Die *die);
0368 
0369 /* Return offset of DIE in CU.  */
0370 extern Dwarf_Off dwarf_cuoffset (Dwarf_Die *die);
0371 
0372 /* Return CU DIE containing given DIE.  */
0373 extern Dwarf_Die *dwarf_diecu (Dwarf_Die *die, Dwarf_Die *result,
0374                    uint8_t *address_sizep, uint8_t *offset_sizep)
0375      __nonnull_attribute__ (2);
0376 
0377 /* Given a Dwarf_Die addr returns a (reconstructed) Dwarf_Die, or NULL
0378    if the given addr didn't come from a valid Dwarf_Die.  In particular
0379    it will make sure that the correct Dwarf_CU pointer is set for the
0380    Dwarf_Die, the Dwarf_Abbrev pointer will not be set up yet (it will
0381    only be once the Dwarf_Die is used to read attributes, children or
0382    siblings).  This functions can be used to keep a reference to a
0383    Dwarf_Die which you want to refer to later.  The addr, and the result
0384    of this function, is only valid while the associated Dwarf is valid.  */
0385 extern Dwarf_Die *dwarf_die_addr_die (Dwarf *dbg, void *addr,
0386                       Dwarf_Die *result)
0387      __nonnull_attribute__ (3);
0388 
0389 /* Return the CU DIE and the header info associated with a Dwarf_Die
0390    or Dwarf_Attribute.  A Dwarf_Die or a Dwarf_Attribute is associated
0391    with a particular Dwarf_CU handle.  This function returns the CU or
0392    type unit DIE and header information for that Dwarf_CU.  The
0393    returned DIE is either a compile_unit, partial_unit or type_unit.
0394    If it is a type_unit, then the type signature and type offset are
0395    also provided, otherwise type_offset will be set to zero.  See also
0396    dwarf_diecu and dwarf_next_unit.  */
0397 extern Dwarf_Die *dwarf_cu_die (Dwarf_CU *cu, Dwarf_Die *result,
0398                 Dwarf_Half *versionp,
0399                 Dwarf_Off *abbrev_offsetp,
0400                 uint8_t *address_sizep,
0401                 uint8_t *offset_sizep,
0402                 uint64_t *type_signaturep,
0403                 Dwarf_Off *type_offsetp)
0404      __nonnull_attribute__ (2);
0405 
0406 /* Return CU DIE containing given address.  */
0407 extern Dwarf_Die *dwarf_addrdie (Dwarf *dbg, Dwarf_Addr addr,
0408                  Dwarf_Die *result) __nonnull_attribute__ (3);
0409 
0410 /* Return child of current DIE.  */
0411 extern int dwarf_child (Dwarf_Die *die, Dwarf_Die *result)
0412      __nonnull_attribute__ (2);
0413 
0414 /* Locates the first sibling of DIE and places it in RESULT.
0415    Returns 0 if a sibling was found, -1 if something went wrong.
0416    Returns 1 if no sibling could be found and, if RESULT is not
0417    the same as DIE, it sets RESULT->addr to the address of the
0418    (non-sibling) DIE that follows this one, or NULL if this DIE
0419    was the last one in the compilation unit.  */
0420 extern int dwarf_siblingof (Dwarf_Die *die, Dwarf_Die *result)
0421      __nonnull_attribute__ (2);
0422 
0423 /* For type aliases and qualifier type DIEs, which don't modify or
0424    change the structural layout of the underlying type, follow the
0425    DW_AT_type attribute (recursively) and return the underlying type
0426    Dwarf_Die.
0427 
0428    Returns 0 when RESULT contains a Dwarf_Die (possibly equal to the
0429    given DIE) that isn't a type alias or qualifier type.  Returns 1
0430    when RESULT contains a type alias or qualifier Dwarf_Die that
0431    couldn't be peeled further (it doesn't have a DW_TAG_type
0432    attribute).  Returns -1 when an error occurred.
0433 
0434    The current DWARF specification defines one type alias tag
0435    (DW_TAG_typedef) and seven modifier/qualifier type tags
0436    (DW_TAG_const_type, DW_TAG_volatile_type, DW_TAG_restrict_type,
0437    DW_TAG_atomic_type, DW_TAG_immutable_type, DW_TAG_packed_type and
0438    DW_TAG_shared_type).  This function won't peel modifier type
0439    tags that change the way the underlying type is accessed such
0440    as the pointer or reference type tags (DW_TAG_pointer_type,
0441    DW_TAG_reference_type or DW_TAG_rvalue_reference_type).
0442 
0443    A future version of this function might peel other alias or
0444    qualifier type tags if a future DWARF version or GNU extension
0445    defines other type aliases or qualifier type tags that don't modify,
0446    change the structural layout or the way to access the underlying type.  */
0447 extern int dwarf_peel_type (Dwarf_Die *die, Dwarf_Die *result)
0448     __nonnull_attribute__ (2);
0449 
0450 /* Check whether the DIE has children.  */
0451 extern int dwarf_haschildren (Dwarf_Die *die) __nonnull_attribute__ (1);
0452 
0453 /* Walks the attributes of DIE, starting at the one OFFSET bytes in,
0454    calling the CALLBACK function for each one.  Stops if the callback
0455    function ever returns a value other than DWARF_CB_OK and returns the
0456    offset of the offending attribute.  If the end of the attributes
0457    is reached 1 is returned.  If something goes wrong -1 is returned and
0458    the dwarf error number is set.  */
0459 extern ptrdiff_t dwarf_getattrs (Dwarf_Die *die,
0460                  int (*callback) (Dwarf_Attribute *, void *),
0461                  void *arg, ptrdiff_t offset)
0462      __nonnull_attribute__ (2);
0463 
0464 /* Return tag of given DIE.  */
0465 extern int dwarf_tag (Dwarf_Die *die) __nonnull_attribute__ (1);
0466 
0467 
0468 /* Return specific attribute of DIE.  */
0469 extern Dwarf_Attribute *dwarf_attr (Dwarf_Die *die, unsigned int search_name,
0470                     Dwarf_Attribute *result)
0471      __nonnull_attribute__ (3);
0472 
0473 /* Check whether given DIE has specific attribute.  */
0474 extern int dwarf_hasattr (Dwarf_Die *die, unsigned int search_name);
0475 
0476 /* These are the same as dwarf_attr and dwarf_hasattr, respectively,
0477    but they resolve an indirect attribute through
0478    DW_AT_abstract_origin, DW_AT_specification or, if the DIE is a
0479    top-level split CU, the skeleton DIE.  Note that the attribute
0480    might come from a DIE in a different CU (possibly from a different
0481    Dwarf file).  In that case all attribute information needs to be
0482    resolved through the CU associated with the returned
0483    Dwarf_Attribute.  The dwarf_form functions already do this
0484    automatically.  */
0485 extern Dwarf_Attribute *dwarf_attr_integrate (Dwarf_Die *die,
0486                           unsigned int search_name,
0487                           Dwarf_Attribute *result)
0488      __nonnull_attribute__ (3);
0489 extern int dwarf_hasattr_integrate (Dwarf_Die *die, unsigned int search_name);
0490 
0491 
0492 
0493 
0494 /* Check whether given attribute has specific form.  */
0495 extern int dwarf_hasform (Dwarf_Attribute *attr, unsigned int search_form);
0496 
0497 /* Return attribute code of given attribute.  */
0498 extern unsigned int dwarf_whatattr (Dwarf_Attribute *attr);
0499 
0500 /* Return form code of given attribute.  */
0501 extern unsigned int dwarf_whatform (Dwarf_Attribute *attr);
0502 
0503 
0504 /* Return string associated with given attribute.  */
0505 extern const char *dwarf_formstring (Dwarf_Attribute *attrp);
0506 
0507 /* Return unsigned constant represented by attribute.  */
0508 extern int dwarf_formudata (Dwarf_Attribute *attr, Dwarf_Word *return_uval)
0509      __nonnull_attribute__ (2);
0510 
0511 /* Return signed constant represented by attribute.  */
0512 extern int dwarf_formsdata (Dwarf_Attribute *attr, Dwarf_Sword *return_uval)
0513      __nonnull_attribute__ (2);
0514 
0515 /* Return address represented by attribute.  */
0516 extern int dwarf_formaddr (Dwarf_Attribute *attr, Dwarf_Addr *return_addr)
0517      __nonnull_attribute__ (2);
0518 
0519 /* This function is deprecated.  Always use dwarf_formref_die instead.
0520    Return reference offset represented by attribute.  */
0521 extern int dwarf_formref (Dwarf_Attribute *attr, Dwarf_Off *return_offset)
0522      __nonnull_attribute__ (2) __deprecated_attribute__;
0523 
0524 /* Look up the DIE in a reference-form attribute.  */
0525 extern Dwarf_Die *dwarf_formref_die (Dwarf_Attribute *attr, Dwarf_Die *die_mem)
0526      __nonnull_attribute__ (2);
0527 
0528 /* Return block represented by attribute.  */
0529 extern int dwarf_formblock (Dwarf_Attribute *attr, Dwarf_Block *return_block)
0530      __nonnull_attribute__ (2);
0531 
0532 /* Return flag represented by attribute.  */
0533 extern int dwarf_formflag (Dwarf_Attribute *attr, bool *return_bool)
0534      __nonnull_attribute__ (2);
0535 
0536 
0537 /* Simplified attribute value access functions.  */
0538 
0539 /* Return string in name attribute of DIE.  */
0540 extern const char *dwarf_diename (Dwarf_Die *die);
0541 
0542 /* Return high PC attribute of DIE.  */
0543 extern int dwarf_highpc (Dwarf_Die *die, Dwarf_Addr *return_addr)
0544      __nonnull_attribute__ (2);
0545 
0546 /* Return low PC attribute of DIE.  */
0547 extern int dwarf_lowpc (Dwarf_Die *die, Dwarf_Addr *return_addr)
0548      __nonnull_attribute__ (2);
0549 
0550 /* Return entry_pc or low_pc attribute of DIE.  */
0551 extern int dwarf_entrypc (Dwarf_Die *die, Dwarf_Addr *return_addr)
0552      __nonnull_attribute__ (2);
0553 
0554 /* Return 1 if DIE's lowpc/highpc or ranges attributes match the PC address,
0555    0 if not, or -1 for errors.  */
0556 extern int dwarf_haspc (Dwarf_Die *die, Dwarf_Addr pc);
0557 
0558 /* Enumerate the PC address ranges covered by this DIE, covering all
0559    addresses where dwarf_haspc returns true.  In the first call OFFSET
0560    should be zero and *BASEP need not be initialized.  Returns -1 for
0561    errors, zero when there are no more address ranges to report, or a
0562    nonzero OFFSET value to pass to the next call.  Each subsequent call
0563    must preserve *BASEP from the prior call.  Successful calls fill in
0564    *STARTP and *ENDP with a contiguous address range.  */
0565 extern ptrdiff_t dwarf_ranges (Dwarf_Die *die,
0566                    ptrdiff_t offset, Dwarf_Addr *basep,
0567                    Dwarf_Addr *startp, Dwarf_Addr *endp);
0568 
0569 
0570 /* Return byte size attribute of DIE.  */
0571 extern int dwarf_bytesize (Dwarf_Die *die);
0572 
0573 /* Return bit size attribute of DIE.  */
0574 extern int dwarf_bitsize (Dwarf_Die *die);
0575 
0576 /* Return bit offset attribute of DIE.  */
0577 extern int dwarf_bitoffset (Dwarf_Die *die);
0578 
0579 /* Return array order attribute of DIE.  */
0580 extern int dwarf_arrayorder (Dwarf_Die *die);
0581 
0582 /* Return source language attribute of DIE.  */
0583 extern int dwarf_srclang (Dwarf_Die *die);
0584 
0585 
0586 /* Get abbreviation at given offset for given DIE.  */
0587 extern Dwarf_Abbrev *dwarf_getabbrev (Dwarf_Die *die, Dwarf_Off offset,
0588                       size_t *lengthp);
0589 
0590 /* Get abbreviation at given offset in .debug_abbrev section.  */
0591 extern int dwarf_offabbrev (Dwarf *dbg, Dwarf_Off offset, size_t *lengthp,
0592                 Dwarf_Abbrev *abbrevp)
0593      __nonnull_attribute__ (4);
0594 
0595 /* Get abbreviation code.  */
0596 extern unsigned int dwarf_getabbrevcode (Dwarf_Abbrev *abbrev);
0597 
0598 /* Get abbreviation tag.  */
0599 extern unsigned int dwarf_getabbrevtag (Dwarf_Abbrev *abbrev);
0600 
0601 /* Return true if abbreviation is children flag set.  */
0602 extern int dwarf_abbrevhaschildren (Dwarf_Abbrev *abbrev);
0603 
0604 /* Get number of attributes of abbreviation.  */
0605 extern int dwarf_getattrcnt (Dwarf_Abbrev *abbrev, size_t *attrcntp)
0606      __nonnull_attribute__ (2);
0607 
0608 /* Get specific attribute of abbreviation.  */
0609 extern int dwarf_getabbrevattr (Dwarf_Abbrev *abbrev, size_t idx,
0610                 unsigned int *namep, unsigned int *formp,
0611                 Dwarf_Off *offset);
0612 
0613 /* Get specific attribute of abbreviation and any data encoded with it.
0614    Specifically for DW_FORM_implicit_const data will be set to the
0615    constant value associated.  */
0616 extern int dwarf_getabbrevattr_data (Dwarf_Abbrev *abbrev, size_t idx,
0617                      unsigned int *namep, unsigned int *formp,
0618                      Dwarf_Sword *datap, Dwarf_Off *offset);
0619 
0620 /* Get string from-debug_str section.  */
0621 extern const char *dwarf_getstring (Dwarf *dbg, Dwarf_Off offset,
0622                     size_t *lenp);
0623 
0624 
0625 /* Get public symbol information.  */
0626 extern ptrdiff_t dwarf_getpubnames (Dwarf *dbg,
0627                     int (*callback) (Dwarf *, Dwarf_Global *,
0628                              void *),
0629                     void *arg, ptrdiff_t offset)
0630      __nonnull_attribute__ (2);
0631 
0632 
0633 /* Get source file information for CU.  */
0634 extern int dwarf_getsrclines (Dwarf_Die *cudie, Dwarf_Lines **lines,
0635                   size_t *nlines) __nonnull_attribute__ (2, 3);
0636 
0637 /* Return one of the source lines of the CU.  */
0638 extern Dwarf_Line *dwarf_onesrcline (Dwarf_Lines *lines, size_t idx);
0639 
0640 /* Get the file source files used in the CU.  */
0641 extern int dwarf_getsrcfiles (Dwarf_Die *cudie, Dwarf_Files **files,
0642                   size_t *nfiles)
0643      __nonnull_attribute__ (2);
0644 
0645 
0646 /* Get source for address in CU.  */
0647 extern Dwarf_Line *dwarf_getsrc_die (Dwarf_Die *cudie, Dwarf_Addr addr);
0648 
0649 /* Get source for file and line number.  */
0650 extern int dwarf_getsrc_file (Dwarf *dbg, const char *fname, int line, int col,
0651                   Dwarf_Line ***srcsp, size_t *nsrcs)
0652      __nonnull_attribute__ (2, 5, 6);
0653 
0654 
0655 /* Return line address.  */
0656 extern int dwarf_lineaddr (Dwarf_Line *line, Dwarf_Addr *addrp);
0657 
0658 /* Return line VLIW operation index.  */
0659 extern int dwarf_lineop_index (Dwarf_Line *line, unsigned int *op_indexp);
0660 
0661 /* Return line number.  */
0662 extern int dwarf_lineno (Dwarf_Line *line, int *linep)
0663      __nonnull_attribute__ (2);
0664 
0665 /* Return column in line.  */
0666 extern int dwarf_linecol (Dwarf_Line *line, int *colp)
0667      __nonnull_attribute__ (2);
0668 
0669 /* Return true if record is for beginning of a statement.  */
0670 extern int dwarf_linebeginstatement (Dwarf_Line *line, bool *flagp)
0671      __nonnull_attribute__ (2);
0672 
0673 /* Return true if record is for end of sequence.  */
0674 extern int dwarf_lineendsequence (Dwarf_Line *line, bool *flagp)
0675      __nonnull_attribute__ (2);
0676 
0677 /* Return true if record is for beginning of a basic block.  */
0678 extern int dwarf_lineblock (Dwarf_Line *line, bool *flagp)
0679      __nonnull_attribute__ (2);
0680 
0681 /* Return true if record is for end of prologue.  */
0682 extern int dwarf_lineprologueend (Dwarf_Line *line, bool *flagp)
0683      __nonnull_attribute__ (2);
0684 
0685 /* Return true if record is for beginning of epilogue.  */
0686 extern int dwarf_lineepiloguebegin (Dwarf_Line *line, bool *flagp)
0687      __nonnull_attribute__ (2);
0688 
0689 /* Return instruction-set architecture in this record.  */
0690 extern int dwarf_lineisa (Dwarf_Line *line, unsigned int *isap)
0691      __nonnull_attribute__ (2);
0692 
0693 /* Return code path discriminator in this record.  */
0694 extern int dwarf_linediscriminator (Dwarf_Line *line, unsigned int *discp)
0695      __nonnull_attribute__ (2);
0696 
0697 
0698 /* Find line information for address.  The returned string is NULL when
0699    an error occurred, or the file path.  The file path is either absolute
0700    or relative to the compilation directory.  See dwarf_decl_file.  */
0701 extern const char *dwarf_linesrc (Dwarf_Line *line,
0702                   Dwarf_Word *mtime, Dwarf_Word *length);
0703 
0704 /* Return the caller of this line if inlined.  If not inlined,
0705    return NULL.  */
0706 extern Dwarf_Line *dwarf_linecontext (Dwarf_Lines *lines, Dwarf_Line *line);
0707 
0708 /* Return the function name in this line record. If this line is
0709    inlined, this is the name of the function that was inlined. If this line
0710    is not inlined, return NULL.  */
0711 extern const char *dwarf_linefunctionname (Dwarf *dbg, Dwarf_Line *line);
0712 
0713 /* Return file information.  The returned string is NULL when
0714    an error occurred, or the file path.  The file path is either absolute
0715    or relative to the compilation directory.  See dwarf_decl_file.  */
0716 extern const char *dwarf_filesrc (Dwarf_Files *file, size_t idx,
0717                   Dwarf_Word *mtime, Dwarf_Word *length);
0718 
0719 /* Return the Dwarf_Files and index associated with the given Dwarf_Line.  */
0720 extern int dwarf_line_file (Dwarf_Line *line,
0721                 Dwarf_Files **files, size_t *idx)
0722     __nonnull_attribute__ (2, 3);
0723 
0724 /* Return the directory list used in the file information extracted.
0725    (*RESULT)[0] is the CU's DW_AT_comp_dir value, and may be null.
0726    (*RESULT)[0..*NDIRS-1] are the compile-time include directory path
0727    encoded by the compiler.  */
0728 extern int dwarf_getsrcdirs (Dwarf_Files *files,
0729                  const char *const **result, size_t *ndirs)
0730   __nonnull_attribute__ (2, 3);
0731 
0732 /* Iterates through the debug line units.  Returns 0 on success, -1 on
0733    error or 1 if there are no more units.  To start iterating use zero
0734    for OFF and set *CU to NULL.  On success NEXT_OFF will be set to
0735    the next offset to use.  The *CU will be set if this line table
0736    needed a specific CU and needs to be given when calling
0737    dwarf_next_lines again (to help dwarf_next_lines quickly find the
0738    next CU).  *CU might be set to NULL when it couldn't be found (the
0739    compilation directory entry will be the empty string in that case)
0740    or for DWARF 5 or later tables, which are self contained.  SRCFILES
0741    and SRCLINES may be NULL if the caller is not interested in the
0742    actual line or file table.  On success and when not NULL, NFILES
0743    and NLINES will be set to the number of files in the file table and
0744    number of lines in the line table.  */
0745 extern int dwarf_next_lines (Dwarf *dwarf, Dwarf_Off off,
0746                  Dwarf_Off *next_off, Dwarf_CU **cu,
0747                  Dwarf_Files **srcfiles, size_t *nfiles,
0748                  Dwarf_Lines **srclines, size_t *nlines)
0749   __nonnull_attribute__ (3,4);
0750 
0751 /* Return location expression, decoded as a list of operations.  */
0752 extern int dwarf_getlocation (Dwarf_Attribute *attr, Dwarf_Op **expr,
0753                   size_t *exprlen) __nonnull_attribute__ (2, 3);
0754 
0755 /* Return location expressions.  If the attribute uses a location list,
0756    ADDRESS selects the relevant location expressions from the list.
0757    There can be multiple matches, resulting in multiple expressions to
0758    return.  EXPRS and EXPRLENS are parallel arrays of NLOCS slots to
0759    fill in.  Returns the number of locations filled in, or -1 for
0760    errors.  If EXPRS is a null pointer, stores nothing and returns the
0761    total number of locations.  A return value of zero means that the
0762    location list indicated no value is accessible.  */
0763 extern int dwarf_getlocation_addr (Dwarf_Attribute *attr, Dwarf_Addr address,
0764                    Dwarf_Op **exprs, size_t *exprlens,
0765                    size_t nlocs);
0766 
0767 /* Enumerate the locations ranges and descriptions covered by the
0768    given attribute.  In the first call OFFSET should be zero and
0769    *BASEP need not be initialized.  Returns -1 for errors, zero when
0770    there are no more locations to report, or a nonzero OFFSET
0771    value to pass to the next call.  Each subsequent call must preserve
0772    *BASEP from the prior call.  Successful calls fill in *STARTP and
0773    *ENDP with a contiguous address range and *EXPR with a pointer to
0774    an array of operations with length *EXPRLEN.  If the attribute
0775    describes a single location description and not a location list the
0776    first call (with OFFSET zero) will return the location description
0777    in *EXPR with *STARTP set to zero and *ENDP set to minus one.  */
0778 extern ptrdiff_t dwarf_getlocations (Dwarf_Attribute *attr,
0779                      ptrdiff_t offset, Dwarf_Addr *basep,
0780                      Dwarf_Addr *startp, Dwarf_Addr *endp,
0781                      Dwarf_Op **expr, size_t *exprlen);
0782 
0783 /* Return the block associated with a DW_OP_implicit_value operation.
0784    The OP pointer must point into an expression that dwarf_getlocation
0785    or dwarf_getlocation_addr has returned given the same ATTR.  */
0786 extern int dwarf_getlocation_implicit_value (Dwarf_Attribute *attr,
0787                          const Dwarf_Op *op,
0788                          Dwarf_Block *return_block)
0789   __nonnull_attribute__ (2, 3);
0790 
0791 /* Return the attribute indicated by a DW_OP_GNU_implicit_pointer operation.
0792    The OP pointer must point into an expression that dwarf_getlocation
0793    or dwarf_getlocation_addr has returned given the same ATTR.
0794    The result is the DW_AT_location or DW_AT_const_value attribute
0795    of the OP->number DIE.  */
0796 extern int dwarf_getlocation_implicit_pointer (Dwarf_Attribute *attr,
0797                            const Dwarf_Op *op,
0798                            Dwarf_Attribute *result)
0799   __nonnull_attribute__ (2, 3);
0800 
0801 /* Return the DIE associated with an operation such as
0802    DW_OP_GNU_implicit_pointer, DW_OP_GNU_parameter_ref, DW_OP_GNU_convert,
0803    DW_OP_GNU_reinterpret, DW_OP_GNU_const_type, DW_OP_GNU_regval_type or
0804    DW_OP_GNU_deref_type.  The OP pointer must point into an expression that
0805    dwarf_getlocation or dwarf_getlocation_addr has returned given the same
0806    ATTR.  The RESULT is a DIE that expresses a type or value needed by the
0807    given OP.  */
0808 extern int dwarf_getlocation_die (Dwarf_Attribute *attr,
0809                   const Dwarf_Op *op,
0810                   Dwarf_Die *result)
0811   __nonnull_attribute__ (2, 3);
0812 
0813 /* Return the attribute expressing a value associated with an operation such
0814    as DW_OP_implicit_value, DW_OP_GNU_entry_value or DW_OP_GNU_const_type.
0815    The OP pointer must point into an expression that dwarf_getlocation
0816    or dwarf_getlocation_addr has returned given the same ATTR.
0817    The RESULT is a value expressed by an attribute such as DW_AT_location
0818    or DW_AT_const_value.  */
0819 extern int dwarf_getlocation_attr (Dwarf_Attribute *attr,
0820                    const Dwarf_Op *op,
0821                    Dwarf_Attribute *result)
0822   __nonnull_attribute__ (2, 3);
0823 
0824 
0825 /* Compute the byte-size of a type DIE according to DWARF rules.
0826    For most types, this is just DW_AT_byte_size.
0827    For DW_TAG_array_type it can apply much more complex rules.  */
0828 extern int dwarf_aggregate_size (Dwarf_Die *die, Dwarf_Word *size);
0829 
0830 /* Given a language code, as returned by dwarf_srclan, get the default
0831    lower bound for a subrange type without a lower bound attribute.
0832    Returns zero on success or -1 on failure when the given language
0833    wasn't recognized.  */
0834 extern int dwarf_default_lower_bound (int lang, Dwarf_Sword *result)
0835   __nonnull_attribute__ (2);
0836 
0837 /* Return scope DIEs containing PC address.
0838    Sets *SCOPES to a malloc'd array of Dwarf_Die structures,
0839    and returns the number of elements in the array.
0840    (*SCOPES)[0] is the DIE for the innermost scope containing PC,
0841    (*SCOPES)[1] is the DIE for the scope containing that scope, and so on.
0842    Returns -1 for errors or 0 if no scopes match PC.  */
0843 extern int dwarf_getscopes (Dwarf_Die *cudie, Dwarf_Addr pc,
0844                 Dwarf_Die **scopes);
0845 
0846 /* Return scope DIEs containing the given DIE.
0847    Sets *SCOPES to a malloc'd array of Dwarf_Die structures,
0848    and returns the number of elements in the array.
0849    (*SCOPES)[0] is a copy of DIE.
0850    (*SCOPES)[1] is the DIE for the scope containing that scope, and so on.
0851    Returns -1 for errors or 0 if DIE is not found in any scope entry.  */
0852 extern int dwarf_getscopes_die (Dwarf_Die *die, Dwarf_Die **scopes);
0853 
0854 
0855 /* Search SCOPES[0..NSCOPES-1] for a variable called NAME.
0856    Ignore the first SKIP_SHADOWS scopes that match the name.
0857    If MATCH_FILE is not null, accept only declaration in that source file;
0858    if MATCH_LINENO or MATCH_LINECOL are also nonzero, accept only declaration
0859    at that line and column.
0860 
0861    If successful, fill in *RESULT with the DIE of the variable found,
0862    and return N where SCOPES[N] is the scope defining the variable.
0863    Return -1 for errors or -2 for no matching variable found.  */
0864 extern int dwarf_getscopevar (Dwarf_Die *scopes, int nscopes,
0865                   const char *name, int skip_shadows,
0866                   const char *match_file,
0867                   int match_lineno, int match_linecol,
0868                   Dwarf_Die *result);
0869 
0870 
0871 
0872 /* Return list address ranges.  */
0873 extern int dwarf_getaranges (Dwarf *dbg, Dwarf_Aranges **aranges,
0874                  size_t *naranges)
0875      __nonnull_attribute__ (2);
0876 
0877 /* Return one of the address range entries.  */
0878 extern Dwarf_Arange *dwarf_onearange (Dwarf_Aranges *aranges, size_t idx);
0879 
0880 /* Return information in address range record.  */
0881 extern int dwarf_getarangeinfo (Dwarf_Arange *arange, Dwarf_Addr *addrp,
0882                 Dwarf_Word *lengthp, Dwarf_Off *offsetp);
0883 
0884 /* Get address range which includes given address.  */
0885 extern Dwarf_Arange *dwarf_getarange_addr (Dwarf_Aranges *aranges,
0886                        Dwarf_Addr addr);
0887 
0888 
0889 
0890 /* Get functions in CUDIE.  The given callback will be called for all
0891    defining DW_TAG_subprograms in the CU DIE tree.  If the callback
0892    returns DWARF_CB_ABORT the return value can be used as offset argument
0893    to resume the function to find all remaining functions (this is not
0894    really recommended, since it needs to rewalk the CU DIE tree first till
0895    that offset is found again).  If the callback returns DWARF_CB_OK
0896    dwarf_getfuncs will not return but keep calling the callback for each
0897    function DIE it finds.  Pass zero for offset on the first call to walk
0898    the full CU DIE tree.  If no more functions can be found and the callback
0899    returned DWARF_CB_OK then the function returns zero.  */
0900 extern ptrdiff_t dwarf_getfuncs (Dwarf_Die *cudie,
0901                  int (*callback) (Dwarf_Die *, void *),
0902                  void *arg, ptrdiff_t offset);
0903 
0904 
0905 /* Return file name containing definition of the given declaration.
0906    Of the DECL has an (indirect, see dwarf_attr_integrate) decl_file
0907    attribute.  The returned file path is either absolute, or relative
0908    to the compilation directory.  Given the decl DIE, the compilation
0909    directory can be retrieved through:
0910    dwarf_formstring (dwarf_attr (dwarf_diecu (decl, &cudie, NULL, NULL),
0911                                  DW_AT_comp_dir, &attr));
0912    Returns NULL if no decl_file could be found or an error occurred.  */
0913 extern const char *dwarf_decl_file (Dwarf_Die *decl);
0914 
0915 /* Get line number of beginning of given declaration.  */
0916 extern int dwarf_decl_line (Dwarf_Die *decl, int *linep)
0917      __nonnull_attribute__ (2);
0918 
0919 /* Get column number of beginning of given declaration.  */
0920 extern int dwarf_decl_column (Dwarf_Die *decl, int *colp)
0921      __nonnull_attribute__ (2);
0922 
0923 
0924 /* Return nonzero if given function is an abstract inline definition.  */
0925 extern int dwarf_func_inline (Dwarf_Die *func);
0926 
0927 /* Find each concrete inlined instance of the abstract inline definition.  */
0928 extern int dwarf_func_inline_instances (Dwarf_Die *func,
0929                     int (*callback) (Dwarf_Die *, void *),
0930                     void *arg);
0931 
0932 
0933 /* Find the appropriate PC location or locations for function entry
0934    breakpoints for the given DW_TAG_subprogram DIE.  Returns -1 for errors.
0935    On success, returns the number of breakpoint locations (never zero)
0936    and sets *BKPTS to a malloc'd vector of addresses.  */
0937 extern int dwarf_entry_breakpoints (Dwarf_Die *die, Dwarf_Addr **bkpts);
0938 
0939 
0940 /* Iterate through the macro unit referenced by CUDIE and call
0941    CALLBACK for each macro information entry.  To start the iteration,
0942    one would pass DWARF_GETMACROS_START for TOKEN.
0943 
0944    The iteration continues while CALLBACK returns DWARF_CB_OK.  If the
0945    callback returns DWARF_CB_ABORT, the iteration stops and a
0946    continuation token is returned, which can be used to restart the
0947    iteration at the point where it ended.  Returns -1 for errors or 0
0948    if there are no more macro entries.
0949 
0950    Note that the Dwarf_Macro pointer passed to the callback is only
0951    valid for the duration of the callback invocation.
0952 
0953    For backward compatibility, a token of 0 is accepted for starting
0954    the iteration as well, but in that case this interface will refuse
0955    to serve opcode 0xff from .debug_macro sections.  Such opcode would
0956    be considered invalid and would cause dwarf_getmacros to return
0957    with error.  */
0958 #define DWARF_GETMACROS_START PTRDIFF_MIN
0959 extern ptrdiff_t dwarf_getmacros (Dwarf_Die *cudie,
0960                   int (*callback) (Dwarf_Macro *, void *),
0961                   void *arg, ptrdiff_t token)
0962      __nonnull_attribute__ (2);
0963 
0964 /* This is similar in operation to dwarf_getmacros, but selects the
0965    unit to iterate through by offset instead of by CU, and always
0966    iterates .debug_macro.  This can be used for handling
0967    DW_MACRO_GNU_transparent_include's or similar opcodes.
0968 
0969    TOKEN value of DWARF_GETMACROS_START can be used to start the
0970    iteration.
0971 
0972    It is not appropriate to obtain macro unit offset by hand from a CU
0973    DIE and then request iteration through this interface.  The reason
0974    for this is that if a dwarf_macro_getsrcfiles is later called,
0975    there would be no way to figure out what DW_AT_comp_dir was present
0976    on the CU DIE, and file names referenced in either the macro unit
0977    itself, or the .debug_line unit that it references, might be wrong.
0978    Use dwarf_getmacros.  */
0979 extern ptrdiff_t dwarf_getmacros_off (Dwarf *dbg, Dwarf_Off macoff,
0980                       int (*callback) (Dwarf_Macro *, void *),
0981                       void *arg, ptrdiff_t token)
0982   __nonnull_attribute__ (3);
0983 
0984 /* Get the source files used by the macro entry.  You shouldn't assume
0985    that Dwarf_Files references will remain valid after MACRO becomes
0986    invalid.  (Which is to say it's only valid within the
0987    dwarf_getmacros* callback.)  Returns 0 for success or a negative
0988    value in case of an error.  */
0989 extern int dwarf_macro_getsrcfiles (Dwarf *dbg, Dwarf_Macro *macro,
0990                     Dwarf_Files **files, size_t *nfiles)
0991   __nonnull_attribute__ (2, 3, 4);
0992 
0993 /* Return macro opcode.  That's a constant that can be either from
0994    DW_MACINFO_* domain or DW_MACRO_GNU_* domain.  The two domains have
0995    compatible values, so it's OK to use either of them for
0996    comparisons.  The only differences is 0xff, which could be either
0997    DW_MACINFO_vendor_ext or a vendor-defined DW_MACRO_* constant.  One
0998    would need to look if the CU DIE which the iteration was requested
0999    for has attribute DW_AT_macro_info, or either of DW_AT_GNU_macros
1000    or DW_AT_macros to differentiate the two interpretations.  */
1001 extern int dwarf_macro_opcode (Dwarf_Macro *macro, unsigned int *opcodep)
1002      __nonnull_attribute__ (2);
1003 
1004 /* Get number of parameters of MACRO and store it to *PARAMCNTP.  */
1005 extern int dwarf_macro_getparamcnt (Dwarf_Macro *macro, size_t *paramcntp);
1006 
1007 /* Get IDX-th parameter of MACRO (numbered from zero), and stores it
1008    to *ATTRIBUTE.  Returns 0 on success or -1 for errors.
1009 
1010    After a successful call, you can query ATTRIBUTE by dwarf_whatform
1011    to determine which of the dwarf_formX calls to make to get actual
1012    value out of ATTRIBUTE.  Note that calling dwarf_whatattr is not
1013    meaningful for pseudo-attributes formed this way.  */
1014 extern int dwarf_macro_param (Dwarf_Macro *macro, size_t idx,
1015                   Dwarf_Attribute *attribute);
1016 
1017 /* Return macro parameter with index 0.  This will return -1 if the
1018    parameter is not an integral value.  Use dwarf_macro_param for more
1019    general access.  */
1020 extern int dwarf_macro_param1 (Dwarf_Macro *macro, Dwarf_Word *paramp)
1021      __nonnull_attribute__ (2);
1022 
1023 /* Return macro parameter with index 1.  This will return -1 if the
1024    parameter is not an integral or string value.  Use
1025    dwarf_macro_param for more general access.  */
1026 extern int dwarf_macro_param2 (Dwarf_Macro *macro, Dwarf_Word *paramp,
1027                    const char **strp);
1028 
1029 /* Compute what's known about a call frame when the PC is at ADDRESS.
1030    Returns 0 for success or -1 for errors.
1031    On success, *FRAME is a malloc'd pointer.  */
1032 extern int dwarf_cfi_addrframe (Dwarf_CFI *cache,
1033                 Dwarf_Addr address, Dwarf_Frame **frame)
1034   __nonnull_attribute__ (3);
1035 
1036 /* Return the DWARF register number used in FRAME to denote
1037    the return address in FRAME's caller frame.  The remaining
1038    arguments can be non-null to fill in more information.
1039 
1040    Fill [*START, *END) with the PC range to which FRAME's information applies.
1041    Fill in *SIGNALP to indicate whether this is a signal-handling frame.
1042    If true, this is the implicit call frame that calls a signal handler.
1043    This frame's "caller" is actually the interrupted state, not a call;
1044    its return address is an exact PC, not a PC after a call instruction.  */
1045 extern int dwarf_frame_info (Dwarf_Frame *frame,
1046                  Dwarf_Addr *start, Dwarf_Addr *end, bool *signalp);
1047 
1048 /* Return a DWARF expression that yields the Canonical Frame Address at
1049    this frame state.  Returns -1 for errors, or zero for success, with
1050    *NOPS set to the number of operations stored at *OPS.  That pointer
1051    can be used only as long as FRAME is alive and unchanged.  *NOPS is
1052    zero if the CFA cannot be determined here.  Note that if nonempty,
1053    *OPS is a DWARF expression, not a location description--append
1054    DW_OP_stack_value to a get a location description for the CFA.  */
1055 extern int dwarf_frame_cfa (Dwarf_Frame *frame, Dwarf_Op **ops, size_t *nops)
1056   __nonnull_attribute__ (2);
1057 
1058 /* Deliver a DWARF location description that yields the location or
1059    value of DWARF register number REGNO in the state described by FRAME.
1060 
1061    Returns -1 for errors or zero for success, setting *NOPS to the
1062    number of operations in the array stored at *OPS.  Note the last
1063    operation is DW_OP_stack_value if there is no mutable location but
1064    only a computable value.
1065 
1066    *NOPS zero with *OPS set to OPS_MEM means CFI says the caller's
1067    REGNO is "undefined", i.e. it's call-clobbered and cannot be recovered.
1068 
1069    *NOPS zero with *OPS set to a null pointer means CFI says the
1070    caller's REGNO is "same_value", i.e. this frame did not change it;
1071    ask the caller frame where to find it.
1072 
1073    For common simple expressions *OPS is OPS_MEM (which is a caller
1074    owned array for at least 3 Dwarf_Ops).  For arbitrary DWARF
1075    expressions in the CFI, *OPS is an internal pointer that can be
1076    used as long as the Dwarf_CFI used to create FRAME remains
1077    alive.  */
1078 extern int dwarf_frame_register (Dwarf_Frame *frame, int regno,
1079                  Dwarf_Op ops_mem[3],
1080                  Dwarf_Op **ops, size_t *nops)
1081   __nonnull_attribute__ (3, 4, 5);
1082 
1083 
1084 /* Return offset and/or size of CU's contribution to SECTION in a
1085    DWARF package file.
1086 
1087    If CU is not from a DWARF package file, the file does not have
1088    SECTION, or CU does not contribute to SECTION, then *OFFSETP and
1089    *SIZEP are set to 0 (this is not an error and the function will
1090    return 0 in that case).
1091 
1092    SECTION is a DW_SECT section identifier.  Note that the original
1093    GNU DWARF package file extension for DWARF 4 used slightly
1094    different section identifiers.  This function uses the standardized
1095    section identifiers and maps the GNU DWARF 4 identifiers to their
1096    standard DWARF 5 analogues: DW_SECT_LOCLISTS (5) refers to
1097    .debug_locs.dwo for DWARF 4.  DW_SECT_MACRO (7) refers to
1098    .debug_macinfo.dwo for DWARF 4 or .debug_macro.dwo for the GNU
1099    .debug_macro extension for DWARF 4 (section identifier 8 is
1100    DW_SECT_RNGLISTS in DWARF 5, NOT DW_SECT_MACRO like in the GNU
1101    extension.)  .debug_types.dwo does not have a DWARF 5 equivalent,
1102    so this function accepts the original DW_SECT_TYPES (2).
1103 
1104    Returns 0 for success or -1 for errors reading the DWARF package
1105    file data or if an unknown SECTION constant is given.  OFFSETP and
1106    SIZEP may be NULL.  */
1107 extern int dwarf_cu_dwp_section_info (Dwarf_CU *cu, unsigned int section,
1108                       Dwarf_Off *offsetp, Dwarf_Off *sizep);
1109 
1110 
1111 /* Return error code of last failing function call.  This value is kept
1112    separately for each thread.  */
1113 extern int dwarf_errno (void);
1114 
1115 /* Return error string for ERROR.  If ERROR is zero, return error string
1116    for most recent error or NULL is none occurred.  If ERROR is -1 the
1117    behaviour is similar to the last case except that not NULL but a legal
1118    string is returned.  */
1119 extern const char *dwarf_errmsg (int err);
1120 
1121 
1122 /* Register new Out-Of-Memory handler.  The old handler is returned.  */
1123 extern Dwarf_OOM dwarf_new_oom_handler (Dwarf *dbg, Dwarf_OOM handler);
1124 
1125 
1126 /* Inline optimizations.  */
1127 #ifdef __OPTIMIZE__
1128 /* Return attribute code of given attribute.  */
1129 __libdw_extern_inline unsigned int
1130 dwarf_whatattr (Dwarf_Attribute *attr)
1131 {
1132   return attr == NULL ? 0 : attr->code;
1133 }
1134 
1135 /* Return attribute code of given attribute.  */
1136 __libdw_extern_inline unsigned int
1137 dwarf_whatform (Dwarf_Attribute *attr)
1138 {
1139   return attr == NULL ? 0 : attr->form;
1140 }
1141 #endif  /* Optimize.  */
1142 
1143 #ifdef __cplusplus
1144 }
1145 #endif
1146 
1147 #endif  /* libdw.h */