14d9fdb4Robert Mustacchi/*
24d9fdb4Robert Mustacchi
34d9fdb4Robert Mustacchi  Copyright (C) 2000-2010 Silicon Graphics, Inc.  All Rights Reserved.
44d9fdb4Robert Mustacchi  Portions Copyright 2007-2010 Sun Microsystems, Inc. All rights reserved.
54d9fdb4Robert Mustacchi  Portions Copyright 2008-2018 David Anderson. All rights reserved.
64d9fdb4Robert Mustacchi  Portions Copyright 2008-2010 Arxan Technologies, Inc. All rights reserved.
74d9fdb4Robert Mustacchi  Portions Copyright 2010-2012 SN Systems Ltd. All rights reserved.
84d9fdb4Robert Mustacchi
94d9fdb4Robert Mustacchi  This program is free software; you can redistribute it
104d9fdb4Robert Mustacchi  and/or modify it under the terms of version 2.1 of the
114d9fdb4Robert Mustacchi  GNU Lesser General Public License as published by the Free
124d9fdb4Robert Mustacchi  Software Foundation.
134d9fdb4Robert Mustacchi
144d9fdb4Robert Mustacchi  This program is distributed in the hope that it would be
154d9fdb4Robert Mustacchi  useful, but WITHOUT ANY WARRANTY; without even the implied
164d9fdb4Robert Mustacchi  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
174d9fdb4Robert Mustacchi  PURPOSE.
184d9fdb4Robert Mustacchi
194d9fdb4Robert Mustacchi  Further, this software is distributed without any warranty
204d9fdb4Robert Mustacchi  that it is free of the rightful claim of any third person
214d9fdb4Robert Mustacchi  regarding infringement or the like.  Any license provided
224d9fdb4Robert Mustacchi  herein, whether implied or otherwise, applies only to this
234d9fdb4Robert Mustacchi  software file.  Patent licenses, if any, provided herein
244d9fdb4Robert Mustacchi  do not apply to combinations of this program with other
254d9fdb4Robert Mustacchi  software, or any other product whatsoever.
264d9fdb4Robert Mustacchi
274d9fdb4Robert Mustacchi  You should have received a copy of the GNU Lesser General
284d9fdb4Robert Mustacchi  Public License along with this program; if not, write the
294d9fdb4Robert Mustacchi  Free Software Foundation, Inc., 51 Franklin Street - Fifth
304d9fdb4Robert Mustacchi  Floor, Boston MA 02110-1301, USA.
314d9fdb4Robert Mustacchi
324d9fdb4Robert Mustacchi*/
334d9fdb4Robert Mustacchi
344d9fdb4Robert Mustacchi
354d9fdb4Robert Mustacchi#ifndef _LIBDWARF_H
364d9fdb4Robert Mustacchi#define _LIBDWARF_H
374d9fdb4Robert Mustacchi#ifdef __cplusplus
384d9fdb4Robert Mustacchiextern "C" {
394d9fdb4Robert Mustacchi#endif
404d9fdb4Robert Mustacchi/*
414d9fdb4Robert Mustacchi    libdwarf.h
424d9fdb4Robert Mustacchi    $Revision: #9 $ $Date: 2008/01/17 $
434d9fdb4Robert Mustacchi
444d9fdb4Robert Mustacchi    For libdwarf producers and consumers
454d9fdb4Robert Mustacchi
464d9fdb4Robert Mustacchi    The interface is defined as having 8-byte signed and unsigned
474d9fdb4Robert Mustacchi    values so it can handle 64-or-32bit target on 64-or-32bit host.
484d9fdb4Robert Mustacchi    Dwarf_Ptr is the native size: it represents pointers on
494d9fdb4Robert Mustacchi    the host machine (not the target!).
504d9fdb4Robert Mustacchi
514d9fdb4Robert Mustacchi    This contains declarations for types and all producer
524d9fdb4Robert Mustacchi    and consumer functions.
534d9fdb4Robert Mustacchi
544d9fdb4Robert Mustacchi    Function declarations are written on a single line each here
554d9fdb4Robert Mustacchi    so one can use grep  to each declaration in its entirety.
564d9fdb4Robert Mustacchi    The declarations are a little harder to read this way, but...
574d9fdb4Robert Mustacchi
584d9fdb4Robert Mustacchi    The seeming duplication of the Elf typedef allows
594d9fdb4Robert Mustacchi    both verification we have the right struct name (when
604d9fdb4Robert Mustacchi    libelf.h included before this) and
614d9fdb4Robert Mustacchi    creation of a local handle so we have the struct pointer
624d9fdb4Robert Mustacchi    here (if libelf.h is not included before this file).
634d9fdb4Robert Mustacchi
644d9fdb4Robert Mustacchi*/
654d9fdb4Robert Mustacchi
664d9fdb4Robert Mustacchitypedef struct _Elf Elf;
674d9fdb4Robert Mustacchitypedef struct _Elf* dwarf_elf_handle;
684d9fdb4Robert Mustacchi
694d9fdb4Robert Mustacchi/* To enable printing with printf regardless of the
704d9fdb4Robert Mustacchi   actual underlying data type, we define the DW_PR_xxx macros.
714d9fdb4Robert Mustacchi   To ensure uses of DW_PR_DUx or DW_PR_DSx look the way you want
724d9fdb4Robert Mustacchi   ensure the right DW_PR_XZEROS define is uncommented.
734d9fdb4Robert Mustacchi*/
744d9fdb4Robert Mustacchi/*#define DW_PR_XZEROS "" */
754d9fdb4Robert Mustacchi#define DW_PR_XZEROS "08"
764d9fdb4Robert Mustacchi
774d9fdb4Robert Mustacchitypedef unsigned long long Dwarf_Unsigned;
784d9fdb4Robert Mustacchitypedef signed   long long Dwarf_Signed;
794d9fdb4Robert Mustacchitypedef unsigned long long Dwarf_Off;
804d9fdb4Robert Mustacchitypedef unsigned long long Dwarf_Addr;
814d9fdb4Robert Mustacchitypedef int                Dwarf_Bool;   /* boolean type */
824d9fdb4Robert Mustacchitypedef unsigned short     Dwarf_Half;   /* 2 byte unsigned value */
834d9fdb4Robert Mustacchitypedef unsigned char      Dwarf_Small;  /* 1 byte unsigned value */
844d9fdb4Robert Mustacchi/*  If sizeof(Dwarf_Half) is greater than 2
854d9fdb4Robert Mustacchi    we believe libdwarf still works properly. */
864d9fdb4Robert Mustacchi
874d9fdb4Robert Mustacchi#if defined(_WIN32) && defined(HAVE_NONSTANDARD_PRINTF_64_FORMAT)
884d9fdb4Robert Mustacchi#define DW_PR_DUx "I64x"
894d9fdb4Robert Mustacchi#define DW_PR_DSx "I64x"
904d9fdb4Robert Mustacchi#define DW_PR_DUu "I64u"
914d9fdb4Robert Mustacchi#define DW_PR_DSd "I64d"
924d9fdb4Robert Mustacchi#else
934d9fdb4Robert Mustacchi#define DW_PR_DUx "llx"
944d9fdb4Robert Mustacchi#define DW_PR_DSx "llx"
954d9fdb4Robert Mustacchi#define DW_PR_DUu "llu"
964d9fdb4Robert Mustacchi#define DW_PR_DSd "lld"
974d9fdb4Robert Mustacchi#endif /* DW_PR defines */
984d9fdb4Robert Mustacchi
994d9fdb4Robert Mustacchitypedef void*        Dwarf_Ptr;          /* host machine pointer */
1004d9fdb4Robert Mustacchi
1014d9fdb4Robert Mustacchi/*  DWARF5: a container for a DW_FORM_data16 data item.
1024d9fdb4Robert Mustacchi    We have no integer types suitable so this special
1034d9fdb4Robert Mustacchi    struct is used instead.  It is up to consumers/producers
1044d9fdb4Robert Mustacchi    to deal with the contents.
1054d9fdb4Robert Mustacchi    New October 18, 2017 .  */
1064d9fdb4Robert Mustacchitypedef struct Dwarf_Form_Data16_s {
1074d9fdb4Robert Mustacchi    unsigned char fd_data[16];
1084d9fdb4Robert Mustacchi} Dwarf_Form_Data16;
1094d9fdb4Robert Mustacchi
1104d9fdb4Robert Mustacchi
1114d9fdb4Robert Mustacchi
1124d9fdb4Robert Mustacchi/* Used for signatures where ever they appear.
1134d9fdb4Robert Mustacchi   It is not a string, it
1144d9fdb4Robert Mustacchi   is 8 bytes of a signature one would use to find
1154d9fdb4Robert Mustacchi   a type unit. See dwarf_formsig8()
1164d9fdb4Robert Mustacchi
1174d9fdb4Robert Mustacchi   Sometimes it is used in calculations as
1184d9fdb4Robert Mustacchi   Dwarf_Unsigned, but that is done inside libdwarf
1194d9fdb4Robert Mustacchi   and the endianness question makes it a bit sketchy.
1204d9fdb4Robert Mustacchi*/
1214d9fdb4Robert Mustacchistruct Dwarf_Sig8_s  {
1224d9fdb4Robert Mustacchi    char signature[8];
1234d9fdb4Robert Mustacchi};
1244d9fdb4Robert Mustacchitypedef struct Dwarf_Sig8_s Dwarf_Sig8;
1254d9fdb4Robert Mustacchi
1264d9fdb4Robert Mustacchi/* Contains info on an uninterpreted block of data
1274d9fdb4Robert Mustacchi   Used with certain frame information functions and
1284d9fdb4Robert Mustacchi   also used with DW_FORM_block<>.
1294d9fdb4Robert Mustacchi*/
1304d9fdb4Robert Mustacchitypedef struct {
1314d9fdb4Robert Mustacchi    Dwarf_Unsigned  bl_len;         /* length of block bl_data points at */
1324d9fdb4Robert Mustacchi    Dwarf_Ptr       bl_data;        /* uninterpreted data */
1334d9fdb4Robert Mustacchi
1344d9fdb4Robert Mustacchi    /*  See libdwarf.h DW_LKIND*  */
1354d9fdb4Robert Mustacchi    Dwarf_Small     bl_from_loclist;
1364d9fdb4Robert Mustacchi
1374d9fdb4Robert Mustacchi    /* Section (not CU) offset which 'data' comes from. */
1384d9fdb4Robert Mustacchi    Dwarf_Unsigned  bl_section_offset;
1394d9fdb4Robert Mustacchi} Dwarf_Block;
1404d9fdb4Robert Mustacchi
1414d9fdb4Robert Mustacchi
1424d9fdb4Robert Mustacchi/*  NEW October 2015.  */
1434d9fdb4Robert Mustacchi/*  This provides access to Dwarf_Locdesc_c, a single
1444d9fdb4Robert Mustacchi    location description */
1454d9fdb4Robert Mustacchistruct  Dwarf_Locdesc_c_s;
1464d9fdb4Robert Mustacchitypedef struct Dwarf_Locdesc_c_s * Dwarf_Locdesc_c;
1474d9fdb4Robert Mustacchi
1484d9fdb4Robert Mustacchi/*  NEW October 2015.  */
1494d9fdb4Robert Mustacchi/*  This provides access to Dwarf_Locdesc_c, a single
1504d9fdb4Robert Mustacchi    location list entry (or for a locexpr, the fake
1514d9fdb4Robert Mustacchi    Loc_Head for the locexpr) */
1524d9fdb4Robert Mustacchistruct Dwarf_Loc_Head_c_s;
1534d9fdb4Robert Mustacchitypedef struct Dwarf_Loc_Head_c_s * Dwarf_Loc_Head_c;
1544d9fdb4Robert Mustacchi
1554d9fdb4Robert Mustacchi/* NEW November 2015. For DWARF5 .debug_macro section */
1564d9fdb4Robert Mustacchistruct Dwarf_Macro_Context_s;
1574d9fdb4Robert Mustacchitypedef struct Dwarf_Macro_Context_s * Dwarf_Loc_Macro_Context;
1584d9fdb4Robert Mustacchi
1594d9fdb4Robert Mustacchi/*  NEW September 2016. Allows easy access to DW_AT_discr_list
1604d9fdb4Robert Mustacchi    array of discriminant values. Input in blockpointer
1614d9fdb4Robert Mustacchi    is a block with a list of uleb or sleb numbers
1624d9fdb4Robert Mustacchi    (all one or the other, lebunsignedflag instructs
1634d9fdb4Robert Mustacchi    how to read the leb values properly) */
1644d9fdb4Robert Mustacchitypedef struct Dwarf_Dsc_Head_s * Dwarf_Dsc_Head;
1654d9fdb4Robert Mustacchi
1664d9fdb4Robert Mustacchi/*  Location record. Records up to 2 operand values.
1674d9fdb4Robert Mustacchi    Not usable with DWARF5 or DWARF4 with location
1684d9fdb4Robert Mustacchi    operator  extensions. */
1694d9fdb4Robert Mustacchitypedef struct {
1704d9fdb4Robert Mustacchi    Dwarf_Small     lr_atom;        /* location operation */
1714d9fdb4Robert Mustacchi    Dwarf_Unsigned  lr_number;      /* operand */
1724d9fdb4Robert Mustacchi    Dwarf_Unsigned  lr_number2;     /* for OP_BREGx  and DW_OP_GNU_const_type*/
1734d9fdb4Robert Mustacchi    Dwarf_Unsigned  lr_offset;      /* offset in locexpr for OP_BRA etc */
1744d9fdb4Robert Mustacchi} Dwarf_Loc;
1754d9fdb4Robert Mustacchi
1764d9fdb4Robert Mustacchi
1774d9fdb4Robert Mustacchi/* Location description. DWARF 2,3,4.
1784d9fdb4Robert Mustacchi   When this is from a split-dwarf loclist (.debug_loc.dwo)
1794d9fdb4Robert Mustacchi   and no tied object is present
1804d9fdb4Robert Mustacchi   then ld_lowpc and ld_highpc are actually indices in
1814d9fdb4Robert Mustacchi   the .debug_addr section of the tied object).
1824d9fdb4Robert Mustacchi   If there is a tied object then these fields are actuall
1834d9fdb4Robert Mustacchi   addresses and DW_AT_addr_base in the skeleton CU DIE applies to
1844d9fdb4Robert Mustacchi   that .debug_addr.
1854d9fdb4Robert Mustacchi
1864d9fdb4Robert Mustacchi   Location record. Records up to 2 operand values.
1874d9fdb4Robert Mustacchi   Not usable with DWARF5 or DWARF4 with extensions.
1884d9fdb4Robert Mustacchi
1894d9fdb4Robert Mustacchi   If from DWARF2,3,4 non-split dwarf then things operate as
1904d9fdb4Robert Mustacchi   in DWARF2.
1914d9fdb4Robert Mustacchi   See dwarf_get_loclist_b() and the other related
1924d9fdb4Robert Mustacchi   new functions that
1934d9fdb4Robert Mustacchi   avoid using public structures Dwarf_Loc and Dwarf_Locdesc.
1944d9fdb4Robert Mustacchi*/
1954d9fdb4Robert Mustacchitypedef struct {
1964d9fdb4Robert Mustacchi    /*  Beginning of active range. This is actually an offset
1974d9fdb4Robert Mustacchi        of an applicable base address, not a pc value.  */
1984d9fdb4Robert Mustacchi    Dwarf_Addr      ld_lopc;
1994d9fdb4Robert Mustacchi
2004d9fdb4Robert Mustacchi    /*  End of active range. This is actually an offset
2014d9fdb4Robert Mustacchi        of an applicable base address, not a pc value.  */
2024d9fdb4Robert Mustacchi    Dwarf_Addr      ld_hipc;
2034d9fdb4Robert Mustacchi
2044d9fdb4Robert Mustacchi    Dwarf_Half      ld_cents;       /* count of location records */
2054d9fdb4Robert Mustacchi    Dwarf_Loc*      ld_s;           /* pointer to list of same */
2064d9fdb4Robert Mustacchi
2074d9fdb4Robert Mustacchi    /*  non-0 if loclist, 1 if non-split (dwarf 2,3,4) */
2084d9fdb4Robert Mustacchi    Dwarf_Small     ld_from_loclist;
2094d9fdb4Robert Mustacchi
2104d9fdb4Robert Mustacchi    Dwarf_Unsigned  ld_section_offset; /* Section (not CU) offset
2114d9fdb4Robert Mustacchi        where loc-expr begins*/
2124d9fdb4Robert Mustacchi} Dwarf_Locdesc;
2134d9fdb4Robert Mustacchi
2144d9fdb4Robert Mustacchi/*  First appears in DWARF3, and only ranges entries exist.
2154d9fdb4Robert Mustacchi    The dwr_addr1/addr2 data is either an offset (DW_RANGES_ENTRY)
2164d9fdb4Robert Mustacchi    or an address (dwr_addr2 in DW_RANGES_ADDRESS_SELECTION) or
2174d9fdb4Robert Mustacchi    both are zero (DW_RANGES_END).
2184d9fdb4Robert Mustacchi    For DWARF5 each table starts with a header
2194d9fdb4Robert Mustacchi    followed by range list entries defined
2204d9fdb4Robert Mustacchi    as here.
2214d9fdb4Robert Mustacchi*/
2224d9fdb4Robert Mustacchienum Dwarf_Ranges_Entry_Type { DW_RANGES_ENTRY,
2234d9fdb4Robert Mustacchi    DW_RANGES_ADDRESS_SELECTION,
2244d9fdb4Robert Mustacchi    DW_RANGES_END
2254d9fdb4Robert Mustacchi};
2264d9fdb4Robert Mustacchitypedef struct {
2274d9fdb4Robert Mustacchi    Dwarf_Addr dwr_addr1;
2284d9fdb4Robert Mustacchi    Dwarf_Addr dwr_addr2;
2294d9fdb4Robert Mustacchi    enum Dwarf_Ranges_Entry_Type  dwr_type;
2304d9fdb4Robert Mustacchi} Dwarf_Ranges;
2314d9fdb4Robert Mustacchi
2324d9fdb4Robert Mustacchi/* Frame description instructions expanded.
2334d9fdb4Robert Mustacchi*/
2344d9fdb4Robert Mustacchitypedef struct {
2354d9fdb4Robert Mustacchi    Dwarf_Small     fp_base_op;
2364d9fdb4Robert Mustacchi    Dwarf_Small     fp_extended_op;
2374d9fdb4Robert Mustacchi    Dwarf_Half      fp_register;
2384d9fdb4Robert Mustacchi
2394d9fdb4Robert Mustacchi    /*  Value may be signed, depends on op.
2404d9fdb4Robert Mustacchi        Any applicable data_alignment_factor has
2414d9fdb4Robert Mustacchi        not been applied, this is the  raw offset. */
2424d9fdb4Robert Mustacchi    Dwarf_Unsigned  fp_offset;
2434d9fdb4Robert Mustacchi    Dwarf_Off       fp_instr_offset;
2444d9fdb4Robert Mustacchi} Dwarf_Frame_Op; /* DWARF2 */
2454d9fdb4Robert Mustacchi
2464d9fdb4Robert Mustacchi/*  ***IMPORTANT NOTE, TARGET DEPENDENCY ****
2474d9fdb4Robert Mustacchi    DW_REG_TABLE_SIZE must be at least as large as
2484d9fdb4Robert Mustacchi    the number of registers
2494d9fdb4Robert Mustacchi    (DW_FRAME_LAST_REG_NUM) as defined in dwarf.h
2504d9fdb4Robert Mustacchi    Preferably identical to DW_FRAME_LAST_REG_NUM.
2514d9fdb4Robert Mustacchi    Ensure [0-DW_REG_TABLE_SIZE] does not overlap
2524d9fdb4Robert Mustacchi    DW_FRAME_UNDEFINED_VAL or DW_FRAME_SAME_VAL.
2534d9fdb4Robert Mustacchi    Also ensure DW_FRAME_REG_INITIAL_VALUE is set to what
2544d9fdb4Robert Mustacchi    is appropriate to your cpu.
2554d9fdb4Robert Mustacchi    For various CPUs  DW_FRAME_UNDEFINED_VAL is correct
2564d9fdb4Robert Mustacchi    as the value for DW_FRAME_REG_INITIAL_VALUE.
2574d9fdb4Robert Mustacchi
2584d9fdb4Robert Mustacchi    For consumer apps, this can be set dynamically: see
2594d9fdb4Robert Mustacchi    dwarf_set_frame_rule_table_size(); */
2604d9fdb4Robert Mustacchi#ifndef DW_REG_TABLE_SIZE
2614d9fdb4Robert Mustacchi#define DW_REG_TABLE_SIZE  66
2624d9fdb4Robert Mustacchi#endif
2634d9fdb4Robert Mustacchi
2644d9fdb4Robert Mustacchi/* For MIPS, DW_FRAME_SAME_VAL is the correct default value
2654d9fdb4Robert Mustacchi   for a frame register value. For other CPUS another value
2664d9fdb4Robert Mustacchi   may be better, such as DW_FRAME_UNDEFINED_VAL.
2674d9fdb4Robert Mustacchi   See dwarf_set_frame_rule_table_size
2684d9fdb4Robert Mustacchi*/
2694d9fdb4Robert Mustacchi#ifndef DW_FRAME_REG_INITIAL_VALUE
2704d9fdb4Robert Mustacchi#define DW_FRAME_REG_INITIAL_VALUE DW_FRAME_SAME_VAL
2714d9fdb4Robert Mustacchi#endif
2724d9fdb4Robert Mustacchi
2734d9fdb4Robert Mustacchi/* Taken as meaning 'undefined value', this is not
2744d9fdb4Robert Mustacchi   a column or register number.
2754d9fdb4Robert Mustacchi   Only present at libdwarf runtime in the consumer
2764d9fdb4Robert Mustacchi   interfaces. Never on disk.
2774d9fdb4Robert Mustacchi   DW_FRAME_* Values present on disk are in dwarf.h
2784d9fdb4Robert Mustacchi   Ensure this is > DW_REG_TABLE_SIZE (the reg table
2794d9fdb4Robert Mustacchi   size is changeable at runtime with the *reg3() interfaces,
2804d9fdb4Robert Mustacchi   and this value must be greater than the reg table size).
2814d9fdb4Robert Mustacchi*/
2824d9fdb4Robert Mustacchi#define DW_FRAME_UNDEFINED_VAL          1034
2834d9fdb4Robert Mustacchi
2844d9fdb4Robert Mustacchi/* Taken as meaning 'same value' as caller had, not a column
2854d9fdb4Robert Mustacchi   or register number.
2864d9fdb4Robert Mustacchi   Only present at libdwarf runtime in the consumer
2874d9fdb4Robert Mustacchi   interfaces. Never on disk.
2884d9fdb4Robert Mustacchi   DW_FRAME_* Values present on disk are in dwarf.h
2894d9fdb4Robert Mustacchi   Ensure this is > DW_REG_TABLE_SIZE (the reg table
2904d9fdb4Robert Mustacchi   size is changeable at runtime with the *reg3() interfaces,
2914d9fdb4Robert Mustacchi   and this value must be greater than the reg table size).
2924d9fdb4Robert Mustacchi*/
2934d9fdb4Robert Mustacchi#define DW_FRAME_SAME_VAL               1035
2944d9fdb4Robert Mustacchi
2954d9fdb4Robert Mustacchi/* For DWARF3 consumer interfaces, make the CFA a column with no
2964d9fdb4Robert Mustacchi   real table number.  This is what should have been done
2974d9fdb4Robert Mustacchi   for the DWARF2 interfaces.  This actually works for
2984d9fdb4Robert Mustacchi   both DWARF2 and DWARF3, but see the libdwarf documentation
2994d9fdb4Robert Mustacchi   on Dwarf_Regtable3 and  dwarf_get_fde_info_for_reg3()
3004d9fdb4Robert Mustacchi   and  dwarf_get_fde_info_for_all_regs3()
3014d9fdb4Robert Mustacchi   Do NOT use this with the older dwarf_get_fde_info_for_reg()
3024d9fdb4Robert Mustacchi   or dwarf_get_fde_info_for_all_regs() consumer interfaces.
3034d9fdb4Robert Mustacchi   Must be higher than any register count for *any* ABI
3044d9fdb4Robert Mustacchi   (ensures maximum applicability with minimum effort).
3054d9fdb4Robert Mustacchi   Ensure this is > DW_REG_TABLE_SIZE (the reg table
3064d9fdb4Robert Mustacchi   size is changeable at runtime with the *reg3() interfaces,
3074d9fdb4Robert Mustacchi   and this value must be greater than the reg table size).
3084d9fdb4Robert Mustacchi   Only present at libdwarf runtime in the consumer
3094d9fdb4Robert Mustacchi   interfaces. Never on disk.
3104d9fdb4Robert Mustacchi*/
3114d9fdb4Robert Mustacchi#define DW_FRAME_CFA_COL3               1436
3124d9fdb4Robert Mustacchi
3134d9fdb4Robert Mustacchi/* The following are all needed to evaluate DWARF3 register rules.
3144d9fdb4Robert Mustacchi*/
3154d9fdb4Robert Mustacchi#define DW_EXPR_OFFSET 0  /* DWARF2 only sees this. */
3164d9fdb4Robert Mustacchi#define DW_EXPR_VAL_OFFSET 1
3174d9fdb4Robert Mustacchi#define DW_EXPR_EXPRESSION 2
3184d9fdb4Robert Mustacchi#define DW_EXPR_VAL_EXPRESSION 3
3194d9fdb4Robert Mustacchi
3204d9fdb4Robert Mustacchitypedef struct Dwarf_Regtable_Entry_s {
3214d9fdb4Robert Mustacchi    /*  For each index i (naming a hardware register with dwarf number
3224d9fdb4Robert Mustacchi        i) the following is true and defines the value of that register:
3234d9fdb4Robert Mustacchi
3244d9fdb4Robert Mustacchi        If dw_regnum is Register DW_FRAME_UNDEFINED_VAL
3254d9fdb4Robert Mustacchi            it is not DWARF register number but
3264d9fdb4Robert Mustacchi            a place holder indicating the register has no defined value.
3274d9fdb4Robert Mustacchi        If dw_regnum is Register DW_FRAME_SAME_VAL
3284d9fdb4Robert Mustacchi            it  is not DWARF register number but
3294d9fdb4Robert Mustacchi            a place holder indicating the register has the same
3304d9fdb4Robert Mustacchi            value in the previous frame.
3314d9fdb4Robert Mustacchi
3324d9fdb4Robert Mustacchi            DW_FRAME_UNDEFINED_VAL, DW_FRAME_SAME_VAL are
3334d9fdb4Robert Mustacchi            only present at libdwarf runtime. Never on disk.
3344d9fdb4Robert Mustacchi            DW_FRAME_* Values present on disk are in dwarf.h
3354d9fdb4Robert Mustacchi
3364d9fdb4Robert Mustacchi        Otherwise: the register number is a DWARF register number
3374d9fdb4Robert Mustacchi            (see ABI documents for how this translates to hardware/
3384d9fdb4Robert Mustacchi            software register numbers in the machine hardware)
3394d9fdb4Robert Mustacchi            and the following applies:
3404d9fdb4Robert Mustacchi
3414d9fdb4Robert Mustacchi            if dw_value_type == DW_EXPR_OFFSET (the only case for dwarf2):
3424d9fdb4Robert Mustacchi                If dw_offset_relevant is non-zero, then
3434d9fdb4Robert Mustacchi                    the value is stored at at the address CFA+N where
3444d9fdb4Robert Mustacchi                    N is a signed offset.
3454d9fdb4Robert Mustacchi                    Rule: Offset(N)
3464d9fdb4Robert Mustacchi                If dw_offset_relevant is zero, then the value of the register
3474d9fdb4Robert Mustacchi                    is the value of (DWARF) register number dw_regnum.
3484d9fdb4Robert Mustacchi                    Rule: register(F)
3494d9fdb4Robert Mustacchi            Other values of dw_value_type are an error.
3504d9fdb4Robert Mustacchi    */
3514d9fdb4Robert Mustacchi    Dwarf_Small         dw_offset_relevant;
3524d9fdb4Robert Mustacchi
3534d9fdb4Robert Mustacchi    /* For DWARF2, always 0 */
3544d9fdb4Robert Mustacchi    Dwarf_Small         dw_value_type;
3554d9fdb4Robert Mustacchi
3564d9fdb4Robert Mustacchi    Dwarf_Half          dw_regnum;
3574d9fdb4Robert Mustacchi
3584d9fdb4Robert Mustacchi    /*  The data type here should  the larger of Dwarf_Addr
3594d9fdb4Robert Mustacchi        and Dwarf_Unsigned and Dwarf_Signed. */
3604d9fdb4Robert Mustacchi    Dwarf_Addr          dw_offset;
3614d9fdb4Robert Mustacchi} Dwarf_Regtable_Entry;
3624d9fdb4Robert Mustacchi
3634d9fdb4Robert Mustacchitypedef struct Dwarf_Regtable_s {
3644d9fdb4Robert Mustacchi    struct Dwarf_Regtable_Entry_s rules[DW_REG_TABLE_SIZE];
3654d9fdb4Robert Mustacchi} Dwarf_Regtable;
3664d9fdb4Robert Mustacchi
3674d9fdb4Robert Mustacchi/* opaque type. Functional interface shown later. */
3684d9fdb4Robert Mustacchistruct Dwarf_Reg_value3_s;
3694d9fdb4Robert Mustacchitypedef struct Dwarf_Reg_value3_s Dwarf_Reg_Value3;
3704d9fdb4Robert Mustacchi
3714d9fdb4Robert Mustacchitypedef struct Dwarf_Regtable_Entry3_s {
3724d9fdb4Robert Mustacchi/*  For each index i (naming a hardware register with dwarf number
3734d9fdb4Robert Mustacchi    i) the following is true and defines the value of that register:
3744d9fdb4Robert Mustacchi
3754d9fdb4Robert Mustacchi        If dw_regnum is Register DW_FRAME_UNDEFINED_VAL
3764d9fdb4Robert Mustacchi            it is not DWARF register number but
3774d9fdb4Robert Mustacchi            a place holder indicating the register has no defined value.
3784d9fdb4Robert Mustacchi        If dw_regnum is Register DW_FRAME_SAME_VAL
3794d9fdb4Robert Mustacchi            it  is not DWARF register number but
3804d9fdb4Robert Mustacchi            a place holder indicating the register has the same
3814d9fdb4Robert Mustacchi            value in the previous frame.
3824d9fdb4Robert Mustacchi
3834d9fdb4Robert Mustacchi            DW_FRAME_UNDEFINED_VAL, DW_FRAME_SAME_VAL and
3844d9fdb4Robert Mustacchi            DW_FRAME_CFA_COL3 are only present at libdwarf runtime.
3854d9fdb4Robert Mustacchi            Never on disk.
3864d9fdb4Robert Mustacchi            DW_FRAME_* Values present on disk are in dwarf.h
3874d9fdb4Robert Mustacchi            Because DW_FRAME_SAME_VAL and DW_FRAME_UNDEFINED_VAL
3884d9fdb4Robert Mustacchi            and DW_FRAME_CFA_COL3 are definable at runtime
3894d9fdb4Robert Mustacchi            consider the names symbolic in this comment, not absolute.
3904d9fdb4Robert Mustacchi
3914d9fdb4Robert Mustacchi        Otherwise: the register number is a DWARF register number
3924d9fdb4Robert Mustacchi            (see ABI documents for how this translates to hardware/
3934d9fdb4Robert Mustacchi            software register numbers in the machine hardware)
3944d9fdb4Robert Mustacchi            and the following applies:
3954d9fdb4Robert Mustacchi
3964d9fdb4Robert Mustacchi        In a cfa-defining entry (rt3_cfa_rule) the regnum is the
3974d9fdb4Robert Mustacchi        CFA 'register number'. Which is some 'normal' register,
3984d9fdb4Robert Mustacchi        not DW_FRAME_CFA_COL3, nor DW_FRAME_SAME_VAL, nor
3994d9fdb4Robert Mustacchi        DW_FRAME_UNDEFINED_VAL.
4004d9fdb4Robert Mustacchi
4014d9fdb4Robert Mustacchi        If dw_value_type == DW_EXPR_OFFSET (the only  possible case for
4024d9fdb4Robert Mustacchi        dwarf2):
4034d9fdb4Robert Mustacchi            If dw_offset_relevant is non-zero, then
4044d9fdb4Robert Mustacchi                the value is stored at at the address
4054d9fdb4Robert Mustacchi                CFA+N where N is a signed offset.
4064d9fdb4Robert Mustacchi                dw_regnum is the cfa register rule which means
4074d9fdb4Robert Mustacchi                one ignores dw_regnum and uses the CFA appropriately.
4084d9fdb4Robert Mustacchi                So dw_offset_or_block_len is a signed value, really,
4094d9fdb4Robert Mustacchi                and must be printed/evaluated as such.
4104d9fdb4Robert Mustacchi                Rule: Offset(N)
4114d9fdb4Robert Mustacchi            If dw_offset_relevant is zero, then the value of the register
4124d9fdb4Robert Mustacchi                is the value of (DWARF) register number dw_regnum.
4134d9fdb4Robert Mustacchi                Rule: register(R)
4144d9fdb4Robert Mustacchi        If dw_value_type  == DW_EXPR_VAL_OFFSET
4154d9fdb4Robert Mustacchi            the  value of this register is CFA +N where N is a signed offset.
4164d9fdb4Robert Mustacchi            dw_regnum is the cfa register rule which means
4174d9fdb4Robert Mustacchi            one ignores dw_regnum and uses the CFA appropriately.
4184d9fdb4Robert Mustacchi            Rule: val_offset(N)
4194d9fdb4Robert Mustacchi        If dw_value_type  == DW_EXPR_EXPRESSION
4204d9fdb4Robert Mustacchi            The value of the register is the value at the address
4214d9fdb4Robert Mustacchi            computed by evaluating the DWARF expression E.
4224d9fdb4Robert Mustacchi            Rule: expression(E)
4234d9fdb4Robert Mustacchi            The expression E byte stream is pointed to by dw_block_ptr.
4244d9fdb4Robert Mustacchi            The expression length in bytes is given by
4254d9fdb4Robert Mustacchi            dw_offset_or_block_len.
4264d9fdb4Robert Mustacchi        If dw_value_type  == DW_EXPR_VAL_EXPRESSION
4274d9fdb4Robert Mustacchi            The value of the register is the value
4284d9fdb4Robert Mustacchi            computed by evaluating the DWARF expression E.
4294d9fdb4Robert Mustacchi            Rule: val_expression(E)
4304d9fdb4Robert Mustacchi            The expression E byte stream is pointed to by dw_block_ptr.
4314d9fdb4Robert Mustacchi            The expression length in bytes is given by
4324d9fdb4Robert Mustacchi            dw_offset_or_block_len.
4334d9fdb4Robert Mustacchi        Other values of dw_value_type are an error.
4344d9fdb4Robert Mustacchi*/
4354d9fdb4Robert Mustacchi    Dwarf_Small         dw_offset_relevant;
4364d9fdb4Robert Mustacchi    Dwarf_Small         dw_value_type;
4374d9fdb4Robert Mustacchi    Dwarf_Half          dw_regnum;
4384d9fdb4Robert Mustacchi    Dwarf_Unsigned      dw_offset_or_block_len;
4394d9fdb4Robert Mustacchi    Dwarf_Ptr           dw_block_ptr;
4404d9fdb4Robert Mustacchi
4414d9fdb4Robert Mustacchi}Dwarf_Regtable_Entry3;
4424d9fdb4Robert Mustacchi
4434d9fdb4Robert Mustacchi/*  For the DWARF3 version, moved the DW_FRAME_CFA_COL
4444d9fdb4Robert Mustacchi    out of the array and into its own struct.
4454d9fdb4Robert Mustacchi    Having it part of the array is not very easy to work
4464d9fdb4Robert Mustacchi    with from a portability point of view: changing
4474d9fdb4Robert Mustacchi    the number for every architecture is a pain (if one fails
4484d9fdb4Robert Mustacchi    to set it correctly a register rule gets clobbered when
4494d9fdb4Robert Mustacchi    setting CFA).  With MIPS it just happened to be easy to use
4504d9fdb4Robert Mustacchi    DW_FRAME_CFA_COL (it was wrong conceptually but it was easy...).
4514d9fdb4Robert Mustacchi
4524d9fdb4Robert Mustacchi    rt3_rules and rt3_reg_table_size must be filled in before
4534d9fdb4Robert Mustacchi    calling libdwarf.  Filled in with a pointer to an array
4544d9fdb4Robert Mustacchi    (pointer and array  set up by the calling application)
4554d9fdb4Robert Mustacchi    of rt3_reg_table_size Dwarf_Regtable_Entry3_s structs.
4564d9fdb4Robert Mustacchi    libdwarf does not allocate or deallocate space for the
4574d9fdb4Robert Mustacchi    rules, you must do so.   libdwarf will initialize the
4584d9fdb4Robert Mustacchi    contents rules array, you do not need to do so (though
4594d9fdb4Robert Mustacchi    if you choose to initialize the array somehow that is ok:
4604d9fdb4Robert Mustacchi    libdwarf will overwrite your initializations with its own).
4614d9fdb4Robert Mustacchi
4624d9fdb4Robert Mustacchi*/
4634d9fdb4Robert Mustacchitypedef struct Dwarf_Regtable3_s {
4644d9fdb4Robert Mustacchi    struct Dwarf_Regtable_Entry3_s   rt3_cfa_rule;
4654d9fdb4Robert Mustacchi
4664d9fdb4Robert Mustacchi    Dwarf_Half                       rt3_reg_table_size;
4674d9fdb4Robert Mustacchi    struct Dwarf_Regtable_Entry3_s * rt3_rules;
4684d9fdb4Robert Mustacchi} Dwarf_Regtable3;
4694d9fdb4Robert Mustacchi
4704d9fdb4Robert Mustacchi
4714d9fdb4Robert Mustacchi/*  Use for DW_EPXR_STANDARD., DW_EXPR_VAL_OFFSET.
4724d9fdb4Robert Mustacchi    Returns DW_DLV_OK if the value is available.
4734d9fdb4Robert Mustacchi    If DW_DLV_OK returns the regnum and offset thru the pointers
4744d9fdb4Robert Mustacchi    (which the consumer must use appropriately).
4754d9fdb4Robert Mustacchi*/
4764d9fdb4Robert Mustacchiint dwarf_frame_get_reg_register(struct Dwarf_Regtable_Entry3_s *reg_in,
4774d9fdb4Robert Mustacchi    Dwarf_Small *offset_relevant,
4784d9fdb4Robert Mustacchi    Dwarf_Half *regnum_out,
4794d9fdb4Robert Mustacchi    Dwarf_Signed *offset_out);
4804d9fdb4Robert Mustacchi
4814d9fdb4Robert Mustacchi/*  Use for DW_EXPR_EXPRESSION, DW_EXPR_VAL_EXPRESSION.
4824d9fdb4Robert Mustacchi    Returns DW_DLV_OK if the value is available.
4834d9fdb4Robert Mustacchi    The caller must pass in the address of a valid
4844d9fdb4Robert Mustacchi    Dwarf_Block (the caller need not initialize it).
4854d9fdb4Robert Mustacchi*/
4864d9fdb4Robert Mustacchiint dwarf_frame_get_reg_expression(struct Dwarf_Regtable_Entry3_s *reg_in,
4874d9fdb4Robert Mustacchi    Dwarf_Block *block_out);
4884d9fdb4Robert Mustacchi
4894d9fdb4Robert Mustacchi
4904d9fdb4Robert Mustacchi/*  For DW_DLC_SYMBOLIC_RELOCATIONS output to caller
4914d9fdb4Robert Mustacchi    v2, adding drd_length: some relocations are 4 and
4924d9fdb4Robert Mustacchi    some 8 bytes (pointers are 8, section offsets 4) in
4934d9fdb4Robert Mustacchi    some dwarf environments. (MIPS relocations are all one
4944d9fdb4Robert Mustacchi    size in any given ABI.) Changing drd_type to an unsigned char
4954d9fdb4Robert Mustacchi    to keep struct size down.
4964d9fdb4Robert Mustacchi*/
4974d9fdb4Robert Mustacchienum Dwarf_Rel_Type {
4984d9fdb4Robert Mustacchi    dwarf_drt_none,        /* Should not get to caller */
4994d9fdb4Robert Mustacchi    dwarf_drt_data_reloc,  /* Simple normal relocation. */
5004d9fdb4Robert Mustacchi    dwarf_drt_segment_rel, /* Special reloc, exceptions. */
5014d9fdb4Robert Mustacchi    /* dwarf_drt_first_of_length_pair  and drt_second
5024d9fdb4Robert Mustacchi        are for for the  .word end - begin case. */
5034d9fdb4Robert Mustacchi    dwarf_drt_first_of_length_pair,
5044d9fdb4Robert Mustacchi    dwarf_drt_second_of_length_pair
5054d9fdb4Robert Mustacchi};
5064d9fdb4Robert Mustacchi
5074d9fdb4Robert Mustacchitypedef struct Dwarf_P_Marker_s * Dwarf_P_Marker;
5084d9fdb4Robert Mustacchistruct Dwarf_P_Marker_s {
5094d9fdb4Robert Mustacchi    Dwarf_Unsigned ma_marker;
5104d9fdb4Robert Mustacchi    Dwarf_Unsigned ma_offset;
5114d9fdb4Robert Mustacchi};
5124d9fdb4Robert Mustacchi
5134d9fdb4Robert Mustacchitypedef struct Dwarf_Relocation_Data_s  * Dwarf_Relocation_Data;
5144d9fdb4Robert Mustacchistruct Dwarf_Relocation_Data_s {
5154d9fdb4Robert Mustacchi    unsigned char drd_type;   /* Cast to/from Dwarf_Rel_Type
5164d9fdb4Robert Mustacchi        to keep size small in struct. */
5174d9fdb4Robert Mustacchi    unsigned char drd_length; /* Length in bytes of data being
5184d9fdb4Robert Mustacchi        relocated. 4 for 32bit data,
5194d9fdb4Robert Mustacchi        8 for 64bit data. */
5204d9fdb4Robert Mustacchi    Dwarf_Unsigned       drd_offset; /* Where the data to reloc is. */
5214d9fdb4Robert Mustacchi    Dwarf_Unsigned       drd_symbol_index;
5224d9fdb4Robert Mustacchi};
5234d9fdb4Robert Mustacchi
5244d9fdb4Robert Mustacchitypedef struct Dwarf_P_String_Attr_s  * Dwarf_P_String_Attr;
5254d9fdb4Robert Mustacchistruct Dwarf_P_String_Attr_s {
5264d9fdb4Robert Mustacchi    Dwarf_Unsigned        sa_offset;  /* Offset of string attribute data */
5274d9fdb4Robert Mustacchi    Dwarf_Unsigned        sa_nbytes;
5284d9fdb4Robert Mustacchi};
5294d9fdb4Robert Mustacchi
5304d9fdb4Robert Mustacchi
5314d9fdb4Robert Mustacchi/* Opaque types for Consumer Library. */
5324d9fdb4Robert Mustacchitypedef struct Dwarf_Debug_s*      Dwarf_Debug;
5334d9fdb4Robert Mustacchitypedef struct Dwarf_Die_s*        Dwarf_Die;
5344d9fdb4Robert Mustacchitypedef struct Dwarf_Line_s*       Dwarf_Line;
5354d9fdb4Robert Mustacchitypedef struct Dwarf_Global_s*     Dwarf_Global;
5364d9fdb4Robert Mustacchitypedef struct Dwarf_Func_s*       Dwarf_Func;
5374d9fdb4Robert Mustacchitypedef struct Dwarf_Type_s*       Dwarf_Type;
5384d9fdb4Robert Mustacchitypedef struct Dwarf_Var_s*        Dwarf_Var;
5394d9fdb4Robert Mustacchitypedef struct Dwarf_Weak_s*       Dwarf_Weak;
5404d9fdb4Robert Mustacchitypedef struct Dwarf_Error_s*      Dwarf_Error;
5414d9fdb4Robert Mustacchitypedef struct Dwarf_Attribute_s*  Dwarf_Attribute;
5424d9fdb4Robert Mustacchitypedef struct Dwarf_Abbrev_s*     Dwarf_Abbrev;
5434d9fdb4Robert Mustacchitypedef struct Dwarf_Fde_s*        Dwarf_Fde;
5444d9fdb4Robert Mustacchitypedef struct Dwarf_Cie_s*        Dwarf_Cie;
5454d9fdb4Robert Mustacchitypedef struct Dwarf_Arange_s*     Dwarf_Arange;
5464d9fdb4Robert Mustacchitypedef struct Dwarf_Gdbindex_s*   Dwarf_Gdbindex;
5474d9fdb4Robert Mustacchistruct Dwarf_Xu_Index_Header_s;
5484d9fdb4Robert Mustacchitypedef struct Dwarf_Xu_Index_Header_s  *Dwarf_Xu_Index_Header;
5494d9fdb4Robert Mustacchistruct Dwarf_Line_Context_s;
5504d9fdb4Robert Mustacchitypedef struct Dwarf_Line_Context_s     *Dwarf_Line_Context;
5514d9fdb4Robert Mustacchistruct Dwarf_Macro_Context_s;
5524d9fdb4Robert Mustacchitypedef struct Dwarf_Macro_Context_s    *Dwarf_Macro_Context;
5534d9fdb4Robert Mustacchistruct Dwarf_Dnames_Head_s;
5544d9fdb4Robert Mustacchitypedef struct Dwarf_Dnames_Head_s      *Dwarf_Dnames_Head;
5554d9fdb4Robert Mustacchi
5564d9fdb4Robert Mustacchi
5574d9fdb4Robert Mustacchi/* Opaque types for Producer Library. */
5584d9fdb4Robert Mustacchitypedef struct Dwarf_P_Debug_s*       Dwarf_P_Debug;
5594d9fdb4Robert Mustacchitypedef struct Dwarf_P_Die_s*         Dwarf_P_Die;
5604d9fdb4Robert Mustacchitypedef struct Dwarf_P_Attribute_s*   Dwarf_P_Attribute;
5614d9fdb4Robert Mustacchitypedef struct Dwarf_P_Fde_s*         Dwarf_P_Fde;
5624d9fdb4Robert Mustacchitypedef struct Dwarf_P_Expr_s*        Dwarf_P_Expr;
5634d9fdb4Robert Mustacchitypedef Dwarf_Unsigned                Dwarf_Tag;
5644d9fdb4Robert Mustacchi
5654d9fdb4Robert Mustacchi
5664d9fdb4Robert Mustacchi/* error handler function
5674d9fdb4Robert Mustacchi*/
5684d9fdb4Robert Mustacchitypedef void  (*Dwarf_Handler)(Dwarf_Error /*error*/, Dwarf_Ptr /*errarg*/);
5694d9fdb4Robert Mustacchi
5704d9fdb4Robert Mustacchi
5714d9fdb4Robert Mustacchi/* Begin libdwarf Object File Interface declarations.
5724d9fdb4Robert Mustacchi
5734d9fdb4Robert MustacchiAs of February 2008 there are multiple dwarf_reader object access
5744d9fdb4Robert Mustacchiinitialization methods available:
5754d9fdb4Robert MustacchiThe traditional dwarf_elf_init() and dwarf_init()  and dwarf_finish()
5764d9fdb4Robert Mustacchi    which assume libelf and POSIX file access.
5774d9fdb4Robert MustacchiAn object-file and library agnostic dwarf_object_init() and dwarf_object_finish()
5784d9fdb4Robert Mustacchi    which allow the coder to provide object access routines
5794d9fdb4Robert Mustacchi    abstracting away the elf interface.  So there is no dependence in the
5804d9fdb4Robert Mustacchi    reader code on the object format and no dependence on libelf.
5814d9fdb4Robert Mustacchi    See the code in dwarf_elf_access.c  and dwarf_original_elf_init.c
5824d9fdb4Robert Mustacchi    to see an example of initializing the structures mentioned below.
5834d9fdb4Robert Mustacchi
5844d9fdb4Robert MustacchiProjects using dwarf_elf_init() or dwarf_init() can ignore
5854d9fdb4Robert Mustacchithe Dwarf_Obj_Access* structures entirely as all these details
5864d9fdb4Robert Mustacchiare completed for you.
5874d9fdb4Robert Mustacchi
5884d9fdb4Robert MustacchiAs of March 2017 additional
5894d9fdb4Robert Mustacchifunctions dwarf_elf_init_b
5904d9fdb4Robert Mustacchiand dwarf_init_b
5914d9fdb4Robert Mustacchiand dwarf_object_init_b
5924d9fdb4Robert Mustacchiadd a groupnumber argument so DWARF5
5934d9fdb4Robert Mustacchisplit-dwarf sections can be accessed.
5944d9fdb4Robert Mustacchi*/
5954d9fdb4Robert Mustacchi
5964d9fdb4Robert Mustacchitypedef struct Dwarf_Obj_Access_Interface_s   Dwarf_Obj_Access_Interface;
5974d9fdb4Robert Mustacchitypedef struct Dwarf_Obj_Access_Methods_s     Dwarf_Obj_Access_Methods;
5984d9fdb4Robert Mustacchitypedef struct Dwarf_Obj_Access_Section_s     Dwarf_Obj_Access_Section;
5994d9fdb4Robert Mustacchi
6004d9fdb4Robert Mustacchi
6014d9fdb4Robert Mustacchi/*  Used in the get_section interface function
6024d9fdb4Robert Mustacchi    in Dwarf_Obj_Access_Section_s.  Since libdwarf
6034d9fdb4Robert Mustacchi    depends on standard DWARF section names an object
6044d9fdb4Robert Mustacchi    format that has no such names (but has some
6054d9fdb4Robert Mustacchi    method of setting up 'sections equivalents')
6064d9fdb4Robert Mustacchi    must arrange to return standard DWARF section
6074d9fdb4Robert Mustacchi    names in the 'name' field.  libdwarf does
6084d9fdb4Robert Mustacchi    not free the strings in 'name'. */
6094d9fdb4Robert Mustacchistruct Dwarf_Obj_Access_Section_s {
6104d9fdb4Robert Mustacchi    /*  addr is the virtual address of the first byte of
6114d9fdb4Robert Mustacchi        the section data.  Usually zero when the address
6124d9fdb4Robert Mustacchi        makes no sense for a given section. */
6134d9fdb4Robert Mustacchi    Dwarf_Addr     addr;
6144d9fdb4Robert Mustacchi
6154d9fdb4Robert Mustacchi    /* Section type. */
6164d9fdb4Robert Mustacchi    Dwarf_Unsigned type;
6174d9fdb4Robert Mustacchi
6184d9fdb4Robert Mustacchi    /* Size in bytes of the section. */
6194d9fdb4Robert Mustacchi    Dwarf_Unsigned size;
6204d9fdb4Robert Mustacchi
6214d9fdb4Robert Mustacchi    /*  Having an accurate section name makes debugging of libdwarf easier.
6224d9fdb4Robert Mustacchi        and is essential to find the .debug_ sections.  */
6234d9fdb4Robert Mustacchi    const char*    name;
6244d9fdb4Robert Mustacchi    /*  Set link to zero if it is meaningless.  If non-zero
6254d9fdb4Robert Mustacchi        it should be a link to a rela section or from symtab
6264d9fdb4Robert Mustacchi        to strtab.  In Elf it is sh_link. */
6274d9fdb4Robert Mustacchi    Dwarf_Unsigned link;
6284d9fdb4Robert Mustacchi
6294d9fdb4Robert Mustacchi    /*  The section header index of the section to which the
6304d9fdb4Robert Mustacchi        relocation applies. In Elf it is sh_info. */
6314d9fdb4Robert Mustacchi    Dwarf_Unsigned info;
6324d9fdb4Robert Mustacchi
6334d9fdb4Robert Mustacchi    /*  Elf sections that are tables have a non-zero entrysize so
6344d9fdb4Robert Mustacchi        the count of entries can be calculated even without
6354d9fdb4Robert Mustacchi        the right structure definition. If your object format
6364d9fdb4Robert Mustacchi        does not have this data leave this zero. */
6374d9fdb4Robert Mustacchi    Dwarf_Unsigned entrysize;
6384d9fdb4Robert Mustacchi};
6394d9fdb4Robert Mustacchi
6404d9fdb4Robert Mustacchi/*  Returned by the get_endianness function in
6414d9fdb4Robert Mustacchi    Dwarf_Obj_Access_Methods_s. */
6424d9fdb4Robert Mustacchitypedef enum {
6434d9fdb4Robert Mustacchi    DW_OBJECT_MSB,
6444d9fdb4Robert Mustacchi    DW_OBJECT_LSB
6454d9fdb4Robert Mustacchi} Dwarf_Endianness;
6464d9fdb4Robert Mustacchi
6474d9fdb4Robert Mustacchi/*  The functions we need to access object data from libdwarf are declared here.
6484d9fdb4Robert Mustacchi
6494d9fdb4Robert Mustacchi    In these function pointer declarations
6504d9fdb4Robert Mustacchi    'void *obj' is intended to be a pointer (the object field in
6514d9fdb4Robert Mustacchi    Dwarf_Obj_Access_Interface_s)
6524d9fdb4Robert Mustacchi    that hides the library-specific and object-specific data that makes
6534d9fdb4Robert Mustacchi    it possible to handle multiple object formats and multiple libraries.
6544d9fdb4Robert Mustacchi    It's not required that one handles multiple such in a single libdwarf
6554d9fdb4Robert Mustacchi    archive/shared-library (but not ruled out either).
6564d9fdb4Robert Mustacchi    See  dwarf_elf_object_access_internals_t and dwarf_elf_access.c
6574d9fdb4Robert Mustacchi    for an example.
6584d9fdb4Robert Mustacchi
6594d9fdb4Robert Mustacchi*/
6604d9fdb4Robert Mustacchistruct Dwarf_Obj_Access_Methods_s {
6614d9fdb4Robert Mustacchi    /*
6624d9fdb4Robert Mustacchi        get_section_info
6634d9fdb4Robert Mustacchi
6644d9fdb4Robert Mustacchi        Get address, size, and name info about a section.
6654d9fdb4Robert Mustacchi
6664d9fdb4Robert Mustacchi        Parameters
6674d9fdb4Robert Mustacchi        section_index - Zero-based index.
6684d9fdb4Robert Mustacchi        return_section - Pointer to a structure in which section info
6694d9fdb4Robert Mustacchi            will be placed.   Caller must provide a valid pointer to a
6704d9fdb4Robert Mustacchi            structure area.  The structure's contents will be overwritten
6714d9fdb4Robert Mustacchi            by the call to get_section_info.
6724d9fdb4Robert Mustacchi        error - A pointer to an integer in which an error code may be stored.
6734d9fdb4Robert Mustacchi
6744d9fdb4Robert Mustacchi        Return
6754d9fdb4Robert Mustacchi        DW_DLV_OK - Everything ok.
6764d9fdb4Robert Mustacchi        DW_DLV_ERROR - Error occurred. Use 'error' to determine the
6774d9fdb4Robert Mustacchi            libdwarf defined error.
6784d9fdb4Robert Mustacchi        DW_DLV_NO_ENTRY - No such section.  */
6794d9fdb4Robert Mustacchi    int    (*get_section_info)(void* obj, Dwarf_Half section_index,
6804d9fdb4Robert Mustacchi        Dwarf_Obj_Access_Section* return_section, int* error);
6814d9fdb4Robert Mustacchi    /*
6824d9fdb4Robert Mustacchi        get_byte_order
6834d9fdb4Robert Mustacchi
6844d9fdb4Robert Mustacchi        Get whether the object file represented by this interface is big-endian
6854d9fdb4Robert Mustacchi        (DW_OBJECT_MSB) or little endian (DW_OBJECT_LSB).
6864d9fdb4Robert Mustacchi
6874d9fdb4Robert Mustacchi        Parameters
6884d9fdb4Robert Mustacchi        obj - Equivalent to 'this' in OO languages.
6894d9fdb4Robert Mustacchi
6904d9fdb4Robert Mustacchi        Return
6914d9fdb4Robert Mustacchi        Endianness of object. Cannot fail.  */
6924d9fdb4Robert Mustacchi    Dwarf_Endianness  (*get_byte_order)(void* obj);
6934d9fdb4Robert Mustacchi    /*
6944d9fdb4Robert Mustacchi        get_length_size
6954d9fdb4Robert Mustacchi
6964d9fdb4Robert Mustacchi        Get the size of a length field in the underlying object file.
6974d9fdb4Robert Mustacchi        libdwarf currently supports * 4 and 8 byte sizes, but may
6984d9fdb4Robert Mustacchi        support larger in the future.
6994d9fdb4Robert Mustacchi        Perhaps the return type should be an enumeration?
7004d9fdb4Robert Mustacchi
7014d9fdb4Robert Mustacchi        Parameters
7024d9fdb4Robert Mustacchi        obj - Equivalent to 'this' in OO languages.
7034d9fdb4Robert Mustacchi
7044d9fdb4Robert Mustacchi        Return
7054d9fdb4Robert Mustacchi        Size of length. Cannot fail.  */
7064d9fdb4Robert Mustacchi    Dwarf_Small   (*get_length_size)(void* obj);
7074d9fdb4Robert Mustacchi    /*
7084d9fdb4Robert Mustacchi        get_pointer_size
7094d9fdb4Robert Mustacchi
7104d9fdb4Robert Mustacchi        Get the size of a pointer field in the underlying object file.
7114d9fdb4Robert Mustacchi        libdwarf currently supports  4 and 8 byte sizes.
7124d9fdb4Robert Mustacchi        Perhaps the return type should be an enumeration?
7134d9fdb4Robert Mustacchi
7144d9fdb4Robert Mustacchi        Return
7154d9fdb4Robert Mustacchi        Size of pointer. Cannot fail.  */
7164d9fdb4Robert Mustacchi    Dwarf_Small   (*get_pointer_size)(void* obj);
7174d9fdb4Robert Mustacchi    /*
7184d9fdb4Robert Mustacchi        get_section_count
7194d9fdb4Robert Mustacchi
7204d9fdb4Robert Mustacchi        Get the number of sections in the object file.
7214d9fdb4Robert Mustacchi
7224d9fdb4Robert Mustacchi        Parameters
7234d9fdb4Robert Mustacchi
7244d9fdb4Robert Mustacchi        Return
7254d9fdb4Robert Mustacchi        Number of sections */
7264d9fdb4Robert Mustacchi    Dwarf_Unsigned  (*get_section_count)(void* obj);
7274d9fdb4Robert Mustacchi    /*
7284d9fdb4Robert Mustacchi        load_section
7294d9fdb4Robert Mustacchi
7304d9fdb4Robert Mustacchi        Get a pointer to an array of bytes that represent the section.
7314d9fdb4Robert Mustacchi
7324d9fdb4Robert Mustacchi        Parameters
7334d9fdb4Robert Mustacchi        section_index - Zero-based index.
7344d9fdb4Robert Mustacchi        return_data - The address of a pointer to which the section data block
7354d9fdb4Robert Mustacchi            will be assigned.
7364d9fdb4Robert Mustacchi        error - Pointer to an integer for returning libdwarf-defined
7374d9fdb4Robert Mustacchi            error numbers.
7384d9fdb4Robert Mustacchi
7394d9fdb4Robert Mustacchi        Return
7404d9fdb4Robert Mustacchi        DW_DLV_OK - No error.
7414d9fdb4Robert Mustacchi        DW_DLV_ERROR - Error. Use 'error' to indicate a libdwarf-defined
7424d9fdb4Robert Mustacchi            error number.
7434d9fdb4Robert Mustacchi        DW_DLV_NO_ENTRY - No such section.  */
7444d9fdb4Robert Mustacchi    int    (*load_section)(void* obj, Dwarf_Half section_index,
7454d9fdb4Robert Mustacchi        Dwarf_Small** return_data, int* error);
7464d9fdb4Robert Mustacchi
7474d9fdb4Robert Mustacchi    /**
7484d9fdb4Robert Mustacchi        relocate_a_section
7494d9fdb4Robert Mustacchi        If relocations are not supported leave this pointer NULL.
7504d9fdb4Robert Mustacchi
7514d9fdb4Robert Mustacchi        Get a pointer to an array of bytes that represent the section.
7524d9fdb4Robert Mustacchi
7534d9fdb4Robert Mustacchi        Parameters
7544d9fdb4Robert Mustacchi        section_index - Zero-based index of the section to be relocated.
7554d9fdb4Robert Mustacchi        error - Pointer to an integer for returning libdwarf-defined
7564d9fdb4Robert Mustacchi            error numbers.
7574d9fdb4Robert Mustacchi
7584d9fdb4Robert Mustacchi        Return
7594d9fdb4Robert Mustacchi        DW_DLV_OK - No error.
7604d9fdb4Robert Mustacchi        DW_DLV_ERROR - Error. Use 'error' to indicate a libdwarf-defined
7614d9fdb4Robert Mustacchi            error number.
7624d9fdb4Robert Mustacchi        DW_DLV_NO_ENTRY - No such section.  */
7634d9fdb4Robert Mustacchi    int    (*relocate_a_section)(void* obj, Dwarf_Half section_index,
7644d9fdb4Robert Mustacchi        Dwarf_Debug dbg,
7654d9fdb4Robert Mustacchi        int* error);
7664d9fdb4Robert Mustacchi
7674d9fdb4Robert Mustacchi};
7684d9fdb4Robert Mustacchi
7694d9fdb4Robert Mustacchi
7704d9fdb4Robert Mustacchi
7714d9fdb4Robert Mustacchi/*  These structures are allocated and deallocated by your code
7724d9fdb4Robert Mustacchi    when you are using the libdwarf Object File Interface
7734d9fdb4Robert Mustacchi    [dwarf_object_init and dwarf_object_finish)] directly.
7744d9fdb4Robert Mustacchi    dwarf_object_finish) does not free
7754d9fdb4Robert Mustacchi    struct Dwarf_Obj_Access_Interface_s or its content.
7764d9fdb4Robert Mustacchi    (libdwarf does record a pointer to this struct: you must
7774d9fdb4Robert Mustacchi    ensure that pointer remains valid for as long as
7784d9fdb4Robert Mustacchi    a libdwarf instance is open (meaning
7794d9fdb4Robert Mustacchi    after dwarf_init) and before dwarf_finish)).
7804d9fdb4Robert Mustacchi
7814d9fdb4Robert Mustacchi    If you are reading Elf objects and libelf use dwarf_init()
7824d9fdb4Robert Mustacchi    or dwarf_elf_init() which take care of these details.
7834d9fdb4Robert Mustacchi*/
7844d9fdb4Robert Mustacchistruct Dwarf_Obj_Access_Interface_s {
7854d9fdb4Robert Mustacchi    /*  object is a void* as it hides the data the object access routines
7864d9fdb4Robert Mustacchi        need (which varies by library in use and object format).
7874d9fdb4Robert Mustacchi    */
7884d9fdb4Robert Mustacchi    void* object;
7894d9fdb4Robert Mustacchi    const Dwarf_Obj_Access_Methods * methods;
7904d9fdb4Robert Mustacchi};
7914d9fdb4Robert Mustacchi
7924d9fdb4Robert Mustacchi/* End libdwarf Object File Interface */
7934d9fdb4Robert Mustacchi
7944d9fdb4Robert Mustacchi/*
7954d9fdb4Robert Mustacchi    Dwarf_dealloc() alloc_type arguments.
7964d9fdb4Robert Mustacchi    Argument points to:
7974d9fdb4Robert Mustacchi*/
7984d9fdb4Robert Mustacchi#define DW_DLA_STRING          0x01     /* char* */
7994d9fdb4Robert Mustacchi#define DW_DLA_LOC             0x02     /* Dwarf_Loc */
8004d9fdb4Robert Mustacchi#define DW_DLA_LOCDESC         0x03     /* Dwarf_Locdesc */
8014d9fdb4Robert Mustacchi#define DW_DLA_ELLIST          0x04     /* Dwarf_Ellist (not used)*/
8024d9fdb4Robert Mustacchi#define DW_DLA_BOUNDS          0x05     /* Dwarf_Bounds (not used) */
8034d9fdb4Robert Mustacchi#define DW_DLA_BLOCK           0x06     /* Dwarf_Block */
8044d9fdb4Robert Mustacchi#define DW_DLA_DEBUG           0x07     /* Dwarf_Debug */
8054d9fdb4Robert Mustacchi#define DW_DLA_DIE             0x08     /* Dwarf_Die */
8064d9fdb4Robert Mustacchi#define DW_DLA_LINE            0x09     /* Dwarf_Line */
8074d9fdb4Robert Mustacchi#define DW_DLA_ATTR            0x0a     /* Dwarf_Attribute */
8084d9fdb4Robert Mustacchi#define DW_DLA_TYPE            0x0b     /* Dwarf_Type  (not used) */
8094d9fdb4Robert Mustacchi#define DW_DLA_SUBSCR          0x0c     /* Dwarf_Subscr (not used) */
8104d9fdb4Robert Mustacchi#define DW_DLA_GLOBAL          0x0d     /* Dwarf_Global */
8114d9fdb4Robert Mustacchi#define DW_DLA_ERROR           0x0e     /* Dwarf_Error */
8124d9fdb4Robert Mustacchi#define DW_DLA_LIST            0x0f     /* a list */
8134d9fdb4Robert Mustacchi#define DW_DLA_LINEBUF         0x10     /* Dwarf_Line* (not used) */
8144d9fdb4Robert Mustacchi#define DW_DLA_ARANGE          0x11     /* Dwarf_Arange */
8154d9fdb4Robert Mustacchi#define DW_DLA_ABBREV          0x12     /* Dwarf_Abbrev */
8164d9fdb4Robert Mustacchi#define DW_DLA_FRAME_OP        0x13     /* Dwarf_Frame_Op */
8174d9fdb4Robert Mustacchi#define DW_DLA_CIE             0x14     /* Dwarf_Cie */
8184d9fdb4Robert Mustacchi#define DW_DLA_FDE             0x15     /* Dwarf_Fde */
8194d9fdb4Robert Mustacchi#define DW_DLA_LOC_BLOCK       0x16     /* Dwarf_Loc */
8204d9fdb4Robert Mustacchi#define DW_DLA_FRAME_BLOCK     0x17     /* Dwarf_Frame Block (not used) */
8214d9fdb4Robert Mustacchi#define DW_DLA_FUNC            0x18     /* Dwarf_Func */
8224d9fdb4Robert Mustacchi#define DW_DLA_TYPENAME        0x19     /* Dwarf_Type */
8234d9fdb4Robert Mustacchi#define DW_DLA_VAR             0x1a     /* Dwarf_Var */
8244d9fdb4Robert Mustacchi#define DW_DLA_WEAK            0x1b     /* Dwarf_Weak */
8254d9fdb4Robert Mustacchi#define DW_DLA_ADDR            0x1c     /* Dwarf_Addr sized entries */
8264d9fdb4Robert Mustacchi#define DW_DLA_RANGES          0x1d     /* Dwarf_Ranges */
8274d9fdb4Robert Mustacchi/* 0x1e (30) to 0x34 (52) reserved for internal to libdwarf types. */
8284d9fdb4Robert Mustacchi#define DW_DLA_LOCLISTS_HEAD   0x35     /* .debug_loclists DW5 */
8294d9fdb4Robert Mustacchi#define DW_DLA_RNGLISTS_HEAD   0x36     /* .debug_rnglists DW5 */
8304d9fdb4Robert Mustacchi#define DW_DLA_GDBINDEX        0x37     /* Dwarf_Gdbindex */
8314d9fdb4Robert Mustacchi#define DW_DLA_XU_INDEX        0x38     /* Dwarf_Xu_Index_Header */
8324d9fdb4Robert Mustacchi#define DW_DLA_LOC_BLOCK_C     0x39     /* Dwarf_Loc_c*/
8334d9fdb4Robert Mustacchi#define DW_DLA_LOCDESC_C       0x3a     /* Dwarf_Locdesc_c */
8344d9fdb4Robert Mustacchi#define DW_DLA_LOC_HEAD_C      0x3b     /* Dwarf_Loc_Head_c */
8354d9fdb4Robert Mustacchi#define DW_DLA_MACRO_CONTEXT   0x3c     /* Dwarf_Macro_Context */
8364d9fdb4Robert Mustacchi/*  0x3d (61) is for libdwarf internal use.               */
8374d9fdb4Robert Mustacchi#define DW_DLA_DSC_HEAD        0x3e     /* Dwarf_Dsc_Head */
8384d9fdb4Robert Mustacchi#define DW_DLA_DNAMES_HEAD     0x3f     /* Dwarf_Dnames_Head */
8394d9fdb4Robert Mustacchi#define DW_DLA_STR_OFFSETS     0x40     /* struct Dwarf_Str_Offsets_Table_s */
8404d9fdb4Robert Mustacchi
8414d9fdb4Robert Mustacchi/* The augmenter string for CIE */
8424d9fdb4Robert Mustacchi#define DW_CIE_AUGMENTER_STRING_V0              "z"
8434d9fdb4Robert Mustacchi
8444d9fdb4Robert Mustacchi/* dwarf_init() access arguments
8454d9fdb4Robert Mustacchi*/
8464d9fdb4Robert Mustacchi#define DW_DLC_READ        0        /* read only access */
8474d9fdb4Robert Mustacchi#define DW_DLC_WRITE       1        /* write only access */
8484d9fdb4Robert Mustacchi#define DW_DLC_RDWR        2        /* read/write access NOT SUPPORTED*/
8494d9fdb4Robert Mustacchi
8504d9fdb4Robert Mustacchi/* dwarf_producer_init* access flag modifiers
8514d9fdb4Robert Mustacchi   No longer depends on compile-time settings for
8524d9fdb4Robert Mustacchi   how to produce 64bit offset. See DW_DLC_IRIX_OFFSET64.
8534d9fdb4Robert Mustacchi   Historic  versions. One of
8544d9fdb4Robert Mustacchi   If DW_DLC_POINTER64 is not set DW_DLC_POINTER32 is assumed.
8554d9fdb4Robert Mustacchi   If DW_DLC_OFFSET64 or DW_DLC_IRIX_OFFSET64 is not
8564d9fdb4Robert Mustacchi   set 32bit offset DWARF is assumed.
8574d9fdb4Robert Mustacchi   Non-MIPS Non IA64 should use DW_DLC_SYMBOLIC_RELOCATIONS
8584d9fdb4Robert Mustacchi   and handle the relocation creation for the target
8594d9fdb4Robert Mustacchi   itself using the symbolic relocations to do so, those
8604d9fdb4Robert Mustacchi   use the Dwarf_Rel_Type enum relocation indicators.
8614d9fdb4Robert Mustacchi
8624d9fdb4Robert Mustacchi*/
8634d9fdb4Robert Mustacchi/*  The first three are traditional dwarf producer names.
8644d9fdb4Robert Mustacchi    These names still work.
8654d9fdb4Robert Mustacchi    Newer names below.
8664d9fdb4Robert Mustacchi*/
8674d9fdb4Robert Mustacchi/* 64-bit address-size target */
8684d9fdb4Robert Mustacchi#define DW_DLC_SIZE_64              0x40000000
8694d9fdb4Robert Mustacchi
8704d9fdb4Robert Mustacchi/* 32-bit address-size target */
8714d9fdb4Robert Mustacchi#define DW_DLC_SIZE_32              0x20000000
8724d9fdb4Robert Mustacchi
8734d9fdb4Robert Mustacchi/* 64-bit offset-size DWARF offsets (else 32bit) */
8744d9fdb4Robert Mustacchi#define DW_DLC_OFFSET_SIZE_64       0x10000000
8754d9fdb4Robert Mustacchi
8764d9fdb4Robert Mustacchi/* 32-bit offset-size ELF object (ELFCLASS32) */
8774d9fdb4Robert Mustacchi#define DW_DLC_ELF_OFFSET_SIZE_32   0x00400000
8784d9fdb4Robert Mustacchi
8794d9fdb4Robert Mustacchi/* 64-bit offset-size ELF object (ELFCLASS64)  */
8804d9fdb4Robert Mustacchi#define DW_DLC_ELF_OFFSET_SIZE_64   0x00020000
8814d9fdb4Robert Mustacchi
8824d9fdb4Robert Mustacchi/* dwarf_producer_init* access flag modifiers
8834d9fdb4Robert Mustacchi   Some new April 2014.
8844d9fdb4Robert Mustacchi   If DW_DLC_STREAM_RELOCATIONS is set the
8854d9fdb4Robert Mustacchi   DW_DLC_ISA_* flags are ignored. See the Dwarf_Rel_Type enum.
8864d9fdb4Robert Mustacchi*/
8874d9fdb4Robert Mustacchi
8884d9fdb4Robert Mustacchi/* Old style Elf binary relocation (.rel) records. The default. */
8894d9fdb4Robert Mustacchi#define DW_DLC_STREAM_RELOCATIONS   0x02000000
8904d9fdb4Robert Mustacchi
8914d9fdb4Robert Mustacchi/* use 32-bit  sec  offsets */
8924d9fdb4Robert Mustacchi#define DW_DLC_OFFSET32             0x00010000
8934d9fdb4Robert Mustacchi
8944d9fdb4Robert Mustacchi/* The following 3 are new sensible names.
8954d9fdb4Robert MustacchiOld names above with same values. */
8964d9fdb4Robert Mustacchi/* use 64-bit sec offsets in ELF */
8974d9fdb4Robert Mustacchi#define DW_DLC_OFFSET64             0x10000000
8984d9fdb4Robert Mustacchi
8994d9fdb4Robert Mustacchi/* use 4 for address_size */
9004d9fdb4Robert Mustacchi#define DW_DLC_POINTER32            0x20000000
9014d9fdb4Robert Mustacchi
9024d9fdb4Robert Mustacchi/* use 8 for address_size */
9034d9fdb4Robert Mustacchi#define DW_DLC_POINTER64            0x40000000
9044d9fdb4Robert Mustacchi
9054d9fdb4Robert Mustacchi/* Special for IRIX only */
9064d9fdb4Robert Mustacchi/* use Elf 64bit offset headers and non-std IRIX 64bitoffset headers */
9074d9fdb4Robert Mustacchi#define DW_DLC_IRIX_OFFSET64        0x00200000
9084d9fdb4Robert Mustacchi
9094d9fdb4Robert Mustacchi/*  Usable with assembly output because it is up to the producer to
9104d9fdb4Robert Mustacchi    deal with locations in whatever manner the calling producer
9114d9fdb4Robert Mustacchi    code wishes.  For example, when the libdwarf caller wishes
9124d9fdb4Robert Mustacchi    to produce relocations differently than the binary
9134d9fdb4Robert Mustacchi    relocation bits that libdwarf Stream Relocations generate.
9144d9fdb4Robert Mustacchi    */
9154d9fdb4Robert Mustacchi#define DW_DLC_SYMBOLIC_RELOCATIONS 0x04000000
9164d9fdb4Robert Mustacchi
9174d9fdb4Robert Mustacchi
9184d9fdb4Robert Mustacchi#define DW_DLC_TARGET_BIGENDIAN     0x08000000 /* Big    endian target */
9194d9fdb4Robert Mustacchi#define DW_DLC_TARGET_LITTLEENDIAN  0x00100000 /* Little endian target */
9204d9fdb4Robert Mustacchi
9214d9fdb4Robert Mustacchi
9224d9fdb4Robert Mustacchi/* dwarf_pcline function, slide arguments
9234d9fdb4Robert Mustacchi*/
9244d9fdb4Robert Mustacchi#define DW_DLS_BACKWARD   -1       /* slide backward to find line */
9254d9fdb4Robert Mustacchi#define DW_DLS_NOSLIDE     0       /* match exactly without sliding */
9264d9fdb4Robert Mustacchi#define DW_DLS_FORWARD     1       /* slide forward to find line */
9274d9fdb4Robert Mustacchi
9284d9fdb4Robert Mustacchi/* libdwarf error numbers
9294d9fdb4Robert Mustacchi*/
9304d9fdb4Robert Mustacchi#define DW_DLE_NE          0     /* no error */
9314d9fdb4Robert Mustacchi#define DW_DLE_VMM         1     /* dwarf format/library version mismatch */
9324d9fdb4Robert Mustacchi#define DW_DLE_MAP         2     /* memory map failure */
9334d9fdb4Robert Mustacchi#define DW_DLE_LEE         3     /* libelf error */
9344d9fdb4Robert Mustacchi#define DW_DLE_NDS         4     /* no debug section */
9354d9fdb4Robert Mustacchi#define DW_DLE_NLS         5     /* no line section */
9364d9fdb4Robert Mustacchi#define DW_DLE_ID          6     /* invalid descriptor for query */
9374d9fdb4Robert Mustacchi#define DW_DLE_IOF         7     /* I/O failure */
9384d9fdb4Robert Mustacchi#define DW_DLE_MAF         8     /* memory allocation failure */
9394d9fdb4Robert Mustacchi#define DW_DLE_IA          9     /* invalid argument */
9404d9fdb4Robert Mustacchi#define DW_DLE_MDE         10     /* mangled debugging entry */
9414d9fdb4Robert Mustacchi#define DW_DLE_MLE         11     /* mangled line number entry */
9424d9fdb4Robert Mustacchi#define DW_DLE_FNO         12     /* file not open */
9434d9fdb4Robert Mustacchi#define DW_DLE_FNR         13     /* file not a regular file */
9444d9fdb4Robert Mustacchi#define DW_DLE_FWA         14     /* file open with wrong access */
9454d9fdb4Robert Mustacchi#define DW_DLE_NOB         15     /* not an object file */
9464d9fdb4Robert Mustacchi#define DW_DLE_MOF         16     /* mangled object file header */
9474d9fdb4Robert Mustacchi#define DW_DLE_EOLL        17     /* end of location list entries */
9484d9fdb4Robert Mustacchi#define DW_DLE_NOLL        18     /* no location list section */
9494d9fdb4Robert Mustacchi#define DW_DLE_BADOFF      19     /* Invalid offset */
9504d9fdb4Robert Mustacchi#define DW_DLE_EOS         20     /* end of section  */
9514d9fdb4Robert Mustacchi#define DW_DLE_ATRUNC      21     /* abbreviations section appears truncated*/
9524d9fdb4Robert Mustacchi#define DW_DLE_BADBITC     22     /* Address size passed to dwarf bad*/
9534d9fdb4Robert Mustacchi                    /* It is not an allowed size (64 or 32) */
9544d9fdb4Robert Mustacchi    /* Error codes defined by the current Libdwarf Implementation. */
9554d9fdb4Robert Mustacchi#define DW_DLE_DBG_ALLOC                        23
9564d9fdb4Robert Mustacchi#define DW_DLE_FSTAT_ERROR                      24
9574d9fdb4Robert Mustacchi#define DW_DLE_FSTAT_MODE_ERROR                 25
9584d9fdb4Robert Mustacchi#define DW_DLE_INIT_ACCESS_WRONG                26
9594d9fdb4Robert Mustacchi#define DW_DLE_ELF_BEGIN_ERROR                  27
9604d9fdb4Robert Mustacchi#define DW_DLE_ELF_GETEHDR_ERROR                28
9614d9fdb4Robert Mustacchi#define DW_DLE_ELF_GETSHDR_ERROR                29
9624d9fdb4Robert Mustacchi#define DW_DLE_ELF_STRPTR_ERROR                 30
9634d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_INFO_DUPLICATE             31
9644d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_INFO_NULL                  32
9654d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_ABBREV_DUPLICATE           33
9664d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_ABBREV_NULL                34
9674d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_ARANGES_DUPLICATE          35
9684d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_ARANGES_NULL               36
9694d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_LINE_DUPLICATE             37
9704d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_LINE_NULL                  38
9714d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_LOC_DUPLICATE              39
9724d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_LOC_NULL                   40
9734d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_MACINFO_DUPLICATE          41
9744d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_MACINFO_NULL               42
9754d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_PUBNAMES_DUPLICATE         43
9764d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_PUBNAMES_NULL              44
9774d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_STR_DUPLICATE              45
9784d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_STR_NULL                   46
9794d9fdb4Robert Mustacchi#define DW_DLE_CU_LENGTH_ERROR                  47
9804d9fdb4Robert Mustacchi#define DW_DLE_VERSION_STAMP_ERROR              48
9814d9fdb4Robert Mustacchi#define DW_DLE_ABBREV_OFFSET_ERROR              49
9824d9fdb4Robert Mustacchi#define DW_DLE_ADDRESS_SIZE_ERROR               50
9834d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_INFO_PTR_NULL              51
9844d9fdb4Robert Mustacchi#define DW_DLE_DIE_NULL                         52
9854d9fdb4Robert Mustacchi#define DW_DLE_STRING_OFFSET_BAD                53
9864d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_LINE_LENGTH_BAD            54
9874d9fdb4Robert Mustacchi#define DW_DLE_LINE_PROLOG_LENGTH_BAD           55
9884d9fdb4Robert Mustacchi#define DW_DLE_LINE_NUM_OPERANDS_BAD            56
9894d9fdb4Robert Mustacchi#define DW_DLE_LINE_SET_ADDR_ERROR              57 /* No longer used. */
9904d9fdb4Robert Mustacchi#define DW_DLE_LINE_EXT_OPCODE_BAD              58
9914d9fdb4Robert Mustacchi#define DW_DLE_DWARF_LINE_NULL                  59
9924d9fdb4Robert Mustacchi#define DW_DLE_INCL_DIR_NUM_BAD                 60
9934d9fdb4Robert Mustacchi#define DW_DLE_LINE_FILE_NUM_BAD                61
9944d9fdb4Robert Mustacchi#define DW_DLE_ALLOC_FAIL                       62
9954d9fdb4Robert Mustacchi#define DW_DLE_NO_CALLBACK_FUNC                 63
9964d9fdb4Robert Mustacchi#define DW_DLE_SECT_ALLOC                       64
9974d9fdb4Robert Mustacchi#define DW_DLE_FILE_ENTRY_ALLOC                 65
9984d9fdb4Robert Mustacchi#define DW_DLE_LINE_ALLOC                       66
9994d9fdb4Robert Mustacchi#define DW_DLE_FPGM_ALLOC                       67
10004d9fdb4Robert Mustacchi#define DW_DLE_INCDIR_ALLOC                     68
10014d9fdb4Robert Mustacchi#define DW_DLE_STRING_ALLOC                     69
10024d9fdb4Robert Mustacchi#define DW_DLE_CHUNK_ALLOC                      70
10034d9fdb4Robert Mustacchi#define DW_DLE_BYTEOFF_ERR                      71
10044d9fdb4Robert Mustacchi#define DW_DLE_CIE_ALLOC                        72
10054d9fdb4Robert Mustacchi#define DW_DLE_FDE_ALLOC                        73
10064d9fdb4Robert Mustacchi#define DW_DLE_REGNO_OVFL                       74
10074d9fdb4Robert Mustacchi#define DW_DLE_CIE_OFFS_ALLOC                   75
10084d9fdb4Robert Mustacchi#define DW_DLE_WRONG_ADDRESS                    76
10094d9fdb4Robert Mustacchi#define DW_DLE_EXTRA_NEIGHBORS                  77
10104d9fdb4Robert Mustacchi#define DW_DLE_WRONG_TAG                        78
10114d9fdb4Robert Mustacchi#define DW_DLE_DIE_ALLOC                        79
10124d9fdb4Robert Mustacchi#define DW_DLE_PARENT_EXISTS                    80
10134d9fdb4Robert Mustacchi#define DW_DLE_DBG_NULL                         81
10144d9fdb4Robert Mustacchi#define DW_DLE_DEBUGLINE_ERROR                  82
10154d9fdb4Robert Mustacchi#define DW_DLE_DEBUGFRAME_ERROR                 83
10164d9fdb4Robert Mustacchi#define DW_DLE_DEBUGINFO_ERROR                  84
10174d9fdb4Robert Mustacchi#define DW_DLE_ATTR_ALLOC                       85
10184d9fdb4Robert Mustacchi#define DW_DLE_ABBREV_ALLOC                     86
10194d9fdb4Robert Mustacchi#define DW_DLE_OFFSET_UFLW                      87
10204d9fdb4Robert Mustacchi#define DW_DLE_ELF_SECT_ERR                     88
10214d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_FRAME_LENGTH_BAD           89
10224d9fdb4Robert Mustacchi#define DW_DLE_FRAME_VERSION_BAD                90
10234d9fdb4Robert Mustacchi#define DW_DLE_CIE_RET_ADDR_REG_ERROR           91
10244d9fdb4Robert Mustacchi#define DW_DLE_FDE_NULL                         92
10254d9fdb4Robert Mustacchi#define DW_DLE_FDE_DBG_NULL                     93
10264d9fdb4Robert Mustacchi#define DW_DLE_CIE_NULL                         94
10274d9fdb4Robert Mustacchi#define DW_DLE_CIE_DBG_NULL                     95
10284d9fdb4Robert Mustacchi#define DW_DLE_FRAME_TABLE_COL_BAD              96
10294d9fdb4Robert Mustacchi#define DW_DLE_PC_NOT_IN_FDE_RANGE              97
10304d9fdb4Robert Mustacchi#define DW_DLE_CIE_INSTR_EXEC_ERROR             98
10314d9fdb4Robert Mustacchi#define DW_DLE_FRAME_INSTR_EXEC_ERROR           99
10324d9fdb4Robert Mustacchi#define DW_DLE_FDE_PTR_NULL                    100
10334d9fdb4Robert Mustacchi#define DW_DLE_RET_OP_LIST_NULL                101
10344d9fdb4Robert Mustacchi#define DW_DLE_LINE_CONTEXT_NULL               102
10354d9fdb4Robert Mustacchi#define DW_DLE_DBG_NO_CU_CONTEXT               103
10364d9fdb4Robert Mustacchi#define DW_DLE_DIE_NO_CU_CONTEXT               104
10374d9fdb4Robert Mustacchi#define DW_DLE_FIRST_DIE_NOT_CU                105
10384d9fdb4Robert Mustacchi#define DW_DLE_NEXT_DIE_PTR_NULL               106
10394d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_FRAME_DUPLICATE           107
10404d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_FRAME_NULL                108
10414d9fdb4Robert Mustacchi#define DW_DLE_ABBREV_DECODE_ERROR             109
10424d9fdb4Robert Mustacchi#define DW_DLE_DWARF_ABBREV_NULL               110
10434d9fdb4Robert Mustacchi#define DW_DLE_ATTR_NULL                       111
10444d9fdb4Robert Mustacchi#define DW_DLE_DIE_BAD                         112
10454d9fdb4Robert Mustacchi#define DW_DLE_DIE_ABBREV_BAD                  113
10464d9fdb4Robert Mustacchi#define DW_DLE_ATTR_FORM_BAD                   114
10474d9fdb4Robert Mustacchi#define DW_DLE_ATTR_NO_CU_CONTEXT              115
10484d9fdb4Robert Mustacchi#define DW_DLE_ATTR_FORM_SIZE_BAD              116
10494d9fdb4Robert Mustacchi#define DW_DLE_ATTR_DBG_NULL                   117
10504d9fdb4Robert Mustacchi#define DW_DLE_BAD_REF_FORM                    118
10514d9fdb4Robert Mustacchi#define DW_DLE_ATTR_FORM_OFFSET_BAD            119
10524d9fdb4Robert Mustacchi#define DW_DLE_LINE_OFFSET_BAD                 120
10534d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_STR_OFFSET_BAD            121
10544d9fdb4Robert Mustacchi#define DW_DLE_STRING_PTR_NULL                 122
10554d9fdb4Robert Mustacchi#define DW_DLE_PUBNAMES_VERSION_ERROR          123
10564d9fdb4Robert Mustacchi#define DW_DLE_PUBNAMES_LENGTH_BAD             124
10574d9fdb4Robert Mustacchi#define DW_DLE_GLOBAL_NULL                     125
10584d9fdb4Robert Mustacchi#define DW_DLE_GLOBAL_CONTEXT_NULL             126
10594d9fdb4Robert Mustacchi#define DW_DLE_DIR_INDEX_BAD                   127
10604d9fdb4Robert Mustacchi#define DW_DLE_LOC_EXPR_BAD                    128
10614d9fdb4Robert Mustacchi#define DW_DLE_DIE_LOC_EXPR_BAD                129
10624d9fdb4Robert Mustacchi#define DW_DLE_ADDR_ALLOC                      130
10634d9fdb4Robert Mustacchi#define DW_DLE_OFFSET_BAD                      131
10644d9fdb4Robert Mustacchi#define DW_DLE_MAKE_CU_CONTEXT_FAIL            132
10654d9fdb4Robert Mustacchi#define DW_DLE_REL_ALLOC                       133
10664d9fdb4Robert Mustacchi#define DW_DLE_ARANGE_OFFSET_BAD               134
10674d9fdb4Robert Mustacchi#define DW_DLE_SEGMENT_SIZE_BAD                135
10684d9fdb4Robert Mustacchi#define DW_DLE_ARANGE_LENGTH_BAD               136
10694d9fdb4Robert Mustacchi#define DW_DLE_ARANGE_DECODE_ERROR             137
10704d9fdb4Robert Mustacchi#define DW_DLE_ARANGES_NULL                    138
10714d9fdb4Robert Mustacchi#define DW_DLE_ARANGE_NULL                     139
10724d9fdb4Robert Mustacchi#define DW_DLE_NO_FILE_NAME                    140
10734d9fdb4Robert Mustacchi#define DW_DLE_NO_COMP_DIR                     141
10744d9fdb4Robert Mustacchi#define DW_DLE_CU_ADDRESS_SIZE_BAD             142
10754d9fdb4Robert Mustacchi#define DW_DLE_INPUT_ATTR_BAD                  143
10764d9fdb4Robert Mustacchi#define DW_DLE_EXPR_NULL                       144
10774d9fdb4Robert Mustacchi#define DW_DLE_BAD_EXPR_OPCODE                 145
10784d9fdb4Robert Mustacchi#define DW_DLE_EXPR_LENGTH_BAD                 146
10794d9fdb4Robert Mustacchi#define DW_DLE_MULTIPLE_RELOC_IN_EXPR          147
10804d9fdb4Robert Mustacchi#define DW_DLE_ELF_GETIDENT_ERROR              148
10814d9fdb4Robert Mustacchi#define DW_DLE_NO_AT_MIPS_FDE                  149
10824d9fdb4Robert Mustacchi#define DW_DLE_NO_CIE_FOR_FDE                  150
10834d9fdb4Robert Mustacchi#define DW_DLE_DIE_ABBREV_LIST_NULL            151
10844d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_FUNCNAMES_DUPLICATE       152
10854d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_FUNCNAMES_NULL            153
10864d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_FUNCNAMES_VERSION_ERROR   154
10874d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_FUNCNAMES_LENGTH_BAD      155
10884d9fdb4Robert Mustacchi#define DW_DLE_FUNC_NULL                       156
10894d9fdb4Robert Mustacchi#define DW_DLE_FUNC_CONTEXT_NULL               157
10904d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_TYPENAMES_DUPLICATE       158
10914d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_TYPENAMES_NULL            159
10924d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_TYPENAMES_VERSION_ERROR   160
10934d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_TYPENAMES_LENGTH_BAD      161
10944d9fdb4Robert Mustacchi#define DW_DLE_TYPE_NULL                       162
10954d9fdb4Robert Mustacchi#define DW_DLE_TYPE_CONTEXT_NULL               163
10964d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_VARNAMES_DUPLICATE        164
10974d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_VARNAMES_NULL             165
10984d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_VARNAMES_VERSION_ERROR    166
10994d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_VARNAMES_LENGTH_BAD       167
11004d9fdb4Robert Mustacchi#define DW_DLE_VAR_NULL                        168
11014d9fdb4Robert Mustacchi#define DW_DLE_VAR_CONTEXT_NULL                169
11024d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_WEAKNAMES_DUPLICATE       170
11034d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_WEAKNAMES_NULL            171
11044d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_WEAKNAMES_VERSION_ERROR   172
11054d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_WEAKNAMES_LENGTH_BAD      173
11064d9fdb4Robert Mustacchi#define DW_DLE_WEAK_NULL                       174
11074d9fdb4Robert Mustacchi#define DW_DLE_WEAK_CONTEXT_NULL               175
11084d9fdb4Robert Mustacchi#define DW_DLE_LOCDESC_COUNT_WRONG             176
11094d9fdb4Robert Mustacchi#define DW_DLE_MACINFO_STRING_NULL             177
11104d9fdb4Robert Mustacchi#define DW_DLE_MACINFO_STRING_EMPTY            178
11114d9fdb4Robert Mustacchi#define DW_DLE_MACINFO_INTERNAL_ERROR_SPACE    179
11124d9fdb4Robert Mustacchi#define DW_DLE_MACINFO_MALLOC_FAIL             180
11134d9fdb4Robert Mustacchi#define DW_DLE_DEBUGMACINFO_ERROR              181
11144d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_MACRO_LENGTH_BAD          182
11154d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_MACRO_MAX_BAD             183
11164d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_MACRO_INTERNAL_ERR        184
11174d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_MACRO_MALLOC_SPACE        185
11184d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_MACRO_INCONSISTENT        186
11194d9fdb4Robert Mustacchi#define DW_DLE_DF_NO_CIE_AUGMENTATION          187
11204d9fdb4Robert Mustacchi#define DW_DLE_DF_REG_NUM_TOO_HIGH             188
11214d9fdb4Robert Mustacchi#define DW_DLE_DF_MAKE_INSTR_NO_INIT           189
11224d9fdb4Robert Mustacchi#define DW_DLE_DF_NEW_LOC_LESS_OLD_LOC         190
11234d9fdb4Robert Mustacchi#define DW_DLE_DF_POP_EMPTY_STACK              191
11244d9fdb4Robert Mustacchi#define DW_DLE_DF_ALLOC_FAIL                   192
11254d9fdb4Robert Mustacchi#define DW_DLE_DF_FRAME_DECODING_ERROR         193
11264d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_LOC_SECTION_SHORT         194
11274d9fdb4Robert Mustacchi#define DW_DLE_FRAME_AUGMENTATION_UNKNOWN      195
11284d9fdb4Robert Mustacchi#define DW_DLE_PUBTYPE_CONTEXT                 196 /* Unused. */
11294d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_PUBTYPES_LENGTH_BAD       197
11304d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_PUBTYPES_VERSION_ERROR    198
11314d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_PUBTYPES_DUPLICATE        199
11324d9fdb4Robert Mustacchi#define DW_DLE_FRAME_CIE_DECODE_ERROR          200
11334d9fdb4Robert Mustacchi#define DW_DLE_FRAME_REGISTER_UNREPRESENTABLE  201
11344d9fdb4Robert Mustacchi#define DW_DLE_FRAME_REGISTER_COUNT_MISMATCH   202
11354d9fdb4Robert Mustacchi#define DW_DLE_LINK_LOOP                       203
11364d9fdb4Robert Mustacchi#define DW_DLE_STRP_OFFSET_BAD                 204
11374d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_RANGES_DUPLICATE          205
11384d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_RANGES_OFFSET_BAD         206
11394d9fdb4Robert Mustacchi#define DW_DLE_DEBUG_RANGES_MISSING_END        207
1140