Convert read_address to a method on comp_unit_head
authorTom Tromey <tom@tromey.com>
Sat, 8 Feb 2020 20:40:54 +0000 (13:40 -0700)
committerTom Tromey <tom@tromey.com>
Sat, 8 Feb 2020 20:43:24 +0000 (13:43 -0700)
This changes read_address to be a method on comp_unit_head.

2020-02-08  Tom Tromey  <tom@tromey.com>

* dwarf2/read.c (read_address): Move to comp-unit.c.
(dwarf2_rnglists_process, dwarf2_ranges_process)
(read_attribute_value, dwarf_decode_lines_1)
(var_decode_location, decode_locdesc): Update.
* dwarf2/comp-unit.c (comp_unit_head::read_address): Move from
read.c.  Remove "cu" parameter.
* dwarf2/comp-unit.h (struct comp_unit_head) <read_address>: New
method.

Change-Id: Ibd6c7235f2e4d5fd88c272cfd2c3d3328618cc56

gdb/ChangeLog
gdb/dwarf2/comp-unit.c
gdb/dwarf2/comp-unit.h
gdb/dwarf2/read.c

index db821ff24e43905328660c0d381a8acec37c6a85..77555485476896debdb4a3320db1e1ad86d9df22 100644 (file)
@@ -1,3 +1,14 @@
+2020-02-08  Tom Tromey  <tom@tromey.com>
+
+       * dwarf2/read.c (read_address): Move to comp-unit.c.
+       (dwarf2_rnglists_process, dwarf2_ranges_process)
+       (read_attribute_value, dwarf_decode_lines_1)
+       (var_decode_location, decode_locdesc): Update.
+       * dwarf2/comp-unit.c (comp_unit_head::read_address): Move from
+       read.c.  Remove "cu" parameter.
+       * dwarf2/comp-unit.h (struct comp_unit_head) <read_address>: New
+       method.
+
 2020-02-08  Tom Tromey  <tom@tromey.com>
 
        * dwarf2/read.c (read_attribute_value, read_indirect_string)
index 847a148cbd2528a758f4b84a1ad221db43fb2637..0b6629f14cea41fc117b60e1e276d18006b4b014 100644 (file)
@@ -221,3 +221,53 @@ read_and_check_comp_unit_head (struct dwarf2_per_objfile *dwarf2_per_objfile,
 
   return info_ptr;
 }
+
+CORE_ADDR
+comp_unit_head::read_address (bfd *abfd, const gdb_byte *buf,
+                             unsigned int *bytes_read) const
+{
+  CORE_ADDR retval = 0;
+
+  if (signed_addr_p)
+    {
+      switch (addr_size)
+       {
+       case 2:
+         retval = bfd_get_signed_16 (abfd, buf);
+         break;
+       case 4:
+         retval = bfd_get_signed_32 (abfd, buf);
+         break;
+       case 8:
+         retval = bfd_get_signed_64 (abfd, buf);
+         break;
+       default:
+         internal_error (__FILE__, __LINE__,
+                         _("read_address: bad switch, signed [in module %s]"),
+                         bfd_get_filename (abfd));
+       }
+    }
+  else
+    {
+      switch (addr_size)
+       {
+       case 2:
+         retval = bfd_get_16 (abfd, buf);
+         break;
+       case 4:
+         retval = bfd_get_32 (abfd, buf);
+         break;
+       case 8:
+         retval = bfd_get_64 (abfd, buf);
+         break;
+       default:
+         internal_error (__FILE__, __LINE__,
+                         _("read_address: bad switch, "
+                           "unsigned [in module %s]"),
+                         bfd_get_filename (abfd));
+       }
+    }
+
+  *bytes_read = addr_size;
+  return retval;
+}
index e61b1000b9e42b1d27f1c8b861c2a1147d2d5ccc..2dd80901b8f852245a3885ed024411db056dda37 100644 (file)
@@ -89,6 +89,10 @@ struct comp_unit_head
     *bytes_read = offset_size;
     return offset;
   }
+
+  /* Read an address from BUF.  BYTES_READ is updated.  */
+  CORE_ADDR read_address (bfd *abfd, const gdb_byte *buf,
+                         unsigned int *bytes_read) const;
 };
 
 /* Expected enum dwarf_unit_type for read_comp_unit_head.  */
index 8ea0b60e187d6f99dea0642ad24a165f33dea236..d340906c75b09d619850e217bd2b696c68018391 100644 (file)
@@ -1238,9 +1238,6 @@ static void read_attribute_reprocess (const struct die_reader_specs *reader,
 
 static CORE_ADDR read_addr_index (struct dwarf2_cu *cu, unsigned int addr_index);
 
-static CORE_ADDR read_address (bfd *, const gdb_byte *ptr, struct dwarf2_cu *,
-                              unsigned int *);
-
 static LONGEST read_checked_initial_length_and_offset
   (bfd *, const gdb_byte *, const struct comp_unit_head *,
    unsigned int *, unsigned int *);
@@ -13514,7 +13511,7 @@ dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu,
              overflow = true;
              break;
            }
-         base = read_address (obfd, buffer, cu, &bytes_read);
+         base = cu->header.read_address (obfd, buffer, &bytes_read);
          found_base = 1;
          buffer += bytes_read;
          break;
@@ -13524,7 +13521,8 @@ dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu,
              overflow = true;
              break;
            }
-         range_beginning = read_address (obfd, buffer, cu, &bytes_read);
+         range_beginning = cu->header.read_address (obfd, buffer,
+                                                    &bytes_read);
          buffer += bytes_read;
          range_end = (range_beginning
                       + read_unsigned_leb128 (obfd, buffer, &bytes_read));
@@ -13557,9 +13555,10 @@ dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu,
              overflow = true;
              break;
            }
-         range_beginning = read_address (obfd, buffer, cu, &bytes_read);
+         range_beginning = cu->header.read_address (obfd, buffer,
+                                                    &bytes_read);
          buffer += bytes_read;
-         range_end = read_address (obfd, buffer, cu, &bytes_read);
+         range_end = cu->header.read_address (obfd, buffer, &bytes_read);
          buffer += bytes_read;
          break;
        default:
@@ -13662,9 +13661,9 @@ dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu,
     {
       CORE_ADDR range_beginning, range_end;
 
-      range_beginning = read_address (obfd, buffer, cu, &dummy);
+      range_beginning = cu->header.read_address (obfd, buffer, &dummy);
       buffer += addr_size;
-      range_end = read_address (obfd, buffer, cu, &dummy);
+      range_end = cu->header.read_address (obfd, buffer, &dummy);
       buffer += addr_size;
       offset += 2 * addr_size;
 
@@ -18446,7 +18445,8 @@ read_attribute_value (const struct die_reader_specs *reader,
     {
     case DW_FORM_ref_addr:
       if (cu->header.version == 2)
-       DW_UNSND (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
+       DW_UNSND (attr) = cu->header.read_address (abfd, info_ptr,
+                                                  &bytes_read);
       else
        DW_UNSND (attr) = cu->header.read_offset (abfd, info_ptr,
                                                  &bytes_read);
@@ -18457,7 +18457,7 @@ read_attribute_value (const struct die_reader_specs *reader,
       info_ptr += bytes_read;
       break;
     case DW_FORM_addr:
-      DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
+      DW_ADDR (attr) = cu->header.read_address (abfd, info_ptr, &bytes_read);
       DW_ADDR (attr) = gdbarch_adjust_dwarf2_addr (gdbarch, DW_ADDR (attr));
       info_ptr += bytes_read;
       break;
@@ -18704,57 +18704,6 @@ read_attribute (const struct die_reader_specs *reader,
                               need_reprocess);
 }
 
-static CORE_ADDR
-read_address (bfd *abfd, const gdb_byte *buf, struct dwarf2_cu *cu,
-             unsigned int *bytes_read)
-{
-  struct comp_unit_head *cu_header = &cu->header;
-  CORE_ADDR retval = 0;
-
-  if (cu_header->signed_addr_p)
-    {
-      switch (cu_header->addr_size)
-       {
-       case 2:
-         retval = bfd_get_signed_16 (abfd, buf);
-         break;
-       case 4:
-         retval = bfd_get_signed_32 (abfd, buf);
-         break;
-       case 8:
-         retval = bfd_get_signed_64 (abfd, buf);
-         break;
-       default:
-         internal_error (__FILE__, __LINE__,
-                         _("read_address: bad switch, signed [in module %s]"),
-                         bfd_get_filename (abfd));
-       }
-    }
-  else
-    {
-      switch (cu_header->addr_size)
-       {
-       case 2:
-         retval = bfd_get_16 (abfd, buf);
-         break;
-       case 4:
-         retval = bfd_get_32 (abfd, buf);
-         break;
-       case 8:
-         retval = bfd_get_64 (abfd, buf);
-         break;
-       default:
-         internal_error (__FILE__, __LINE__,
-                         _("read_address: bad switch, "
-                           "unsigned [in module %s]"),
-                         bfd_get_filename (abfd));
-       }
-    }
-
-  *bytes_read = cu_header->addr_size;
-  return retval;
-}
-
 /* Cover function for read_initial_length.
    Returns the length of the object at BUF, and stores the size of the
    initial length in *BYTES_READ and stores the size that offsets will be in
@@ -20204,7 +20153,7 @@ dwarf_decode_lines_1 (struct line_header *lh, struct dwarf2_cu *cu,
                case DW_LNE_set_address:
                  {
                    CORE_ADDR address
-                     = read_address (abfd, line_ptr, cu, &bytes_read);
+                     = cu->header.read_address (abfd, line_ptr, &bytes_read);
                    line_ptr += bytes_read;
 
                    state_machine.check_line_address (cu, line_ptr,
@@ -20525,10 +20474,10 @@ var_decode_location (struct attribute *attr, struct symbol *sym,
       unsigned int dummy;
 
       if (DW_BLOCK (attr)->data[0] == DW_OP_addr)
-       SET_SYMBOL_VALUE_ADDRESS (sym,
-                                 read_address (objfile->obfd,
-                                               DW_BLOCK (attr)->data + 1,
-                                               cu, &dummy));
+       SET_SYMBOL_VALUE_ADDRESS
+         (sym, cu->header.read_address (objfile->obfd,
+                                        DW_BLOCK (attr)->data + 1,
+                                        &dummy));
       else
        SET_SYMBOL_VALUE_ADDRESS
          (sym, read_addr_index_from_leb128 (cu, DW_BLOCK (attr)->data + 1,
@@ -22994,8 +22943,8 @@ decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
          break;
 
        case DW_OP_addr:
-         stack[++stacki] = read_address (objfile->obfd, &data[i],
-                                         cu, &bytes_read);
+         stack[++stacki] = cu->header.read_address (objfile->obfd, &data[i],
+                                                    &bytes_read);
          i += bytes_read;
          break;