tools/elf4rom/libs/dwarf-20071209/libdwarf/pro_opaque.h
changeset 34 92d87f2e53c2
equal deleted inserted replaced
33:1af5c1be89f8 34:92d87f2e53c2
       
     1 /*
       
     2 
       
     3   Copyright (C) 2000,2002,2004 Silicon Graphics, Inc.  All Rights Reserved.
       
     4   Portions Copyright 2002 Sun Microsystems, Inc. All rights reserved.
       
     5 
       
     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.
       
     9 
       
    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.  
       
    13 
       
    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.  
       
    20 
       
    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,
       
    24   USA.
       
    25 
       
    26   Contact information:  Silicon Graphics, Inc., 1500 Crittenden Lane,
       
    27   Mountain View, CA 94043, or:
       
    28 
       
    29   http://www.sgi.com
       
    30 
       
    31   For further information regarding this notice, see:
       
    32 
       
    33   http://oss.sgi.com/projects/GenInfo/NoticeExplan
       
    34 
       
    35 */
       
    36 
       
    37 
       
    38 #include <stddef.h>
       
    39 
       
    40 /* 
       
    41     Sgidefs included to define __uint32_t, 
       
    42     a guaranteed 4-byte quantity.            
       
    43 */
       
    44 #include "libdwarfdefs.h"
       
    45 
       
    46 #define true                    1
       
    47 #define false                   0
       
    48 
       
    49 /* to identify a cie */
       
    50 #define DW_CIE_ID 		~(0x0)
       
    51 #define DW_CIE_VERSION		1
       
    52 
       
    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.
       
    58 */
       
    59 
       
    60 typedef unsigned long Dwarf_Word;
       
    61 typedef long Dwarf_Sword;
       
    62 
       
    63 
       
    64 typedef signed char Dwarf_Sbyte;
       
    65 typedef unsigned char Dwarf_Ubyte;
       
    66 typedef signed short Dwarf_Shalf;
       
    67 
       
    68 /*
       
    69 	On any change that makes libdwarf producer
       
    70 	incompatible, increment this number.
       
    71 	1->2->3 ...
       
    72 
       
    73 */
       
    74 #define  PRO_VERSION_MAGIC 0xdead1
       
    75 
       
    76 
       
    77 /* these 2 are fixed sizes which must not vary with the
       
    78 ** ILP32/LP64 model. These two stay at 32 bit.
       
    79 */
       
    80 typedef __uint32_t Dwarf_ufixed;
       
    81 typedef __int32_t Dwarf_sfixed;
       
    82 
       
    83 /* 
       
    84 	producer:
       
    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
       
    89 */
       
    90 typedef struct Dwarf_P_Section_Data_s *Dwarf_P_Section_Data;
       
    91 
       
    92 /*
       
    93 	producer:
       
    94 	This struct is used to hold entries in the include directories
       
    95 	part of statement prologue. Definition in pro_line.h
       
    96 */
       
    97 typedef struct Dwarf_P_Inc_Dir_s *Dwarf_P_Inc_Dir;
       
    98 
       
    99 /*
       
   100 	producer:
       
   101 	This struct holds file entries for the statement prologue. 
       
   102 	Defined in pro_line.h
       
   103 */
       
   104 typedef struct Dwarf_P_F_Entry_s *Dwarf_P_F_Entry;
       
   105 
       
   106 /*
       
   107 	producer:
       
   108 	This struct holds information for each cie. Defn in pro_frame.h
       
   109 */
       
   110 typedef struct Dwarf_P_Cie_s *Dwarf_P_Cie;
       
   111 
       
   112 /*
       
   113 	producer:
       
   114 	Struct to hold line number information, different from 
       
   115 	Dwarf_Line opaque type.
       
   116 */
       
   117 typedef struct Dwarf_P_Line_s *Dwarf_P_Line;
       
   118 
       
   119 /*
       
   120 	producer:
       
   121 	Struct to hold information about address ranges.
       
   122 */
       
   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;
       
   128 
       
   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
       
   132    exactly.
       
   133 */
       
   134 #define         DEBUG_INFO      0
       
   135 #define         DEBUG_LINE      1
       
   136 #define         DEBUG_ABBREV    2
       
   137 #define         DEBUG_FRAME     3
       
   138 #define         DEBUG_ARANGES   4
       
   139 #define         DEBUG_PUBNAMES  5
       
   140 #define         DEBUG_STR       6
       
   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
       
   146 #define         DEBUG_LOC   12
       
   147 
       
   148     /* number of debug_* sections not including the relocations */
       
   149 #define         NUM_DEBUG_SECTIONS      DEBUG_LOC + 1
       
   150 
       
   151 
       
   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 */
       
   156     Dwarf_Tag di_tag;
       
   157     Dwarf_P_Die di_parent;	/* parent of current die */
       
   158     Dwarf_P_Die di_child;	/* first child */
       
   159     Dwarf_P_Die di_left;	/* left sibling */
       
   160     Dwarf_P_Die di_right;	/* right sibling */
       
   161     Dwarf_P_Attribute di_attrs;	/* list of attributes */
       
   162     Dwarf_P_Attribute di_last_attr;	/* last attribute */
       
   163     int di_n_attr;		/* number of attributes */
       
   164     Dwarf_P_Debug di_dbg;	/* For memory management */
       
   165     Dwarf_Unsigned di_marker;   /* used to attach symbols to dies */
       
   166 };
       
   167 
       
   168 
       
   169 /* producer fields */
       
   170 struct Dwarf_P_Attribute_s {
       
   171     Dwarf_Half ar_attribute;	/* Attribute Value. */
       
   172     Dwarf_Half ar_attribute_form;	/* Attribute Form. */
       
   173     Dwarf_P_Die ar_ref_die;	/* die pointer if form ref */
       
   174     char *ar_data;		/* data, format given by form */
       
   175     Dwarf_Unsigned ar_nbytes;	/* no. of bytes of data */
       
   176     Dwarf_Unsigned ar_rel_symidx;	/* when attribute has a
       
   177 					   relocatable value, holds
       
   178 					   index of symbol in SYMTAB */
       
   179     Dwarf_Ubyte ar_rel_type;	/* relocation type */
       
   180     Dwarf_Word ar_rel_offset;	/* Offset of relocation within block */
       
   181     char ar_reloc_len;		/* Number of bytes that relocation
       
   182 				   applies to. 4 or 8. Unused and may
       
   183 				   be 0 if if ar_rel_type is
       
   184 				   R_MIPS_NONE */
       
   185     Dwarf_P_Attribute ar_next;
       
   186 };
       
   187 
       
   188 /* A block of .debug_macinfo data: this forms a series of blocks.
       
   189 ** Each macinfo input is compressed immediately and put into
       
   190 ** the current block if room, else a newblock allocated.
       
   191 ** The space allocation is such that the block and the macinfo
       
   192 ** data are one malloc block: free with a pointer to this and the
       
   193 ** mb_data is freed automatically.
       
   194 ** Like the struct hack, but legal ANSI C.
       
   195 */
       
   196 struct dw_macinfo_block_s {
       
   197     struct dw_macinfo_block_s *mb_next;
       
   198     unsigned long mb_avail_len;
       
   199     unsigned long mb_used_len;
       
   200     unsigned long mb_macinfo_data_space_len;
       
   201     char *mb_data;		/* original malloc ptr. */
       
   202 };
       
   203 
       
   204 /* dwarf_sn_kind is for the array of similarly-treated
       
   205    name -> cu ties
       
   206 */
       
   207 enum dwarf_sn_kind { dwarf_snk_pubname, dwarf_snk_funcname,
       
   208     dwarf_snk_weakname, dwarf_snk_typename,
       
   209     dwarf_snk_varname,
       
   210     dwarf_snk_entrycount	/* this one must be last */
       
   211 };
       
   212 
       
   213 
       
   214 
       
   215 /* The calls to add a varname etc use a list of
       
   216    these as the list.
       
   217 */
       
   218 struct Dwarf_P_Simple_nameentry_s {
       
   219     Dwarf_P_Die sne_die;
       
   220     char *sne_name;
       
   221     int sne_name_len;
       
   222     Dwarf_P_Simple_nameentry sne_next;
       
   223 };
       
   224 
       
   225 /* An array of these, each of which heads a list
       
   226    of Dwarf_P_Simple_nameentry
       
   227 */
       
   228 struct Dwarf_P_Simple_name_header_s {
       
   229     Dwarf_P_Simple_nameentry sn_head;
       
   230     Dwarf_P_Simple_nameentry sn_tail;
       
   231     Dwarf_Signed sn_count;
       
   232 
       
   233     /* length that will be generated, not counting fixed header or
       
   234        trailer */
       
   235     Dwarf_Signed sn_net_len;
       
   236 };
       
   237 typedef int (*_dwarf_pro_reloc_name_func_ptr) (Dwarf_P_Debug dbg, int sec_index, Dwarf_Unsigned offset,	/* r_offset 
       
   238 													 */
       
   239 					       Dwarf_Unsigned symidx,
       
   240 					       enum Dwarf_Rel_Type type,
       
   241 					       int reltarget_length);
       
   242 
       
   243 typedef int (*_dwarf_pro_reloc_length_func_ptr) (Dwarf_P_Debug dbg, int sec_index, Dwarf_Unsigned offset,	/* r_offset 
       
   244 														 */
       
   245 						 Dwarf_Unsigned
       
   246 						 start_symidx,
       
   247 						 Dwarf_Unsigned
       
   248 						 end_symidx,
       
   249 						 enum Dwarf_Rel_Type
       
   250 						 type,
       
   251 						 int reltarget_length);
       
   252 typedef int (*_dwarf_pro_transform_relocs_func_ptr) (Dwarf_P_Debug dbg,
       
   253 						     Dwarf_Signed *
       
   254 						     new_sec_count);
       
   255 
       
   256 /*
       
   257 	Each slot in a block of slots could be:
       
   258 	a binary stream relocation entry (32 or 64bit relocation data)
       
   259         a SYMBOLIC relocation entry.
       
   260 	During creation sometimes we create multiple chained blocks,
       
   261 	but sometimes we create a single long block.
       
   262         Before returning reloc data to caller, 
       
   263         we switch to a single, long-enough,
       
   264 	block.
       
   265 
       
   266 	We make counters here Dwarf_Unsigned so that we
       
   267 	get sufficient alignment. Since we use space after
       
   268 	the struct (at malloc time) for user data which
       
   269         must have Dwarf_Unsigned alignment, this
       
   270 	struct must have that alignment too.
       
   271 
       
   272 */
       
   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
       
   278 				   end, depending on
       
   279 				   rb_next_slot_to_use) */
       
   280     char *rb_data;		/* data area */
       
   281 };
       
   282 
       
   283 /* One of these per potential relocation section 
       
   284    So one per actual dwarf section.
       
   285    Left zeroed when not used (some sections have
       
   286    no relocations).
       
   287 */
       
   288 struct Dwarf_P_Per_Reloc_Sect_s {
       
   289 
       
   290 
       
   291     unsigned long pr_reloc_total_count;	/* total number of entries
       
   292 					   across all blocks */
       
   293 
       
   294     unsigned long pr_slots_per_block_to_alloc;	/* at Block alloc, this 
       
   295 						   is the default
       
   296 						   number of slots to
       
   297 						   use */
       
   298 
       
   299     int pr_sect_num_of_reloc_sect;	/* sect number returned by
       
   300 					   de_func() or de_func_b()
       
   301 					   call, this is the sect
       
   302 					   number of the relocation
       
   303 					   section. */
       
   304 
       
   305 
       
   306     /* singly-linked list. add at and ('last') with count of blocks */
       
   307     struct Dwarf_P_Relocation_Block_s *pr_first_block;
       
   308     struct Dwarf_P_Relocation_Block_s *pr_last_block;
       
   309     unsigned long pr_block_count;
       
   310 };
       
   311 
       
   312 #define DEFAULT_SLOTS_PER_BLOCK 3
       
   313 
       
   314 typedef struct memory_list_s {
       
   315   struct memory_list_s *prev;
       
   316   struct memory_list_s *next;
       
   317 } memory_list_t;
       
   318 
       
   319 
       
   320 struct Dwarf_P_Per_Sect_String_Attrs_s {
       
   321     int sect_sa_section_number;
       
   322     unsigned sect_sa_n_alloc;
       
   323     unsigned sect_sa_n_used;
       
   324     Dwarf_P_String_Attr sect_sa_list;
       
   325 };
       
   326 
       
   327 /* Fields used by producer */
       
   328 struct Dwarf_P_Debug_s {
       
   329     /* used to catch dso passing dbg to another DSO with incompatible
       
   330        version of libdwarf See PRO_VERSION_MAGIC */
       
   331     int de_version_magic_number;
       
   332 
       
   333     Dwarf_Unsigned de_access;
       
   334     Dwarf_Handler de_errhand;
       
   335     Dwarf_Ptr de_errarg;
       
   336 
       
   337     /* 
       
   338        Call back function, used to create .debug* sections. Provided
       
   339        by user. Only of these used per dbg. */
       
   340     Dwarf_Callback_Func de_func;
       
   341     Dwarf_Callback_Func_b de_func_b;
       
   342 
       
   343     /* Flags from producer_init call */
       
   344     Dwarf_Unsigned de_flags;
       
   345 
       
   346     /* This holds information on debug section stream output, including
       
   347        the stream data */
       
   348     Dwarf_P_Section_Data de_debug_sects;
       
   349 
       
   350     /* Pointer to the 'current active' section */
       
   351     Dwarf_P_Section_Data de_current_active_section;
       
   352 
       
   353     /* Number of debug data streams globs. */
       
   354     Dwarf_Word de_n_debug_sect;
       
   355 
       
   356     /* File entry information, null terminated singly-linked list */
       
   357     Dwarf_P_F_Entry de_file_entries;
       
   358     Dwarf_P_F_Entry de_last_file_entry;
       
   359     Dwarf_Unsigned de_n_file_entries;
       
   360 
       
   361     /* Has the directories used to search for source files */
       
   362     Dwarf_P_Inc_Dir de_inc_dirs;
       
   363     Dwarf_P_Inc_Dir de_last_inc_dir;
       
   364     Dwarf_Unsigned de_n_inc_dirs;
       
   365 
       
   366     /* Has all the line number info for the stmt program */
       
   367     Dwarf_P_Line de_lines;
       
   368     Dwarf_P_Line de_last_line;
       
   369 
       
   370     /* List of cie's for the debug unit */
       
   371     Dwarf_P_Cie de_frame_cies;
       
   372     Dwarf_P_Cie de_last_cie;
       
   373     Dwarf_Unsigned de_n_cie;
       
   374 
       
   375     /* Singly-linked list of fde's for the debug unit */
       
   376     Dwarf_P_Fde de_frame_fdes;
       
   377     Dwarf_P_Fde de_last_fde;
       
   378     Dwarf_Unsigned de_n_fde;
       
   379 
       
   380     /* First die, leads to all others */
       
   381     Dwarf_P_Die de_dies;
       
   382 
       
   383     /* Pointer to list of strings */
       
   384     char *de_strings;
       
   385 
       
   386     /* Pointer to chain of aranges */
       
   387     Dwarf_P_Arange de_arange;
       
   388     Dwarf_P_Arange de_last_arange;
       
   389     Dwarf_Sword de_arange_count;
       
   390 
       
   391     /* macinfo controls. */
       
   392     /* first points to beginning of the list during creation */
       
   393     struct dw_macinfo_block_s *de_first_macinfo;
       
   394 
       
   395     /* current points to the current, unfilled, block */
       
   396     struct dw_macinfo_block_s *de_current_macinfo;
       
   397 
       
   398 
       
   399     /* Pointer to the first section, to support reset_section_bytes */
       
   400     Dwarf_P_Section_Data de_first_debug_sect;
       
   401 
       
   402     /* handles pubnames, weaknames, etc. See dwarf_sn_kind in
       
   403        pro_opaque.h */
       
   404     struct Dwarf_P_Simple_name_header_s
       
   405       de_simple_name_headers[dwarf_snk_entrycount];
       
   406 
       
   407     /* relocation data. not all sections will actally have relocation
       
   408        info, of course */
       
   409     struct Dwarf_P_Per_Reloc_Sect_s de_reloc_sect[NUM_DEBUG_SECTIONS];
       
   410     int de_reloc_next_to_return;	/* iterator on reloc sections
       
   411 					   (SYMBOLIC output) */
       
   412 
       
   413     /* used in remembering sections */
       
   414     int de_elf_sects[NUM_DEBUG_SECTIONS];	/* 
       
   415 						   elf sect number of
       
   416 						   the section itself,
       
   417 						   DEBUG_LINE for
       
   418 						   example */
       
   419 
       
   420     Dwarf_Unsigned de_sect_name_idx[NUM_DEBUG_SECTIONS];	/* section 
       
   421 								   name 
       
   422 								   index 
       
   423 								   or
       
   424 								   handle 
       
   425 								   for
       
   426 								   the
       
   427 								   name 
       
   428 								   of
       
   429 								   the
       
   430 								   symbol 
       
   431 								   for
       
   432 								   DEBUG_LINE 
       
   433 								   for
       
   434 								   example 
       
   435 								 */
       
   436 
       
   437 
       
   438 
       
   439     int de_offset_reloc;	/* offset reloc type, R_MIPS_32 for
       
   440 				   example. Specific to the ABI being
       
   441 				   produced. Relocates offset size
       
   442 				   field */
       
   443     int de_exc_reloc;		/* reloc type specific to exception
       
   444 				   table relocs. */
       
   445     int de_ptr_reloc;		/* standard reloc type, R_MIPS_32 for
       
   446 				   example. Specific to the ABI being
       
   447 				   produced. relocates pointer size
       
   448 				   field */
       
   449 
       
   450     unsigned char de_offset_size;	/* section offset. Here to
       
   451 					   avoid test of abi in macro
       
   452 					   at run time MIPS -n32 4,
       
   453 					   -64 8.  */
       
   454 
       
   455     unsigned char de_pointer_size;	/* size of pointer in target.
       
   456 					   Here to avoid test of abi in 
       
   457 					   macro at run time MIPS -n32 
       
   458 					   4, -64 is 8.  */
       
   459 
       
   460     unsigned char de_is_64bit;	/* non-zero if is 64bit. Else 32 bit:
       
   461 				   used for passing this info as a flag 
       
   462 				 */
       
   463     unsigned char de_relocation_record_size;	/* reloc record size
       
   464 						   varies by ABI and
       
   465 						   relocation-output
       
   466 						   method (stream or
       
   467 						   symbolic) */
       
   468 
       
   469     unsigned char de_64bit_extension;	/* non-zero if creating 64 bit
       
   470 					   offsets using dwarf2-99
       
   471 					   extension proposal */
       
   472 
       
   473     int de_ar_data_attribute_form;	/* data8, data4 abi dependent */
       
   474     int de_ar_ref_attr_form;	/* ref8 ref4 , abi dependent */
       
   475 
       
   476     /* simple name relocations */
       
   477     _dwarf_pro_reloc_name_func_ptr de_reloc_name;
       
   478 
       
   479     /* relocations for a length, requiring a pair of symbols */
       
   480     _dwarf_pro_reloc_length_func_ptr de_reloc_pair;
       
   481 
       
   482     _dwarf_pro_transform_relocs_func_ptr de_transform_relocs_to_disk;
       
   483 
       
   484     /* following used for macro buffers */
       
   485     unsigned long de_compose_avail;
       
   486     unsigned long de_compose_used_len;
       
   487 
       
   488     unsigned char de_same_endian;
       
   489     void *(*de_copy_word) (void *, const void *, size_t);
       
   490 
       
   491     /* Add new fields at the END of this struct to preserve some hope
       
   492        of sensible behavior on dbg passing between DSOs linked with
       
   493        mismatched libdwarf producer versions. */
       
   494 
       
   495     Dwarf_P_Marker de_markers;  /* pointer to array of markers */
       
   496     unsigned de_marker_n_alloc;
       
   497     unsigned de_marker_n_used;
       
   498     int de_sect_sa_next_to_return;  /* Iterator on sring attrib sects */
       
   499     /* String attributes data of each section. */
       
   500     struct Dwarf_P_Per_Sect_String_Attrs_s de_sect_string_attr[NUM_DEBUG_SECTIONS];
       
   501 };
       
   502 
       
   503 
       
   504 #define CURRENT_VERSION_STAMP		2
       
   505 
       
   506 Dwarf_Unsigned _dwarf_add_simple_name_entry(Dwarf_P_Debug dbg,
       
   507 					    Dwarf_P_Die die,
       
   508 					    char *entry_name,
       
   509 					    enum dwarf_sn_kind
       
   510 					    entrykind,
       
   511 					    Dwarf_Error * error);
       
   512 
       
   513 
       
   514 #define DISTINGUISHED_VALUE 0xffffffff	/* 64bit extension flag */