3 Copyright (C) 2000,2002,2004 Silicon Graphics, Inc. All Rights Reserved.
4 Portions Copyright 2002-2010 Sun Microsystems, Inc. All rights reserved.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of version 2.1 of the GNU Lesser General Public License
8 as published by the Free Software Foundation.
10 This program is distributed in the hope that it would be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 Further, this software is distributed without any warranty that it is
15 free of the rightful claim of any third person regarding infringement
16 or the like. Any license provided herein, whether implied or
17 otherwise, applies only to this software file. Patent licenses, if
18 any, provided herein do not apply to combinations of this program with
19 other software, or any other product whatsoever.
21 You should have received a copy of the GNU Lesser General Public
22 License along with this program; if not, write the Free Software
23 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
26 Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane,
27 Mountain View, CA 94043, or:
31 For further information regarding this notice, see:
33 http://oss.sgi.com/projects/GenInfo/NoticeExplan
41 Sgidefs included to define __uint32_t,
42 a guaranteed 4-byte quantity.
44 #include "libdwarfdefs.h"
49 /* to identify a cie */
50 #define DW_CIE_ID ~(0x0)
51 #define DW_CIE_VERSION 1
53 /*Dwarf_Word is unsigned word usable for index, count in memory */
54 /*Dwarf_Sword is signed word usable for index, count in memory */
55 /* The are 32 or 64 bits depending if 64 bit longs or not, which
56 ** fits the ILP32 and LP64 models
57 ** These work equally well with ILP64.
60 typedef unsigned long Dwarf_Word
;
61 typedef long Dwarf_Sword
;
64 typedef signed char Dwarf_Sbyte
;
65 typedef unsigned char Dwarf_Ubyte
;
66 typedef signed short Dwarf_Shalf
;
69 On any change that makes libdwarf producer
70 incompatible, increment this number.
74 #define PRO_VERSION_MAGIC 0xdead1
77 /* these 2 are fixed sizes which must not vary with the
78 ** ILP32/LP64 model. These two stay at 32 bit.
80 typedef __uint32_t Dwarf_ufixed
;
81 typedef __int32_t Dwarf_sfixed
;
85 This struct is used to hold information about all
86 debug* sections. On creating a new section, section
87 names and indices are added to this struct
88 definition in pro_section.h
90 typedef struct Dwarf_P_Section_Data_s
*Dwarf_P_Section_Data
;
94 This struct is used to hold entries in the include directories
95 part of statement prologue. Definition in pro_line.h
97 typedef struct Dwarf_P_Inc_Dir_s
*Dwarf_P_Inc_Dir
;
101 This struct holds file entries for the statement prologue.
102 Defined in pro_line.h
104 typedef struct Dwarf_P_F_Entry_s
*Dwarf_P_F_Entry
;
108 This struct holds information for each cie. Defn in pro_frame.h
110 typedef struct Dwarf_P_Cie_s
*Dwarf_P_Cie
;
114 Struct to hold line number information, different from
115 Dwarf_Line opaque type.
117 typedef struct Dwarf_P_Line_s
*Dwarf_P_Line
;
121 Struct to hold information about address ranges.
123 typedef struct Dwarf_P_Simple_nameentry_s
*Dwarf_P_Simple_nameentry
;
124 typedef struct Dwarf_P_Simple_name_header_s
*Dwarf_P_Simple_name_header
;
125 typedef struct Dwarf_P_Arange_s
*Dwarf_P_Arange
;
126 typedef struct Dwarf_P_Per_Reloc_Sect_s
*Dwarf_P_Per_Reloc_Sect
;
127 typedef struct Dwarf_P_Per_Sect_String_Attrs_s
*Dwarf_P_Per_Sect_String_Attrs
;
129 /* Defined to get at the elf section numbers and section name
130 indices in symtab for the dwarf sections
131 Must match .rel.* names in _dwarf_rel_section_names
136 #define DEBUG_ABBREV 2
137 #define DEBUG_FRAME 3
138 #define DEBUG_ARANGES 4
139 #define DEBUG_PUBNAMES 5
141 #define DEBUG_FUNCNAMES 7
142 #define DEBUG_TYPENAMES 8
143 #define DEBUG_VARNAMES 9
144 #define DEBUG_WEAKNAMES 10
145 #define DEBUG_MACINFO 11
148 /* number of debug_* sections not including the relocations */
149 #define NUM_DEBUG_SECTIONS DEBUG_LOC + 1
152 struct Dwarf_P_Die_s
{
153 Dwarf_Unsigned di_offset
; /* offset in debug info */
154 char *di_abbrev
; /* abbreviation */
155 Dwarf_Word di_abbrev_nbytes
; /* # of bytes in abbrev */
157 Dwarf_P_Die di_parent
; /* parent of current die */
158 Dwarf_P_Die di_child
; /* first child */
159 /* The last child field makes linking up children an O(1) operation,
161 Dwarf_P_Die di_last_child
;
162 Dwarf_P_Die di_left
; /* left sibling */
163 Dwarf_P_Die di_right
; /* right sibling */
164 Dwarf_P_Attribute di_attrs
; /* list of attributes */
165 Dwarf_P_Attribute di_last_attr
; /* last attribute */
166 int di_n_attr
; /* number of attributes */
167 Dwarf_P_Debug di_dbg
; /* For memory management */
168 Dwarf_Unsigned di_marker
; /* used to attach symbols to dies */
172 /* producer fields */
173 struct Dwarf_P_Attribute_s
{
174 Dwarf_Half ar_attribute
; /* Attribute Value. */
175 Dwarf_Half ar_attribute_form
; /* Attribute Form. */
176 Dwarf_P_Die ar_ref_die
; /* die pointer if form ref */
177 char *ar_data
; /* data, format given by form */
178 Dwarf_Unsigned ar_nbytes
; /* no. of bytes of data */
179 Dwarf_Unsigned ar_rel_symidx
; /* when attribute has a
180 relocatable value, holds
181 index of symbol in SYMTAB */
182 Dwarf_Ubyte ar_rel_type
; /* relocation type */
183 Dwarf_Word ar_rel_offset
; /* Offset of relocation within block */
184 char ar_reloc_len
; /* Number of bytes that relocation
185 applies to. 4 or 8. Unused and may
186 be 0 if if ar_rel_type is
188 Dwarf_P_Attribute ar_next
;
191 /* A block of .debug_macinfo data: this forms a series of blocks.
192 ** Each macinfo input is compressed immediately and put into
193 ** the current block if room, else a newblock allocated.
194 ** The space allocation is such that the block and the macinfo
195 ** data are one malloc block: free with a pointer to this and the
196 ** mb_data is freed automatically.
197 ** Like the struct hack, but legal ANSI C.
199 struct dw_macinfo_block_s
{
200 struct dw_macinfo_block_s
*mb_next
;
201 unsigned long mb_avail_len
;
202 unsigned long mb_used_len
;
203 unsigned long mb_macinfo_data_space_len
;
204 char *mb_data
; /* original malloc ptr. */
207 /* dwarf_sn_kind is for the array of similarly-treated
210 enum dwarf_sn_kind
{ dwarf_snk_pubname
, dwarf_snk_funcname
,
211 dwarf_snk_weakname
, dwarf_snk_typename
,
213 dwarf_snk_entrycount
/* this one must be last */
218 /* The calls to add a varname etc use a list of
221 struct Dwarf_P_Simple_nameentry_s
{
225 Dwarf_P_Simple_nameentry sne_next
;
228 /* An array of these, each of which heads a list
229 of Dwarf_P_Simple_nameentry
231 struct Dwarf_P_Simple_name_header_s
{
232 Dwarf_P_Simple_nameentry sn_head
;
233 Dwarf_P_Simple_nameentry sn_tail
;
234 Dwarf_Signed sn_count
;
236 /* length that will be generated, not counting fixed header or
238 Dwarf_Signed sn_net_len
;
240 typedef int (*_dwarf_pro_reloc_name_func_ptr
) (Dwarf_P_Debug dbg
,
242 Dwarf_Unsigned offset
,/* r_offset */
243 Dwarf_Unsigned symidx
,
244 enum Dwarf_Rel_Type type
,
245 int reltarget_length
);
247 typedef int (*_dwarf_pro_reloc_length_func_ptr
) (Dwarf_P_Debug dbg
,
248 int sec_index
, Dwarf_Unsigned offset
,/* r_offset */
249 Dwarf_Unsigned start_symidx
,
250 Dwarf_Unsigned end_symidx
,
251 enum Dwarf_Rel_Type type
,
252 int reltarget_length
);
253 typedef int (*_dwarf_pro_transform_relocs_func_ptr
) (Dwarf_P_Debug dbg
,
258 Each slot in a block of slots could be:
259 a binary stream relocation entry (32 or 64bit relocation data)
260 a SYMBOLIC relocation entry.
261 During creation sometimes we create multiple chained blocks,
262 but sometimes we create a single long block.
263 Before returning reloc data to caller,
264 we switch to a single, long-enough,
267 We make counters here Dwarf_Unsigned so that we
268 get sufficient alignment. Since we use space after
269 the struct (at malloc time) for user data which
270 must have Dwarf_Unsigned alignment, this
271 struct must have that alignment too.
273 struct Dwarf_P_Relocation_Block_s
{
274 Dwarf_Unsigned rb_slots_in_block
; /* slots in block, as created */
275 Dwarf_Unsigned rb_next_slot_to_use
; /* counter, start at 0. */
276 struct Dwarf_P_Relocation_Block_s
*rb_next
;
277 char *rb_where_to_add_next
; /* pointer to next slot (might be past
279 rb_next_slot_to_use) */
280 char *rb_data
; /* data area */
283 /* One of these per potential relocation section
284 So one per actual dwarf section.
285 Left zeroed when not used (some sections have
288 struct Dwarf_P_Per_Reloc_Sect_s
{
289 unsigned long pr_reloc_total_count
; /* total number of entries
292 unsigned long pr_slots_per_block_to_alloc
; /* at Block alloc, this
293 is the default number of slots to use */
295 int pr_sect_num_of_reloc_sect
; /* sect number returned by
296 de_callback_func() or de_callback_func_b() call, this is the sect
297 number of the relocation section. */
299 /* singly-linked list. add at and ('last') with count of blocks */
300 struct Dwarf_P_Relocation_Block_s
*pr_first_block
;
301 struct Dwarf_P_Relocation_Block_s
*pr_last_block
;
302 unsigned long pr_block_count
;
305 #define DEFAULT_SLOTS_PER_BLOCK 3
307 typedef struct memory_list_s
{
308 struct memory_list_s
*prev
;
309 struct memory_list_s
*next
;
312 struct Dwarf_P_Per_Sect_String_Attrs_s
{
313 int sect_sa_section_number
;
314 unsigned sect_sa_n_alloc
;
315 unsigned sect_sa_n_used
;
316 Dwarf_P_String_Attr sect_sa_list
;
319 /* Fields used by producer */
320 struct Dwarf_P_Debug_s
{
321 /* used to catch dso passing dbg to another DSO with incompatible
322 version of libdwarf See PRO_VERSION_MAGIC */
323 int de_version_magic_number
;
325 Dwarf_Handler de_errhand
;
328 /* Call back function, used to create .debug* sections. Provided
329 by user. Only of these used per dbg. */
330 Dwarf_Callback_Func de_callback_func
;
331 Dwarf_Callback_Func_b de_callback_func_b
;
333 /* Flags from producer_init call */
334 Dwarf_Unsigned de_flags
;
336 /* This holds information on debug section stream output, including
338 Dwarf_P_Section_Data de_debug_sects
;
340 /* Pointer to the 'current active' section */
341 Dwarf_P_Section_Data de_current_active_section
;
343 /* Number of debug data streams globs. */
344 Dwarf_Word de_n_debug_sect
;
346 /* File entry information, null terminated singly-linked list */
347 Dwarf_P_F_Entry de_file_entries
;
348 Dwarf_P_F_Entry de_last_file_entry
;
349 Dwarf_Unsigned de_n_file_entries
;
351 /* Has the directories used to search for source files */
352 Dwarf_P_Inc_Dir de_inc_dirs
;
353 Dwarf_P_Inc_Dir de_last_inc_dir
;
354 Dwarf_Unsigned de_n_inc_dirs
;
356 /* Has all the line number info for the stmt program */
357 Dwarf_P_Line de_lines
;
358 Dwarf_P_Line de_last_line
;
360 /* List of cie's for the debug unit */
361 Dwarf_P_Cie de_frame_cies
;
362 Dwarf_P_Cie de_last_cie
;
363 Dwarf_Unsigned de_n_cie
;
365 /* Singly-linked list of fde's for the debug unit */
366 Dwarf_P_Fde de_frame_fdes
;
367 Dwarf_P_Fde de_last_fde
;
368 Dwarf_Unsigned de_n_fde
;
370 /* First die, leads to all others */
373 /* Pointer to list of strings */
376 /* Pointer to chain of aranges */
377 Dwarf_P_Arange de_arange
;
378 Dwarf_P_Arange de_last_arange
;
379 Dwarf_Sword de_arange_count
;
381 /* macinfo controls. */
382 /* first points to beginning of the list during creation */
383 struct dw_macinfo_block_s
*de_first_macinfo
;
385 /* current points to the current, unfilled, block */
386 struct dw_macinfo_block_s
*de_current_macinfo
;
388 /* Pointer to the first section, to support reset_section_bytes */
389 Dwarf_P_Section_Data de_first_debug_sect
;
391 /* handles pubnames, weaknames, etc. See dwarf_sn_kind in
393 struct Dwarf_P_Simple_name_header_s
394 de_simple_name_headers
[dwarf_snk_entrycount
];
396 /* relocation data. not all sections will actally have relocation
398 struct Dwarf_P_Per_Reloc_Sect_s de_reloc_sect
[NUM_DEBUG_SECTIONS
];
399 int de_reloc_next_to_return
; /* iterator on reloc sections
402 /* used in remembering sections */
403 int de_elf_sects
[NUM_DEBUG_SECTIONS
]; /* elf sect number of
404 the section itself, DEBUG_LINE for example */
406 Dwarf_Unsigned de_sect_name_idx
[NUM_DEBUG_SECTIONS
]; /* section
407 name index or handle for the name of the symbol for
408 DEBUG_LINE for example */
410 int de_offset_reloc
; /* offset reloc type, R_MIPS_32 for
411 example. Specific to the ABI being
412 produced. Relocates offset size
414 int de_exc_reloc
; /* reloc type specific to exception
416 int de_ptr_reloc
; /* standard reloc type, R_MIPS_32 for
417 example. Specific to the ABI being
418 produced. relocates pointer size
421 unsigned char de_offset_size
; /* section offset. Here to
422 avoid test of abi in macro
423 at run time MIPS -n32 4,
426 unsigned char de_pointer_size
; /* size of pointer in target.
427 Here to avoid test of abi in
428 macro at run time MIPS -n32
431 unsigned char de_is_64bit
; /* non-zero if is 64bit. Else 32 bit:
432 used for passing this info as a flag
434 unsigned char de_relocation_record_size
; /* reloc record size
440 unsigned char de_64bit_extension
; /* non-zero if creating 64 bit
441 offsets using dwarf2-99
442 extension proposal */
444 int de_ar_data_attribute_form
; /* data8, data4 abi dependent */
445 int de_ar_ref_attr_form
; /* ref8 ref4 , abi dependent */
447 /* simple name relocations */
448 _dwarf_pro_reloc_name_func_ptr de_reloc_name
;
450 /* relocations for a length, requiring a pair of symbols */
451 _dwarf_pro_reloc_length_func_ptr de_reloc_pair
;
453 _dwarf_pro_transform_relocs_func_ptr de_transform_relocs_to_disk
;
455 /* following used for macro buffers */
456 unsigned long de_compose_avail
;
457 unsigned long de_compose_used_len
;
459 unsigned char de_same_endian
;
460 void *(*de_copy_word
) (void *, const void *, size_t);
462 /* Add new fields at the END of this struct to preserve some hope
463 of sensible behavior on dbg passing between DSOs linked with
464 mismatched libdwarf producer versions. */
466 Dwarf_P_Marker de_markers
; /* pointer to array of markers */
467 unsigned de_marker_n_alloc
;
468 unsigned de_marker_n_used
;
469 int de_sect_sa_next_to_return
; /* Iterator on sring attrib sects */
470 /* String attributes data of each section. */
471 struct Dwarf_P_Per_Sect_String_Attrs_s de_sect_string_attr
[NUM_DEBUG_SECTIONS
];
474 #define CURRENT_VERSION_STAMP 2
476 Dwarf_Unsigned
_dwarf_add_simple_name_entry(Dwarf_P_Debug dbg
,
481 Dwarf_Error
* error
);
484 #define DISTINGUISHED_VALUE 0xffffffff /* 64bit extension flag */