[02/10] Factor out block::containing_function_block

Message ID 20260501124504.2233495-3-tdevries@suse.de
State New
Headers
Series Add superblocks range loops |

Commit Message

Tom de Vries May 1, 2026, 12:44 p.m. UTC
  Factor out new function block::containing_function_block out of
block::containing_function.
---
 gdb/block.c | 18 ++++++++++++++----
 gdb/block.h |  5 +++++
 2 files changed, 19 insertions(+), 4 deletions(-)
  

Patch

diff --git a/gdb/block.c b/gdb/block.c
index e7424c52aff..7b006617d1a 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -99,15 +99,25 @@  block::linkage_function () const
 
 /* See block.h.  */
 
-struct symbol *
-block::containing_function () const
+const struct block *
+block::containing_function_block () const
 {
   const block *bl = this;
 
-  while (bl->function () == NULL && bl->superblock () != NULL)
+  while (bl->function () == nullptr && bl->superblock () != nullptr)
     bl = bl->superblock ();
 
-  return bl->function ();
+  return bl->function () != nullptr ? bl : nullptr;
+}
+
+/* See block.h.  */
+
+struct symbol *
+block::containing_function () const
+{
+  const block *bl = containing_function_block ();
+
+  return bl != nullptr ? bl->function () : nullptr;
 }
 
 /* See block.h.  */
diff --git a/gdb/block.h b/gdb/block.h
index cd02006f860..b70b27f6509 100644
--- a/gdb/block.h
+++ b/gdb/block.h
@@ -258,6 +258,11 @@  struct block : public allocate_on_obstack<block>
 
   struct symbol *containing_function () const;
 
+  /* Return the block for the closest enclosing function, which might be an
+     inline function.  */
+
+  const struct block *containing_function_block () const;
+
   /* Return the static block associated with this block.  Return NULL
      if block is a global block.  */