* config/tc-s390.c (md_parse_option): Set s390_arch_size to 32
[deliverable/binutils-gdb.git] / bfd / dwarf2.c
index f129e0b60cb551c83087feb854c60116b20e9cd5..7c000b9890e54562186aaa1f11fda3d42f2cf9c1 100644 (file)
    based on Fred Fish's (Cygnus Support) implementation of DWARF 1
    support in dwarfread.c
 
-This file is part of BFD.
+   This file is part of BFD.
 
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or (at
-your option) any later version.
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or (at
+   your option) any later version.
 
-This program is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-General Public License for more details.
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
 
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #include "bfd.h"
 #include "sysdep.h"
@@ -42,7 +42,7 @@ struct line_head
 {
   bfd_vma total_length;
   unsigned short version;
-  unsigned int prologue_length;
+  bfd_vma prologue_length;
   unsigned char minimum_instruction_length;
   unsigned char default_is_stmt;
   int line_base;
@@ -225,7 +225,7 @@ static bfd_vma read_address PARAMS ((struct comp_unit *, char *));
 static struct abbrev_info *lookup_abbrev
   PARAMS ((unsigned int, struct abbrev_info **));
 static struct abbrev_info **read_abbrevs
-  PARAMS ((bfd *, unsigned int, struct dwarf2_debug *));
+  PARAMS ((bfd *, bfd_vma, struct dwarf2_debug *));
 static char *read_attribute
   PARAMS ((struct attribute *, struct attr_abbrev *,
           struct comp_unit *, char *));
@@ -396,8 +396,8 @@ read_indirect_string (unit, buf, bytes_read_ptr)
 
   if (offset >= stash->dwarf_str_size)
     {
-      (*_bfd_error_handler) (_("Dwarf Error: DW_FORM_strp offset (%u) greater than or equal to .debug_str size (%u)."),
-                            offset, stash->dwarf_str_size);
+      (*_bfd_error_handler) (_("Dwarf Error: DW_FORM_strp offset (%lu) greater than or equal to .debug_str size (%lu)."),
+                            (unsigned long) offset, stash->dwarf_str_size);
       bfd_set_error (bfd_error_bad_value);
       return NULL;
     }
@@ -523,7 +523,7 @@ lookup_abbrev (number,abbrevs)
 static struct abbrev_info**
 read_abbrevs (abfd, offset, stash)
      bfd * abfd;
-     unsigned int offset;
+     bfd_vma offset;
      struct dwarf2_debug *stash;
 {
   struct abbrev_info **abbrevs;
@@ -557,8 +557,8 @@ read_abbrevs (abfd, offset, stash)
 
   if (offset >= stash->dwarf_abbrev_size)
     {
-      (*_bfd_error_handler) (_("Dwarf Error: Abbrev offset (%u) greater than or equal to .debug_abbrev size (%u)."),
-                            offset, stash->dwarf_abbrev_size);
+      (*_bfd_error_handler) (_("Dwarf Error: Abbrev offset (%lu) greater than or equal to .debug_abbrev size (%lu)."),
+                            (unsigned long) offset, stash->dwarf_abbrev_size);
       bfd_set_error (bfd_error_bad_value);
       return 0;
     }
@@ -754,7 +754,7 @@ read_attribute_value (attr, form, unit, info_ptr)
       info_ptr = read_attribute_value (attr, form, unit, info_ptr);
       break;
     default:
-      (*_bfd_error_handler) (_("Dwarf Error: Invalid or unhandled FORM value: %d."),
+      (*_bfd_error_handler) (_("Dwarf Error: Invalid or unhandled FORM value: %u."),
                             form);
       bfd_set_error (bfd_error_bad_value);
     }
@@ -856,13 +856,18 @@ concat_filename (table, file)
   filename = table->files[file - 1].name;
   if (IS_ABSOLUTE_PATH(filename))
     return filename;
-
   else
     {
       char* dirname = (table->files[file - 1].dir
                       ? table->dirs[table->files[file - 1].dir - 1]
                       : table->comp_dir);
-      return (char*) concat (dirname, "/", filename, NULL);
+
+      /* Not all tools set DW_AT_comp_dir, so dirname may be unknown.  The
+        best we can do is return the filename part.  */
+      if (dirname == NULL)
+       return filename;
+      else
+       return (char*) concat (dirname, "/", filename, NULL);
     }
 }
 
@@ -958,7 +963,7 @@ decode_line_info (unit, stash)
      below.  */
   if (unit->line_offset >= stash->dwarf_line_size)
     {
-      (*_bfd_error_handler) (_("Dwarf Error: Line offset (%u) greater than or equal to .debug_line size (%u)."),
+      (*_bfd_error_handler) (_("Dwarf Error: Line offset (%lu) greater than or equal to .debug_line size (%lu)."),
                             unit->line_offset, stash->dwarf_line_size);
       bfd_set_error (bfd_error_bad_value);
       return 0;
@@ -990,6 +995,13 @@ decode_line_info (unit, stash)
       line_ptr += 8;
       offset_size = 8;
     }
+  else if (lh.total_length == 0 && unit->addr_size == 8)
+    {
+      /* Handle (non-standard) 64-bit DWARF2 formats.  */
+      lh.total_length = read_4_bytes (abfd, line_ptr);
+      line_ptr += 4;
+      offset_size = 8;
+    }
   line_end = line_ptr + lh.total_length;
   lh.version = read_2_bytes (abfd, line_ptr);
   line_ptr += 2;
@@ -1072,13 +1084,19 @@ decode_line_info (unit, stash)
     {
       /* State machine registers.  */
       bfd_vma address = 0;
-      char* filename = concat_filename (table, 1);
+      char * filename = concat_filename (table, 1);
       unsigned int line = 1;
       unsigned int column = 0;
       int is_stmt = lh.default_is_stmt;
       int basic_block = 0;
-      int end_sequence = 0, need_low_pc = 1;
-      bfd_vma low_pc = 0;
+      int end_sequence = 0;
+      /* eraxxon@alumni.rice.edu: Against the DWARF2 specs, some
+         compilers generate address sequences that are wildly out of
+         order using DW_LNE_set_address (e.g. Intel C++ 6.0 compiler
+         for ia64-Linux).  Thus, to determine the low and high
+         address, we must compare on every DW_LNS_copy, etc.  */
+      bfd_vma low_pc  = 0;
+      bfd_vma high_pc = 0;
 
       /* Decode the table.  */
       while (! end_sequence)
@@ -1087,7 +1105,8 @@ decode_line_info (unit, stash)
          line_ptr += 1;
 
          if (op_code >= lh.opcode_base)
-           {           /* Special operand.  */
+           {
+             /* Special operand.  */
              adj_opcode = op_code - lh.opcode_base;
              address += (adj_opcode / lh.line_range)
                * lh.minimum_instruction_length;
@@ -1095,30 +1114,30 @@ decode_line_info (unit, stash)
              /* Append row to matrix using current values.  */
              add_line_info (table, address, filename, line, column, 0);
              basic_block = 1;
-             if (need_low_pc)
-               {
-                 need_low_pc = 0;
-                 low_pc = address;
-               }
+             if (low_pc == 0 || address < low_pc)
+               low_pc = address;
+             if (address > high_pc)
+               high_pc = address;
            }
          else switch (op_code)
            {
            case DW_LNS_extended_op:
-             line_ptr += 1;    /* Ignore length.  */
+             /* Ignore length.  */
+             line_ptr += 1;
              extended_op = read_1_byte (abfd, line_ptr);
              line_ptr += 1;
+
              switch (extended_op)
                {
                case DW_LNE_end_sequence:
                  end_sequence = 1;
                  add_line_info (table, address, filename, line, column,
                                 end_sequence);
-                 if (need_low_pc)
-                   {
-                     need_low_pc = 0;
-                     low_pc = address;
-                   }
-                 arange_add (unit, low_pc, address);
+                 if (low_pc == 0 || address < low_pc)
+                   low_pc = address;
+                 if (address > high_pc)
+                   high_pc = address;
+                 arange_add (unit, low_pc, high_pc);
                  break;
                case DW_LNE_set_address:
                  address = read_address (unit, line_ptr);
@@ -1157,11 +1176,10 @@ decode_line_info (unit, stash)
            case DW_LNS_copy:
              add_line_info (table, address, filename, line, column, 0);
              basic_block = 0;
-             if (need_low_pc)
-               {
-                 need_low_pc = 0;
-                 low_pc = address;
-               }
+             if (low_pc == 0 || address < low_pc)
+               low_pc = address;
+             if (address > high_pc)
+               high_pc = address;
              break;
            case DW_LNS_advance_pc:
              address += lh.minimum_instruction_length
@@ -1176,8 +1194,8 @@ decode_line_info (unit, stash)
              {
                unsigned int file;
 
-               /* The file and directory tables are 0 based, the references
-                  are 1 based.  */
+               /* The file and directory tables are 0
+                  based, the references are 1 based.  */
                file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
                line_ptr += bytes_read;
                filename = concat_filename (table, file);
@@ -1202,8 +1220,9 @@ decode_line_info (unit, stash)
              line_ptr += 2;
              break;
            default:
-             {  /* Unknown standard opcode, ignore it.  */
+             {
                int i;
+               /* Unknown standard opcode, ignore it.  */
                for (i = 0; i < lh.standard_opcode_lengths[op_code]; i++)
                  {
                    (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
@@ -1222,10 +1241,7 @@ decode_line_info (unit, stash)
    LINENUMBER_PTR, are pointers to the objects to be filled in.  */
 
 static boolean
-lookup_address_in_line_info_table (table,
-                                  addr,
-                                  function,
-                                  filename_ptr,
+lookup_address_in_line_info_table (table, addr, function, filename_ptr,
                                   linenumber_ptr)
      struct line_info_table* table;
      bfd_vma addr;
@@ -1286,9 +1302,7 @@ lookup_address_in_line_info_table (table,
 /* If ADDR is within TABLE, set FUNCTIONNAME_PTR, and return true.  */
 
 static boolean
-lookup_address_in_function_table (table,
-                                 addr,
-                                 function_ptr,
+lookup_address_in_function_table (table, addr, function_ptr,
                                  functionname_ptr)
      struct funcinfo* table;
      bfd_vma addr;
@@ -1345,7 +1359,7 @@ scan_unit_for_functions (unit)
       abbrev = lookup_abbrev (abbrev_number,unit->abbrevs);
       if (! abbrev)
        {
-         (*_bfd_error_handler) (_("Dwarf Error: Could not find abbrev number %d."),
+         (*_bfd_error_handler) (_("Dwarf Error: Could not find abbrev number %u."),
                             abbrev_number);
          bfd_set_error (bfd_error_bad_value);
          return false;
@@ -1486,9 +1500,9 @@ parse_comp_unit (abfd, stash, unit_length, offset_size)
      unsigned int offset_size;
 {
   struct comp_unit* unit;
-  unsigned short version;
-  unsigned int abbrev_offset = 0;
-  unsigned char addr_size;
+  unsigned int version;
+  bfd_vma abbrev_offset = 0;
+  unsigned int addr_size;
   struct abbrev_info** abbrevs;
   unsigned int abbrev_number, bytes_read, i;
   struct abbrev_info *abbrev;
@@ -1517,7 +1531,7 @@ parse_comp_unit (abfd, stash, unit_length, offset_size)
 
   if (version != 2)
     {
-      (*_bfd_error_handler) (_("Dwarf Error: found dwarf version '%hu', this reader only handles version 2 information."), version);
+      (*_bfd_error_handler) (_("Dwarf Error: found dwarf version '%u', this reader only handles version 2 information."), version);
       bfd_set_error (bfd_error_bad_value);
       return 0;
     }
@@ -1526,7 +1540,7 @@ parse_comp_unit (abfd, stash, unit_length, offset_size)
     {
       (*_bfd_error_handler) (_("Dwarf Error: found address size '%u', this reader can not handle sizes greater than '%u'."),
                         addr_size,
-                        sizeof (bfd_vma));
+                        (unsigned int) sizeof (bfd_vma));
       bfd_set_error (bfd_error_bad_value);
       return 0;
     }
@@ -1547,7 +1561,7 @@ parse_comp_unit (abfd, stash, unit_length, offset_size)
   info_ptr += bytes_read;
   if (! abbrev_number)
     {
-      (*_bfd_error_handler) (_("Dwarf Error: Bad abbrev number: %d."),
+      (*_bfd_error_handler) (_("Dwarf Error: Bad abbrev number: %u."),
                         abbrev_number);
       bfd_set_error (bfd_error_bad_value);
       return 0;
@@ -1556,7 +1570,7 @@ parse_comp_unit (abfd, stash, unit_length, offset_size)
   abbrev = lookup_abbrev (abbrev_number, abbrevs);
   if (! abbrev)
     {
-      (*_bfd_error_handler) (_("Dwarf Error: Could not find abbrev number %d."),
+      (*_bfd_error_handler) (_("Dwarf Error: Could not find abbrev number %u."),
                         abbrev_number);
       bfd_set_error (bfd_error_bad_value);
       return 0;
@@ -1654,9 +1668,8 @@ comp_unit_contains_address (unit, addr)
    false otherwise.  */
 
 static boolean
-comp_unit_find_nearest_line (unit, addr,
-                            filename_ptr, functionname_ptr, linenumber_ptr,
-                            stash)
+comp_unit_find_nearest_line (unit, addr, filename_ptr, functionname_ptr,
+                            linenumber_ptr, stash)
      struct comp_unit* unit;
      bfd_vma addr;
      const char **filename_ptr;
@@ -1696,26 +1709,23 @@ comp_unit_find_nearest_line (unit, addr,
     }
 
   function = NULL;
-  func_p = lookup_address_in_function_table (unit->function_table,
-                                            addr,
-                                            &function,
-                                            functionname_ptr);
-  line_p = lookup_address_in_line_info_table (unit->line_table,
-                                             addr,
-                                             function,
-                                             filename_ptr,
+  func_p = lookup_address_in_function_table (unit->function_table, addr,
+                                            &function, functionname_ptr);
+  line_p = lookup_address_in_line_info_table (unit->line_table, addr,
+                                             function, filename_ptr,
                                              linenumber_ptr);
   return line_p || func_p;
 }
 
-/* Locate a section in a BFD containing debugging info.  The search starts from the
-   section after AFTER_SEC, or from the first section in the BFD if AFTER_SEC is
-   NULL.  The search works by examining the names of the sections.  There are two
-   permissiable names.  The first is .debug_info.  This is the standard DWARF2 name.
-   The second is a prefix .gnu.linkonce.wi.  This is a variation on the .debug_info
-   section which has a checksum describing the contents appended onto the name.  This
-   allows the linker to identify and discard duplicate debugging sections for
-   different compilation units.  */
+/* Locate a section in a BFD containing debugging info.  The search starts
+   from the section after AFTER_SEC, or from the first section in the BFD if
+   AFTER_SEC is NULL.  The search works by examining the names of the
+   sections.  There are two permissiable names.  The first is .debug_info.
+   This is the standard DWARF2 name.  The second is a prefix .gnu.linkonce.wi.
+   This is a variation on the .debug_info section which has a checksum
+   describing the contents appended onto the name.  This allows the linker to
+   identify and discard duplicate debugging sections for different
+   compilation units.  */
 #define DWARF2_DEBUG_INFO ".debug_info"
 #define GNU_LINKONCE_INFO ".gnu.linkonce.wi."
 
@@ -1754,8 +1764,7 @@ find_debug_info (abfd, after_sec)
 boolean
 _bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
                               filename_ptr, functionname_ptr,
-                              linenumber_ptr,
-                              addr_size, pinfo)
+                              linenumber_ptr, addr_size, pinfo)
      bfd *abfd;
      asection *section;
      asymbol **symbols;
@@ -1895,6 +1904,13 @@ _bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
              length = read_8_bytes (abfd, stash->info_ptr + 4);
              stash->info_ptr += 8;
            }
+         else if (length == 0)
+           {
+             /* Handle (non-standard) 64-bit DWARF2 formats.  */
+             offset_size = 8;
+             length = read_4_bytes (abfd, stash->info_ptr + 4);
+             stash->info_ptr += 4;
+           }
        }
       else
        length = read_8_bytes (abfd, stash->info_ptr);
This page took 0.028955 seconds and 4 git commands to generate.