xref: /illumos-gate/usr/src/lib/libdwarf/common/pro_opaque.h (revision 4d9fdb46b215739778ebc12079842c9905586999)
149d3bc91SRichard Lowe /*
249d3bc91SRichard Lowe 
307dc1947SRichard Lowe   Copyright (C) 2000,2002,2004 Silicon Graphics, Inc.  All Rights Reserved.
407dc1947SRichard Lowe   Portions Copyright 2002-2010 Sun Microsystems, Inc. All rights reserved.
5*4d9fdb46SRobert Mustacchi   Portions Copyright 2011-2017 David Anderson. All Rights Reserved.
649d3bc91SRichard Lowe 
749d3bc91SRichard Lowe   This program is free software; you can redistribute it and/or modify it
8*4d9fdb46SRobert Mustacchi   under the terms of version 2.1 of the GNU Lesser General Public License
949d3bc91SRichard Lowe   as published by the Free Software Foundation.
1049d3bc91SRichard Lowe 
1149d3bc91SRichard Lowe   This program is distributed in the hope that it would be useful, but
1249d3bc91SRichard Lowe   WITHOUT ANY WARRANTY; without even the implied warranty of
13*4d9fdb46SRobert Mustacchi   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1449d3bc91SRichard Lowe 
1549d3bc91SRichard Lowe   Further, this software is distributed without any warranty that it is
16*4d9fdb46SRobert Mustacchi   free of the rightful claim of any third person regarding infringement
17*4d9fdb46SRobert Mustacchi   or the like.  Any license provided herein, whether implied or
1849d3bc91SRichard Lowe   otherwise, applies only to this software file.  Patent licenses, if
19*4d9fdb46SRobert Mustacchi   any, provided herein do not apply to combinations of this program with
20*4d9fdb46SRobert Mustacchi   other software, or any other product whatsoever.
2149d3bc91SRichard Lowe 
2207dc1947SRichard Lowe   You should have received a copy of the GNU Lesser General Public
2307dc1947SRichard Lowe   License along with this program; if not, write the Free Software
2407dc1947SRichard Lowe   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
2549d3bc91SRichard Lowe   USA.
2649d3bc91SRichard Lowe 
2749d3bc91SRichard Lowe */
2849d3bc91SRichard Lowe 
2949d3bc91SRichard Lowe #include "libdwarfdefs.h"
3049d3bc91SRichard Lowe 
3149d3bc91SRichard Lowe #define true                    1
3249d3bc91SRichard Lowe #define false                   0
3349d3bc91SRichard Lowe 
34*4d9fdb46SRobert Mustacchi /*  The DISTINGUISHED VALUE is 4 byte value defined by DWARF
35*4d9fdb46SRobert Mustacchi     since DWARF3. */
36*4d9fdb46SRobert Mustacchi #define DISTINGUISHED_VALUE_ARRAY(x)  unsigned char x[4] = { 0xff,0xff,0xff,0xff }
37*4d9fdb46SRobert Mustacchi #define DISTINGUISHED_VALUE 0xffffffff /* 64bit extension flag */
3849d3bc91SRichard Lowe 
39*4d9fdb46SRobert Mustacchi /* to identify a cie */
40*4d9fdb46SRobert Mustacchi #define DW_CIE_ID          ~(0x0)
41*4d9fdb46SRobert Mustacchi #define DW_CIE_VERSION     1
4249d3bc91SRichard Lowe 
4349d3bc91SRichard Lowe typedef signed char Dwarf_Sbyte;
4449d3bc91SRichard Lowe typedef unsigned char Dwarf_Ubyte;
4549d3bc91SRichard Lowe typedef signed short Dwarf_Shalf;
4649d3bc91SRichard Lowe 
4749d3bc91SRichard Lowe /*
48*4d9fdb46SRobert Mustacchi     On any change that makes libdwarf producer
49*4d9fdb46SRobert Mustacchi     incompatible, increment this number.
50*4d9fdb46SRobert Mustacchi     1->2->3 ...  */
5149d3bc91SRichard Lowe #define  PRO_VERSION_MAGIC 0xdead1
5249d3bc91SRichard Lowe 
5349d3bc91SRichard Lowe 
54*4d9fdb46SRobert Mustacchi #define DWARF_HALF_SIZE 2
55*4d9fdb46SRobert Mustacchi #define DWARF_32BIT_SIZE 4
56*4d9fdb46SRobert Mustacchi #define DWARF_64BIT_SIZE 8
5749d3bc91SRichard Lowe 
5849d3bc91SRichard Lowe /*
59*4d9fdb46SRobert Mustacchi     producer:
60*4d9fdb46SRobert Mustacchi     This struct is used to hold information about all
61*4d9fdb46SRobert Mustacchi     debug* sections. On creating a new section, section
62*4d9fdb46SRobert Mustacchi     names and indices are added to this struct
63*4d9fdb46SRobert Mustacchi     definition in pro_section.h */
64*4d9fdb46SRobert Mustacchi typedef struct Dwarf_P_Section_Data_s *Dwarf_P_Section_Data;
6549d3bc91SRichard Lowe 
6649d3bc91SRichard Lowe /*
67*4d9fdb46SRobert Mustacchi     producer:
68*4d9fdb46SRobert Mustacchi     This struct holds file entries or
69*4d9fdb46SRobert Mustacchi     include file entries for the statement prologue.
70*4d9fdb46SRobert Mustacchi     Defined in pro_line.h
7149d3bc91SRichard Lowe */
7249d3bc91SRichard Lowe typedef struct Dwarf_P_F_Entry_s *Dwarf_P_F_Entry;
7349d3bc91SRichard Lowe 
7449d3bc91SRichard Lowe /*
75*4d9fdb46SRobert Mustacchi     producer:
76*4d9fdb46SRobert Mustacchi     This struct holds information for each cie. Defn in pro_frame.h
7749d3bc91SRichard Lowe */
7849d3bc91SRichard Lowe typedef struct Dwarf_P_Cie_s *Dwarf_P_Cie;
7949d3bc91SRichard Lowe 
8049d3bc91SRichard Lowe /*
81*4d9fdb46SRobert Mustacchi     producer:
82*4d9fdb46SRobert Mustacchi     Struct to hold line number information, different from
83*4d9fdb46SRobert Mustacchi     Dwarf_Line opaque type.
8449d3bc91SRichard Lowe */
8549d3bc91SRichard Lowe typedef struct Dwarf_P_Line_s *Dwarf_P_Line;
8649d3bc91SRichard Lowe 
8749d3bc91SRichard Lowe /*
88*4d9fdb46SRobert Mustacchi     producer:
89*4d9fdb46SRobert Mustacchi     Struct to hold information about address ranges.
9049d3bc91SRichard Lowe */
9149d3bc91SRichard Lowe typedef struct Dwarf_P_Simple_nameentry_s *Dwarf_P_Simple_nameentry;
9249d3bc91SRichard Lowe typedef struct Dwarf_P_Simple_name_header_s *Dwarf_P_Simple_name_header;
9349d3bc91SRichard Lowe typedef struct Dwarf_P_Arange_s *Dwarf_P_Arange;
9449d3bc91SRichard Lowe typedef struct Dwarf_P_Per_Reloc_Sect_s *Dwarf_P_Per_Reloc_Sect;
9507dc1947SRichard Lowe typedef struct Dwarf_P_Per_Sect_String_Attrs_s *Dwarf_P_Per_Sect_String_Attrs;
96*4d9fdb46SRobert Mustacchi typedef struct Dwarf_P_Dnames_s *Dwarf_P_Dnames;
9749d3bc91SRichard Lowe 
9849d3bc91SRichard Lowe /* Defined to get at the elf section numbers and section name
9949d3bc91SRichard Lowe    indices in symtab for the dwarf sections
10049d3bc91SRichard Lowe    Must match .rel.* names in _dwarf_rel_section_names
10149d3bc91SRichard Lowe    exactly.
10249d3bc91SRichard Lowe */
10349d3bc91SRichard Lowe #define         DEBUG_INFO      0
10449d3bc91SRichard Lowe #define         DEBUG_LINE      1
10549d3bc91SRichard Lowe #define         DEBUG_ABBREV    2
10649d3bc91SRichard Lowe #define         DEBUG_FRAME     3
10749d3bc91SRichard Lowe #define         DEBUG_ARANGES   4
10849d3bc91SRichard Lowe #define         DEBUG_PUBNAMES  5
109*4d9fdb46SRobert Mustacchi #define         DEBUG_FUNCNAMES 6
110*4d9fdb46SRobert Mustacchi #define         DEBUG_TYPENAMES 7
111*4d9fdb46SRobert Mustacchi #define         DEBUG_VARNAMES  8
112*4d9fdb46SRobert Mustacchi #define         DEBUG_WEAKNAMES 9
113*4d9fdb46SRobert Mustacchi #define         DEBUG_MACINFO   10 /* DWARF 2,3,4 only */
114*4d9fdb46SRobert Mustacchi #define         DEBUG_LOC       11
115*4d9fdb46SRobert Mustacchi #define         DEBUG_RANGES    12
116*4d9fdb46SRobert Mustacchi #define         DEBUG_TYPES     13
117*4d9fdb46SRobert Mustacchi #define         DEBUG_PUBTYPES  14
118*4d9fdb46SRobert Mustacchi #define         DEBUG_NAMES     15 /* DWARF5. aka dnames */
119*4d9fdb46SRobert Mustacchi #define         DEBUG_STR       16
120*4d9fdb46SRobert Mustacchi #define         DEBUG_LINE_STR  17
121*4d9fdb46SRobert Mustacchi #define         DEBUG_MACRO     18 /* DWARF 5. */
122*4d9fdb46SRobert Mustacchi #define         DEBUG_LOCLISTS  19 /* DWARF 5. */
123*4d9fdb46SRobert Mustacchi #define         DEBUG_RNGLISTS  20 /* DWARF 5. */
124*4d9fdb46SRobert Mustacchi 
125*4d9fdb46SRobert Mustacchi /* Maximum number of debug_* sections not including the relocations */
126*4d9fdb46SRobert Mustacchi #define         NUM_DEBUG_SECTIONS      21
127*4d9fdb46SRobert Mustacchi 
128*4d9fdb46SRobert Mustacchi /*  The FORM codes available are defined in DWARF5
129*4d9fdb46SRobert Mustacchi     on page 158, DW_LNCT_path  */
130*4d9fdb46SRobert Mustacchi struct Dwarf_P_Line_format_s {
131*4d9fdb46SRobert Mustacchi     /* DW_LNCT_path etc. */
132*4d9fdb46SRobert Mustacchi     unsigned def_content_type;
133*4d9fdb46SRobert Mustacchi 
134*4d9fdb46SRobert Mustacchi     /* DW_FORM_string or DW_FORM_strp or DW_FORM_strp
135*4d9fdb46SRobert Mustacchi         or DW_FORM_strp_sup or for dwo, some others. */
136*4d9fdb46SRobert Mustacchi     unsigned def_form_code;
137*4d9fdb46SRobert Mustacchi };
13849d3bc91SRichard Lowe 
139*4d9fdb46SRobert Mustacchi #define DW_LINE_FORMATS_MAX 6
140*4d9fdb46SRobert Mustacchi /*  Describes the data needed to generate line table header info
141*4d9fdb46SRobert Mustacchi     so we can vary the init at runtime. */
142*4d9fdb46SRobert Mustacchi struct Dwarf_P_Line_Inits_s {
143*4d9fdb46SRobert Mustacchi     unsigned pi_linetable_version; /* line table version number */
144*4d9fdb46SRobert Mustacchi     unsigned pi_default_is_stmt; /* default value for is_stmt */
145*4d9fdb46SRobert Mustacchi 
146*4d9fdb46SRobert Mustacchi     /* Size of the smallest instruction, in bytes. */
147*4d9fdb46SRobert Mustacchi     unsigned pi_minimum_instruction_length;
148*4d9fdb46SRobert Mustacchi 
149*4d9fdb46SRobert Mustacchi     /*  Normally opcode_base is determined by pi_version, but we
150*4d9fdb46SRobert Mustacchi         allow manual setting here so we can generate data like
151*4d9fdb46SRobert Mustacchi         GNU with a DWARF3 opcode base in a DWARF2 section.
152*4d9fdb46SRobert Mustacchi         This determines how much of the header_opcode_lengths
153*4d9fdb46SRobert Mustacchi         table is emitted in the line table header */
154*4d9fdb46SRobert Mustacchi     unsigned pi_opcode_base;
155*4d9fdb46SRobert Mustacchi 
156*4d9fdb46SRobert Mustacchi     int      pi_line_base;   /* For line table header. */
157*4d9fdb46SRobert Mustacchi     int      pi_line_range;  /* For line table header. */
158*4d9fdb46SRobert Mustacchi 
159*4d9fdb46SRobert Mustacchi     /* Make this >1 for VLIW machines.  DWARF4,DWARF5 */
160*4d9fdb46SRobert Mustacchi     unsigned pi_maximum_operations_per_instruction;
161*4d9fdb46SRobert Mustacchi 
162*4d9fdb46SRobert Mustacchi     /* DWARF 5  */
163*4d9fdb46SRobert Mustacchi     unsigned pi_segment_selector_size;
164*4d9fdb46SRobert Mustacchi     unsigned pi_address_size;
165*4d9fdb46SRobert Mustacchi     unsigned pi_segment_size;
166*4d9fdb46SRobert Mustacchi     unsigned pi_directory_entry_format_count;
167*4d9fdb46SRobert Mustacchi     struct Dwarf_P_Line_format_s pi_incformats[DW_LINE_FORMATS_MAX];
168*4d9fdb46SRobert Mustacchi 
169*4d9fdb46SRobert Mustacchi     unsigned pi_file_entry_format_count;
170*4d9fdb46SRobert Mustacchi     struct Dwarf_P_Line_format_s pi_fileformats[DW_LINE_FORMATS_MAX];
171*4d9fdb46SRobert Mustacchi };
17249d3bc91SRichard Lowe 
17349d3bc91SRichard Lowe 
17449d3bc91SRichard Lowe struct Dwarf_P_Die_s {
175*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned di_offset; /* offset in debug info */
176*4d9fdb46SRobert Mustacchi     char *di_abbrev;  /* abbreviation */
177*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned di_abbrev_nbytes; /* # of bytes in abbrev */
17849d3bc91SRichard Lowe     Dwarf_Tag di_tag;
179*4d9fdb46SRobert Mustacchi     Dwarf_P_Die di_parent; /* parent of current die */
180*4d9fdb46SRobert Mustacchi     Dwarf_P_Die di_child; /* first child */
181*4d9fdb46SRobert Mustacchi     /*  The last child field makes linking up children an O(1) operation,
182*4d9fdb46SRobert Mustacchi         See pro_die.c. */
183*4d9fdb46SRobert Mustacchi     Dwarf_P_Die di_last_child;
184*4d9fdb46SRobert Mustacchi     Dwarf_P_Die di_left; /* left sibling */
185*4d9fdb46SRobert Mustacchi     Dwarf_P_Die di_right; /* right sibling */
186*4d9fdb46SRobert Mustacchi     Dwarf_P_Attribute di_attrs; /* list of attributes */
187*4d9fdb46SRobert Mustacchi     Dwarf_P_Attribute di_last_attr; /* last attribute */
188*4d9fdb46SRobert Mustacchi     int di_n_attr;  /* number of attributes */
189*4d9fdb46SRobert Mustacchi     Dwarf_P_Debug di_dbg; /* For memory management */
19007dc1947SRichard Lowe     Dwarf_Unsigned di_marker;   /* used to attach symbols to dies */
19149d3bc91SRichard Lowe };
19249d3bc91SRichard Lowe 
19349d3bc91SRichard Lowe 
19449d3bc91SRichard Lowe /* producer fields */
19549d3bc91SRichard Lowe struct Dwarf_P_Attribute_s {
196*4d9fdb46SRobert Mustacchi     Dwarf_Half ar_attribute; /* Attribute Value. */
197*4d9fdb46SRobert Mustacchi     Dwarf_Half ar_attribute_form; /* Attribute Form. */
198*4d9fdb46SRobert Mustacchi     Dwarf_P_Die ar_ref_die; /* die pointer if form ref */
199*4d9fdb46SRobert Mustacchi     char *ar_data; /* data, format given by form */
200*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned ar_nbytes; /* no. of bytes of data */
201*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned ar_rel_symidx; /* when attribute has a
202*4d9fdb46SRobert Mustacchi         relocatable value, holds
203*4d9fdb46SRobert Mustacchi         index of symbol in SYMTAB */
204*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned ar_debug_str_offset; /* Offset in .debug_str
205*4d9fdb46SRobert Mustacchi         if non-zero. Zero offset never assigned a string. */
206*4d9fdb46SRobert Mustacchi     Dwarf_Ubyte ar_rel_type;  /* relocation type */
207*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned ar_rel_offset; /* Offset of relocation within block */
208*4d9fdb46SRobert Mustacchi     char ar_reloc_len; /* Number of bytes that relocation
209*4d9fdb46SRobert Mustacchi         applies to. 4 or 8. Unused and may
210*4d9fdb46SRobert Mustacchi         be 0 if if ar_rel_type is
211*4d9fdb46SRobert Mustacchi         R_MIPS_NONE */
21249d3bc91SRichard Lowe     Dwarf_P_Attribute ar_next;
213*4d9fdb46SRobert Mustacchi     /*  set if form = DW_FORM_implicit_const; */
214*4d9fdb46SRobert Mustacchi     Dwarf_Signed  ar_implicit_const;
21549d3bc91SRichard Lowe };
21649d3bc91SRichard Lowe 
21749d3bc91SRichard Lowe /* A block of .debug_macinfo data: this forms a series of blocks.
21849d3bc91SRichard Lowe ** Each macinfo input is compressed immediately and put into
21949d3bc91SRichard Lowe ** the current block if room, else a newblock allocated.
22049d3bc91SRichard Lowe ** The space allocation is such that the block and the macinfo
22149d3bc91SRichard Lowe ** data are one malloc block: free with a pointer to this and the
22249d3bc91SRichard Lowe ** mb_data is freed automatically.
22349d3bc91SRichard Lowe ** Like the struct hack, but legal ANSI C.
22449d3bc91SRichard Lowe */
22549d3bc91SRichard Lowe struct dw_macinfo_block_s {
22649d3bc91SRichard Lowe     struct dw_macinfo_block_s *mb_next;
22749d3bc91SRichard Lowe     unsigned long mb_avail_len;
22849d3bc91SRichard Lowe     unsigned long mb_used_len;
22949d3bc91SRichard Lowe     unsigned long mb_macinfo_data_space_len;
230*4d9fdb46SRobert Mustacchi     char *mb_data;/* original malloc ptr. */
23149d3bc91SRichard Lowe };
23249d3bc91SRichard Lowe 
233*4d9fdb46SRobert Mustacchi /*  dwarf_sn_kind is for the array of similarly-treated
234*4d9fdb46SRobert Mustacchi     name -> cu ties
23549d3bc91SRichard Lowe */
236*4d9fdb46SRobert Mustacchi enum dwarf_sn_kind { dwarf_snk_pubname,  /* .debug_pubnames */
237*4d9fdb46SRobert Mustacchi     dwarf_snk_funcname,  /* SGI extension. */
238*4d9fdb46SRobert Mustacchi     dwarf_snk_weakname,  /* SGI extension. */
239*4d9fdb46SRobert Mustacchi     dwarf_snk_typename,  /* SGI extension. */
240*4d9fdb46SRobert Mustacchi     dwarf_snk_varname,   /* SGI extension. */
241*4d9fdb46SRobert Mustacchi     dwarf_snk_pubtype,   /* .debug_pubtypes */
242*4d9fdb46SRobert Mustacchi     dwarf_snk_entrycount /* this one must be last */
24349d3bc91SRichard Lowe };
24449d3bc91SRichard Lowe 
24549d3bc91SRichard Lowe 
24649d3bc91SRichard Lowe 
24749d3bc91SRichard Lowe /* The calls to add a varname etc use a list of
24849d3bc91SRichard Lowe    these as the list.
24949d3bc91SRichard Lowe */
25049d3bc91SRichard Lowe struct Dwarf_P_Simple_nameentry_s {
25149d3bc91SRichard Lowe     Dwarf_P_Die sne_die;
25249d3bc91SRichard Lowe     char *sne_name;
25349d3bc91SRichard Lowe     int sne_name_len;
25449d3bc91SRichard Lowe     Dwarf_P_Simple_nameentry sne_next;
25549d3bc91SRichard Lowe };
25649d3bc91SRichard Lowe 
257*4d9fdb46SRobert Mustacchi /*  An array of these, each of which heads a list
258*4d9fdb46SRobert Mustacchi     of Dwarf_P_Simple_nameentry
25949d3bc91SRichard Lowe */
26049d3bc91SRichard Lowe struct Dwarf_P_Simple_name_header_s {
26149d3bc91SRichard Lowe     Dwarf_P_Simple_nameentry sn_head;
26249d3bc91SRichard Lowe     Dwarf_P_Simple_nameentry sn_tail;
26349d3bc91SRichard Lowe     Dwarf_Signed sn_count;
26449d3bc91SRichard Lowe 
265*4d9fdb46SRobert Mustacchi     /*  Length that will be generated, not counting fixed header or
266*4d9fdb46SRobert Mustacchi         trailer */
26749d3bc91SRichard Lowe     Dwarf_Signed sn_net_len;
26849d3bc91SRichard Lowe };
269*4d9fdb46SRobert Mustacchi typedef int (*_dwarf_pro_reloc_name_func_ptr) (Dwarf_P_Debug dbg,
270*4d9fdb46SRobert Mustacchi     int sec_index,
27107dc1947SRichard Lowe     Dwarf_Unsigned offset,/* r_offset */
27207dc1947SRichard Lowe     Dwarf_Unsigned symidx,
27307dc1947SRichard Lowe     enum Dwarf_Rel_Type type,
27407dc1947SRichard Lowe     int reltarget_length);
27507dc1947SRichard Lowe 
276*4d9fdb46SRobert Mustacchi typedef int (*_dwarf_pro_reloc_length_func_ptr) (Dwarf_P_Debug dbg,
27707dc1947SRichard Lowe     int sec_index, Dwarf_Unsigned offset,/* r_offset */
27807dc1947SRichard Lowe     Dwarf_Unsigned start_symidx,
27907dc1947SRichard Lowe     Dwarf_Unsigned end_symidx,
28007dc1947SRichard Lowe     enum Dwarf_Rel_Type type,
28107dc1947SRichard Lowe     int reltarget_length);
28249d3bc91SRichard Lowe typedef int (*_dwarf_pro_transform_relocs_func_ptr) (Dwarf_P_Debug dbg,
283*4d9fdb46SRobert Mustacchi     Dwarf_Signed *
284*4d9fdb46SRobert Mustacchi     new_sec_count);
28549d3bc91SRichard Lowe 
28649d3bc91SRichard Lowe /*
28707dc1947SRichard Lowe     Each slot in a block of slots could be:
28807dc1947SRichard Lowe     a binary stream relocation entry (32 or 64bit relocation data)
28907dc1947SRichard Lowe     a SYMBOLIC relocation entry.
29007dc1947SRichard Lowe     During creation sometimes we create multiple chained blocks,
29107dc1947SRichard Lowe     but sometimes we create a single long block.
292*4d9fdb46SRobert Mustacchi     Before returning reloc data to caller,
29307dc1947SRichard Lowe     we switch to a single, long-enough,
29407dc1947SRichard Lowe     block.
29507dc1947SRichard Lowe 
29607dc1947SRichard Lowe     We make counters here Dwarf_Unsigned so that we
29707dc1947SRichard Lowe     get sufficient alignment. Since we use space after
29807dc1947SRichard Lowe     the struct (at malloc time) for user data which
29907dc1947SRichard Lowe     must have Dwarf_Unsigned alignment, this
30007dc1947SRichard Lowe     struct must have that alignment too.
30149d3bc91SRichard Lowe */
30249d3bc91SRichard Lowe struct Dwarf_P_Relocation_Block_s {
303*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned rb_slots_in_block; /* slots in block, as created */
304*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned rb_next_slot_to_use; /* counter, start at 0. */
30549d3bc91SRichard Lowe     struct Dwarf_P_Relocation_Block_s *rb_next;
306*4d9fdb46SRobert Mustacchi     char *rb_where_to_add_next; /* pointer to next slot (might be past
307*4d9fdb46SRobert Mustacchi         end, depending on
308*4d9fdb46SRobert Mustacchi         rb_next_slot_to_use) */
309*4d9fdb46SRobert Mustacchi     char *rb_data; /* data area */
31049d3bc91SRichard Lowe };
31149d3bc91SRichard Lowe 
312*4d9fdb46SRobert Mustacchi /* One of these per potential relocation section
31349d3bc91SRichard Lowe    So one per actual dwarf section.
31449d3bc91SRichard Lowe    Left zeroed when not used (some sections have
31549d3bc91SRichard Lowe    no relocations).
31649d3bc91SRichard Lowe */
31749d3bc91SRichard Lowe struct Dwarf_P_Per_Reloc_Sect_s {
318*4d9fdb46SRobert Mustacchi     unsigned long pr_reloc_total_count; /* total number of entries
31907dc1947SRichard Lowe         across all blocks */
32049d3bc91SRichard Lowe 
321*4d9fdb46SRobert Mustacchi     unsigned long pr_slots_per_block_to_alloc; /* at Block alloc, this
32207dc1947SRichard Lowe         is the default number of slots to use */
32349d3bc91SRichard Lowe 
324*4d9fdb46SRobert Mustacchi     int pr_sect_num_of_reloc_sect; /* sect number returned by
325*4d9fdb46SRobert Mustacchi         de_callback_func() or de_callback_func_b() or_c()
326*4d9fdb46SRobert Mustacchi         call, this is the sect
32707dc1947SRichard Lowe         number of the relocation section. */
32849d3bc91SRichard Lowe 
32949d3bc91SRichard Lowe     /* singly-linked list. add at and ('last') with count of blocks */
33049d3bc91SRichard Lowe     struct Dwarf_P_Relocation_Block_s *pr_first_block;
33149d3bc91SRichard Lowe     struct Dwarf_P_Relocation_Block_s *pr_last_block;
33249d3bc91SRichard Lowe     unsigned long pr_block_count;
33349d3bc91SRichard Lowe };
33449d3bc91SRichard Lowe 
33549d3bc91SRichard Lowe #define DEFAULT_SLOTS_PER_BLOCK 3
33649d3bc91SRichard Lowe 
33707dc1947SRichard Lowe typedef struct memory_list_s {
33807dc1947SRichard Lowe   struct memory_list_s *prev;
33907dc1947SRichard Lowe   struct memory_list_s *next;
34007dc1947SRichard Lowe } memory_list_t;
34107dc1947SRichard Lowe 
34207dc1947SRichard Lowe struct Dwarf_P_Per_Sect_String_Attrs_s {
34307dc1947SRichard Lowe     int sect_sa_section_number;
34407dc1947SRichard Lowe     unsigned sect_sa_n_alloc;
34507dc1947SRichard Lowe     unsigned sect_sa_n_used;
34607dc1947SRichard Lowe     Dwarf_P_String_Attr sect_sa_list;
34707dc1947SRichard Lowe };
34849d3bc91SRichard Lowe 
349*4d9fdb46SRobert Mustacchi struct Dwarf_P_debug_str_entry_s {
350*4d9fdb46SRobert Mustacchi     Dwarf_P_Debug  dse_dbg;
351*4d9fdb46SRobert Mustacchi     /*  Name used initially with tfind. */
352*4d9fdb46SRobert Mustacchi     char *dse_name;
353*4d9fdb46SRobert Mustacchi 
354*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned dse_slen; /* includes space for NUL terminator */
355*4d9fdb46SRobert Mustacchi 
356*4d9fdb46SRobert Mustacchi     /*  See dse_has_table_offset below. */
357*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned dse_table_offset;
358*4d9fdb46SRobert Mustacchi 
359*4d9fdb46SRobert Mustacchi     /*  For tsearch a hash table exists and we have a table offset.
360*4d9fdb46SRobert Mustacchi         dse_dbg->de_debug_str->ds_data + dse_table_offset
361*4d9fdb46SRobert Mustacchi         points to the string iff dse_has_table_offset != 0. */
362*4d9fdb46SRobert Mustacchi     unsigned char  dse_has_table_offset;
363*4d9fdb46SRobert Mustacchi };
364*4d9fdb46SRobert Mustacchi 
365*4d9fdb46SRobert Mustacchi struct Dwarf_P_Str_stats_s {
366*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned ps_strp_count_debug_str;
367*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned ps_strp_len_debug_str;
368*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned ps_strp_len_debug_line_str;
369*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned ps_strp_reused_count;
370*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned ps_strp_reused_len;
371*4d9fdb46SRobert Mustacchi };
372*4d9fdb46SRobert Mustacchi 
373*4d9fdb46SRobert Mustacchi struct Dwarf_P_Stats_s {
374*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned ps_str_count;
375*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned ps_str_total_length;
376*4d9fdb46SRobert Mustacchi     struct Dwarf_P_Str_stats_s ps_strp;
377*4d9fdb46SRobert Mustacchi     struct Dwarf_P_Str_stats_s ps_line_strp;
378*4d9fdb46SRobert Mustacchi };
379*4d9fdb46SRobert Mustacchi 
38049d3bc91SRichard Lowe /* Fields used by producer */
38149d3bc91SRichard Lowe struct Dwarf_P_Debug_s {
382*4d9fdb46SRobert Mustacchi     /*  Used to catch dso passing dbg to another DSO with incompatible
383*4d9fdb46SRobert Mustacchi         version of libdwarf See PRO_VERSION_MAGIC */
38449d3bc91SRichard Lowe     int de_version_magic_number;
38549d3bc91SRichard Lowe 
38649d3bc91SRichard Lowe     Dwarf_Handler de_errhand;
387*4d9fdb46SRobert Mustacchi     /*  de_user_data is provided so users can use it to readily tie
388*4d9fdb46SRobert Mustacchi         a callback to anything they desire.  The contents are not
389*4d9fdb46SRobert Mustacchi         used by libdwarf except to pass the data as a callback
390*4d9fdb46SRobert Mustacchi         argument.  New in June 2011. Available in
391*4d9fdb46SRobert Mustacchi         dwarf_pro_init_c() and its callback function.  */
392*4d9fdb46SRobert Mustacchi     void *    de_user_data;
39349d3bc91SRichard Lowe     Dwarf_Ptr de_errarg;
39449d3bc91SRichard Lowe 
395*4d9fdb46SRobert Mustacchi     /*  Call back function, used to create .debug* sections. Provided
396*4d9fdb46SRobert Mustacchi         By user.  */
39707dc1947SRichard Lowe     Dwarf_Callback_Func de_callback_func;
39849d3bc91SRichard Lowe 
399*4d9fdb46SRobert Mustacchi     /*  Flags from producer_init call */
40049d3bc91SRichard Lowe     Dwarf_Unsigned de_flags;
40149d3bc91SRichard Lowe 
402*4d9fdb46SRobert Mustacchi     /*  This holds information on debug info section
403*4d9fdb46SRobert Mustacchi         stream output, including the stream data */
40449d3bc91SRichard Lowe     Dwarf_P_Section_Data de_debug_sects;
40549d3bc91SRichard Lowe 
406*4d9fdb46SRobert Mustacchi     /*  Defaults set as DW_FORM_string,
407*4d9fdb46SRobert Mustacchi         meaning not using .debug_str by default.
408*4d9fdb46SRobert Mustacchi         This intended for the .debug_info section. */
409*4d9fdb46SRobert Mustacchi     int de_debug_default_str_form;
410*4d9fdb46SRobert Mustacchi 
411*4d9fdb46SRobert Mustacchi     /* If form DW_FORM_strp */
412*4d9fdb46SRobert Mustacchi     Dwarf_P_Section_Data de_debug_str;
413*4d9fdb46SRobert Mustacchi     void *de_debug_str_hashtab; /* for tsearch */
414*4d9fdb46SRobert Mustacchi 
415*4d9fdb46SRobert Mustacchi     /* .debug_line_str section data if form DW_FORM_line_strp */
416*4d9fdb46SRobert Mustacchi     Dwarf_P_Section_Data de_debug_line_str;
417*4d9fdb46SRobert Mustacchi     void *de_debug_line_str_hashtab; /* for tsearch */
418*4d9fdb46SRobert Mustacchi 
419*4d9fdb46SRobert Mustacchi     /*  Pointer to the 'current active' section */
42049d3bc91SRichard Lowe     Dwarf_P_Section_Data de_current_active_section;
42149d3bc91SRichard Lowe 
422*4d9fdb46SRobert Mustacchi     /*  Number of debug data streams globs. */
423*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned de_n_debug_sect;
42449d3bc91SRichard Lowe 
425*4d9fdb46SRobert Mustacchi     /*  File entry information, null terminated singly-linked list */
42649d3bc91SRichard Lowe     Dwarf_P_F_Entry de_file_entries;
42749d3bc91SRichard Lowe     Dwarf_P_F_Entry de_last_file_entry;
42849d3bc91SRichard Lowe     Dwarf_Unsigned de_n_file_entries;
42949d3bc91SRichard Lowe 
430*4d9fdb46SRobert Mustacchi     /*  Has the directories used to search for source files */
431*4d9fdb46SRobert Mustacchi     Dwarf_P_F_Entry de_inc_dirs;
432*4d9fdb46SRobert Mustacchi     Dwarf_P_F_Entry de_last_inc_dir;
43349d3bc91SRichard Lowe     Dwarf_Unsigned de_n_inc_dirs;
43449d3bc91SRichard Lowe 
435*4d9fdb46SRobert Mustacchi     /*  Has all the line number info for the stmt program */
43649d3bc91SRichard Lowe     Dwarf_P_Line de_lines;
43749d3bc91SRichard Lowe     Dwarf_P_Line de_last_line;
43849d3bc91SRichard Lowe 
439*4d9fdb46SRobert Mustacchi     /*  List of cie's for the debug unit */
44049d3bc91SRichard Lowe     Dwarf_P_Cie de_frame_cies;
44149d3bc91SRichard Lowe     Dwarf_P_Cie de_last_cie;
44249d3bc91SRichard Lowe     Dwarf_Unsigned de_n_cie;
44349d3bc91SRichard Lowe 
44449d3bc91SRichard Lowe     /* Singly-linked list of fde's for the debug unit */
44549d3bc91SRichard Lowe     Dwarf_P_Fde de_frame_fdes;
44649d3bc91SRichard Lowe     Dwarf_P_Fde de_last_fde;
44749d3bc91SRichard Lowe     Dwarf_Unsigned de_n_fde;
44849d3bc91SRichard Lowe 
44949d3bc91SRichard Lowe     /* First die, leads to all others */
45049d3bc91SRichard Lowe     Dwarf_P_Die de_dies;
45149d3bc91SRichard Lowe 
45249d3bc91SRichard Lowe     /* Pointer to chain of aranges */
45349d3bc91SRichard Lowe     Dwarf_P_Arange de_arange;
45449d3bc91SRichard Lowe     Dwarf_P_Arange de_last_arange;
455*4d9fdb46SRobert Mustacchi     Dwarf_Signed de_arange_count;
456*4d9fdb46SRobert Mustacchi 
457*4d9fdb46SRobert Mustacchi     /*  debug_names  de_dnames is base of dnames info
458*4d9fdb46SRobert Mustacchi         before disk form */
459*4d9fdb46SRobert Mustacchi     Dwarf_P_Dnames de_dnames;
460*4d9fdb46SRobert Mustacchi     Dwarf_P_Section_Data de_dnames_sect;
46149d3bc91SRichard Lowe 
46249d3bc91SRichard Lowe     /* macinfo controls. */
46349d3bc91SRichard Lowe     /* first points to beginning of the list during creation */
46449d3bc91SRichard Lowe     struct dw_macinfo_block_s *de_first_macinfo;
46549d3bc91SRichard Lowe 
46649d3bc91SRichard Lowe     /* current points to the current, unfilled, block */
46749d3bc91SRichard Lowe     struct dw_macinfo_block_s *de_current_macinfo;
46849d3bc91SRichard Lowe 
46949d3bc91SRichard Lowe     /* Pointer to the first section, to support reset_section_bytes */
47049d3bc91SRichard Lowe     Dwarf_P_Section_Data de_first_debug_sect;
47149d3bc91SRichard Lowe 
472*4d9fdb46SRobert Mustacchi     /*  Handles pubnames, weaknames, etc. See dwarf_sn_kind in
473*4d9fdb46SRobert Mustacchi         pro_opaque.h */
47449d3bc91SRichard Lowe     struct Dwarf_P_Simple_name_header_s
475*4d9fdb46SRobert Mustacchi         de_simple_name_headers[dwarf_snk_entrycount];
47649d3bc91SRichard Lowe 
477*4d9fdb46SRobert Mustacchi     /*  Relocation data. not all sections will actally have relocation
478*4d9fdb46SRobert Mustacchi         info, of course.  de_reloc_sect, de_elf_sects, and de_sect_name_idx
479*4d9fdb46SRobert Mustacchi         arrays are exactly in parallel. Not every de_elf_sect has
480*4d9fdb46SRobert Mustacchi         any relocations for it, of course. */
48149d3bc91SRichard Lowe     struct Dwarf_P_Per_Reloc_Sect_s de_reloc_sect[NUM_DEBUG_SECTIONS];
482*4d9fdb46SRobert Mustacchi     int de_reloc_next_to_return; /* iterator on reloc sections
483*4d9fdb46SRobert Mustacchi         (SYMBOLIC output) */
48449d3bc91SRichard Lowe 
485*4d9fdb46SRobert Mustacchi     /*  Used in remembering sections. See de_reloc_sect above.  */
48607dc1947SRichard Lowe     int de_elf_sects[NUM_DEBUG_SECTIONS];  /* elf sect number of
48707dc1947SRichard Lowe         the section itself, DEBUG_LINE for example */
48849d3bc91SRichard Lowe 
489*4d9fdb46SRobert Mustacchi     /*  Section name index or handle for the name of the symbol for
49007dc1947SRichard Lowe         DEBUG_LINE for example */
491*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned de_sect_name_idx[NUM_DEBUG_SECTIONS];
492*4d9fdb46SRobert Mustacchi 
493*4d9fdb46SRobert Mustacchi     int de_offset_reloc; /* offset reloc type, R_MIPS_32 for
494*4d9fdb46SRobert Mustacchi         example. Specific to the ABI being
495*4d9fdb46SRobert Mustacchi         produced. Relocates offset size
496*4d9fdb46SRobert Mustacchi         field */
497*4d9fdb46SRobert Mustacchi     int de_exc_reloc; /* reloc type specific to exception
498*4d9fdb46SRobert Mustacchi         table relocs. */
499*4d9fdb46SRobert Mustacchi     int de_ptr_reloc;  /* standard reloc type, R_MIPS_32 for
500*4d9fdb46SRobert Mustacchi         example. Specific to the ABI being
501*4d9fdb46SRobert Mustacchi         produced. relocates pointer size
502*4d9fdb46SRobert Mustacchi         field */
503*4d9fdb46SRobert Mustacchi     unsigned char de_irix_exc_augmentation; /* If non-zero means
504*4d9fdb46SRobert Mustacchi         that producing an IRIX exception-table offset in a CIE header
505*4d9fdb46SRobert Mustacchi         is allowed (depending on the augmentation string). */
506*4d9fdb46SRobert Mustacchi 
507*4d9fdb46SRobert Mustacchi     unsigned char de_dwarf_offset_size; /* dwarf  offset size. */
508*4d9fdb46SRobert Mustacchi     unsigned char de_elf_offset_size;  /* object section offset size. */
509*4d9fdb46SRobert Mustacchi     unsigned char de_pointer_size; /* size of address in target. */
510*4d9fdb46SRobert Mustacchi 
511*4d9fdb46SRobert Mustacchi     /*  Added April 19, 2017.  For DWARF5 */
512*4d9fdb46SRobert Mustacchi     unsigned char de_segment_selector_size;
513*4d9fdb46SRobert Mustacchi 
514*4d9fdb46SRobert Mustacchi     unsigned char de_relocation_record_size; /* reloc record size
515*4d9fdb46SRobert Mustacchi         varies by ABI and
516*4d9fdb46SRobert Mustacchi         relocation-output
517*4d9fdb46SRobert Mustacchi         method (stream or
518*4d9fdb46SRobert Mustacchi         symbolic) */
519*4d9fdb46SRobert Mustacchi 
520*4d9fdb46SRobert Mustacchi     unsigned char de_64bit_extension;/* non-zero if creating 64 bit
521*4d9fdb46SRobert Mustacchi         offsets using dwarf2-99
522*4d9fdb46SRobert Mustacchi         extension proposal */
523*4d9fdb46SRobert Mustacchi 
524*4d9fdb46SRobert Mustacchi     unsigned char de_output_version; /* 2,3,4, or 5. The version number
525*4d9fdb46SRobert Mustacchi         of the output. (not necessarily that of each section,
526*4d9fdb46SRobert Mustacchi         which depends on the base version). */
527*4d9fdb46SRobert Mustacchi 
528*4d9fdb46SRobert Mustacchi     /*  Defaults will be mostly useless, but such do exist */
529*4d9fdb46SRobert Mustacchi     unsigned       de_big_endian; /* if 0 target is little-endian */
530*4d9fdb46SRobert Mustacchi 
531*4d9fdb46SRobert Mustacchi     int de_ar_data_attribute_form; /* data8, data4 abi &version dependent */
532*4d9fdb46SRobert Mustacchi     int de_ar_ref_attr_form; /* ref8 ref4 , abi dependent */
53349d3bc91SRichard Lowe 
53449d3bc91SRichard Lowe     /* simple name relocations */
535*4d9fdb46SRobert Mustacchi     _dwarf_pro_reloc_name_func_ptr de_relocate_by_name_symbol;
53649d3bc91SRichard Lowe 
53749d3bc91SRichard Lowe     /* relocations for a length, requiring a pair of symbols */
538*4d9fdb46SRobert Mustacchi     _dwarf_pro_reloc_length_func_ptr de_relocate_pair_by_symbol;
53949d3bc91SRichard Lowe 
54049d3bc91SRichard Lowe     _dwarf_pro_transform_relocs_func_ptr de_transform_relocs_to_disk;
54149d3bc91SRichard Lowe 
54249d3bc91SRichard Lowe     /* following used for macro buffers */
54349d3bc91SRichard Lowe     unsigned long de_compose_avail;
54449d3bc91SRichard Lowe     unsigned long de_compose_used_len;
54549d3bc91SRichard Lowe 
54649d3bc91SRichard Lowe     unsigned char de_same_endian;
547*4d9fdb46SRobert Mustacchi     void (*de_copy_word) (void *, const void *, unsigned long);
54849d3bc91SRichard Lowe 
549*4d9fdb46SRobert Mustacchi     /*  Add new fields at the END of this struct to preserve some hope
550*4d9fdb46SRobert Mustacchi         of sensible behavior on dbg passing between DSOs linked with
551*4d9fdb46SRobert Mustacchi         mismatched libdwarf producer versions. */
55249d3bc91SRichard Lowe 
55307dc1947SRichard Lowe     Dwarf_P_Marker de_markers;  /* pointer to array of markers */
55407dc1947SRichard Lowe     unsigned de_marker_n_alloc;
55507dc1947SRichard Lowe     unsigned de_marker_n_used;
55607dc1947SRichard Lowe     int de_sect_sa_next_to_return;  /* Iterator on sring attrib sects */
55707dc1947SRichard Lowe     /* String attributes data of each section. */
55807dc1947SRichard Lowe     struct Dwarf_P_Per_Sect_String_Attrs_s de_sect_string_attr[NUM_DEBUG_SECTIONS];
559*4d9fdb46SRobert Mustacchi 
560*4d9fdb46SRobert Mustacchi     /* Hold data needed to init line output flexibly. */
561*4d9fdb46SRobert Mustacchi     struct Dwarf_P_Line_Inits_s de_line_inits;
562*4d9fdb46SRobert Mustacchi 
563*4d9fdb46SRobert Mustacchi     struct Dwarf_P_Stats_s de_stats;
56449d3bc91SRichard Lowe };
56549d3bc91SRichard Lowe 
566*4d9fdb46SRobert Mustacchi #define CURRENT_VERSION_STAMP   2
56749d3bc91SRichard Lowe 
568*4d9fdb46SRobert Mustacchi int _dwarf_add_simple_name_entry(Dwarf_P_Debug dbg,
569*4d9fdb46SRobert Mustacchi     Dwarf_P_Die die,
570*4d9fdb46SRobert Mustacchi     char *entry_name,
571*4d9fdb46SRobert Mustacchi     enum dwarf_sn_kind
572*4d9fdb46SRobert Mustacchi     entrykind,
573*4d9fdb46SRobert Mustacchi     Dwarf_Error * error);
57449d3bc91SRichard Lowe 
575*4d9fdb46SRobert Mustacchi enum dwarf_which_hash {
576*4d9fdb46SRobert Mustacchi     _dwarf_hash_debug_str,
577*4d9fdb46SRobert Mustacchi     _dwarf_hash_debug_line_str,
578*4d9fdb46SRobert Mustacchi     _dwarf_hash_debug_str_sup
579*4d9fdb46SRobert Mustacchi };
58049d3bc91SRichard Lowe 
581*4d9fdb46SRobert Mustacchi int
582*4d9fdb46SRobert Mustacchi _dwarf_insert_or_find_in_debug_str(Dwarf_P_Debug dbg,
583*4d9fdb46SRobert Mustacchi     char *name,
584*4d9fdb46SRobert Mustacchi     enum  dwarf_which_hash,
585*4d9fdb46SRobert Mustacchi     unsigned slen, /* includes space for trailing NUL */
586*4d9fdb46SRobert Mustacchi     Dwarf_Unsigned *offset_in_debug_str,
587*4d9fdb46SRobert Mustacchi     Dwarf_Error *error);
588*4d9fdb46SRobert Mustacchi 
589*4d9fdb46SRobert Mustacchi int _dwarf_log_extra_flagstrings(Dwarf_P_Debug dbg,
590*4d9fdb46SRobert Mustacchi   const char *extra,
591*4d9fdb46SRobert Mustacchi   int *err);
592