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

Simon Marchi via Gdb-cvs <[email protected]>
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1ad21a3c59c6a515b07f9e898d30e1dd65b898c3

commit 1ad21a3c59c6a515b07f9e898d30e1dd65b898c3
Author: Simon Marchi <[email protected]>
Date:   Wed Mar 11 14:05:47 2026 -0400

    gdb/dwarf: change dwarf_block_to_sp_offset to return bool
    
    Change-Id: I7607e0b1cbbbb0c7be0ec309d7d936154a910554
    Approved-By: Tom Tromey <[email protected]>

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

diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c
index a5ea43e0bcc..217f494ebd3 100644
--- a/gdb/dwarf2/expr.c
+++ b/gdb/dwarf2/expr.c
@@ -1493,11 +1493,9 @@ dwarf_block_to_fb_offset (const gdb_byte *buf, const gdb_byte *buf_end,
   return 1;
 }
 
-/* If <BUF..BUF_END] contains DW_FORM_block* with single DW_OP_bregSP(X) fill
-   in SP_OFFSET_RETURN with the X offset and return 1.  Otherwise return 0.
-   The matched SP register number depends on GDBARCH.  */
+/* See expr.h.  */
 
-int
+bool
 dwarf_block_to_sp_offset (struct gdbarch *gdbarch, const gdb_byte *buf,
 			  const gdb_byte *buf_end, CORE_ADDR *sp_offset_return)
 {
@@ -1505,7 +1503,8 @@ dwarf_block_to_sp_offset (struct gdbarch *gdbarch, const gdb_byte *buf,
   int64_t sp_offset;
 
   if (buf_end <= buf)
-    return 0;
+    return false;
+
   if (*buf >= DW_OP_breg0 && *buf <= DW_OP_breg31)
     {
       dwarf_reg = *buf - DW_OP_breg0;
@@ -1514,25 +1513,25 @@ dwarf_block_to_sp_offset (struct gdbarch *gdbarch, const gdb_byte *buf,
   else
     {
       if (*buf != DW_OP_bregx)
-       return 0;
+       return false;
+
       buf++;
       buf = gdb_read_uleb128 (buf, buf_end, &dwarf_reg);
       if (buf == NULL)
-	return 0;
+	return false;
     }
 
   if (dwarf_reg_to_regnum (gdbarch, dwarf_reg)
       != gdbarch_sp_regnum (gdbarch))
-    return 0;
+    return false;
 
   buf = gdb_read_sleb128 (buf, buf_end, &sp_offset);
   if (buf == NULL)
-    return 0;
+    return false;
+
   *sp_offset_return = sp_offset;
-  if (buf != buf_end || sp_offset != (LONGEST) *sp_offset_return)
-    return 0;
 
-  return 1;
+  return buf == buf_end && sp_offset == (LONGEST) *sp_offset_return;
 }
 
 /* Return true if, for an expr evaluated in the context of FRAME, we can
diff --git a/gdb/dwarf2/expr.h b/gdb/dwarf2/expr.h
index e25492f29a7..ad841658f63 100644
--- a/gdb/dwarf2/expr.h
+++ b/gdb/dwarf2/expr.h
@@ -278,9 +278,13 @@ int dwarf_block_to_dwarf_reg_deref (const gdb_byte *buf,
 int dwarf_block_to_fb_offset (const gdb_byte *buf, const gdb_byte *buf_end,
 			      CORE_ADDR *fb_offset_return);
 
-int dwarf_block_to_sp_offset (struct gdbarch *gdbarch, const gdb_byte *buf,
-			      const gdb_byte *buf_end,
-			      CORE_ADDR *sp_offset_return);
+/* If <BUF..BUF_END] contains DW_FORM_block* with single DW_OP_bregSP(X) fill
+   in SP_OFFSET_RETURN with the X offset and return true.  Otherwise return
+   false.  The matched SP register number depends on GDBARCH.  */
+
+bool dwarf_block_to_sp_offset (struct gdbarch *gdbarch, const gdb_byte *buf,
+			       const gdb_byte *buf_end,
+			       CORE_ADDR *sp_offset_return);
 
 /* Wrappers around the leb128 reader routines to simplify them for our
    purposes.  */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 74c6ab7eff7..5e310afc3f9 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -8258,7 +8258,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
 	  if (parameter->u.dwarf_reg != -1)
 	    parameter->kind = CALL_SITE_PARAMETER_DWARF_REG;
 	  else if (dwarf_block_to_sp_offset (gdbarch, block->data,
-				    &block->data[block->size],
+					     &block->data[block->size],
 					     &parameter->u.fb_offset))
 	    parameter->kind = CALL_SITE_PARAMETER_FB_OFFSET;
 	  else
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.