tools/elf4rom/libs/dwarf-20071209/libdwarf/dwarf_opaque.h
changeset 34 92d87f2e53c2
equal deleted inserted replaced
33:1af5c1be89f8 34:92d87f2e53c2
       
     1 /*
       
     2 
       
     3   Copyright (C) 2000,2002,2003,2004,2005 Silicon Graphics, Inc.  All Rights Reserved.
       
     4   Portions Copyright (C) 2007  David Anderson. 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 /* The versions applicable by section are:
       
    37                        DWARF2    DWARF3 DWARF4
       
    38  .debug_info             2         3     4
       
    39  .debug_abbrev           -         -     -
       
    40  .debug_frame            1         3     3
       
    41  .debug_str              -         -     -
       
    42  .debug_loc              -         -     -
       
    43  .debug_line             2         3     3
       
    44  .debug_aranges          2         2     2
       
    45  .debug_ranges           x         -     -
       
    46  .debug_pubtypes         x         2     2
       
    47  .debug_pubnames         2         2     2
       
    48  .debug_macinfo          -         -     -
       
    49 */
       
    50 
       
    51 #include <stddef.h>
       
    52 
       
    53 
       
    54 struct Dwarf_Die_s {
       
    55     /* 
       
    56        Points to the start of the portion corresponding to this Die in 
       
    57        the .debug_info section. */
       
    58     Dwarf_Byte_Ptr di_debug_info_ptr;
       
    59 
       
    60     Dwarf_Abbrev_List di_abbrev_list;
       
    61 
       
    62     /* Points to cu context for this die.  */
       
    63     Dwarf_CU_Context di_cu_context;
       
    64 };
       
    65 
       
    66 struct Dwarf_Attribute_s {
       
    67     Dwarf_Half ar_attribute;	/* Attribute Value. */
       
    68     Dwarf_Half ar_attribute_form;	/* Attribute Form. */
       
    69     Dwarf_Half ar_attribute_form_direct;
       
    70 	        /* Identical to ar_attribute_form except that if
       
    71 		the original form uleb was DW_FORM_indirect,
       
    72 		ar_attribute_form_direct contains DW_FORM_indirect
       
    73 		but ar_attribute_form contains the true form. */
       
    74 
       
    75     Dwarf_CU_Context ar_cu_context;
       
    76     Dwarf_Small *ar_debug_info_ptr;
       
    77     Dwarf_Attribute ar_next;
       
    78 };
       
    79 
       
    80 /*
       
    81     This structure provides the context for a compilation unit.  
       
    82     Thus, it contains the Dwarf_Debug, cc_dbg, that this cu
       
    83     belongs to.  It contains the information in the compilation 
       
    84     unit header, cc_length, cc_version_stamp, cc_abbrev_offset,
       
    85     and cc_address_size, in the .debug_info section for that cu.  
       
    86     In addition, it contains the count, cc_count_cu, of the cu 
       
    87     number of that cu in the list of cu's in the .debug_info.  
       
    88     The count starts at 1, ie cc_count_cu is 1 for the first cu, 
       
    89     2 for the second and so on.  This struct also contains a 
       
    90     pointer, cc_abbrev_table, to a list of pairs of abbrev code 
       
    91     and a pointer to the start of that abbrev 
       
    92     in the .debug_abbrev section.
       
    93 
       
    94     Each die will also contain a pointer to such a struct to 
       
    95     record the context for that die.  
       
    96     
       
    97     **Updated by dwarf_next_cu_header in dwarf_die_deliv.c
       
    98 */
       
    99 struct Dwarf_CU_Context_s {
       
   100     Dwarf_Debug cc_dbg;
       
   101     Dwarf_Word cc_length;
       
   102     Dwarf_Small cc_length_size;
       
   103     Dwarf_Small cc_extension_size;
       
   104     Dwarf_Half cc_version_stamp;
       
   105     Dwarf_Sword cc_abbrev_offset;
       
   106     Dwarf_Small cc_address_size;
       
   107     Dwarf_Word cc_debug_info_offset;
       
   108     Dwarf_Byte_Ptr cc_last_abbrev_ptr;
       
   109     Dwarf_Hash_Table cc_abbrev_hash_table;
       
   110     Dwarf_CU_Context cc_next;
       
   111     unsigned char cc_offset_length;
       
   112 };
       
   113 
       
   114 
       
   115 struct Dwarf_Debug_s {
       
   116     dwarf_elf_handle de_elf; /* see de_elf_must_close at end of struct */
       
   117 
       
   118     Dwarf_Unsigned de_access;
       
   119     Dwarf_Handler de_errhand;
       
   120     Dwarf_Ptr de_errarg;
       
   121 
       
   122     /* 
       
   123        Context for the compilation_unit just read by a call to
       
   124        dwarf_next_cu_header. **Updated by dwarf_next_cu_header in
       
   125        dwarf_die_deliv.c */
       
   126     Dwarf_CU_Context de_cu_context;
       
   127 
       
   128     /* 
       
   129        Points to linked list of CU Contexts for the CU's already read.
       
   130        These are only CU's read by dwarf_next_cu_header(). */
       
   131     Dwarf_CU_Context de_cu_context_list;
       
   132 
       
   133     /* 
       
   134        Points to the last CU Context added to the list by
       
   135        dwarf_next_cu_header(). */
       
   136     Dwarf_CU_Context de_cu_context_list_end;
       
   137 
       
   138     /* 
       
   139        This is the list of CU contexts read for dwarf_offdie().  These
       
   140        may read ahead of dwarf_next_cu_header(). */
       
   141     Dwarf_CU_Context de_offdie_cu_context;
       
   142     Dwarf_CU_Context de_offdie_cu_context_end;
       
   143 
       
   144     /* Offset of last byte of last CU read. */
       
   145     Dwarf_Word de_info_last_offset;
       
   146 
       
   147     /* 
       
   148        Number of bytes in the length, and offset field in various
       
   149        .debug_* sections.  It's not very meaningful, and is
       
   150        only used in one 'approximate' calculation.  */
       
   151     Dwarf_Small de_length_size;
       
   152 
       
   153     /* number of bytes in a pointer of the target in various .debug_
       
   154        sections. 4 in 32bit, 8 in MIPS 64, ia64. */
       
   155     Dwarf_Small de_pointer_size;
       
   156 
       
   157     /* set at creation of a Dwarf_Debug to say if form_string should be 
       
   158        checked for valid length at every call. 0 means do the check.
       
   159        non-zero means do not do the check. */
       
   160     Dwarf_Small de_assume_string_in_bounds;
       
   161 
       
   162     /* 
       
   163        Dwarf_Alloc_Hdr_s structs used to manage chunks that are
       
   164        malloc'ed for each allocation type for structs. */
       
   165     struct Dwarf_Alloc_Hdr_s de_alloc_hdr[ALLOC_AREA_REAL_TABLE_MAX];
       
   166 #ifdef DWARF_SIMPLE_MALLOC
       
   167     struct simple_malloc_record_s *  de_simple_malloc_base;
       
   168 #endif
       
   169     
       
   170 
       
   171     /* 
       
   172        These fields are used to process debug_frame section.  **Updated 
       
   173        by dwarf_get_fde_list in dwarf_frame.h */
       
   174     /* 
       
   175        Points to contiguous block of pointers to Dwarf_Cie_s structs. */
       
   176     Dwarf_Cie *de_cie_data;
       
   177     /* Count of number of Dwarf_Cie_s structs. */
       
   178     Dwarf_Signed de_cie_count;
       
   179     /* 
       
   180        Points to contiguous block of pointers to Dwarf_Fde_s structs. */
       
   181     Dwarf_Fde *de_fde_data;
       
   182     /* Count of number of Dwarf_Fde_s structs. */
       
   183     Dwarf_Signed de_fde_count;
       
   184 
       
   185     Dwarf_Small *de_debug_info;
       
   186     Dwarf_Small *de_debug_abbrev;
       
   187     Dwarf_Small *de_debug_line;
       
   188     Dwarf_Small *de_debug_loc;
       
   189     Dwarf_Small *de_debug_aranges;
       
   190     Dwarf_Small *de_debug_macinfo;
       
   191     Dwarf_Small *de_debug_pubnames;
       
   192     Dwarf_Small *de_debug_str;
       
   193     Dwarf_Small *de_debug_frame;
       
   194     Dwarf_Small *de_debug_pubtypes; /* DWARF3 .debug_pubtypes */
       
   195     Dwarf_Small *de_debug_frame_eh_gnu;	/* gnu for the g++ eh_frame
       
   196 					   section */
       
   197     Dwarf_Addr   de_debug_frame_eh_addr; /* gnu for the g++ eh_frame
       
   198                                            section. Section address
       
   199 		                           from Elf. Purpose: to handle
       
   200 					DW_EH_PE_pcrel encoding. */
       
   201 
       
   202     Dwarf_Small *de_debug_funcnames;
       
   203     Dwarf_Small *de_debug_typenames; /* SGI IRIX extension essentially
       
   204 			identical to DWARF3 .debug_pubtypes. */
       
   205     Dwarf_Small *de_debug_varnames;
       
   206     Dwarf_Small *de_debug_weaknames;
       
   207 
       
   208     Dwarf_Unsigned de_debug_info_size;
       
   209     Dwarf_Unsigned de_debug_abbrev_size;
       
   210     Dwarf_Unsigned de_debug_line_size;
       
   211     Dwarf_Unsigned de_debug_loc_size;
       
   212     Dwarf_Unsigned de_debug_aranges_size;
       
   213     Dwarf_Unsigned de_debug_macinfo_size;
       
   214     Dwarf_Unsigned de_debug_pubnames_size;
       
   215     Dwarf_Unsigned de_debug_str_size;
       
   216     Dwarf_Unsigned de_debug_pubtypes_size; /* DWARF3 .debug_pubtypes*/
       
   217 
       
   218 
       
   219     Dwarf_Unsigned de_debug_frame_size;
       
   220 
       
   221     Dwarf_Unsigned de_debug_frame_size_eh_gnu;	/* gnu for the g++
       
   222 					   eh_frame section */
       
   223 
       
   224     Dwarf_Unsigned de_debug_funcnames_size;
       
   225     Dwarf_Unsigned de_debug_typenames_size;
       
   226     Dwarf_Unsigned de_debug_varnames_size;
       
   227     Dwarf_Unsigned de_debug_weaknames_size;
       
   228 
       
   229     void *(*de_copy_word) (void *, const void *, size_t);
       
   230     unsigned char de_same_endian;
       
   231     unsigned char de_elf_must_close; /* if non-zero, then
       
   232 	it was dwarf_init (not dwarf_elf_init)
       
   233 	so must elf_end() */
       
   234 
       
   235     /*
       
   236        The following are used for storing section indicies.
       
   237 
       
   238        After a Dwarf_Debug is initialized, a zero for any of
       
   239        these indicies indicates an absent section.
       
   240 
       
   241        If the ELF spec is ever changed to permit 32-bit section
       
   242        indicies, these will need to be changed.
       
   243      */
       
   244     Dwarf_Half de_debug_aranges_index;
       
   245     Dwarf_Half de_debug_line_index;
       
   246     Dwarf_Half de_debug_loc_index;
       
   247     Dwarf_Half de_debug_macinfo_index;
       
   248     Dwarf_Half de_debug_pubnames_index;
       
   249     Dwarf_Half de_debug_funcnames_index;
       
   250     Dwarf_Half de_debug_typenames_index;
       
   251     Dwarf_Half de_debug_varnames_index;
       
   252     Dwarf_Half de_debug_weaknames_index;
       
   253     Dwarf_Half de_debug_frame_index;
       
   254     Dwarf_Half de_debug_frame_eh_gnu_index;
       
   255     Dwarf_Half de_debug_str_index;
       
   256     Dwarf_Half de_debug_info_index;
       
   257     Dwarf_Half de_debug_abbrev_index;
       
   258     Dwarf_Half de_debug_pubtypes_index; /* DWARF3 .debug_pubtypes */
       
   259 
       
   260     /* Default is DW_FRAME_INITIAL_VALUE from header. */
       
   261     Dwarf_Half de_frame_rule_initial_value;  
       
   262 
       
   263     /* Default is   DW_FRAME_LAST_REG_NUM. */
       
   264     Dwarf_Half de_frame_reg_rules_entry_count; 
       
   265 
       
   266 
       
   267     unsigned char de_big_endian_object; /* non-zero if big-endian
       
   268 		object opened. */
       
   269 };
       
   270 
       
   271 typedef struct Dwarf_Chain_s *Dwarf_Chain;
       
   272 struct Dwarf_Chain_s {
       
   273     void *ch_item;
       
   274     Dwarf_Chain ch_next;
       
   275 };
       
   276 
       
   277 
       
   278 #define CURRENT_VERSION_STAMP		2 /* DWARF2 */
       
   279 #define CURRENT_VERSION_STAMP3		3 /* DWARF3 */
       
   280 #define CURRENT_VERSION_STAMP4		3 /* DWARF4 */
       
   281 
       
   282     /* Size of cu header version stamp field. */
       
   283 #define CU_VERSION_STAMP_SIZE   sizeof(Dwarf_Half)
       
   284 
       
   285     /* Size of cu header address size field. */
       
   286 #define CU_ADDRESS_SIZE_SIZE	sizeof(Dwarf_Small)
       
   287 
       
   288 void *_dwarf_memcpy_swap_bytes(void *s1, const void *s2, size_t len);
       
   289 
       
   290 #define ORIGINAL_DWARF_OFFSET_SIZE  4
       
   291 #define DISTINGUISHED_VALUE  0xffffffff
       
   292 #define DISTINGUISHED_VALUE_OFFSET_SIZE 8
       
   293 
       
   294 /*
       
   295     We don't load the sections until they are needed. This function is
       
   296     used to load the section.
       
   297  */
       
   298 int _dwarf_load_section(Dwarf_Debug,
       
   299 		        Dwarf_Half,
       
   300 			Dwarf_Small **,
       
   301 			Dwarf_Error *);