[PATCH 1/5] Add suitable defines to use at call and use sites

Guillaume VACHERIAS guillaume.vacherias@foss.st.com
Wed Aug 27 15:10:10 GMT 2025


I've modified the code accordingly.

Thank you for the review.

Guillaume.

--

binutils/

	* dwarf.c (process_debug_info): Change arguments do_loc and do_types
	to single unsigned int do_flags.
---
 binutils/dwarf.c | 66 +++++++++++++++++++++++++-----------------------
 1 file changed, 35 insertions(+), 31 deletions(-)

diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index bc5aa2b6b1b..648bc42e301 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -51,6 +51,9 @@
 #define MAX(a, b) ((a) > (b) ? (a) : (b))
 #define MIN(a, b) ((a) < (b) ? (a) : (b))
 
+#define DO_LOC     0X1
+#define DO_TYPES   0X2
+
 static const char *regname (unsigned int regno, int row);
 static const char *regname_internal_by_table_only (unsigned int regno);
 
@@ -3759,8 +3762,7 @@ static bool
 process_debug_info (struct dwarf_section * section,
 		    void *file,
 		    enum dwarf_section_display_enum abbrev_sec,
-		    bool do_loc,
-		    bool do_types)
+		    unsigned int do_flags)
 {
   unsigned char *start = section->start;
   unsigned char *end = start + section->size;
@@ -3808,9 +3810,9 @@ process_debug_info (struct dwarf_section * section,
       return false;
     }
 
-  if ((do_loc || do_debug_loc || do_debug_ranges || do_debug_info)
+  if (((do_flags & DO_LOC) || do_debug_loc || do_debug_ranges || do_debug_info)
       && alloc_num_debug_info_entries == 0
-      && !do_types)
+      && !(do_flags & DO_TYPES))
     {
       /* Then allocate an array to hold the information.  */
       debug_information = cmalloc (num_units, sizeof (*debug_information));
@@ -3832,7 +3834,7 @@ process_debug_info (struct dwarf_section * section,
       alloc_num_debug_info_entries = num_units;
     }
 
-  if (!do_loc)
+  if (!(do_flags & DO_LOC))
     {
       load_debug_section_with_follow (str, file);
       load_debug_section_with_follow (line_str, file);
@@ -3855,7 +3857,7 @@ process_debug_info (struct dwarf_section * section,
       return false;
     }
 
-  if (!do_loc && dwarf_start_die == 0)
+  if (!(do_flags & DO_LOC) && dwarf_start_die == 0)
     introduce (section, false);
 
   free_all_abbrevs ();
@@ -3891,7 +3893,7 @@ process_debug_info (struct dwarf_section * section,
 
       SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end_cu);
 
-      this_set = find_cu_tu_set_v2 (cu_offset, do_types);
+      this_set = find_cu_tu_set_v2 (cu_offset, (do_flags & DO_TYPES));
 
       if (compunit.cu_version < 5)
 	{
@@ -3902,7 +3904,7 @@ process_debug_info (struct dwarf_section * section,
       else
 	{
 	  SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end_cu);
-	  do_types = (compunit.cu_unit_type == DW_UT_type);
+	  do_flags |= (compunit.cu_unit_type == DW_UT_type) ? DO_TYPES : 0;
 
 	  SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end_cu);
 	}
@@ -3973,7 +3975,7 @@ process_debug_info (struct dwarf_section * section,
 
       SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end_cu);
 
-      this_set = find_cu_tu_set_v2 (cu_offset, do_types);
+      this_set = find_cu_tu_set_v2 (cu_offset, (do_flags & DO_TYPES));
 
       if (compunit.cu_version < 5)
 	{
@@ -3984,7 +3986,7 @@ process_debug_info (struct dwarf_section * section,
       else
 	{
 	  SAFE_BYTE_GET_AND_INC (compunit.cu_unit_type, hdrptr, 1, end_cu);
-	  do_types = (compunit.cu_unit_type == DW_UT_type);
+	  do_flags |= (compunit.cu_unit_type == DW_UT_type) ? DO_TYPES : 0;
 
 	  SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end_cu);
 	}
@@ -4022,7 +4024,7 @@ process_debug_info (struct dwarf_section * section,
 	  compunit.cu_pointer_size = offset_size;
 	}
 
-      if (do_types)
+      if ((do_flags & DO_TYPES))
 	{
 	  SAFE_BYTE_GET_AND_INC (signature, hdrptr, 8, end_cu);
 	  SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end_cu);
@@ -4034,10 +4036,11 @@ process_debug_info (struct dwarf_section * section,
 	  continue;
 	}
 
-      if ((do_loc || do_debug_loc || do_debug_ranges || do_debug_info)
+      if (((do_flags & DO_LOC) || do_debug_loc
+	  || do_debug_ranges || do_debug_info)
 	  && num_debug_info_entries == 0
 	  && alloc_num_debug_info_entries > unit
-	  && ! do_types)
+	  && ! (do_flags & DO_TYPES))
 	{
 	  free_debug_information (&debug_information[unit]);
 	  memset (&debug_information[unit], 0, sizeof (*debug_information));
@@ -4049,7 +4052,7 @@ process_debug_info (struct dwarf_section * section,
 	  debug_information[unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
 	}
 
-      if (!do_loc && dwarf_start_die == 0)
+      if (!(do_flags & DO_LOC) && dwarf_start_die == 0)
 	{
 	  printf (_("  Compilation Unit @ offset %#" PRIx64 ":\n"),
 		  cu_offset);
@@ -4068,7 +4071,7 @@ process_debug_info (struct dwarf_section * section,
 	  printf (_("   Abbrev Offset: %#" PRIx64 "\n"),
 		  compunit.cu_abbrev_offset);
 	  printf (_("   Pointer Size:  %d\n"), compunit.cu_pointer_size);
-	  if (do_types)
+	  if ((do_flags & DO_TYPES))
 	    {
 	      printf (_("   Signature:     %#" PRIx64 "\n"), signature);
 	      printf (_("   Type Offset:   %#" PRIx64 "\n"), type_offset);
@@ -4151,7 +4154,7 @@ process_debug_info (struct dwarf_section * section,
 		    break;
 		}
 
-	      if (!do_loc && die_offset >= dwarf_start_die
+	      if (!(do_flags & DO_LOC) && die_offset >= dwarf_start_die
 		  && (dwarf_cutoff_level == -1
 		      || level < dwarf_cutoff_level))
 		printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
@@ -4180,7 +4183,7 @@ process_debug_info (struct dwarf_section * section,
 	      continue;
 	    }
 
-	  if (!do_loc)
+	  if (!(do_flags & DO_LOC))
 	    {
 	      if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
 		do_printing = 0;
@@ -4210,7 +4213,7 @@ process_debug_info (struct dwarf_section * section,
 
 	  if (entry == NULL)
 	    {
-	      if (!do_loc && do_printing)
+	      if (!(do_flags & DO_LOC) && do_printing)
 		{
 		  printf ("\n");
 		  fflush (stdout);
@@ -4222,7 +4225,7 @@ process_debug_info (struct dwarf_section * section,
 	      return false;
 	    }
 
-	  if (!do_loc && do_printing)
+	  if (!(do_flags & DO_LOC) && do_printing)
 	    printf (" (%s)\n", get_TAG_name (entry->tag));
 
 	  switch (entry->tag)
@@ -4233,7 +4236,7 @@ process_debug_info (struct dwarf_section * section,
 	    case DW_TAG_compile_unit:
 	    case DW_TAG_skeleton_unit:
 	      need_base_address = 1;
-	      need_dwo_info = do_loc;
+	      need_dwo_info = do_flags & DO_LOC;
 	      break;
 	    case DW_TAG_entry_point:
 	      need_base_address = 0;
@@ -4289,7 +4292,7 @@ process_debug_info (struct dwarf_section * section,
 	       attr && attr->attribute;
 	       attr = attr->next)
 	    {
-	      if (! do_loc && do_printing)
+	      if (! (do_flags & DO_LOC) && do_printing)
 		/* Show the offset from where the tag was extracted.  */
 		printf ("    <%tx>", tags - section_begin);
 	      tags = read_and_display_attr (attr->attribute,
@@ -4303,7 +4306,7 @@ process_debug_info (struct dwarf_section * section,
 					    offset_size,
 					    compunit.cu_version,
 					    debug_info_p,
-					    do_loc || ! do_printing,
+					    do_flags & DO_LOC|| ! do_printing,
 					    section,
 					    this_set,
 					    level);
@@ -4343,9 +4346,9 @@ process_debug_info (struct dwarf_section * section,
 
   /* Set num_debug_info_entries here so that it can be used to check if
      we need to process .debug_loc and .debug_ranges sections.  */
-  if ((do_loc || do_debug_loc || do_debug_ranges || do_debug_info)
+  if (((do_flags & DO_LOC) || do_debug_loc || do_debug_ranges || do_debug_info)
       && num_debug_info_entries == 0
-      && ! do_types)
+      && ! (do_flags & DO_TYPES))
     {
       if (num_units > alloc_num_debug_info_entries)
 	num_debug_info_entries = alloc_num_debug_info_entries;
@@ -4353,7 +4356,7 @@ process_debug_info (struct dwarf_section * section,
 	num_debug_info_entries = num_units;
     }
 
-  if (!do_loc)
+  if (!(do_flags & DO_LOC))
     printf ("\n");
 
   return true;
@@ -4381,12 +4384,13 @@ load_debug_info (void * file)
   (void) load_cu_tu_indexes (file);
 
   if (load_debug_section_with_follow (info, file)
-      && process_debug_info (&debug_displays [info].section, file, abbrev, true, false))
+      && process_debug_info (&debug_displays [info].section, file,
+			     abbrev, DO_LOC))
     return num_debug_info_entries;
 
   if (load_debug_section_with_follow (info_dwo, file)
       && process_debug_info (&debug_displays [info_dwo].section, file,
-			     abbrev_dwo, true, false))
+			     abbrev_dwo, DO_LOC))
     return num_debug_info_entries;
 
   num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
@@ -7675,19 +7679,19 @@ display_debug_str (struct dwarf_section *section,
 static int
 display_debug_info (struct dwarf_section *section, void *file)
 {
-  return process_debug_info (section, file, section->abbrev_sec, false, false);
+  return process_debug_info (section, file, section->abbrev_sec, 0x0);
 }
 
 static int
 display_debug_types (struct dwarf_section *section, void *file)
 {
-  return process_debug_info (section, file, section->abbrev_sec, false, true);
+  return process_debug_info (section, file, section->abbrev_sec, DO_TYPES);
 }
 
 static int
 display_trace_info (struct dwarf_section *section, void *file)
 {
-  return process_debug_info (section, file, section->abbrev_sec, false, true);
+  return process_debug_info (section, file, section->abbrev_sec, DO_TYPES);
 }
 
 static int
@@ -12559,7 +12563,7 @@ load_separate_debug_files (void * file, const char * filename)
       free_dwo_info ();
 
       if (process_debug_info (& debug_displays[info].section, file, abbrev,
-			      true, false))
+			      DO_LOC))
 	{
 	  bool introduced = false;
 	  dwo_info *dwinfo;
-- 
2.25.1



More information about the Binutils mailing list