xref: /titanic_44/usr/src/tools/ctf/dwarf/common/dwarf_opaque.h (revision f05d7fc81533be643136e12ce92516d1d4292921)
1 /*
2 
3   Copyright (C) 2000,2002,2003 Silicon Graphics, Inc.  All Rights Reserved.
4 
5   This program is free software; you can redistribute it and/or modify it
6   under the terms of version 2.1 of the GNU Lesser General Public License
7   as published by the Free Software Foundation.
8 
9   This program is distributed in the hope that it would be useful, but
10   WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13   Further, this software is distributed without any warranty that it is
14   free of the rightful claim of any third person regarding infringement
15   or the like.  Any license provided herein, whether implied or
16   otherwise, applies only to this software file.  Patent licenses, if
17   any, provided herein do not apply to combinations of this program with
18   other software, or any other product whatsoever.
19 
20   You should have received a copy of the GNU Lesser General Public
21   License along with this program; if not, write the Free Software
22   Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307,
23   USA.
24 
25   Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pky,
26   Mountain View, CA 94043, or:
27 
28   http://www.sgi.com
29 
30   For further information regarding this notice, see:
31 
32   http://oss.sgi.com/projects/GenInfo/NoticeExplan
33 
34 */
35 
36 #include <stddef.h>
37 
38 
39 struct Dwarf_Die_s {
40     /*
41        Points to the start of the portion corresponding to this Die in
42        the .debug_info section. */
43     Dwarf_Byte_Ptr di_debug_info_ptr;
44 
45     Dwarf_Abbrev_List di_abbrev_list;
46 
47     /* Points to cu context for this die.  */
48     Dwarf_CU_Context di_cu_context;
49 };
50 
51 struct Dwarf_Attribute_s {
52     Dwarf_Half ar_attribute;	/* Attribute Value. */
53     Dwarf_Half ar_attribute_form;	/* Attribute Form. */
54     Dwarf_Half ar_attribute_form_direct;
55 	        /* Identical to ar_attribute_form except that if
56 		the original form uleb was DW_FORM_indirect,
57 		ar_attribute_form_direct contains DW_FORM_indirect
58 		but ar_attribute_form contains the true form. */
59 
60     Dwarf_CU_Context ar_cu_context;
61     Dwarf_Small *ar_debug_info_ptr;
62     Dwarf_Attribute ar_next;
63 };
64 
65 /*
66     This structure provides the context for a compilation unit.
67     Thus, it contains the Dwarf_Debug, cc_dbg, that this cu
68     belongs to.  It contains the information in the compilation
69     unit header, cc_length, cc_version_stamp, cc_abbrev_offset,
70     and cc_address_size, in the .debug_info section for that cu.
71     In addition, it contains the count, cc_count_cu, of the cu
72     number of that cu in the list of cu's in the .debug_info.
73     The count starts at 1, ie cc_count_cu is 1 for the first cu,
74     2 for the second and so on.  This struct also contains a
75     pointer, cc_abbrev_table, to a list of pairs of abbrev code
76     and a pointer to the start of that abbrev
77     in the .debug_abbrev section.
78 
79     Each die will also contain a pointer to such a struct to
80     record the context for that die.
81 
82     **Updated by dwarf_next_cu_header in dwarf_die_deliv.c
83 */
84 struct Dwarf_CU_Context_s {
85     Dwarf_Debug cc_dbg;
86     Dwarf_Word cc_length;
87     Dwarf_Small cc_length_size;
88     Dwarf_Small cc_extension_size;
89     Dwarf_Half cc_version_stamp;
90     Dwarf_Sword cc_abbrev_offset;
91     Dwarf_Small cc_address_size;
92     Dwarf_Word cc_debug_info_offset;
93     Dwarf_Byte_Ptr cc_last_abbrev_ptr;
94     Dwarf_Hash_Table cc_abbrev_hash_table;
95     Dwarf_CU_Context cc_next;
96     unsigned char cc_offset_length;
97 };
98 
99 
100 struct Dwarf_Debug_s {
101     dwarf_elf_handle de_elf; /* see de_elf_must_close at end of struct */
102     unsigned int de_nelfsecs;
103 
104     Dwarf_Unsigned de_access;
105     Dwarf_Handler de_errhand;
106     Dwarf_Ptr de_errarg;
107 
108     /*
109        Context for the compilation_unit just read by a call to
110        dwarf_next_cu_header. **Updated by dwarf_next_cu_header in
111        dwarf_die_deliv.c */
112     Dwarf_CU_Context de_cu_context;
113 
114     /*
115        Points to linked list of CU Contexts for the CU's already read.
116        These are only CU's read by dwarf_next_cu_header(). */
117     Dwarf_CU_Context de_cu_context_list;
118 
119     /*
120        Points to the last CU Context added to the list by
121        dwarf_next_cu_header(). */
122     Dwarf_CU_Context de_cu_context_list_end;
123 
124     /*
125        This is the list of CU contexts read for dwarf_offdie().  These
126        may read ahead of dwarf_next_cu_header(). */
127     Dwarf_CU_Context de_offdie_cu_context;
128     Dwarf_CU_Context de_offdie_cu_context_end;
129 
130     /* Offset of last byte of last CU read. */
131     Dwarf_Word de_info_last_offset;
132 
133     /*
134        Number of bytes in the length, and offset field in various
135        .debug_* sections.  It's not very meaningful, and is
136        only used in one 'approximate' calculation.  */
137     Dwarf_Small de_length_size;
138 
139     /* number of bytes in a pointer of the target in various .debug_
140        sections. 4 in 32bit, 8 in MIPS 64, ia64. */
141     Dwarf_Small de_pointer_size;
142 
143     /* set at creation of a Dwarf_Debug to say if form_string should be
144        checked for valid length at every call. 0 means do the check.
145        non-zero means do not do the check. */
146     Dwarf_Small de_assume_string_in_bounds;
147 
148     /*
149        Dwarf_Alloc_Hdr_s structs used to manage chunks that are
150        malloc'ed for each allocation type for structs. */
151     struct Dwarf_Alloc_Hdr_s de_alloc_hdr[ALLOC_AREA_REAL_TABLE_MAX];
152 #ifdef DWARF_SIMPLE_MALLOC
153     struct simple_malloc_record_s *  de_simple_malloc_base;
154     struct simple_malloc_record_s *  de_simple_malloc_current;
155 #endif
156 
157 
158     /*
159        These fields are used to process debug_frame section.  **Updated
160        by dwarf_get_fde_list in dwarf_frame.h */
161     /*
162        Points to contiguous block of pointers to Dwarf_Cie_s structs. */
163     Dwarf_Cie *de_cie_data;
164     /* Count of number of Dwarf_Cie_s structs. */
165     Dwarf_Signed de_cie_count;
166     /*
167        Points to contiguous block of pointers to Dwarf_Fde_s structs. */
168     Dwarf_Fde *de_fde_data;
169     /* Count of number of Dwarf_Fde_s structs. */
170     Dwarf_Signed de_fde_count;
171 
172     Dwarf_Small *de_debug_info;
173     Dwarf_Small *de_debug_abbrev;
174     Dwarf_Small *de_debug_line;
175     Dwarf_Small *de_debug_loc;
176     Dwarf_Small *de_debug_aranges;
177     Dwarf_Small *de_debug_macinfo;
178     Dwarf_Small *de_debug_pubnames;
179     Dwarf_Small *de_debug_str;
180     Dwarf_Small *de_debug_frame;
181     Dwarf_Small *de_debug_frame_eh_gnu;	/* gnu for the g++ eh_frame
182 					   section */
183 
184     Dwarf_Small *de_debug_funcnames;
185     Dwarf_Small *de_debug_typenames;
186     Dwarf_Small *de_debug_varnames;
187     Dwarf_Small *de_debug_weaknames;
188 
189     Dwarf_Unsigned de_debug_info_size;
190     Dwarf_Unsigned de_debug_abbrev_size;
191     Dwarf_Unsigned de_debug_line_size;
192     Dwarf_Unsigned de_debug_loc_size;
193     Dwarf_Unsigned de_debug_aranges_size;
194     Dwarf_Unsigned de_debug_macinfo_size;
195     Dwarf_Unsigned de_debug_pubnames_size;
196     Dwarf_Unsigned de_debug_str_size;
197 
198 
199     Dwarf_Unsigned de_debug_frame_size;
200 
201     Dwarf_Unsigned de_debug_frame_size_eh_gnu;	/* gnu for the g++
202 					   eh_frame section */
203 
204     Dwarf_Unsigned de_debug_funcnames_size;
205     Dwarf_Unsigned de_debug_typenames_size;
206     Dwarf_Unsigned de_debug_varnames_size;
207     Dwarf_Unsigned de_debug_weaknames_size;
208 
209     void *(*de_copy_word) (void *, const void *, size_t);
210     unsigned char de_same_endian;
211     unsigned char de_elf_must_close; /* if non-zero, then
212 	it was dwarf_init (not dwarf_elf_init)
213 	so must elf_end() */
214 
215     /*
216        The following are used for storing section indicies.
217 
218        After a Dwarf_Debug is initialized, a zero for any of
219        these indicies indicates an absent section.
220 
221        If the ELF spec is ever changed to permit 32-bit section
222        indicies, these will need to be changed.
223      */
224     Dwarf_Half de_debug_aranges_index;
225     Dwarf_Half de_debug_line_index;
226     Dwarf_Half de_debug_loc_index;
227     Dwarf_Half de_debug_macinfo_index;
228     Dwarf_Half de_debug_pubnames_index;
229     Dwarf_Half de_debug_funcnames_index;
230     Dwarf_Half de_debug_typenames_index;
231     Dwarf_Half de_debug_varnames_index;
232     Dwarf_Half de_debug_weaknames_index;
233     Dwarf_Half de_debug_frame_index;
234     Dwarf_Half de_debug_frame_eh_gnu_index;
235     Dwarf_Half de_debug_str_index;
236     Dwarf_Half de_debug_info_index;
237     Dwarf_Half de_debug_abbrev_index;
238     unsigned char de_big_endian_object; /* non-zero if big-endian
239 		object opened. */
240 };
241 
242 typedef struct Dwarf_Chain_s *Dwarf_Chain;
243 struct Dwarf_Chain_s {
244     void *ch_item;
245     Dwarf_Chain ch_next;
246 };
247 
248 #define CURRENT_VERSION_STAMP		2
249 
250     /* Size of cu header version stamp field. */
251 #define CU_VERSION_STAMP_SIZE   sizeof(Dwarf_Half)
252 
253     /* Size of cu header address size field. */
254 #define CU_ADDRESS_SIZE_SIZE	sizeof(Dwarf_Small)
255 
256 void *_dwarf_memcpy_swap_bytes(void *s1, const void *s2, size_t len);
257 
258 #define ORIGINAL_DWARF_OFFSET_SIZE  4
259 #define DISTINGUISHED_VALUE  0xffffffff
260 #define DISTINGUISHED_VALUE_OFFSET_SIZE 8
261 
262 /*
263     We don't load the sections until they are needed. This function is
264     used to load the section.
265  */
266 int _dwarf_load_section(Dwarf_Debug,
267 		        Dwarf_Half,
268 			Dwarf_Small **,
269 			Dwarf_Error *);
270