1*4d9fdb46SRobert Mustacchi/*
2*4d9fdb46SRobert Mustacchi
3*4d9fdb46SRobert Mustacchi  Copyright (C) 2000-2010 Silicon Graphics, Inc.  All Rights Reserved.
4*4d9fdb46SRobert Mustacchi  Portions Copyright 2007-2010 Sun Microsystems, Inc. All rights reserved.
5*4d9fdb46SRobert Mustacchi  Portions Copyright 2008-2018 David Anderson. All rights reserved.
6*4d9fdb46SRobert Mustacchi  Portions Copyright 2008-2010 Arxan Technologies, Inc. All rights reserved.
7*4d9fdb46SRobert Mustacchi  Portions Copyright 2010-2012 SN Systems Ltd. All rights reserved.
8*4d9fdb46SRobert Mustacchi
9*4d9fdb46SRobert Mustacchi  This program is free software; you can redistribute it
10*4d9fdb46SRobert Mustacchi  and/or modify it under the terms of version 2.1 of the
11*4d9fdb46SRobert Mustacchi  GNU Lesser General Public License as published by the Free
12*4d9fdb46SRobert Mustacchi  Software Foundation.
13*4d9fdb46SRobert Mustacchi
14*4d9fdb46SRobert Mustacchi  This program is distributed in the hope that it would be
15*4d9fdb46SRobert Mustacchi  useful, but WITHOUT ANY WARRANTY; without even the implied
16*4d9fdb46SRobert Mustacchi  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17*4d9fdb46SRobert Mustacchi  PURPOSE.
18*4d9fdb46SRobert Mustacchi
19*4d9fdb46SRobert Mustacchi  Further, this software is distributed without any warranty
20*4d9fdb46SRobert Mustacchi  that it is free of the rightful claim of any third person
21*4d9fdb46SRobert Mustacchi  regarding infringement or the like.  Any license provided
22*4d9fdb46SRobert Mustacchi  herein, whether implied or otherwise, applies only to this
23*4d9fdb46SRobert Mustacchi  software file.  Patent licenses, if any, provided herein
24*4d9fdb46SRobert Mustacchi  do not apply to combinations of this program with other
25*4d9fdb46SRobert Mustacchi  software, or any other product whatsoever.
26*4d9fdb46SRobert Mustacchi
27*4d9fdb46SRobert Mustacchi  You should have received a copy of the GNU Lesser General
28*4d9fdb46SRobert Mustacchi  Public License along with this program; if not, write the
29*4d9fdb46SRobert Mustacchi  Free Software Foundation, Inc., 51 Franklin Street - Fifth
30*4d9fdb46SRobert Mustacchi  Floor, Boston MA 02110-1301, USA.
31*4d9fdb46SRobert Mustacchi
32*4d9fdb46SRobert Mustacchi*/
33*4d9fdb46SRobert Mustacchi
34*4d9fdb46SRobert Mustacchi
35*4d9fdb46SRobert Mustacchi#ifndef _LIBDWARF_H
36*4d9fdb46SRobert Mustacchi#define _LIBDWARF_H
37*4d9fdb46SRobert Mustacchi#ifdef __cplusplus
38*4d9fdb46SRobert Mustacchiextern "C" {
39*4d9fdb46SRobert Mustacchi#endif
40*4d9fdb46SRobert Mustacchi/*
41*4d9fdb46SRobert Mustacchi    libdwarf.h
42*4d9fdb46SRobert Mustacchi    $Revision: #9 $ $Date: 2008/01/17 $
43*4d9fdb46SRobert Mustacchi
44*4d9fdb46SRobert Mustacchi    For libdwarf producers and consumers
45*4d9fdb46SRobert Mustacchi
46*4d9fdb46SRobert Mustacchi    The interface is defined as having 8-byte signed and unsigned
47*4d9fdb46SRobert Mustacchi    values so it can handle 64-or-32bit target on 64-or-32bit host.
48*4d9fdb46SRobert Mustacchi    Dwarf_Ptr is the native size: it represents pointers on
49*4d9fdb46SRobert Mustacchi    the host machine (not the target!).
50*4d9fdb46SRobert Mustacchi
51*4d9fdb46SRobert Mustacchi    This contains declarations for types and all producer
52*4d9fdb46SRobert Mustacchi    and consumer functions.
53*4d9fdb46SRobert Mustacchi
54*4d9fdb46SRobert Mustacchi    Function declarations are written on a single line each here
55*4d9fdb46SRobert Mustacchi    so one can use grep  to each declaration in its entirety.
56*4d9fdb46SRobert Mustacchi    The declarations are a little harder to read this way, but...
57*4d9fdb46SRobert Mustacchi
58*4d9fdb46SRobert Mustacchi    The seeming duplication of the Elf typedef allows
59*4d9fdb46SRobert Mustacchi    both verification we have the right struct name (when
60*4d9fdb46SRobert Mustacchi    libelf.h included before this) and
61*4d9fdb46SRobert Mustacchi    creation of a local handle so we have the struct pointer
62*4d9fdb46SRobert Mustacchi    here (if libelf.h is not included before this file).
63*4d9fdb46SRobert Mustacchi
64*4d9fdb46SRobert Mustacchi*/
65*4d9fdb46SRobert Mustacchi
66*4d9fdb46SRobert Mustacchitypedef struct _Elf Elf;
67*4d9fdb46SRobert Mustacchitypedef struct _Elf* dwarf_elf_handle;
68*4d9fdb46SRobert Mustacchi
69*4d9fdb46SRobert Mustacchi/* To enable printing with printf regardless of the
70*4d9fdb46SRobert Mustacchi   actual underlying data type, we define the DW_PR_xxx macros.
71*4d9fdb46SRobert Mustacchi   To ensure uses of DW_PR_DUx or DW_PR_DSx look the way you want
72*4d9fdb46SRobert Mustacchi   ensure the right DW_PR_XZEROS define is uncommented.
73*4d9fdb46SRobert Mustacchi*/
74*4d9fdb46SRobert Mustacchi/*#define DW_PR_XZEROS "" */
75*4d9fdb46SRobert Mustacchi#define DW_PR_XZEROS "08"
76*4d9fdb46SRobert Mustacchi
77*4d9fdb46SRobert Mustacchitypedef unsigned long long Dwarf_Unsigned;
78*4d9fdb46SRobert Mustacchitypedef signed   long long Dwarf_Signed;
79*4d9fdb46SRobert Mustacchitypedef unsigned long long Dwarf_Off;
80*4d9fdb46SRobert Mustacchitypedef unsigned long long Dwarf_Addr;
81*4d9fdb46SRobert Mustacchitypedef int                Dwarf_Bool;   /* boolean type */
82*4d9fdb46SRobert Mustacchitypedef unsigned short     Dwarf_Half;   /* 2 byte unsigned value */
83*4d9fdb46SRobert Mustacchitypedef unsigned char      Dwarf_Small;  /* 1 byte unsigned value */
84*4d9fdb46SRobert Mustacchi/*  If sizeof(Dwarf_Half) is greater than 2
85*4d9fdb46SRobert Mustacchi    we believe libdwarf still works properly. */
86*4d9fdb46SRobert Mustacchi
87*4d9fdb46SRobert Mustacchi#if defined(_WIN32) && defined(HAVE_NONSTANDARD_PRINTF_64_FORMAT)
88*4d9fdb46SRobert Mustacchi#define DW_PR_DUx "I64x"
89*4d9fdb46SRobert Mustacchi#define DW_PR_DSx "I64x"
90*4d9fdb46SRobert Mustacchi#define DW_PR_DUu "I64u"
91*4d9fdb46SRobert Mustacchi#define DW_PR_DSd "I64d"
92*4d9fdb46SRobert Mustacchi#else
93*4d9fdb46SRobert Mustacchi#define DW_PR_DUx "llx"
94*4d9fdb46SRobert Mustacchi#define DW_PR_DSx "llx"
95*4d9fdb46SRobert Mustacchi#define DW_PR_DUu "llu"
96*4d9fdb46SRobert Mustacchi#define DW_PR_DSd "lld"
97*4d9fdb46SRobert Mustacchi#endif /* DW_PR defines */
98*4d9fdb46SRobert Mustacchi
99*4d9fdb46SRobert Mustacchitypedef void*        Dwarf_Ptr;          /* host machine pointer */
100*4d9fdb46SRobert Mustacchi
101*4d9fdb46SRobert Mustacchi/*  DWARF5: a container for a DW_FORM_data16 data item.
102*4d9fdb46SRobert Mustacchi    We have no integer types suitable so this special
103*4d9fdb46SRobert Mustacchi    struct is used instead.  It is up to consumers/producers
104*4d9fdb46SRobert Mustacchi    to deal with the contents.
105*4d9fdb46SRobert Mustacchi    New October 18, 2017 .  */
106*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Form_Data16_s {
107*4d9fdb46SRobert Mustacchi    unsigned char fd_data[16];
108*4d9fdb46SRobert Mustacchi} Dwarf_Form_Data16;
109*4d9fdb46SRobert Mustacchi
110*4d9fdb46SRobert Mustacchi
111*4d9fdb46SRobert Mustacchi
112*4d9fdb46SRobert Mustacchi/* Used for signatures where ever they appear.
113*4d9fdb46SRobert Mustacchi   It is not a string, it
114*4d9fdb46SRobert Mustacchi   is 8 bytes of a signature one would use to find
115*4d9fdb46SRobert Mustacchi   a type unit. See dwarf_formsig8()
116*4d9fdb46SRobert Mustacchi
117*4d9fdb46SRobert Mustacchi   Sometimes it is used in calculations as
118*4d9fdb46SRobert Mustacchi   Dwarf_Unsigned, but that is done inside libdwarf
119*4d9fdb46SRobert Mustacchi   and the endianness question makes it a bit sketchy.
120*4d9fdb46SRobert Mustacchi*/
121*4d9fdb46SRobert Mustacchistruct Dwarf_Sig8_s  {
122*4d9fdb46SRobert Mustacchi    char signature[8];
123*4d9fdb46SRobert Mustacchi};
124*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Sig8_s Dwarf_Sig8;
125*4d9fdb46SRobert Mustacchi
126*4d9fdb46SRobert Mustacchi/* Contains info on an uninterpreted block of data
127*4d9fdb46SRobert Mustacchi   Used with certain frame information functions and
128*4d9fdb46SRobert Mustacchi   also used with DW_FORM_block<>.
129*4d9fdb46SRobert Mustacchi*/
130*4d9fdb46SRobert Mustacchitypedef struct {
131*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned  bl_len;         /* length of block bl_data points at */
132*4d9fdb46SRobert Mustacchi    Dwarf_Ptr       bl_data;        /* uninterpreted data */
133*4d9fdb46SRobert Mustacchi
134*4d9fdb46SRobert Mustacchi    /*  See libdwarf.h DW_LKIND*  */
135*4d9fdb46SRobert Mustacchi    Dwarf_Small     bl_from_loclist;
136*4d9fdb46SRobert Mustacchi
137*4d9fdb46SRobert Mustacchi    /* Section (not CU) offset which 'data' comes from. */
138*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned  bl_section_offset;
139*4d9fdb46SRobert Mustacchi} Dwarf_Block;
140*4d9fdb46SRobert Mustacchi
141*4d9fdb46SRobert Mustacchi
142*4d9fdb46SRobert Mustacchi/*  NEW October 2015.  */
143*4d9fdb46SRobert Mustacchi/*  This provides access to Dwarf_Locdesc_c, a single
144*4d9fdb46SRobert Mustacchi    location description */
145*4d9fdb46SRobert Mustacchistruct  Dwarf_Locdesc_c_s;
146*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Locdesc_c_s * Dwarf_Locdesc_c;
147*4d9fdb46SRobert Mustacchi
148*4d9fdb46SRobert Mustacchi/*  NEW October 2015.  */
149*4d9fdb46SRobert Mustacchi/*  This provides access to Dwarf_Locdesc_c, a single
150*4d9fdb46SRobert Mustacchi    location list entry (or for a locexpr, the fake
151*4d9fdb46SRobert Mustacchi    Loc_Head for the locexpr) */
152*4d9fdb46SRobert Mustacchistruct Dwarf_Loc_Head_c_s;
153*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Loc_Head_c_s * Dwarf_Loc_Head_c;
154*4d9fdb46SRobert Mustacchi
155*4d9fdb46SRobert Mustacchi/* NEW November 2015. For DWARF5 .debug_macro section */
156*4d9fdb46SRobert Mustacchistruct Dwarf_Macro_Context_s;
157*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Macro_Context_s * Dwarf_Loc_Macro_Context;
158*4d9fdb46SRobert Mustacchi
159*4d9fdb46SRobert Mustacchi/*  NEW September 2016. Allows easy access to DW_AT_discr_list
160*4d9fdb46SRobert Mustacchi    array of discriminant values. Input in blockpointer
161*4d9fdb46SRobert Mustacchi    is a block with a list of uleb or sleb numbers
162*4d9fdb46SRobert Mustacchi    (all one or the other, lebunsignedflag instructs
163*4d9fdb46SRobert Mustacchi    how to read the leb values properly) */
164*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Dsc_Head_s * Dwarf_Dsc_Head;
165*4d9fdb46SRobert Mustacchi
166*4d9fdb46SRobert Mustacchi/*  Location record. Records up to 2 operand values.
167*4d9fdb46SRobert Mustacchi    Not usable with DWARF5 or DWARF4 with location
168*4d9fdb46SRobert Mustacchi    operator  extensions. */
169*4d9fdb46SRobert Mustacchitypedef struct {
170*4d9fdb46SRobert Mustacchi    Dwarf_Small     lr_atom;        /* location operation */
171*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned  lr_number;      /* operand */
172*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned  lr_number2;     /* for OP_BREGx  and DW_OP_GNU_const_type*/
173*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned  lr_offset;      /* offset in locexpr for OP_BRA etc */
174*4d9fdb46SRobert Mustacchi} Dwarf_Loc;
175*4d9fdb46SRobert Mustacchi
176*4d9fdb46SRobert Mustacchi
177*4d9fdb46SRobert Mustacchi/* Location description. DWARF 2,3,4.
178*4d9fdb46SRobert Mustacchi   When this is from a split-dwarf loclist (.debug_loc.dwo)
179*4d9fdb46SRobert Mustacchi   and no tied object is present
180*4d9fdb46SRobert Mustacchi   then ld_lowpc and ld_highpc are actually indices in
181*4d9fdb46SRobert Mustacchi   the .debug_addr section of the tied object).
182*4d9fdb46SRobert Mustacchi   If there is a tied object then these fields are actuall
183*4d9fdb46SRobert Mustacchi   addresses and DW_AT_addr_base in the skeleton CU DIE applies to
184*4d9fdb46SRobert Mustacchi   that .debug_addr.
185*4d9fdb46SRobert Mustacchi
186*4d9fdb46SRobert Mustacchi   Location record. Records up to 2 operand values.
187*4d9fdb46SRobert Mustacchi   Not usable with DWARF5 or DWARF4 with extensions.
188*4d9fdb46SRobert Mustacchi
189*4d9fdb46SRobert Mustacchi   If from DWARF2,3,4 non-split dwarf then things operate as
190*4d9fdb46SRobert Mustacchi   in DWARF2.
191*4d9fdb46SRobert Mustacchi   See dwarf_get_loclist_b() and the other related
192*4d9fdb46SRobert Mustacchi   new functions that
193*4d9fdb46SRobert Mustacchi   avoid using public structures Dwarf_Loc and Dwarf_Locdesc.
194*4d9fdb46SRobert Mustacchi*/
195*4d9fdb46SRobert Mustacchitypedef struct {
196*4d9fdb46SRobert Mustacchi    /*  Beginning of active range. This is actually an offset
197*4d9fdb46SRobert Mustacchi        of an applicable base address, not a pc value.  */
198*4d9fdb46SRobert Mustacchi    Dwarf_Addr      ld_lopc;
199*4d9fdb46SRobert Mustacchi
200*4d9fdb46SRobert Mustacchi    /*  End of active range. This is actually an offset
201*4d9fdb46SRobert Mustacchi        of an applicable base address, not a pc value.  */
202*4d9fdb46SRobert Mustacchi    Dwarf_Addr      ld_hipc;
203*4d9fdb46SRobert Mustacchi
204*4d9fdb46SRobert Mustacchi    Dwarf_Half      ld_cents;       /* count of location records */
205*4d9fdb46SRobert Mustacchi    Dwarf_Loc*      ld_s;           /* pointer to list of same */
206*4d9fdb46SRobert Mustacchi
207*4d9fdb46SRobert Mustacchi    /*  non-0 if loclist, 1 if non-split (dwarf 2,3,4) */
208*4d9fdb46SRobert Mustacchi    Dwarf_Small     ld_from_loclist;
209*4d9fdb46SRobert Mustacchi
210*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned  ld_section_offset; /* Section (not CU) offset
211*4d9fdb46SRobert Mustacchi        where loc-expr begins*/
212*4d9fdb46SRobert Mustacchi} Dwarf_Locdesc;
213*4d9fdb46SRobert Mustacchi
214*4d9fdb46SRobert Mustacchi/*  First appears in DWARF3, and only ranges entries exist.
215*4d9fdb46SRobert Mustacchi    The dwr_addr1/addr2 data is either an offset (DW_RANGES_ENTRY)
216*4d9fdb46SRobert Mustacchi    or an address (dwr_addr2 in DW_RANGES_ADDRESS_SELECTION) or
217*4d9fdb46SRobert Mustacchi    both are zero (DW_RANGES_END).
218*4d9fdb46SRobert Mustacchi    For DWARF5 each table starts with a header
219*4d9fdb46SRobert Mustacchi    followed by range list entries defined
220*4d9fdb46SRobert Mustacchi    as here.
221*4d9fdb46SRobert Mustacchi*/
222*4d9fdb46SRobert Mustacchienum Dwarf_Ranges_Entry_Type { DW_RANGES_ENTRY,
223*4d9fdb46SRobert Mustacchi    DW_RANGES_ADDRESS_SELECTION,
224*4d9fdb46SRobert Mustacchi    DW_RANGES_END
225*4d9fdb46SRobert Mustacchi};
226*4d9fdb46SRobert Mustacchitypedef struct {
227*4d9fdb46SRobert Mustacchi    Dwarf_Addr dwr_addr1;
228*4d9fdb46SRobert Mustacchi    Dwarf_Addr dwr_addr2;
229*4d9fdb46SRobert Mustacchi    enum Dwarf_Ranges_Entry_Type  dwr_type;
230*4d9fdb46SRobert Mustacchi} Dwarf_Ranges;
231*4d9fdb46SRobert Mustacchi
232*4d9fdb46SRobert Mustacchi/* Frame description instructions expanded.
233*4d9fdb46SRobert Mustacchi*/
234*4d9fdb46SRobert Mustacchitypedef struct {
235*4d9fdb46SRobert Mustacchi    Dwarf_Small     fp_base_op;
236*4d9fdb46SRobert Mustacchi    Dwarf_Small     fp_extended_op;
237*4d9fdb46SRobert Mustacchi    Dwarf_Half      fp_register;
238*4d9fdb46SRobert Mustacchi
239*4d9fdb46SRobert Mustacchi    /*  Value may be signed, depends on op.
240*4d9fdb46SRobert Mustacchi        Any applicable data_alignment_factor has
241*4d9fdb46SRobert Mustacchi        not been applied, this is the  raw offset. */
242*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned  fp_offset;
243*4d9fdb46SRobert Mustacchi    Dwarf_Off       fp_instr_offset;
244*4d9fdb46SRobert Mustacchi} Dwarf_Frame_Op; /* DWARF2 */
245*4d9fdb46SRobert Mustacchi
246*4d9fdb46SRobert Mustacchi/*  ***IMPORTANT NOTE, TARGET DEPENDENCY ****
247*4d9fdb46SRobert Mustacchi    DW_REG_TABLE_SIZE must be at least as large as
248*4d9fdb46SRobert Mustacchi    the number of registers
249*4d9fdb46SRobert Mustacchi    (DW_FRAME_LAST_REG_NUM) as defined in dwarf.h
250*4d9fdb46SRobert Mustacchi    Preferably identical to DW_FRAME_LAST_REG_NUM.
251*4d9fdb46SRobert Mustacchi    Ensure [0-DW_REG_TABLE_SIZE] does not overlap
252*4d9fdb46SRobert Mustacchi    DW_FRAME_UNDEFINED_VAL or DW_FRAME_SAME_VAL.
253*4d9fdb46SRobert Mustacchi    Also ensure DW_FRAME_REG_INITIAL_VALUE is set to what
254*4d9fdb46SRobert Mustacchi    is appropriate to your cpu.
255*4d9fdb46SRobert Mustacchi    For various CPUs  DW_FRAME_UNDEFINED_VAL is correct
256*4d9fdb46SRobert Mustacchi    as the value for DW_FRAME_REG_INITIAL_VALUE.
257*4d9fdb46SRobert Mustacchi
258*4d9fdb46SRobert Mustacchi    For consumer apps, this can be set dynamically: see
259*4d9fdb46SRobert Mustacchi    dwarf_set_frame_rule_table_size(); */
260*4d9fdb46SRobert Mustacchi#ifndef DW_REG_TABLE_SIZE
261*4d9fdb46SRobert Mustacchi#define DW_REG_TABLE_SIZE  66
262*4d9fdb46SRobert Mustacchi#endif
263*4d9fdb46SRobert Mustacchi
264*4d9fdb46SRobert Mustacchi/* For MIPS, DW_FRAME_SAME_VAL is the correct default value
265*4d9fdb46SRobert Mustacchi   for a frame register value. For other CPUS another value
266*4d9fdb46SRobert Mustacchi   may be better, such as DW_FRAME_UNDEFINED_VAL.
267*4d9fdb46SRobert Mustacchi   See dwarf_set_frame_rule_table_size
268*4d9fdb46SRobert Mustacchi*/
269*4d9fdb46SRobert Mustacchi#ifndef DW_FRAME_REG_INITIAL_VALUE
270*4d9fdb46SRobert Mustacchi#define DW_FRAME_REG_INITIAL_VALUE DW_FRAME_SAME_VAL
271*4d9fdb46SRobert Mustacchi#endif
272*4d9fdb46SRobert Mustacchi
273*4d9fdb46SRobert Mustacchi/* Taken as meaning 'undefined value', this is not
274*4d9fdb46SRobert Mustacchi   a column or register number.
275*4d9fdb46SRobert Mustacchi   Only present at libdwarf runtime in the consumer
276*4d9fdb46SRobert Mustacchi   interfaces. Never on disk.
277*4d9fdb46SRobert Mustacchi   DW_FRAME_* Values present on disk are in dwarf.h
278*4d9fdb46SRobert Mustacchi   Ensure this is > DW_REG_TABLE_SIZE (the reg table
279*4d9fdb46SRobert Mustacchi   size is changeable at runtime with the *reg3() interfaces,
280*4d9fdb46SRobert Mustacchi   and this value must be greater than the reg table size).
281*4d9fdb46SRobert Mustacchi*/
282*4d9fdb46SRobert Mustacchi#define DW_FRAME_UNDEFINED_VAL          1034
283*4d9fdb46SRobert Mustacchi
284*4d9fdb46SRobert Mustacchi/* Taken as meaning 'same value' as caller had, not a column
285*4d9fdb46SRobert Mustacchi   or register number.
286*4d9fdb46SRobert Mustacchi   Only present at libdwarf runtime in the consumer
287*4d9fdb46SRobert Mustacchi   interfaces. Never on disk.
288*4d9fdb46SRobert Mustacchi   DW_FRAME_* Values present on disk are in dwarf.h
289*4d9fdb46SRobert Mustacchi   Ensure this is > DW_REG_TABLE_SIZE (the reg table
290*4d9fdb46SRobert Mustacchi   size is changeable at runtime with the *reg3() interfaces,
291*4d9fdb46SRobert Mustacchi   and this value must be greater than the reg table size).
292*4d9fdb46SRobert Mustacchi*/
293*4d9fdb46SRobert Mustacchi#define DW_FRAME_SAME_VAL               1035
294*4d9fdb46SRobert Mustacchi
295*4d9fdb46SRobert Mustacchi/* For DWARF3 consumer interfaces, make the CFA a column with no
296*4d9fdb46SRobert Mustacchi   real table number.  This is what should have been done
297*4d9fdb46SRobert Mustacchi   for the DWARF2 interfaces.  This actually works for
298*4d9fdb46SRobert Mustacchi   both DWARF2 and DWARF3, but see the libdwarf documentation
299*4d9fdb46SRobert Mustacchi   on Dwarf_Regtable3 and  dwarf_get_fde_info_for_reg3()
300*4d9fdb46SRobert Mustacchi   and  dwarf_get_fde_info_for_all_regs3()
301*4d9fdb46SRobert Mustacchi   Do NOT use this with the older dwarf_get_fde_info_for_reg()
302*4d9fdb46SRobert Mustacchi   or dwarf_get_fde_info_for_all_regs() consumer interfaces.
303*4d9fdb46SRobert Mustacchi   Must be higher than any register count for *any* ABI
304*4d9fdb46SRobert Mustacchi   (ensures maximum applicability with minimum effort).
305*4d9fdb46SRobert Mustacchi   Ensure this is > DW_REG_TABLE_SIZE (the reg table
306*4d9fdb46SRobert Mustacchi   size is changeable at runtime with the *reg3() interfaces,
307*4d9fdb46SRobert Mustacchi   and this value must be greater than the reg table size).
308*4d9fdb46SRobert Mustacchi   Only present at libdwarf runtime in the consumer
309*4d9fdb46SRobert Mustacchi   interfaces. Never on disk.
310*4d9fdb46SRobert Mustacchi*/
311*4d9fdb46SRobert Mustacchi#define DW_FRAME_CFA_COL3               1436
312*4d9fdb46SRobert Mustacchi
313*4d9fdb46SRobert Mustacchi/* The following are all needed to evaluate DWARF3 register rules.
314*4d9fdb46SRobert Mustacchi*/
315*4d9fdb46SRobert Mustacchi#define DW_EXPR_OFFSET 0  /* DWARF2 only sees this. */
316*4d9fdb46SRobert Mustacchi#define DW_EXPR_VAL_OFFSET 1
317*4d9fdb46SRobert Mustacchi#define DW_EXPR_EXPRESSION 2
318*4d9fdb46SRobert Mustacchi#define DW_EXPR_VAL_EXPRESSION 3
319*4d9fdb46SRobert Mustacchi
320*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Regtable_Entry_s {
321*4d9fdb46SRobert Mustacchi    /*  For each index i (naming a hardware register with dwarf number
322*4d9fdb46SRobert Mustacchi        i) the following is true and defines the value of that register:
323*4d9fdb46SRobert Mustacchi
324*4d9fdb46SRobert Mustacchi        If dw_regnum is Register DW_FRAME_UNDEFINED_VAL
325*4d9fdb46SRobert Mustacchi            it is not DWARF register number but
326*4d9fdb46SRobert Mustacchi            a place holder indicating the register has no defined value.
327*4d9fdb46SRobert Mustacchi        If dw_regnum is Register DW_FRAME_SAME_VAL
328*4d9fdb46SRobert Mustacchi            it  is not DWARF register number but
329*4d9fdb46SRobert Mustacchi            a place holder indicating the register has the same
330*4d9fdb46SRobert Mustacchi            value in the previous frame.
331*4d9fdb46SRobert Mustacchi
332*4d9fdb46SRobert Mustacchi            DW_FRAME_UNDEFINED_VAL, DW_FRAME_SAME_VAL are
333*4d9fdb46SRobert Mustacchi            only present at libdwarf runtime. Never on disk.
334*4d9fdb46SRobert Mustacchi            DW_FRAME_* Values present on disk are in dwarf.h
335*4d9fdb46SRobert Mustacchi
336*4d9fdb46SRobert Mustacchi        Otherwise: the register number is a DWARF register number
337*4d9fdb46SRobert Mustacchi            (see ABI documents for how this translates to hardware/
338*4d9fdb46SRobert Mustacchi            software register numbers in the machine hardware)
339*4d9fdb46SRobert Mustacchi            and the following applies:
340*4d9fdb46SRobert Mustacchi
341*4d9fdb46SRobert Mustacchi            if dw_value_type == DW_EXPR_OFFSET (the only case for dwarf2):
342*4d9fdb46SRobert Mustacchi                If dw_offset_relevant is non-zero, then
343*4d9fdb46SRobert Mustacchi                    the value is stored at at the address CFA+N where
344*4d9fdb46SRobert Mustacchi                    N is a signed offset.
345*4d9fdb46SRobert Mustacchi                    Rule: Offset(N)
346*4d9fdb46SRobert Mustacchi                If dw_offset_relevant is zero, then the value of the register
347*4d9fdb46SRobert Mustacchi                    is the value of (DWARF) register number dw_regnum.
348*4d9fdb46SRobert Mustacchi                    Rule: register(F)
349*4d9fdb46SRobert Mustacchi            Other values of dw_value_type are an error.
350*4d9fdb46SRobert Mustacchi    */
351*4d9fdb46SRobert Mustacchi    Dwarf_Small         dw_offset_relevant;
352*4d9fdb46SRobert Mustacchi
353*4d9fdb46SRobert Mustacchi    /* For DWARF2, always 0 */
354*4d9fdb46SRobert Mustacchi    Dwarf_Small         dw_value_type;
355*4d9fdb46SRobert Mustacchi
356*4d9fdb46SRobert Mustacchi    Dwarf_Half          dw_regnum;
357*4d9fdb46SRobert Mustacchi
358*4d9fdb46SRobert Mustacchi    /*  The data type here should  the larger of Dwarf_Addr
359*4d9fdb46SRobert Mustacchi        and Dwarf_Unsigned and Dwarf_Signed. */
360*4d9fdb46SRobert Mustacchi    Dwarf_Addr          dw_offset;
361*4d9fdb46SRobert Mustacchi} Dwarf_Regtable_Entry;
362*4d9fdb46SRobert Mustacchi
363*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Regtable_s {
364*4d9fdb46SRobert Mustacchi    struct Dwarf_Regtable_Entry_s rules[DW_REG_TABLE_SIZE];
365*4d9fdb46SRobert Mustacchi} Dwarf_Regtable;
366*4d9fdb46SRobert Mustacchi
367*4d9fdb46SRobert Mustacchi/* opaque type. Functional interface shown later. */
368*4d9fdb46SRobert Mustacchistruct Dwarf_Reg_value3_s;
369*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Reg_value3_s Dwarf_Reg_Value3;
370*4d9fdb46SRobert Mustacchi
371*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Regtable_Entry3_s {
372*4d9fdb46SRobert Mustacchi/*  For each index i (naming a hardware register with dwarf number
373*4d9fdb46SRobert Mustacchi    i) the following is true and defines the value of that register:
374*4d9fdb46SRobert Mustacchi
375*4d9fdb46SRobert Mustacchi        If dw_regnum is Register DW_FRAME_UNDEFINED_VAL
376*4d9fdb46SRobert Mustacchi            it is not DWARF register number but
377*4d9fdb46SRobert Mustacchi            a place holder indicating the register has no defined value.
378*4d9fdb46SRobert Mustacchi        If dw_regnum is Register DW_FRAME_SAME_VAL
379*4d9fdb46SRobert Mustacchi            it  is not DWARF register number but
380*4d9fdb46SRobert Mustacchi            a place holder indicating the register has the same
381*4d9fdb46SRobert Mustacchi            value in the previous frame.
382*4d9fdb46SRobert Mustacchi
383*4d9fdb46SRobert Mustacchi            DW_FRAME_UNDEFINED_VAL, DW_FRAME_SAME_VAL and
384*4d9fdb46SRobert Mustacchi            DW_FRAME_CFA_COL3 are only present at libdwarf runtime.
385*4d9fdb46SRobert Mustacchi            Never on disk.
386*4d9fdb46SRobert Mustacchi            DW_FRAME_* Values present on disk are in dwarf.h
387*4d9fdb46SRobert Mustacchi            Because DW_FRAME_SAME_VAL and DW_FRAME_UNDEFINED_VAL
388*4d9fdb46SRobert Mustacchi            and DW_FRAME_CFA_COL3 are definable at runtime
389*4d9fdb46SRobert Mustacchi            consider the names symbolic in this comment, not absolute.
390*4d9fdb46SRobert Mustacchi
391*4d9fdb46SRobert Mustacchi        Otherwise: the register number is a DWARF register number
392*4d9fdb46SRobert Mustacchi            (see ABI documents for how this translates to hardware/
393*4d9fdb46SRobert Mustacchi            software register numbers in the machine hardware)
394*4d9fdb46SRobert Mustacchi            and the following applies:
395*4d9fdb46SRobert Mustacchi
396*4d9fdb46SRobert Mustacchi        In a cfa-defining entry (rt3_cfa_rule) the regnum is the
397*4d9fdb46SRobert Mustacchi        CFA 'register number'. Which is some 'normal' register,
398*4d9fdb46SRobert Mustacchi        not DW_FRAME_CFA_COL3, nor DW_FRAME_SAME_VAL, nor
399*4d9fdb46SRobert Mustacchi        DW_FRAME_UNDEFINED_VAL.
400*4d9fdb46SRobert Mustacchi
401*4d9fdb46SRobert Mustacchi        If dw_value_type == DW_EXPR_OFFSET (the only  possible case for
402*4d9fdb46SRobert Mustacchi        dwarf2):
403*4d9fdb46SRobert Mustacchi            If dw_offset_relevant is non-zero, then
404*4d9fdb46SRobert Mustacchi                the value is stored at at the address
405*4d9fdb46SRobert Mustacchi                CFA+N where N is a signed offset.
406*4d9fdb46SRobert Mustacchi                dw_regnum is the cfa register rule which means
407*4d9fdb46SRobert Mustacchi                one ignores dw_regnum and uses the CFA appropriately.
408*4d9fdb46SRobert Mustacchi                So dw_offset_or_block_len is a signed value, really,
409*4d9fdb46SRobert Mustacchi                and must be printed/evaluated as such.
410*4d9fdb46SRobert Mustacchi                Rule: Offset(N)
411*4d9fdb46SRobert Mustacchi            If dw_offset_relevant is zero, then the value of the register
412*4d9fdb46SRobert Mustacchi                is the value of (DWARF) register number dw_regnum.
413*4d9fdb46SRobert Mustacchi                Rule: register(R)
414*4d9fdb46SRobert Mustacchi        If dw_value_type  == DW_EXPR_VAL_OFFSET
415*4d9fdb46SRobert Mustacchi            the  value of this register is CFA +N where N is a signed offset.
416*4d9fdb46SRobert Mustacchi            dw_regnum is the cfa register rule which means
417*4d9fdb46SRobert Mustacchi            one ignores dw_regnum and uses the CFA appropriately.
418*4d9fdb46SRobert Mustacchi            Rule: val_offset(N)
419*4d9fdb46SRobert Mustacchi        If dw_value_type  == DW_EXPR_EXPRESSION
420*4d9fdb46SRobert Mustacchi            The value of the register is the value at the address
421*4d9fdb46SRobert Mustacchi            computed by evaluating the DWARF expression E.
422*4d9fdb46SRobert Mustacchi            Rule: expression(E)
423*4d9fdb46SRobert Mustacchi            The expression E byte stream is pointed to by dw_block_ptr.
424*4d9fdb46SRobert Mustacchi            The expression length in bytes is given by
425*4d9fdb46SRobert Mustacchi            dw_offset_or_block_len.
426*4d9fdb46SRobert Mustacchi        If dw_value_type  == DW_EXPR_VAL_EXPRESSION
427*4d9fdb46SRobert Mustacchi            The value of the register is the value
428*4d9fdb46SRobert Mustacchi            computed by evaluating the DWARF expression E.
429*4d9fdb46SRobert Mustacchi            Rule: val_expression(E)
430*4d9fdb46SRobert Mustacchi            The expression E byte stream is pointed to by dw_block_ptr.
431*4d9fdb46SRobert Mustacchi            The expression length in bytes is given by
432*4d9fdb46SRobert Mustacchi            dw_offset_or_block_len.
433*4d9fdb46SRobert Mustacchi        Other values of dw_value_type are an error.
434*4d9fdb46SRobert Mustacchi*/
435*4d9fdb46SRobert Mustacchi    Dwarf_Small         dw_offset_relevant;
436*4d9fdb46SRobert Mustacchi    Dwarf_Small         dw_value_type;
437*4d9fdb46SRobert Mustacchi    Dwarf_Half          dw_regnum;
438*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned      dw_offset_or_block_len;
439*4d9fdb46SRobert Mustacchi    Dwarf_Ptr           dw_block_ptr;
440*4d9fdb46SRobert Mustacchi
441*4d9fdb46SRobert Mustacchi}Dwarf_Regtable_Entry3;
442*4d9fdb46SRobert Mustacchi
443*4d9fdb46SRobert Mustacchi/*  For the DWARF3 version, moved the DW_FRAME_CFA_COL
444*4d9fdb46SRobert Mustacchi    out of the array and into its own struct.
445*4d9fdb46SRobert Mustacchi    Having it part of the array is not very easy to work
446*4d9fdb46SRobert Mustacchi    with from a portability point of view: changing
447*4d9fdb46SRobert Mustacchi    the number for every architecture is a pain (if one fails
448*4d9fdb46SRobert Mustacchi    to set it correctly a register rule gets clobbered when
449*4d9fdb46SRobert Mustacchi    setting CFA).  With MIPS it just happened to be easy to use
450*4d9fdb46SRobert Mustacchi    DW_FRAME_CFA_COL (it was wrong conceptually but it was easy...).
451*4d9fdb46SRobert Mustacchi
452*4d9fdb46SRobert Mustacchi    rt3_rules and rt3_reg_table_size must be filled in before
453*4d9fdb46SRobert Mustacchi    calling libdwarf.  Filled in with a pointer to an array
454*4d9fdb46SRobert Mustacchi    (pointer and array  set up by the calling application)
455*4d9fdb46SRobert Mustacchi    of rt3_reg_table_size Dwarf_Regtable_Entry3_s structs.
456*4d9fdb46SRobert Mustacchi    libdwarf does not allocate or deallocate space for the
457*4d9fdb46SRobert Mustacchi    rules, you must do so.   libdwarf will initialize the
458*4d9fdb46SRobert Mustacchi    contents rules array, you do not need to do so (though
459*4d9fdb46SRobert Mustacchi    if you choose to initialize the array somehow that is ok:
460*4d9fdb46SRobert Mustacchi    libdwarf will overwrite your initializations with its own).
461*4d9fdb46SRobert Mustacchi
462*4d9fdb46SRobert Mustacchi*/
463*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Regtable3_s {
464*4d9fdb46SRobert Mustacchi    struct Dwarf_Regtable_Entry3_s   rt3_cfa_rule;
465*4d9fdb46SRobert Mustacchi
466*4d9fdb46SRobert Mustacchi    Dwarf_Half                       rt3_reg_table_size;
467*4d9fdb46SRobert Mustacchi    struct Dwarf_Regtable_Entry3_s * rt3_rules;
468*4d9fdb46SRobert Mustacchi} Dwarf_Regtable3;
469*4d9fdb46SRobert Mustacchi
470*4d9fdb46SRobert Mustacchi
471*4d9fdb46SRobert Mustacchi/*  Use for DW_EPXR_STANDARD., DW_EXPR_VAL_OFFSET.
472*4d9fdb46SRobert Mustacchi    Returns DW_DLV_OK if the value is available.
473*4d9fdb46SRobert Mustacchi    If DW_DLV_OK returns the regnum and offset thru the pointers
474*4d9fdb46SRobert Mustacchi    (which the consumer must use appropriately).
475*4d9fdb46SRobert Mustacchi*/
476*4d9fdb46SRobert Mustacchiint dwarf_frame_get_reg_register(struct Dwarf_Regtable_Entry3_s *reg_in,
477*4d9fdb46SRobert Mustacchi    Dwarf_Small *offset_relevant,
478*4d9fdb46SRobert Mustacchi    Dwarf_Half *regnum_out,
479*4d9fdb46SRobert Mustacchi    Dwarf_Signed *offset_out);
480*4d9fdb46SRobert Mustacchi
481*4d9fdb46SRobert Mustacchi/*  Use for DW_EXPR_EXPRESSION, DW_EXPR_VAL_EXPRESSION.
482*4d9fdb46SRobert Mustacchi    Returns DW_DLV_OK if the value is available.
483*4d9fdb46SRobert Mustacchi    The caller must pass in the address of a valid
484*4d9fdb46SRobert Mustacchi    Dwarf_Block (the caller need not initialize it).
485*4d9fdb46SRobert Mustacchi*/
486*4d9fdb46SRobert Mustacchiint dwarf_frame_get_reg_expression(struct Dwarf_Regtable_Entry3_s *reg_in,
487*4d9fdb46SRobert Mustacchi    Dwarf_Block *block_out);
488*4d9fdb46SRobert Mustacchi
489*4d9fdb46SRobert Mustacchi
490*4d9fdb46SRobert Mustacchi/*  For DW_DLC_SYMBOLIC_RELOCATIONS output to caller
491*4d9fdb46SRobert Mustacchi    v2, adding drd_length: some relocations are 4 and
492*4d9fdb46SRobert Mustacchi    some 8 bytes (pointers are 8, section offsets 4) in
493*4d9fdb46SRobert Mustacchi    some dwarf environments. (MIPS relocations are all one
494*4d9fdb46SRobert Mustacchi    size in any given ABI.) Changing drd_type to an unsigned char
495*4d9fdb46SRobert Mustacchi    to keep struct size down.
496*4d9fdb46SRobert Mustacchi*/
497*4d9fdb46SRobert Mustacchienum Dwarf_Rel_Type {
498*4d9fdb46SRobert Mustacchi    dwarf_drt_none,        /* Should not get to caller */
499*4d9fdb46SRobert Mustacchi    dwarf_drt_data_reloc,  /* Simple normal relocation. */
500*4d9fdb46SRobert Mustacchi    dwarf_drt_segment_rel, /* Special reloc, exceptions. */
501*4d9fdb46SRobert Mustacchi    /* dwarf_drt_first_of_length_pair  and drt_second
502*4d9fdb46SRobert Mustacchi        are for for the  .word end - begin case. */
503*4d9fdb46SRobert Mustacchi    dwarf_drt_first_of_length_pair,
504*4d9fdb46SRobert Mustacchi    dwarf_drt_second_of_length_pair
505*4d9fdb46SRobert Mustacchi};
506*4d9fdb46SRobert Mustacchi
507*4d9fdb46SRobert Mustacchitypedef struct Dwarf_P_Marker_s * Dwarf_P_Marker;
508*4d9fdb46SRobert Mustacchistruct Dwarf_P_Marker_s {
509*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned ma_marker;
510*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned ma_offset;
511*4d9fdb46SRobert Mustacchi};
512*4d9fdb46SRobert Mustacchi
513*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Relocation_Data_s  * Dwarf_Relocation_Data;
514*4d9fdb46SRobert Mustacchistruct Dwarf_Relocation_Data_s {
515*4d9fdb46SRobert Mustacchi    unsigned char drd_type;   /* Cast to/from Dwarf_Rel_Type
516*4d9fdb46SRobert Mustacchi        to keep size small in struct. */
517*4d9fdb46SRobert Mustacchi    unsigned char drd_length; /* Length in bytes of data being
518*4d9fdb46SRobert Mustacchi        relocated. 4 for 32bit data,
519*4d9fdb46SRobert Mustacchi        8 for 64bit data. */
520*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned       drd_offset; /* Where the data to reloc is. */
521*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned       drd_symbol_index;
522*4d9fdb46SRobert Mustacchi};
523*4d9fdb46SRobert Mustacchi
524*4d9fdb46SRobert Mustacchitypedef struct Dwarf_P_String_Attr_s  * Dwarf_P_String_Attr;
525*4d9fdb46SRobert Mustacchistruct Dwarf_P_String_Attr_s {
526*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned        sa_offset;  /* Offset of string attribute data */
527*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned        sa_nbytes;
528*4d9fdb46SRobert Mustacchi};
529*4d9fdb46SRobert Mustacchi
530*4d9fdb46SRobert Mustacchi
531*4d9fdb46SRobert Mustacchi/* Opaque types for Consumer Library. */
532*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Debug_s*      Dwarf_Debug;
533*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Die_s*        Dwarf_Die;
534*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Line_s*       Dwarf_Line;
535*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Global_s*     Dwarf_Global;
536*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Func_s*       Dwarf_Func;
537*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Type_s*       Dwarf_Type;
538*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Var_s*        Dwarf_Var;
539*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Weak_s*       Dwarf_Weak;
540*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Error_s*      Dwarf_Error;
541*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Attribute_s*  Dwarf_Attribute;
542*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Abbrev_s*     Dwarf_Abbrev;
543*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Fde_s*        Dwarf_Fde;
544*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Cie_s*        Dwarf_Cie;
545*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Arange_s*     Dwarf_Arange;
546*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Gdbindex_s*   Dwarf_Gdbindex;
547*4d9fdb46SRobert Mustacchistruct Dwarf_Xu_Index_Header_s;
548*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Xu_Index_Header_s  *Dwarf_Xu_Index_Header;
549*4d9fdb46SRobert Mustacchistruct Dwarf_Line_Context_s;
550*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Line_Context_s     *Dwarf_Line_Context;
551*4d9fdb46SRobert Mustacchistruct Dwarf_Macro_Context_s;
552*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Macro_Context_s    *Dwarf_Macro_Context;
553*4d9fdb46SRobert Mustacchistruct Dwarf_Dnames_Head_s;
554*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Dnames_Head_s      *Dwarf_Dnames_Head;
555*4d9fdb46SRobert Mustacchi
556*4d9fdb46SRobert Mustacchi
557*4d9fdb46SRobert Mustacchi/* Opaque types for Producer Library. */
558*4d9fdb46SRobert Mustacchitypedef struct Dwarf_P_Debug_s*       Dwarf_P_Debug;
559*4d9fdb46SRobert Mustacchitypedef struct Dwarf_P_Die_s*         Dwarf_P_Die;
560*4d9fdb46SRobert Mustacchitypedef struct Dwarf_P_Attribute_s*   Dwarf_P_Attribute;
561*4d9fdb46SRobert Mustacchitypedef struct Dwarf_P_Fde_s*         Dwarf_P_Fde;
562*4d9fdb46SRobert Mustacchitypedef struct Dwarf_P_Expr_s*        Dwarf_P_Expr;
563*4d9fdb46SRobert Mustacchitypedef Dwarf_Unsigned                Dwarf_Tag;
564*4d9fdb46SRobert Mustacchi
565*4d9fdb46SRobert Mustacchi
566*4d9fdb46SRobert Mustacchi/* error handler function
567*4d9fdb46SRobert Mustacchi*/
568*4d9fdb46SRobert Mustacchitypedef void  (*Dwarf_Handler)(Dwarf_Error /*error*/, Dwarf_Ptr /*errarg*/);
569*4d9fdb46SRobert Mustacchi
570*4d9fdb46SRobert Mustacchi
571*4d9fdb46SRobert Mustacchi/* Begin libdwarf Object File Interface declarations.
572*4d9fdb46SRobert Mustacchi
573*4d9fdb46SRobert MustacchiAs of February 2008 there are multiple dwarf_reader object access
574*4d9fdb46SRobert Mustacchiinitialization methods available:
575*4d9fdb46SRobert MustacchiThe traditional dwarf_elf_init() and dwarf_init()  and dwarf_finish()
576*4d9fdb46SRobert Mustacchi    which assume libelf and POSIX file access.
577*4d9fdb46SRobert MustacchiAn object-file and library agnostic dwarf_object_init() and dwarf_object_finish()
578*4d9fdb46SRobert Mustacchi    which allow the coder to provide object access routines
579*4d9fdb46SRobert Mustacchi    abstracting away the elf interface.  So there is no dependence in the
580*4d9fdb46SRobert Mustacchi    reader code on the object format and no dependence on libelf.
581*4d9fdb46SRobert Mustacchi    See the code in dwarf_elf_access.c  and dwarf_original_elf_init.c
582*4d9fdb46SRobert Mustacchi    to see an example of initializing the structures mentioned below.
583*4d9fdb46SRobert Mustacchi
584*4d9fdb46SRobert MustacchiProjects using dwarf_elf_init() or dwarf_init() can ignore
585*4d9fdb46SRobert Mustacchithe Dwarf_Obj_Access* structures entirely as all these details
586*4d9fdb46SRobert Mustacchiare completed for you.
587*4d9fdb46SRobert Mustacchi
588*4d9fdb46SRobert MustacchiAs of March 2017 additional
589*4d9fdb46SRobert Mustacchifunctions dwarf_elf_init_b
590*4d9fdb46SRobert Mustacchiand dwarf_init_b
591*4d9fdb46SRobert Mustacchiand dwarf_object_init_b
592*4d9fdb46SRobert Mustacchiadd a groupnumber argument so DWARF5
593*4d9fdb46SRobert Mustacchisplit-dwarf sections can be accessed.
594*4d9fdb46SRobert Mustacchi*/
595*4d9fdb46SRobert Mustacchi
596*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Obj_Access_Interface_s   Dwarf_Obj_Access_Interface;
597*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Obj_Access_Methods_s     Dwarf_Obj_Access_Methods;
598*4d9fdb46SRobert Mustacchitypedef struct Dwarf_Obj_Access_Section_s     Dwarf_Obj_Access_Section;
599*4d9fdb46SRobert Mustacchi
600*4d9fdb46SRobert Mustacchi
601*4d9fdb46SRobert Mustacchi/*  Used in the get_section interface function
602*4d9fdb46SRobert Mustacchi    in Dwarf_Obj_Access_Section_s.  Since libdwarf
603*4d9fdb46SRobert Mustacchi    depends on standard DWARF section names an object
604*4d9fdb46SRobert Mustacchi    format that has no such names (but has some
605*4d9fdb46SRobert Mustacchi    method of setting up 'sections equivalents')
606*4d9fdb46SRobert Mustacchi    must arrange to return standard DWARF section
607*4d9fdb46SRobert Mustacchi    names in the 'name' field.  libdwarf does
608*4d9fdb46SRobert Mustacchi    not free the strings in 'name'. */
609*4d9fdb46SRobert Mustacchistruct Dwarf_Obj_Access_Section_s {
610*4d9fdb46SRobert Mustacchi    /*  addr is the virtual address of the first byte of
611*4d9fdb46SRobert Mustacchi        the section data.  Usually zero when the address
612*4d9fdb46SRobert Mustacchi        makes no sense for a given section. */
613*4d9fdb46SRobert Mustacchi    Dwarf_Addr     addr;
614*4d9fdb46SRobert Mustacchi
615*4d9fdb46SRobert Mustacchi    /* Section type. */
616*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned type;
617*4d9fdb46SRobert Mustacchi
618*4d9fdb46SRobert Mustacchi    /* Size in bytes of the section. */
619*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned size;
620*4d9fdb46SRobert Mustacchi
621*4d9fdb46SRobert Mustacchi    /*  Having an accurate section name makes debugging of libdwarf easier.
622*4d9fdb46SRobert Mustacchi        and is essential to find the .debug_ sections.  */
623*4d9fdb46SRobert Mustacchi    const char*    name;
624*4d9fdb46SRobert Mustacchi    /*  Set link to zero if it is meaningless.  If non-zero
625*4d9fdb46SRobert Mustacchi        it should be a link to a rela section or from symtab
626*4d9fdb46SRobert Mustacchi        to strtab.  In Elf it is sh_link. */
627*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned link;
628*4d9fdb46SRobert Mustacchi
629*4d9fdb46SRobert Mustacchi    /*  The section header index of the section to which the
630*4d9fdb46SRobert Mustacchi        relocation applies. In Elf it is sh_info. */
631*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned info;
632*4d9fdb46SRobert Mustacchi
633*4d9fdb46SRobert Mustacchi    /*  Elf sections that are tables have a non-zero entrysize so
634*4d9fdb46SRobert Mustacchi        the count of entries can be calculated even without
635*4d9fdb46SRobert Mustacchi        the right structure definition. If your object format
636*4d9fdb46SRobert Mustacchi        does not have this data leave this zero. */
637*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned entrysize;
638*4d9fdb46SRobert Mustacchi};
639*4d9fdb46SRobert Mustacchi
640*4d9fdb46SRobert Mustacchi/*  Returned by the get_endianness function in
641*4d9fdb46SRobert Mustacchi    Dwarf_Obj_Access_Methods_s. */
642*4d9fdb46SRobert Mustacchitypedef enum {
643*4d9fdb46SRobert Mustacchi    DW_OBJECT_MSB,
644*4d9fdb46SRobert Mustacchi    DW_OBJECT_LSB
645*4d9fdb46SRobert Mustacchi} Dwarf_Endianness;
646*4d9fdb46SRobert Mustacchi
647*4d9fdb46SRobert Mustacchi/*  The functions we need to access object data from libdwarf are declared here.
648*4d9fdb46SRobert Mustacchi
649*4d9fdb46SRobert Mustacchi    In these function pointer declarations
650*4d9fdb46SRobert Mustacchi    'void *obj' is intended to be a pointer (the object field in
651*4d9fdb46SRobert Mustacchi    Dwarf_Obj_Access_Interface_s)
652*4d9fdb46SRobert Mustacchi    that hides the library-specific and object-specific data that makes
653*4d9fdb46SRobert Mustacchi    it possible to handle multiple object formats and multiple libraries.
654*4d9fdb46SRobert Mustacchi    It's not required that one handles multiple such in a single libdwarf
655*4d9fdb46SRobert Mustacchi    archive/shared-library (but not ruled out either).
656*4d9fdb46SRobert Mustacchi    See  dwarf_elf_object_access_internals_t and dwarf_elf_access.c
657*4d9fdb46SRobert Mustacchi    for an example.
658*4d9fdb46SRobert Mustacchi
659*4d9fdb46SRobert Mustacchi*/
660*4d9fdb46SRobert Mustacchistruct Dwarf_Obj_Access_Methods_s {
661*4d9fdb46SRobert Mustacchi    /*
662*4d9fdb46SRobert Mustacchi        get_section_info
663*4d9fdb46SRobert Mustacchi
664*4d9fdb46SRobert Mustacchi        Get address, size, and name info about a section.
665*4d9fdb46SRobert Mustacchi
666*4d9fdb46SRobert Mustacchi        Parameters
667*4d9fdb46SRobert Mustacchi        section_index - Zero-based index.
668*4d9fdb46SRobert Mustacchi        return_section - Pointer to a structure in which section info
669*4d9fdb46SRobert Mustacchi            will be placed.   Caller must provide a valid pointer to a
670*4d9fdb46SRobert Mustacchi            structure area.  The structure's contents will be overwritten
671*4d9fdb46SRobert Mustacchi            by the call to get_section_info.
672*4d9fdb46SRobert Mustacchi        error - A pointer to an integer in which an error code may be stored.
673*4d9fdb46SRobert Mustacchi
674*4d9fdb46SRobert Mustacchi        Return
675*4d9fdb46SRobert Mustacchi        DW_DLV_OK - Everything ok.
676*4d9fdb46SRobert Mustacchi        DW_DLV_ERROR - Error occurred. Use 'error' to determine the
677*4d9fdb46SRobert Mustacchi            libdwarf defined error.
678*4d9fdb46SRobert Mustacchi        DW_DLV_NO_ENTRY - No such section.  */
679*4d9fdb46SRobert Mustacchi    int    (*get_section_info)(void* obj, Dwarf_Half section_index,
680*4d9fdb46SRobert Mustacchi        Dwarf_Obj_Access_Section* return_section, int* error);
681*4d9fdb46SRobert Mustacchi    /*
682*4d9fdb46SRobert Mustacchi        get_byte_order
683*4d9fdb46SRobert Mustacchi
684*4d9fdb46SRobert Mustacchi        Get whether the object file represented by this interface is big-endian
685*4d9fdb46SRobert Mustacchi        (DW_OBJECT_MSB) or little endian (DW_OBJECT_LSB).
686*4d9fdb46SRobert Mustacchi
687*4d9fdb46SRobert Mustacchi        Parameters
688*4d9fdb46SRobert Mustacchi        obj - Equivalent to 'this' in OO languages.
689*4d9fdb46SRobert Mustacchi
690*4d9fdb46SRobert Mustacchi        Return
691*4d9fdb46SRobert Mustacchi        Endianness of object. Cannot fail.  */
692*4d9fdb46SRobert Mustacchi    Dwarf_Endianness  (*get_byte_order)(void* obj);
693*4d9fdb46SRobert Mustacchi    /*
694*4d9fdb46SRobert Mustacchi        get_length_size
695*4d9fdb46SRobert Mustacchi
696*4d9fdb46SRobert Mustacchi        Get the size of a length field in the underlying object file.
697*4d9fdb46SRobert Mustacchi        libdwarf currently supports * 4 and 8 byte sizes, but may
698*4d9fdb46SRobert Mustacchi        support larger in the future.
699*4d9fdb46SRobert Mustacchi        Perhaps the return type should be an enumeration?
700*4d9fdb46SRobert Mustacchi
701*4d9fdb46SRobert Mustacchi        Parameters
702*4d9fdb46SRobert Mustacchi        obj - Equivalent to 'this' in OO languages.
703*4d9fdb46SRobert Mustacchi
704*4d9fdb46SRobert Mustacchi        Return
705*4d9fdb46SRobert Mustacchi        Size of length. Cannot fail.  */
706*4d9fdb46SRobert Mustacchi    Dwarf_Small   (*get_length_size)(void* obj);
707*4d9fdb46SRobert Mustacchi    /*
708*4d9fdb46SRobert Mustacchi        get_pointer_size
709*4d9fdb46SRobert Mustacchi
710*4d9fdb46SRobert Mustacchi        Get the size of a pointer field in the underlying object file.
711*4d9fdb46SRobert Mustacchi        libdwarf currently supports  4 and 8 byte sizes.
712*4d9fdb46SRobert Mustacchi        Perhaps the return type should be an enumeration?
713*4d9fdb46SRobert Mustacchi
714*4d9fdb46SRobert Mustacchi        Return
715*4d9fdb46SRobert Mustacchi        Size of pointer. Cannot fail.  */
716*4d9fdb46SRobert Mustacchi    Dwarf_Small   (*get_pointer_size)(void* obj);
717*4d9fdb46SRobert Mustacchi    /*
718*4d9fdb46SRobert Mustacchi        get_section_count
719*4d9fdb46SRobert Mustacchi
720*4d9fdb46SRobert Mustacchi        Get the number of sections in the object file.
721*4d9fdb46SRobert Mustacchi
722*4d9fdb46SRobert Mustacchi        Parameters
723*4d9fdb46SRobert Mustacchi
724*4d9fdb46SRobert Mustacchi        Return
725*4d9fdb46SRobert Mustacchi        Number of sections */
726*4d9fdb46SRobert Mustacchi    Dwarf_Unsigned  (*get_section_count)(void* obj);
727*4d9fdb46SRobert Mustacchi    /*
728*4d9fdb46SRobert Mustacchi        load_section
729*4d9fdb46SRobert Mustacchi
730*4d9fdb46SRobert Mustacchi        Get a pointer to an array of bytes that represent the section.
731*4d9fdb46SRobert Mustacchi
732*4d9fdb46SRobert Mustacchi        Parameters
733*4d9fdb46SRobert Mustacchi        section_index - Zero-based index.
734*4d9fdb46SRobert Mustacchi        return_data - The address of a pointer to which the section data block
735*4d9fdb46SRobert Mustacchi            will be assigned.
736*4d9fdb46SRobert Mustacchi        error - Pointer to an integer for returning libdwarf-defined
737*4d9fdb46SRobert Mustacchi            error numbers.
738*4d9fdb46SRobert Mustacchi
739*4d9fdb46SRobert Mustacchi        Return
740*4d9fdb46SRobert Mustacchi        DW_DLV_OK - No error.
741*4d9fdb46SRobert Mustacchi        DW_DLV_ERROR - Error. Use 'error' to indicate a libdwarf-defined
742*4d9fdb46SRobert Mustacchi            error number.
743*4d9fdb46SRobert Mustacchi        DW_DLV_NO_ENTRY - No such section.  */
744*4d9fdb46SRobert Mustacchi    int    (*load_section)(void* obj, Dwarf_Half section_index,
745*4d9fdb46SRobert Mustacchi        Dwarf_Small** return_data, int* error);
746*4d9fdb46SRobert Mustacchi
747*4d9fdb46SRobert Mustacchi    /**
748*4d9fdb46SRobert Mustacchi        relocate_a_section
749*4d9fdb46SRobert Mustacchi        If relocations are not supported leave this pointer NULL.
750*4d9fdb46SRobert Mustacchi
751*4d9fdb46SRobert Mustacchi        Get a pointer to an array of bytes that represent the section.
752*4d9fdb46SRobert Mustacchi
753*4d9fdb46SRobert Mustacchi        Parameters
754*4d9fdb46SRobert Mustacchi        section_index - Zero-based index of the section to be relocated.
755*4d9fdb46SRobert Mustacchi        error - Pointer to an integer for returning libdwarf-defined
756*4d9fdb46SRobert Mustacchi            error numbers.
757*4d9fdb46SRobert Mustacchi
758*4d9fdb46SRobert Mustacchi        Return
759*4d9fdb46SRobert Mustacchi        DW_DLV_OK - No error.
760*4d9fdb46SRobert Mustacchi        DW_DLV_ERROR - Error. Use 'error' to indicate a libdwarf-defined
761*4d9fdb46SRobert Mustacchi            error number.
762*4d9fdb46SRobert Mustacchi        DW_DLV_NO_ENTRY - No such section.  */
763*4d9fdb46SRobert Mustacchi    int    (*relocate_a_section)(void* obj, Dwarf_Half section_index,
764*4d9fdb46SRobert Mustacchi        Dwarf_Debug dbg,
765*4d9fdb46SRobert Mustacchi        int* error);
766*4d9fdb46SRobert Mustacchi
767*4d9fdb46SRobert Mustacchi};
768*4d9fdb46SRobert Mustacchi
769*4d9fdb46SRobert Mustacchi
770*4d9fdb46SRobert Mustacchi
771*4d9fdb46SRobert Mustacchi/*  These structures are allocated and deallocated by your code
772*4d9fdb46SRobert Mustacchi    when you are using the libdwarf Object File Interface
773*4d9fdb46SRobert Mustacchi    [dwarf_object_init and dwarf_object_finish)] directly.
774*4d9fdb46SRobert Mustacchi    dwarf_object_finish) does not free
775*4d9fdb46SRobert Mustacchi    struct Dwarf_Obj_Access_Interface_s or its content.
776*4d9fdb46SRobert Mustacchi    (libdwarf does record a pointer to this struct: you must
777*4d9fdb46SRobert Mustacchi    ensure that pointer remains valid for as long as
778*4d9fdb46SRobert Mustacchi    a libdwarf instance is open (meaning
779*4d9fdb46SRobert Mustacchi    after dwarf_init) and before dwarf_finish)).
780*4d9fdb46SRobert Mustacchi
781*4d9fdb46SRobert Mustacchi    If you are reading Elf objects and libelf use dwarf_init()
782*4d9fdb46SRobert Mustacchi    or dwarf_elf_init() which take care of these details.
783*4d9fdb46SRobert Mustacchi*/
784*4d9fdb46SRobert Mustacchistruct Dwarf_Obj_Access_Interface_s {
785*4d9fdb46SRobert Mustacchi    /*  object is a void* as it hides the data the object access routines
786*4d9fdb46SRobert Mustacchi        need (which varies by library in use and object format).
787*4d9fdb46SRobert Mustacchi    */
788*4d9fdb46SRobert Mustacchi    void* object;
789*4d9fdb46SRobert Mustacchi    const Dwarf_Obj_Access_Methods * methods;
790*4d9fdb46SRobert Mustacchi};
791*4d9fdb46SRobert Mustacchi
792*4d9fdb46SRobert Mustacchi/* End libdwarf Object File Interface */
793*4d9fdb46SRobert Mustacchi
794*4d9fdb46SRobert Mustacchi/*
795*4d9fdb46SRobert Mustacchi    Dwarf_dealloc() alloc_type arguments.
796*4d9fdb46SRobert Mustacchi    Argument points to:
797*4d9fdb46SRobert Mustacchi*/
798*4d9fdb46SRobert Mustacchi#define DW_DLA_STRING          0x01     /* char* */
799*4d9fdb46SRobert Mustacchi#define DW_DLA_LOC             0x02     /* Dwarf_Loc */
800*4d9fdb46SRobert Mustacchi#define DW_DLA_LOCDESC         0x03     /* Dwarf_Locdesc */
801*4d9fdb46SRobert Mustacchi#define DW_DLA_ELLIST          0x04     /* Dwarf_Ellist (not used)*/
802*4d9fdb46SRobert Mustacchi#define DW_DLA_BOUNDS          0x05     /* Dwarf_Bounds (not used) */
803*4d9fdb46SRobert Mustacchi#define DW_DLA_BLOCK           0x06     /* Dwarf_Block */
804*4d9fdb46SRobert Mustacchi#define DW_DLA_DEBUG           0x07     /* Dwarf_Debug */
805*4d9fdb46SRobert Mustacchi#define DW_DLA_DIE             0x08     /* Dwarf_Die */
806*4d9fdb46SRobert Mustacchi#define DW_DLA_LINE            0x09     /* Dwarf_Line */
807*4d9fdb46SRobert Mustacchi#define DW_DLA_ATTR            0x0a     /* Dwarf_Attribute */
808*4d9fdb46SRobert Mustacchi#define DW_DLA_TYPE            0x0b     /* Dwarf_Type  (not used) */
809*4d9fdb46SRobert Mustacchi#define DW_DLA_SUBSCR          0x0c     /* Dwarf_Subscr (not used) */
810*4d9fdb46SRobert Mustacchi#define DW_DLA_GLOBAL          0x0d     /* Dwarf_Global */
811*4d9fdb46SRobert Mustacchi#define DW_DLA_ERROR           0x0e     /* Dwarf_Error */
812*4d9fdb46SRobert Mustacchi#define DW_DLA_LIST            0x0f     /* a list */
813*4d9fdb46SRobert Mustacchi#define DW_DLA_LINEBUF         0x10     /* Dwarf_Line* (not used) */
814*4d9fdb46SRobert Mustacchi#define DW_DLA_ARANGE          0x11     /* Dwarf_Arange */
815*4d9fdb46SRobert Mustacchi#define DW_DLA_ABBREV          0x12     /* Dwarf_Abbrev */
816*4d9fdb46SRobert Mustacchi#define DW_DLA_FRAME_OP        0x13     /* Dwarf_Frame_Op */
817*4d9fdb46SRobert Mustacchi#define DW_DLA_CIE             0x14     /* Dwarf_Cie */
818*4d9fdb46SRobert Mustacchi#define DW_DLA_FDE             0x15     /* Dwarf_Fde */
819*4d9fdb46SRobert Mustacchi#define DW_DLA_LOC_BLOCK       0x16     /* Dwarf_Loc */
820*4d9fdb46SRobert Mustacchi#define DW_DLA_FRAME_BLOCK     0x17     /* Dwarf_Frame Block (not used) */
821*4d9fdb46SRobert Mustacchi#define DW_DLA_FUNC            0x18     /* Dwarf_Func */
822*4d9fdb46SRobert Mustacchi#define DW_DLA_TYPENAME        0x19     /* Dwarf_Type */
823*4d9fdb46SRobert Mustacchi#define DW_DLA_VAR             0x1a     /* Dwarf_Var */
824*4d9fdb46SRobert Mustacchi#define DW_DLA_WEAK            0x1b     /* Dwarf_Weak */
825*4d9fdb46SRobert Mustacchi#define DW_DLA_ADDR            0x1c     /* Dwarf_Addr sized entries */
826*4d9fdb46SRobert Mustacchi#define DW_DLA_RANGES          0x1d     /* Dwarf_Ranges */
827*4d9fdb46SRobert Mustacchi/* 0x1e (30) to 0x34 (52) reserved for internal to libdwarf types. */
828*4d9fdb46SRobert Mustacchi#define DW_DLA_LOCLISTS_HEAD   0x35     /* .debug_loclists DW5 */
829*4d9fdb46SRobert Mustacchi#define DW_DLA_RNGLISTS_HEAD   0x36     /* .debug_rnglists DW5 */
830*4d9fdb46SRobert Mustacchi#define DW_DLA_GDBINDEX        0x37     /* Dwarf_Gdbindex */
831*4d9fdb46SRobert Mustacchi#define DW_DLA_XU_INDEX        0x38     /* Dwarf_Xu_Index_Header */
832*4d9fdb46SRobert Mustacchi#define DW_DLA_LOC_BLOCK_C     0x39     /* Dwarf_Loc_c*/
833*4d9fdb46SRobert Mustacchi#define DW_DLA_LOCDESC_C       0x3a     /* Dwarf_Locdesc_c */
834*4d9fdb46SRobert Mustacchi#define DW_DLA_LOC_HEAD_C      0x3b     /* Dwarf_Loc_Head_c */
835*4d9fdb46SRobert Mustacchi#define DW_DLA_MACRO_CONTEXT   0x3c     /* Dwarf_Macro_Context */
836*4d9fdb46SRobert Mustacchi/*  0x3d (61) is for libdwarf internal use.               */
837*4d9fdb46SRobert Mustacchi#define DW_DLA_DSC_HEAD        0x3e     /* Dwarf_Dsc_Head */
838*4d9fdb46SRobert Mustacchi#define DW_DLA_DNAMES_HEAD     0x3f     /* Dwarf_Dnames_Head */
839*4d9fdb46SRobert Mustacchi#define DW_DLA_STR_OFFSETS     0x40     /* struct Dwarf_Str_Offsets_Table_s */
840*4d9fdb46SRobert Mustacchi
841*4d9fdb46SRobert Mustacchi/* The augmenter string for CIE */
842*4d9fdb46SRobert Mustacchi#define DW_CIE_AUGMENTER_STRING_V0              "z"
843*4d9fdb46SRobert Mustacchi
844*4d9fdb46SRobert Mustacchi/* dwarf_init() access arguments
845*4d9fdb46SRobert Mustacchi*/
846*4d9fdb46SRobert Mustacchi#define DW_DLC_READ        0        /* read only access */
847*4d9fdb46SRobert Mustacchi#define DW_DLC_WRITE       1        /* write only access */
848*4d9fdb46SRobert Mustacchi#define DW_DLC_RDWR        2        /* read/write access NOT SUPPORTED*/
849*4d9fdb46SRobert Mustacchi
850*4d9fdb46SRobert Mustacchi/* dwarf_producer_init* access flag modifiers
851*4d9fdb46SRobert Mustacchi   No longer depends on compile-time settings for
852*4d9fdb46SRobert Mustacchi   how to produce 64bit offset. See DW_DLC_IRIX_OFFSET64.
853*4d9fdb46SRobert Mustacchi   Historic  versions. One of
854*4d9fdb46SRobert Mustacchi   If DW_DLC_POINTER64 is not set DW_DLC_POINTER32 is assumed.
855*4d9fdb46SRobert Mustacchi   If DW_DLC_OFFSET64 or DW_DLC_IRIX_OFFSET64 is not
856*4d9fdb46SRobert Mustacchi   set 32bit offset DWARF is assumed.
857*4d9fdb46SRobert Mustacchi   Non-MIPS Non IA64 should use DW_DLC_SYMBOLIC_RELOCATIONS
858*4d9fdb46SRobert Mustacchi   and handle the relocation creation for the target
859*4d9fdb46SRobert Mustacchi   itself using the symbolic relocations to do so, those
860*4d9fdb46SRobert Mustacchi   use the Dwarf_Rel_Type enum relocation indicators.
861*4d9fdb46SRobert Mustacchi
862*4d9fdb46SRobert Mustacchi*/
863*4d9fdb46SRobert Mustacchi/*  The first three are traditional dwarf producer names.
864*4d9fdb46SRobert Mustacchi    These names still work.
865*4d9fdb46SRobert Mustacchi    Newer names below.
866*4d9fdb46SRobert Mustacchi*/
867*4d9fdb46SRobert Mustacchi/* 64-bit address-size target */
868*4d9fdb46SRobert Mustacchi#define DW_DLC_SIZE_64              0x40000000
869*4d9fdb46SRobert Mustacchi
870*4d9fdb46SRobert Mustacchi/* 32-bit address-size target */
871*4d9fdb46SRobert Mustacchi#define DW_DLC_SIZE_32              0x20000000
872*4d9fdb46SRobert Mustacchi
873*4d9fdb46SRobert Mustacchi/* 64-bit offset-size DWARF offsets (else 32bit) */
874*4d9fdb46SRobert Mustacchi#define DW_DLC_OFFSET_SIZE_64       0x10000000
875*4d9fdb46SRobert Mustacchi
876*4d9fdb46SRobert Mustacchi/* 32-bit offset-size ELF object (ELFCLASS32) */
877*4d9fdb46SRobert Mustacchi#define DW_DLC_ELF_OFFSET_SIZE_32   0x00400000
878*4d9fdb46SRobert Mustacchi
879*4d9fdb46SRobert Mustacchi/* 64-bit offset-size ELF object (ELFCLASS64)  */
880*4d9fdb46SRobert Mustacchi#define DW_DLC_ELF_OFFSET_SIZE_64   0x00020000
881*4d9fdb46SRobert Mustacchi
882*4d9fdb46SRobert Mustacchi/* dwarf_producer_init* access flag modifiers
883*4d9fdb46SRobert Mustacchi   Some new April 2014.
884*4d9fdb46SRobert Mustacchi   If DW_DLC_STREAM_RELOCATIONS is set the
885*4d9fdb46SRobert Mustacchi   DW_DLC_ISA_* flags are ignored. See the Dwarf_Rel_Type enum.
886*4d9fdb46SRobert Mustacchi*/
887*4d9fdb46SRobert Mustacchi
888*4d9fdb46SRobert Mustacchi/* Old style Elf binary relocation (.rel) records. The default. */
889*4d9fdb46SRobert Mustacchi#define DW_DLC_STREAM_RELOCATIONS   0x02000000
890*4d9fdb46SRobert Mustacchi
891*4d9fdb46SRobert Mustacchi/* use 32-bit  sec  offsets */
892*4d9fdb46SRobert Mustacchi#define DW_DLC_OFFSET32             0x00010000
893*4d9fdb46SRobert Mustacchi
894*4d9fdb46SRobert Mustacchi/* The following 3 are new sensible names.
895*4d9fdb46SRobert MustacchiOld names above with same values. */
896*4d9fdb46SRobert Mustacchi/* use 64-bit sec offsets in ELF */
897*4d9fdb46SRobert Mustacchi#define DW_DLC_OFFSET64             0x10000000
898*4d9fdb46SRobert Mustacchi
899*4d9fdb46SRobert Mustacchi/* use 4 for address_size */
900*4d9fdb46SRobert Mustacchi#define DW_DLC_POINTER32            0x20000000
901*4d9fdb46SRobert Mustacchi
902*4d9fdb46SRobert Mustacchi/* use 8 for address_size */
903*4d9fdb46SRobert Mustacchi#define DW_DLC_POINTER64            0x40000000
904*4d9fdb46SRobert Mustacchi
905*4d9fdb46SRobert Mustacchi/* Special for IRIX only */
906*4d9fdb46SRobert Mustacchi/* use Elf 64bit offset headers and non-std IRIX 64bitoffset headers */
907*4d9fdb46SRobert Mustacchi#define DW_DLC_IRIX_OFFSET64        0x00200000
908*4d9fdb46SRobert Mustacchi
909*4d9fdb46SRobert Mustacchi/*  Usable with assembly output because it is up to the producer to
910*4d9fdb46SRobert Mustacchi    deal with locations in whatever manner the calling producer
911*4d9fdb46SRobert Mustacchi    code wishes.  For example, when the libdwarf caller wishes
912*4d9fdb46SRobert Mustacchi    to produce relocations differently than the binary
913*4d9fdb46SRobert Mustacchi    relocation bits that libdwarf Stream Relocations generate.
914*4d9fdb46SRobert Mustacchi    */
915*4d9fdb46SRobert Mustacchi#define DW_DLC_SYMBOLIC_RELOCATIONS 0x04000000
916*4d9fdb46SRobert Mustacchi
917*4d9fdb46SRobert Mustacchi
918*4d9fdb46SRobert Mustacchi#define DW_DLC_TARGET_BIGENDIAN     0x08000000 /* Big    endian target */
919*4d9fdb46SRobert Mustacchi#define DW_DLC_TARGET_LITTLEENDIAN  0x00100000 /* Little endian target */
920*4d9fdb46SRobert Mustacchi
921*4d9fdb46SRobert Mustacchi
922*4d9fdb46SRobert Mustacchi/* dwarf_pcline function, slide arguments
923*4d9fdb46SRobert Mustacchi*/
924*4d9fdb46SRobert Mustacchi#define DW_DLS_BACKWARD   -1       /* slide backward to find line */
925*4d9fdb46SRobert Mustacchi#define DW_DLS_NOSLIDE     0       /* match exactly without sliding */
926*4d9fdb46SRobert Mustacchi#define DW_DLS_FORWARD     1       /* slide forward to find line */
927*4d9fdb46SRobert Mustacchi
928*4d9fdb46SRobert Mustacchi/* libdwarf error numbers
929*4d9fdb46SRobert Mustacchi*/
930*4d9fdb46SRobert Mustacchi#define DW_DLE_NE          0     /* no error */
931*4d9fdb46SRobert Mustacchi#define DW_DLE_VMM         1     /* dwarf format/library version mismatch */
932*4d9fdb46SRobert Mustacchi#define DW_DLE_MAP         2     /* memory map failure */
933*4d9fdb46SRobert Mustacchi#define DW_DLE_LEE         3     /* libelf error */
934*4d9fdb46SRobert Mustacchi#define DW_DLE_NDS         4     /* no debug section */
935*4d9fdb46SRobert Mustacchi#define DW_DLE_NLS         5     /* no line section */
936*4d9fdb46SRobert Mustacchi#define DW_DLE_ID          6     /* invalid descriptor for query */
937*4d9fdb46SRobert Mustacchi#define DW_DLE_IOF         7     /* I/O failure */
938*4d9fdb46SRobert Mustacchi#define DW_DLE_MAF         8     /* memory allocation failure */
939*4d9fdb46SRobert Mustacchi#define DW_DLE_IA          9     /* invalid argument */
940*4d9fdb46SRobert Mustacchi#define DW_DLE_MDE         10     /* mangled debugging entry */
941*4d9fdb46SRobert Mustacchi#define DW_DLE_MLE         11     /* mangled line number entry */
942*4d9fdb46SRobert Mustacchi#define DW_DLE_FNO         12     /* file not open */
943*4d9fdb46SRobert Mustacchi#define DW_DLE_FNR         13     /* file not a regular file */
944*4d9fdb46SRobert Mustacchi#define DW_DLE_FWA         14     /* file open with wrong access */
945*4d9fdb46SRobert Mustacchi#define DW_DLE_NOB         15     /* not an object file */
946*4d9fdb46SRobert Mustacchi#define DW_DLE_MOF         16     /* mangled object file header */
947*4d9fdb46SRobert Mustacchi#define DW_DLE_EOLL        17     /* end of location list entries */
948*4d9fdb46SRobert Mustacchi#define DW_DLE_NOLL        18     /* no location list section */
949*4d9fdb46SRobert Mustacchi#define DW_DLE_BADOFF      19     /* Invalid offset */
950*4d9fdb46SRobert Mustacchi#define DW_DLE_EOS         20     /* end of section  */
951*4d9fdb46SRobert Mustacchi#define DW_DLE_ATRUNC      21     /* abbreviations section appears truncated*/
952*4d9fdb46SRobert Mustacchi#define DW_DLE_BADBITC     22     /* Address size passed to dwarf bad*/
953*4d9fdb46SRobert Mustacchi                    /* It is not an allowed size (64 or 32) */
954*4d9fdb46SRobert Mustacchi    /* Error codes defined by the current Libdwarf Implementation. */
955*4d9fdb46SRobert Mustacchi#define DW_DLE_DBG_ALLOC                        23
956*4d9fdb46SRobert Mustacchi#define DW_DLE_FSTAT_ERROR                      24
957*4d9fdb46SRobert Mustacchi#define DW_DLE_FSTAT_MODE_ERROR                 25
958*4d9fdb46SRobert Mustacchi#define DW_DLE_INIT_ACCESS_WRONG                26
959*4d9fdb46SRobert Mustacchi#define DW_DLE_ELF_BEGIN_ERROR                  27
960*4d9fdb46SRobert Mustacchi#define DW_DLE_ELF_GETEHDR_ERROR                28
961*4d9fdb46SRobert Mustacchi#define DW_DLE_ELF_GETSHDR_ERROR                29
962*4d9fdb46SRobert Mustacchi#define DW_DLE_ELF_STRPTR_ERROR                 30
963*4d9fdb46SRobert Mustacchi#define DW_DLE_DEBUG_INFO_DUPLICATE             31
964*4d9fdb46SRobert Mustacchi#define DW_DLE_DEBUG_INFO_NULL                  32
965*4d9fdb46SRobert Mustacchi#define DW_DLE_DEBUG_ABBREV_DUPLICATE           33
966*4d9fdb46SRobert Mustacchi#define DW_DLE_DEBUG_ABBREV_NULL                34
967*4d9fdb46SRobert Mustacchi#define DW_DLE_DEBUG_ARANGES_DUPLICATE          35
968*4d9fdb46SRobert Mustacchi#define DW_DLE_DEBUG_ARANGES_NULL               36
969*4d9fdb46SRobert Mustacchi#define DW_DLE_DEBUG_LINE_DUPLICATE             37
970*4d9fdb46SRobert Mustacchi#define DW_DLE_DEBUG_LINE_NULL                  38
971*4d9fdb46SRobert Mustacchi#define DW_DLE_DEBUG_LOC_DUPLICATE              39
972*4d9fdb46SRobert Mustacchi#define DW_DLE_DEBUG_LOC_NULL                   40
973*4d9fdb46SRobert Mustacchi#define DW_DLE_DEBUG_MACINFO_DUPLICATE          41
974*4d9fdb46SRobert Mustacchi#define DW_DLE_DEBUG_MACINFO_NULL               42
975*4d9fdb46SRobert Mustacchi#define DW_DLE_DEBUG_PUBNAMES_DUPLICATE         43
976*4d9fdb46SRobert Mustacchi#define DW_DLE_DEBUG_PUBNAMES_NULL              44
977*4d9fdb46SRobert Mustacchi#define DW_DLE_DEBUG_STR_DUPLICATE              45
978*4d9fdb46SRobert Mustacchi#define DW_DLE_DEBUG_STR_NULL                   46
979*4d9fdb46SRobert Mustacchi#define DW_DLE_CU_LENGTH_ERROR                  47
980*4d9fdb46SRobert Mustacchi#define DW_DLE_VERSION_STAMP_ERROR              48
981*4d9fdb46SRobert Mustacchi#define DW_DLE_ABBREV_OFFSET_ERROR              49
982*4d9fdb46SRobert Mustacchi#define DW_DLE_ADDRESS_SIZE_ERROR               50
983*4d9fdb46SRobert Mustacchi#define DW_DLE_DEBUG_INFO_PTR_NULL              51
984*4d9fdb46SRobert Mustacchi#define DW_DLE_DIE_NULL                         52
985*4d9fdb46SRobert Mustacchi#define DW_DLE_STRING_OFFSET_BAD                53
986*4d9fdb46SRobert Mustacchi#define DW_DLE_DEBUG_LINE_LENGTH_BAD            54
987*4d9fdb46SRobert Mustacchi#define DW_DLE_LINE_PROLOG_LENGTH_BAD           55
988*4d9fdb46SRobert Mustacchi#define DW_DLE_LINE_NUM_OPERANDS_BAD            56
989*4d9fdb46SRobert Mustacchi#define DW_DLE_LINE_SET_ADDR_ERROR              57 /* No longer used. */
990*4d9fdb46SRobert Mustacchi#define DW_DLE_LINE_EXT_OPCODE_BAD              58
991*4d9fdb46SRobert Mustacchi#define DW_DLE_DWARF_LINE_NULL                  59
992*4d9fdb46SRobert Mustacchi#define DW_DLE_INCL_DIR_NUM_BAD                 60
993*4d9fdb46SRobert Mustacchi#define DW_DLE_LINE_FILE_NUM_BAD                61
994*4d9fdb46SRobert Mustacchi#define DW_DLE_ALLOC_FAIL                       62
995*4d9fdb46SRobert Mustacchi#define DW_DLE_NO_CALLBACK_FUNC                 63
996*4d9fdb46SRobert Mustacchi#define DW_DLE_SECT_ALLOC                       64
997*4d9fdb46SRobert Mustacchi#define DW_DLE_FILE_ENTRY_ALLOC                 65
998*4d9fdb46SRobert Mustacchi#define DW_DLE_LINE_ALLOC                       66
999*4d9fdb46SRobert Mustacchi#define DW_DLE_FPGM_ALLOC                       67
1000*4d9fdb46SRobert Mustacchi#define DW_DLE_INCDIR_ALLOC                     68
1001*4d9fdb46SRobert Mustacchi#define DW_DLE_STRING_ALLOC                     69
1002*4d9fdb46SRobert Mustacchi#define DW_DLE_CHUNK_ALLOC                      70
1003*4d9fdb46SRobert Mustacchi#define DW_DLE_BYTEOFF_ERR                      71
1004*4d9fdb46SRobert Mustacchi#define DW_DLE_CIE_ALLOC                        72
1005*4d9fdb46SRobert Mustacchi#define DW_DLE_FDE_ALLOC                        73
1006*4d9fdb46SRobert Mustacchi#define DW_DLE_REGNO_OVFL                       74
1007*4d9fdb46SRobert Mustacchi#define DW_DLE_CIE_OFFS_ALLOC                   75
1008*4d9fdb46SRobert Mustacchi#define DW_DLE_WRONG_ADDRESS                    76
1009*4d9fdb46SRobert Mustacchi#define DW_DLE_EXTRA_NEIGHBORS                  77
1010*4d9fdb46SRobert Mustacchi#define DW_DLE_WRONG_TAG                        78
1011*4d9fdb46SRobert Mustacchi#define DW_DLE_DIE_ALLOC                        79
1012*4d9fdb46SRobert Mustacchi#define DW_DLE_PARENT_EXISTS                    80
1013*4d9fdb46SRobert Mustacchi#define DW_DLE_DBG_NULL                         81
1014*4d9fdb46SRobert Mustacchi#define DW_DLE_DEBUGLINE_ERROR                  82
1015*4d9fdb46SRobert Mustacchi#define DW_DLE_DEBUGFRAME_ERROR                 83
1016*4d9fdb46SRobert Mustacchi#define DW_DLE_DEBUGINFO_ERROR                  84
1017*4d9fdb46SRobert Mustacchi#define DW_DLE_ATTR_ALLOC                       85
1018*4d9fdb46SRobert Mustacchi#define DW_DLE_ABBREV_ALLOC                     86
1019*4d9fdb46SRobert Mustacchi#define DW_DLE_OFFSET_UFLW                      87
1020*4d9fdb46SRobert Mustacchi#define DW_DLE_ELF_SECT_ERR                     88
1021