From: Simon Marchi Date: Thu, 17 Apr 2025 19:37:20 +0000 (-0400) Subject: gdb/dwarf: remove dwarf2_section_info::get_size X-Git-Tag: binutils-2_45~867 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1a710618a51b6cb10ed3d7a5d2fa4ced7bae4228;p=thirdparty%2Fbinutils-gdb.git gdb/dwarf: remove dwarf2_section_info::get_size 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 --- diff --git a/gdb/dwarf2/comp-unit-head.c b/gdb/dwarf2/comp-unit-head.c index 8ec8897b283..bc80c632cee 100644 --- a/gdb/dwarf2/comp-unit-head.c +++ b/gdb/dwarf2/comp-unit-head.c @@ -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]"), diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 794c3973cb5..28872146344 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -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; diff --git a/gdb/dwarf2/section.h b/gdb/dwarf2/section.h index 85da4859752..b9d3c31453f 100644 --- a/gdb/dwarf2/section.h +++ b/gdb/dwarf2/section.h @@ -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;