tools/elf4rom/libs/dwarf-20071209/libdwarf/dwarf_line.h
changeset 34 92d87f2e53c2
equal deleted inserted replaced
33:1af5c1be89f8 34:92d87f2e53c2
       
     1 /*
       
     2 
       
     3   Copyright (C) 2000, 2004, 2006 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., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
       
    23   USA.
       
    24 
       
    25   Contact information:  Silicon Graphics, Inc., 1500 Crittenden Lane,
       
    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 
       
    37 
       
    38 #define DW_EXTENDED_OPCODE	0
       
    39 
       
    40 /*
       
    41     This is used as the starting value for an algorithm
       
    42     to get the minimum difference between 2 values.
       
    43     UINT_MAX is used as our approximation to infinity.
       
    44 */
       
    45 #define MAX_LINE_DIFF       UINT_MAX
       
    46 
       
    47 
       
    48 /*
       
    49     This structure is used to build a list of all the
       
    50     files that are used in the current compilation unit.
       
    51     All of the fields execpt fi_next have meanings that
       
    52     are obvious from section 6.2.4 of the Libdwarf Doc.
       
    53 */
       
    54 struct Dwarf_File_Entry_s {
       
    55     /* Points to string naming the file. */
       
    56     Dwarf_Small *fi_file_name;
       
    57 
       
    58     /* 
       
    59        Index into the list of directories of the directory in which
       
    60        this file exits. */
       
    61     Dwarf_Sword fi_dir_index;
       
    62 
       
    63     /* Time of last modification of the file. */
       
    64     Dwarf_Unsigned fi_time_last_mod;
       
    65 
       
    66     /* Length in bytes of the file. */
       
    67     Dwarf_Unsigned fi_file_length;
       
    68 
       
    69     /* Pointer for chaining file entries. */
       
    70     Dwarf_File_Entry fi_next;
       
    71 };
       
    72 
       
    73 
       
    74 typedef struct Dwarf_Line_Context_s *Dwarf_Line_Context;
       
    75 
       
    76 /* 
       
    77     This structure provides the context in which the fields of 
       
    78     a Dwarf_Line structure are interpreted.  They come from the 
       
    79     statement program prologue.  **Updated by dwarf_srclines in 
       
    80     dwarf_line.c.
       
    81 */
       
    82 struct Dwarf_Line_Context_s {
       
    83     /* 
       
    84        Points to a chain of entries providing info about source files
       
    85        for the current set of Dwarf_Line structures. File number
       
    86        'li_file 1' is last on the list, the first list entry is the
       
    87        file numbered lc_file_entry_count. The numbering of the file
       
    88        names matches the dwarf2/3 line table specification file table
       
    89        and DW_LNE_define_file numbering rules.  */
       
    90     Dwarf_File_Entry lc_file_entries;
       
    91     /* 
       
    92        Count of number of source files for this set of Dwarf_Line
       
    93        structures. */
       
    94     Dwarf_Sword lc_file_entry_count;
       
    95     /* 
       
    96        Points to the portion of .debug_line section that contains a
       
    97        list of strings naming the included directories. */
       
    98     Dwarf_Small *lc_include_directories;
       
    99 
       
   100     /* Count of the number of included directories. */
       
   101     Dwarf_Sword lc_include_directories_count;
       
   102 
       
   103     /* Count of the number of lines for this cu. */
       
   104     Dwarf_Sword lc_line_count;
       
   105 
       
   106     /* Points to name of compilation directory. */
       
   107     Dwarf_Small *lc_compilation_directory;
       
   108 
       
   109     Dwarf_Debug lc_dbg;
       
   110 
       
   111     Dwarf_Half lc_version_number;	/* DWARF2/3 version number, 2
       
   112 					   for DWARF2, 3 for DWARF3. */
       
   113 };
       
   114 
       
   115 
       
   116 /*
       
   117     This structure defines a row of the line table.
       
   118     All of the fields except li_offset have the exact 
       
   119     same meaning that is defined in Section 6.2.2 
       
   120     of the Libdwarf Document. 
       
   121 
       
   122     li_offset is used by _dwarf_addr_finder() which is called
       
   123     by rqs(1), an sgi utility for 'moving' shared libraries
       
   124     as if the static linker (ld) had linked the shared library
       
   125     at the newly-specified address.  Most libdwarf-using 
       
   126     apps will ignore li_offset and _dwarf_addr_finder().
       
   127     
       
   128 */
       
   129 struct Dwarf_Line_s {
       
   130     Dwarf_Addr li_address;	/* pc value of machine instr */
       
   131     union addr_or_line_s {
       
   132 	struct li_inner_s {
       
   133 	    Dwarf_Sword li_file;	/* int identifying src file */
       
   134 	    /* li_file is a number 1-N, indexing into a conceptual
       
   135 	       source file table as described in dwarf2/3 spec line
       
   136 	       table doc. (see Dwarf_File_Entry lc_file_entries; and
       
   137 	       Dwarf_Sword lc_file_entry_count;) */
       
   138 
       
   139 	    Dwarf_Sword li_line;	/* source file line number. */
       
   140 	    Dwarf_Half li_column;	/* source file column number */
       
   141 	    Dwarf_Small li_isa;
       
   142 
       
   143 	    /* To save space, use bit flags. */
       
   144 	    /* indicate start of stmt */
       
   145 	    unsigned char li_is_stmt:1;
       
   146 
       
   147 	    /* indicate start basic block */
       
   148 	    unsigned char li_basic_block:1;
       
   149 
       
   150 	    /* first post sequence instr */
       
   151 	    unsigned char li_end_sequence:1;
       
   152 
       
   153 	    unsigned char li_prologue_end:1;
       
   154 	    unsigned char li_epilogue_begin:1;
       
   155 	} li_l_data;
       
   156 	Dwarf_Off li_offset;	/* for rqs */
       
   157     } li_addr_line;
       
   158     Dwarf_Line_Context li_context;	/* assoc Dwarf_Line_Context_s */
       
   159 };
       
   160 
       
   161 
       
   162 int _dwarf_line_address_offsets(Dwarf_Debug dbg,
       
   163 				Dwarf_Die die,
       
   164 				Dwarf_Addr ** addrs,
       
   165 				Dwarf_Off ** offs,
       
   166 				Dwarf_Unsigned * returncount,
       
   167 				Dwarf_Error * err);
       
   168 int _dwarf_internal_srclines(Dwarf_Die die,
       
   169 			     Dwarf_Line ** linebuf,
       
   170 			     Dwarf_Signed * count,
       
   171 			     Dwarf_Bool doaddrs,
       
   172 			     Dwarf_Bool dolines, Dwarf_Error * error);
       
   173 
       
   174 
       
   175 
       
   176 /* The LOP, WHAT_IS_OPCODE stuff is here so it can
       
   177    be reused in 3 places.  Seemed hard to keep
       
   178    the 3 places the same without an inline func or
       
   179    a macro.
       
   180 
       
   181    Handling the line section where the header and the
       
   182    file being processed do not match (unusual, but
       
   183    planned for in the  design of .debug_line)
       
   184    is too tricky to recode this several times and keep
       
   185    it right.
       
   186 
       
   187    As it is the code starting up line-reading is duplicated
       
   188    and that is just wrong to do. FIXME!
       
   189 */
       
   190 #define LOP_EXTENDED 1
       
   191 #define LOP_DISCARD  2
       
   192 #define LOP_STANDARD 3
       
   193 #define LOP_SPECIAL  4
       
   194 
       
   195 #define WHAT_IS_OPCODE(type,opcode,base,opcode_length,line_ptr,highest_std) \
       
   196         if( (opcode) < (base) ) {                          \
       
   197            /* we know we must treat as a standard op       \
       
   198                 or a special case.                         \
       
   199            */                                              \
       
   200            if((opcode) == DW_EXTENDED_OPCODE) {            \
       
   201                 type = LOP_EXTENDED;                       \
       
   202            } else  if( ((highest_std)+1) >=  (base)) {     \
       
   203                 /* == Standard case: compile of            \
       
   204                    dwarf_line.c and object                 \
       
   205                    have same standard op codes set.        \
       
   206                                                            \
       
   207                    >  Special case: compile of dwarf_line.c\
       
   208                    has things in standard op codes list    \
       
   209                    in dwarf.h header not                   \
       
   210                    in the object: handle this as a standard\
       
   211                    op code in switch below.                \
       
   212                    The header special ops overlap the      \
       
   213                    object standard ops.                    \
       
   214                    The new standard op codes will not      \
       
   215                    appear in the object.                   \
       
   216                 */                                         \
       
   217                 type = LOP_STANDARD;                       \
       
   218            } else  {                                       \
       
   219                 /* These are standard opcodes in the object\
       
   220                 ** that were not defined  in the header    \
       
   221                 ** at the time dwarf_line.c                \
       
   222                 ** was compiled. Provides the ability of   \
       
   223                 ** out-of-date dwarf reader to read newer  \
       
   224                 ** line table data transparently.          \
       
   225                 */                                         \
       
   226                 type = LOP_DISCARD;                         \
       
   227            }                                                \
       
   228                                                             \
       
   229         } else {                                            \
       
   230 	   /* Is  a special op code.                        \
       
   231 	   */                                               \
       
   232            type =  LOP_SPECIAL;                             \
       
   233         }
       
   234 
       
   235 /* The following is from  the dwarf definition of 'ubyte'
       
   236    and is specifically  mentioned in section  6.2.5.1, page 54
       
   237    of the Rev 2.0.0 dwarf specification.
       
   238 */
       
   239 
       
   240 #define MAX_LINE_OP_CODE  255
       
   241 
       
   242 
       
   243 /* The following structs (Line_Table_File_Entry_s,Line_Table_Prefix_s)
       
   244    and functions allow refactoring common code into a single
       
   245    reader routine.
       
   246 */
       
   247 /* There can be zero of more of these needed for 1 line prologue. */
       
   248 struct Line_Table_File_Entry_s {
       
   249     Dwarf_Small *lte_filename;
       
   250     Dwarf_Unsigned lte_directory_index;
       
   251     Dwarf_Unsigned lte_last_modification_time;
       
   252     Dwarf_Unsigned lte_length_of_file;
       
   253 };
       
   254 
       
   255 /* Data  picked up from the line table prologue for a single
       
   256 CU. */
       
   257 struct Line_Table_Prefix_s {
       
   258 
       
   259     /* pf_total_length is the value of the length field for the line
       
   260        table of this CU. So it does not count the length of itself (the 
       
   261        length value) for consistency with the say lenghts recorded in
       
   262        DWARF2/3. */
       
   263     Dwarf_Unsigned pf_total_length;
       
   264 
       
   265     /* Length of the initial length field itself. */
       
   266     Dwarf_Half pf_length_field_length;
       
   267 
       
   268     /* The version is 2 for DWARF2, 3 for DWARF3 */
       
   269     Dwarf_Half pf_version;
       
   270 
       
   271     Dwarf_Unsigned pf_prologue_length;
       
   272     Dwarf_Small pf_minimum_instruction_length;
       
   273 
       
   274     /* Start and end of this CU line area. pf_line_ptr_start +
       
   275        pf_total_length + pf_length_field_length == pf_line_ptr_end.
       
   276        Meaning pf_line_ptr_start is before the length info. */
       
   277     Dwarf_Small *pf_line_ptr_start;
       
   278     Dwarf_Small *pf_line_ptr_end;
       
   279 
       
   280     /* Used to check that decoding of the line prologue is done right. */
       
   281     Dwarf_Small *pf_line_prologue_start;
       
   282 
       
   283     Dwarf_Small pf_default_is_stmt;
       
   284     Dwarf_Sbyte pf_line_base;
       
   285     Dwarf_Small pf_line_range;
       
   286 
       
   287     /* Highest std opcode (+1).  */
       
   288     Dwarf_Small pf_opcode_base;
       
   289 
       
   290     /* pf_opcode_base -1 entries (each a count, normally the value of
       
   291        each entry is 0 or 1). */
       
   292     Dwarf_Small *pf_opcode_length_table;
       
   293 
       
   294     Dwarf_Unsigned pf_include_directories_count;
       
   295     /* Array of pointers to dir strings. pf_include_directories_count
       
   296        entriesin the array. */
       
   297     Dwarf_Small **pf_include_directories;
       
   298 
       
   299     /* Count of entries in line_table_file_entries array. */
       
   300     Dwarf_Unsigned pf_files_count;
       
   301     struct Line_Table_File_Entry_s *pf_line_table_file_entries;
       
   302 
       
   303     /* The number to treat as standard ops. This is a special
       
   304        accomodation of gcc using the new standard opcodes but not
       
   305        updating the version number. It's legal dwarf2, but much better
       
   306        for the user to understand as dwarf3 when 'it looks ok'. */
       
   307     Dwarf_Bool pf_std_op_count;
       
   308 
       
   309 };
       
   310 
       
   311 void dwarf_init_line_table_prefix(struct Line_Table_Prefix_s *pf);
       
   312 void dwarf_free_line_table_prefix(struct Line_Table_Prefix_s *pf);
       
   313 
       
   314 int
       
   315   dwarf_read_line_table_prefix(Dwarf_Debug dbg,
       
   316 			       Dwarf_Small * data_start,
       
   317 			       Dwarf_Unsigned data_length,
       
   318 			       Dwarf_Small ** updated_data_start_out,
       
   319 			       struct Line_Table_Prefix_s *prefix_out,
       
   320 			       Dwarf_Error * err);