* thread-db.c (enable_thread_event_reporting): Correct warning
[deliverable/binutils-gdb.git] / bfd / dwarf2.c
index 203641e5b6c2c84e576e0e5961793e09b7fdf21a..4a032732c980714d4ba7766d51fea4d5072c211d 100644 (file)
@@ -1,5 +1,6 @@
 /* DWARF 2 support.
-   Copyright 1994, 95, 96, 97, 98, 99, 2000 Free Software Foundation, Inc.
+   Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
+   Free Software Foundation, Inc.
 
    Adapted from gdb/dwarf2read.c by Gavin Koch of Cygnus Solutions
    (gavin@cygnus.com).
@@ -402,18 +403,16 @@ lookup_abbrev (number,abbrevs)
    in a hash table.  */
 
 static struct abbrev_info**
-read_abbrevs (abfd, offset)
+read_abbrevs (abfd, offset, stash)
      bfd * abfd;
      unsigned int offset;
+     struct dwarf2_debug *stash;
 {
   struct abbrev_info **abbrevs;
   char *abbrev_ptr;
   struct abbrev_info *cur_abbrev;
   unsigned int abbrev_number, bytes_read, abbrev_name;
   unsigned int abbrev_form, hash_number;
-  struct dwarf2_debug *stash;
-
-  stash = elf_tdata(abfd)->dwarf2_find_line_info;
 
   if (! stash->dwarf_abbrev_buffer)
     {
@@ -438,9 +437,9 @@ read_abbrevs (abfd, offset)
        return 0;
     }
 
-  if (offset > stash->dwarf_abbrev_size)
+  if (offset >= stash->dwarf_abbrev_size)
     {
-      (*_bfd_error_handler) (_("Dwarf Error: Abbrev offset (%u) bigger than abbrev size (%u)."),
+      (*_bfd_error_handler) (_("Dwarf Error: Abbrev offset (%u) greater than or equal to abbrev size (%u)."),
                             offset, stash->dwarf_abbrev_size );
       bfd_set_error (bfd_error_bad_value);
       return 0;
@@ -701,7 +700,7 @@ concat_filename (table, file)
     }
 
   filename = table->files[file - 1].name;
-  if (*filename == '/')
+  if (IS_ABSOLUTE_PATH(filename))
     return filename;
 
   else
@@ -761,11 +760,11 @@ arange_add (unit, low_pc, high_pc)
 /* Decode the line number information for UNIT.  */
 
 static struct line_info_table*
-decode_line_info (unit)
+decode_line_info (unit, stash)
      struct comp_unit *unit;
+     struct dwarf2_debug *stash;
 {
   bfd *abfd = unit->abfd;
-  struct dwarf2_debug *stash;
   struct line_info_table* table;
   char *line_ptr;
   char *line_end;
@@ -774,8 +773,6 @@ decode_line_info (unit)
   char *cur_file, *cur_dir;
   unsigned char op_code, extended_op, adj_opcode;
 
-  stash = elf_tdata (abfd)->dwarf2_find_line_info;
-
   if (! stash->dwarf_line_buffer)
     {
       asection *msec;
@@ -807,7 +804,7 @@ decode_line_info (unit)
      below.  */
   if (unit->line_offset >= stash->dwarf_line_size)
     {
-      (*_bfd_error_handler) (_("Dwarf Error: Line offset (%u) bigger than line size (%u)."),
+      (*_bfd_error_handler) (_("Dwarf Error: Line offset (%u) greater than or equal to line size (%u)."),
                             unit->line_offset, stash->dwarf_line_size);
       bfd_set_error (bfd_error_bad_value);
       return 0;
@@ -1233,10 +1230,10 @@ scan_unit_for_functions (unit)
    to get to the line number information for the compilation unit.  */
 
 static struct comp_unit *
-parse_comp_unit (abfd, info_ptr, end_ptr, abbrev_length)
+parse_comp_unit (abfd, stash, unit_length, abbrev_length)
      bfd* abfd;
-     char* info_ptr;
-     char* end_ptr;
+     struct dwarf2_debug *stash;
+     bfd_vma unit_length;
      unsigned int abbrev_length;
 {
   struct comp_unit* unit;
@@ -1250,6 +1247,9 @@ parse_comp_unit (abfd, info_ptr, end_ptr, abbrev_length)
   struct abbrev_info *abbrev;
   struct attribute attr;
 
+  char *info_ptr = stash->info_ptr;
+  char *end_ptr = info_ptr + unit_length;
+
   version = read_2_bytes (abfd, info_ptr);
   info_ptr += 2;
   BFD_ASSERT (abbrev_length == 0
@@ -1287,7 +1287,7 @@ parse_comp_unit (abfd, info_ptr, end_ptr, abbrev_length)
     }
 
   /* Read the abbrevs for this compilation unit into a table.  */
-  abbrevs = read_abbrevs (abfd, abbrev_offset);
+  abbrevs = read_abbrevs (abfd, abbrev_offset, stash);
   if (! abbrevs)
       return 0;
 
@@ -1400,12 +1400,14 @@ comp_unit_contains_address (unit, addr)
 
 static boolean
 comp_unit_find_nearest_line (unit, addr,
-                            filename_ptr, functionname_ptr, linenumber_ptr)
+                            filename_ptr, functionname_ptr, linenumber_ptr,
+                            stash)
      struct comp_unit* unit;
      bfd_vma addr;
      const char **filename_ptr;
      const char **functionname_ptr;
      unsigned int *linenumber_ptr;
+     struct dwarf2_debug *stash;
 {
   boolean line_p;
   boolean func_p;
@@ -1421,7 +1423,7 @@ comp_unit_find_nearest_line (unit, addr,
          return false;
        }
 
-      unit->line_table = decode_line_info (unit);
+      unit->line_table = decode_line_info (unit, stash);
 
       if (! unit->line_table)
        {
@@ -1493,7 +1495,7 @@ boolean
 _bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
                               filename_ptr, functionname_ptr,
                               linenumber_ptr,
-                              addr_size)
+                              addr_size, pinfo)
      bfd *abfd;
      asection *section;
      asymbol **symbols ATTRIBUTE_UNUSED;
@@ -1502,6 +1504,7 @@ _bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
      const char **functionname_ptr;
      unsigned int *linenumber_ptr;
      unsigned int addr_size;
+     PTR *pinfo;
 {
   /* Read each compilation unit from the section .debug_info, and check
      to see if it contains the address we are searching for.  If yes,
@@ -1511,7 +1514,7 @@ _bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
      We keep a list of all the previously read compilation units, and
      a pointer to the next un-read compilation unit.  Check the
      previously read units before reading more.  */
-  struct dwarf2_debug *stash = elf_tdata (abfd)->dwarf2_find_line_info;
+  struct dwarf2_debug *stash = (struct dwarf2_debug *) *pinfo;
 
   /* What address are we looking for?  */
   bfd_vma addr = offset + section->vma;
@@ -1534,17 +1537,19 @@ _bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
       unsigned long total_size;
       asection *msec;
 
-      stash = elf_tdata (abfd)->dwarf2_find_line_info =
+      stash =
        (struct dwarf2_debug*) bfd_zalloc (abfd, sizeof (struct dwarf2_debug));
       if (! stash)
        return false;
 
+      *pinfo = (PTR) stash;
+
       msec = find_debug_info (abfd, NULL);
       if (! msec)
        /* No dwarf2 info.  Note that at this point the stash
           has been allocated, but contains zeros, this lets
           future calls to this function fail quicker.  */
-       return false;
+        return false;
 
       /* There can be more than one DWARF2 info section in a BFD these days.
          Read them all in and produce one large stash.  We do this in two
@@ -1606,7 +1611,8 @@ _bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
   for (each = stash->all_comp_units; each; each = each->next_unit)
     if (comp_unit_contains_address (each, addr))
       return comp_unit_find_nearest_line (each, addr, filename_ptr,
-                                         functionname_ptr, linenumber_ptr);
+                                         functionname_ptr, linenumber_ptr,
+                                         stash);
 
   /* Read each remaining comp. units checking each as they are read.  */
   while (stash->info_ptr < stash->info_ptr_end)
@@ -1623,9 +1629,7 @@ _bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
 
       if (length > 0)
         {
-         each = parse_comp_unit (abfd, stash->info_ptr,
-                                 stash->info_ptr + length,
-                                 addr_size);
+         each = parse_comp_unit (abfd, stash, length, addr_size);
          stash->info_ptr += length;
 
          if (each)
@@ -1644,14 +1648,16 @@ _bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
                    return comp_unit_find_nearest_line (each, addr,
                                                       filename_ptr,
                                                       functionname_ptr,
-                                                      linenumber_ptr);
+                                                      linenumber_ptr,
+                                                      stash);
                }
              else
                {
                  found = comp_unit_find_nearest_line (each, addr,
                                                       filename_ptr,
                                                       functionname_ptr,
-                                                      linenumber_ptr);
+                                                      linenumber_ptr,
+                                                      stash);
                  if (found)
                    return true;
                }
This page took 0.026779 seconds and 4 git commands to generate.