[binutils-gdb] dwarf.c is_dwo_section

Alan Modra via Binutils-cvs <[email protected]>
Newsgroups gmane.comp.gnu.binutils.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1ad761d978807cdd3a9972e32db6e3899de2115d

commit 1ad761d978807cdd3a9972e32db6e3899de2115d
Author: Alan Modra <[email protected]>
Date:   Thu Aug 27 22:35:45 2026 +0930

    dwarf.c is_dwo_section
    
    Extract out section name test for .dwo suffix into a new function.
    
            * dwarf.c (is_dwo_section): New function.
            (read_and_display_attr_value, display_debug_macro),
            (display_debug_loc, display_debug_str_offsets): Use it.

Diff:
---
 binutils/dwarf.c | 29 ++++++++++++-----------------
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index 829bcb761f7..3152dbdbd1c 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -2113,6 +2113,13 @@ free_dwo_info (void)
   first_dwo_info = NULL;
 }
 
+static bool
+is_dwo_section (const struct dwarf_section *section)
+{
+  size_t len = strlen (section->name);
+  return len >= 4 && memcmp (section->name + len - 4, ".dwo", 4) == 0;
+}
+
 /* Ensure that START + UVALUE is less than END.
    Return an adjusted UVALUE if necessary to ensure this relationship.  */
 
@@ -3884,8 +3891,7 @@ read_and_display_attr_value (unsigned long attribute,
     case DW_FORM_strx4:
       if (!do_loc)
 	{
-	  const char *suffix = section ? strrchr (section->name, '.') : NULL;
-	  bool dwo = suffix && strcmp (suffix, ".dwo") == 0;
+	  bool dwo = is_dwo_section (section);
 	  const char *strng;
 
 	  strng = fetch_indexed_string (uvalue, this_set, offset_size, dwo,
@@ -3944,8 +3950,7 @@ read_and_display_attr_value (unsigned long attribute,
       if (!do_loc)
 	{
 	  uint64_t base, idx;
-	  const char *suffix = strrchr (section->name, '.');
-	  bool dwo = suffix && strcmp (suffix, ".dwo") == 0;
+	  bool dwo = is_dwo_section (section);
 
 	  if (form == DW_FORM_loclistx)
 	    {
@@ -7586,11 +7591,7 @@ display_debug_macro (struct dwarf_section *section,
   unsigned char *end = start + section->size;
   unsigned char *curr = start;
   unsigned char *extended_op_buf[256];
-  bool is_dwo = false;
-  const char *suffix = strrchr (section->name, '.');
-
-  if (suffix && strcmp (suffix, ".dwo") == 0)
-    is_dwo = true;
+  bool is_dwo = is_dwo_section (section);
 
   if (is_dwo)
     {
@@ -8604,14 +8605,10 @@ display_debug_loc (struct dwarf_section *section, void *file)
   int locs_sorted = 1;
   unsigned char *next = start, *vnext = vstart;
   unsigned int *array = NULL;
-  const char *suffix = strrchr (section->name, '.');
-  bool is_dwo = false;
+  bool is_dwo = is_dwo_section (section);
   bool is_loclists = strstr (section->name, "debug_loclists") != NULL;
   uint64_t next_header_offset = 0;
 
-  if (suffix && strcmp (suffix, ".dwo") == 0)
-    is_dwo = true;
-
   bytes = section->size;
 
   if (bytes == 0)
@@ -9266,9 +9263,7 @@ display_debug_str_offsets (struct dwarf_section *section,
   unsigned char *end = start + section->size;
   unsigned char *curr = start;
   uint64_t debug_str_offsets_hdr_len;
-
-  const char *suffix = strrchr (section->name, '.');
-  bool dwo = suffix && strcmp (suffix, ".dwo") == 0;
+  bool dwo = is_dwo_section (section);
 
   if (dwo)
     load_debug_section_with_follow (str_dwo, file);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.