[binutils-gdb] gdb/dwarf: change dwarf2_ranges_read to return bool

Simon Marchi simark@sourceware.org
Thu Mar 12 14:52:17 GMT 2026


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=67cdd8e7aaf706f90fa90bf5a739caf99a21dac8

commit 67cdd8e7aaf706f90fa90bf5a739caf99a21dac8
Author: Simon Marchi <simon.marchi@efficios.com>
Date:   Wed Mar 11 14:05:35 2026 -0400

    gdb/dwarf: change dwarf2_ranges_read to return bool
    
    Also, do some little cleanups in the function itself.
    
    Change-Id: I83928a31dcdcae34b651828fef27b1fa877241eb
    Approved-By: Tom Tromey <tom@tromey.com>

Diff:
---
 gdb/dwarf2/read.c | 32 ++++++++++++++++++--------------
 gdb/dwarf2/read.h | 10 +++++-----
 2 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 6861b6ad4cd..74c6ab7eff7 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -8712,17 +8712,15 @@ dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu, dwarf_tag tag,
 
 /* See read.h.  */
 
-int
+bool
 dwarf2_ranges_read (unsigned offset, unrelocated_addr *low_return,
 		    unrelocated_addr *high_return, struct dwarf2_cu *cu,
 		    addrmap_mutable *map, void *datum, dwarf_tag tag)
 {
-  int low_set = 0;
+  bool low_set = false;
   unrelocated_addr low = {};
   unrelocated_addr high = {};
-  bool retval;
-
-  retval = dwarf2_ranges_process (offset, cu, tag,
+  bool retval = dwarf2_ranges_process (offset, cu, tag,
     [&] (unrelocated_addr range_beginning, unrelocated_addr range_end)
     {
       if (map != nullptr)
@@ -8737,33 +8735,39 @@ dwarf2_ranges_read (unsigned offset, unrelocated_addr *low_return,
 	 segment of consecutive addresses.  We should have a
 	 data structure for discontiguous block ranges
 	 instead.  */
-      if (! low_set)
+      if (!low_set)
 	{
 	  low = range_beginning;
 	  high = range_end;
-	  low_set = 1;
+	  low_set = true;
 	}
       else
 	{
 	  if (range_beginning < low)
 	    low = range_beginning;
+
 	  if (range_end > high)
 	    high = range_end;
 	}
     });
+
   if (!retval)
-    return 0;
+    return false;
 
-  if (! low_set)
-    /* If the first entry is an end-of-list marker, the range
+  if (!low_set)
+    {
+      /* If the first entry is an end-of-list marker, the range
        describes an empty scope, i.e. no instructions.  */
-    return 0;
+      return false;
+    }
 
-  if (low_return)
+  if (low_return != nullptr)
     *low_return = low;
-  if (high_return)
+
+  if (high_return != nullptr)
     *high_return = high;
-  return 1;
+
+  return true;
 }
 
 /* Process ranges and fill in a vector of the low PC values only.  */
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index e2d75e16146..86f97e7ccf4 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -1381,14 +1381,14 @@ extern dwarf2_per_cu *dwarf2_find_unit (const section_and_offset &start,
 extern bool decode_locdesc (dwarf_block *blk, dwarf2_cu *cu, CORE_ADDR *result);
 
 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
-   Return 1 if the attributes are present and valid, otherwise, return 0.
+   Return true if the attributes are present and valid, otherwise, return false.
    TAG is passed to dwarf2_ranges_process.  If MAP is not NULL, then
    ranges in MAP are set, using DATUM as the value.  */
 
-extern int dwarf2_ranges_read (unsigned offset, unrelocated_addr *low_return,
-			       unrelocated_addr *high_return, dwarf2_cu *cu,
-			       addrmap_mutable *map, void *datum,
-			       dwarf_tag tag);
+extern bool dwarf2_ranges_read (unsigned offset, unrelocated_addr *low_return,
+				unrelocated_addr *high_return, dwarf2_cu *cu,
+				addrmap_mutable *map, void *datum,
+				dwarf_tag tag);
 
 extern file_and_directory &find_file_and_directory (die_info *die,
 						    dwarf2_cu *cu);


More information about the Gdb-cvs mailing list