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

Guillaume VACHERIAS guillaume.vacherias@foss.st.com
Mon Sep 1 17:50:40 GMT 2025


Add missing ChangeLog entries and correctly set and clear do_flags anew
for do_type cases. Is this ok for trunk ?

Changes since v1:
- Added new prerequisite patch to better handle call and use sites.
- Change function process_debug_info arguments bool to unsigned int.
- Change option name to "--map-global-vars" instead of "-Y/--map-file".
- Added information on DWARF dependencues of this option.
- Correct switch-case braces alignment.
- Correct type of structure container field holding DW_AT_name from
(unsigned char *) to plain text (char *).
- Change to sizeof (<expression>) to avoid risk of variable's types being
changed.
- Replace error messages with asserts.
- Rename enumeration identifier UNKNOWN to UNKNWON_TYPE to be less generic.
- Remove unnecessary typedef aliases.

Changes since v2:
- Fix defines DO_LOC and DO_TYPES values to lower-case x-exes.
- Correctly set and clear do_flags anew.
- Remove unnecessary parenthesis.

---
binutils/

	* dwarf.c (DO_LOC, DO_TYPES): Define.
	(process_debug_info): Change arguments do_loc and do_types
	to a single unsigned int do_flags.
	(find_cu_tu_set_v2): Change parameter do_types from int to bool.

Signed-off-by: Guillaume VACHERIAS <guillaume.vacherias@foss.st.com>
---
 binutils/ChangeLog |  6 ++++
 binutils/dwarf.c   | 75 ++++++++++++++++++++++++++--------------------
 2 files changed, 49 insertions(+), 32 deletions(-)

diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 0577cf9bd3f..0c061efcb17 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,9 @@
+2025-09-01  Guillaume Vacherias <guillaume.vacherias@foss.st.com>
+	* dwarf.c (DO_LOC, DO_TYPES): Define.
+	(process_debug_info): Change arguments do_loc and do_types
+	to a single unsigned int do_flags.
+	(find_cu_tu_set_v2): Change parameter do_types from int to bool.
+
 2025-07-13  Nick Clifton  <nickc@redhat.com>
 
 	* 2.45 Branch point.
diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index bc5aa2b6b1b..b2bb3e595fe 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);
 
@@ -1727,7 +1730,7 @@ decode_location_expression (unsigned char * data,
    This is used for DWARF package files.  */
 
 static struct cu_tu_set *
-find_cu_tu_set_v2 (uint64_t cu_offset, int do_types)
+find_cu_tu_set_v2 (uint64_t cu_offset, bool do_types)
 {
   struct cu_tu_set *p;
   unsigned int nsets;
@@ -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,10 @@ 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);
+	  if (compunit.cu_unit_type == DW_UT_type)
+	    do_flags |= DO_TYPES;
+	  else
+	    do_flags &= ~DO_TYPES;
 
 	  SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end_cu);
 	}
@@ -3973,7 +3978,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 +3989,10 @@ 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);
+	  if (compunit.cu_unit_type == DW_UT_type)
+	    do_flags |= DO_TYPES;
+	  else
+	    do_flags &= ~DO_TYPES;
 
 	  SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end_cu);
 	}
@@ -4022,7 +4030,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 +4042,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 +4058,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 +4077,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 +4160,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 +4189,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 +4219,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 +4231,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 +4242,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 +4298,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 +4312,8 @@ 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 +4353,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 +4363,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 +4391,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 +7686,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, 0);
 }
 
 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 +12570,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