]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/dwarf: remove dwarf2_section_info::get_size
authorSimon Marchi <simon.marchi@efficios.com>
Thu, 17 Apr 2025 19:37:20 +0000 (15:37 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Sun, 20 Apr 2025 05:01:57 +0000 (01:01 -0400)
The comment over dwarf2_section_info::get_size says:

    In other cases, you must call this function, because for compressed
    sections the size field is not set correctly until the section has
    been read

From what I can see (while debugging a test case compiled with -gz on
Linux), that's not true.  For compressed sections, bfd_section_size
returns the uncompressed size.  asection::size contains the uncompressed
size while asection::compressed_size contains the compressed size:

    (top-gdb) p sec
    $13 = (asection *) 0x521000119778
    (top-gdb) p sec.compressed_size
    $14 = 6191
    (top-gdb) p sec.size
    $15 = 12116

I therefore propose to remove dwarf2_section_info::get_size, as it
appears that reading in the section is orthogonal to knowing its size.

If the assumption above is false, it would be nice to document in which
case it's false.

I checked the callers, and I don't think that we need to add any
dwarf2_section_info::read calls to compensate for the fact that get_size
used to do it.

Change-Id: I428571e532301d49f1d8242d687e1fcb819b75c1
Approved-By: Tom Tromey <tom@tromey.com>
gdb/dwarf2/comp-unit-head.c
gdb/dwarf2/read.c
gdb/dwarf2/section.h

index 8ec8897b283eb645b572359637d1d0688d0f7f6a..bc80c632cee038946cc6f0ba063025c6fa003959 100644 (file)
@@ -156,8 +156,7 @@ error_check_comp_unit_head (dwarf2_per_objfile *per_objfile,
 {
   const char *filename = section->get_file_name ();
 
-  if (to_underlying (header->abbrev_sect_off)
-      >= abbrev_section->get_size (per_objfile->objfile))
+  if (to_underlying (header->abbrev_sect_off) >= abbrev_section->size)
     error (_(DWARF_ERROR_PREFIX
             "bad offset (%s) in compilation unit header "
             "(offset %s + 6) [in module %s]"),
index 794c3973cb56f61bbe96ff1462aa902e5a35da5f..28872146344c0af679cc9e4d192ee5b754bd80c4 100644 (file)
@@ -19189,7 +19189,7 @@ dwarf2_symbol_mark_computed (const struct attribute *attr, struct symbol *sym,
       /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
         the section.  If so, fall through to the complaint in the
         other branch.  */
-      && attr->as_unsigned () < section->get_size (objfile))
+      && attr->as_unsigned () < section->size)
     {
       struct dwarf2_loclist_baton *baton;
 
index 85da48597521cad62451f81c52ce77ff7b57702b..b9d3c31453f2a2ee3d477e95be8498ba4a2f450c 100644 (file)
@@ -81,19 +81,6 @@ struct dwarf2_section_info
      If the section is compressed, uncompress it before returning.  */
   void read (struct objfile *objfile);
 
-  /* A helper function that returns the size of a section in a safe way.
-     If you are positive that the section has been read before using the
-     size, then it is safe to refer to the dwarf2_section_info object's
-     "size" field directly.  In other cases, you must call this
-     function, because for compressed sections the size field is not set
-     correctly until the section has been read.  */
-  bfd_size_type get_size (struct objfile *objfile)
-  {
-    if (!readin)
-      read (objfile);
-    return size;
-  }
-
   /* Issue a complaint that something was outside the bounds of this
      buffer.  */
   void overflow_complaint () const;