[2/7] Add block::function_block

Message ID 20231101-dap-nested-function-v1-2-0b0c3b228ac7@adacore.com
State New
Headers
Series Handle nested functions in DAP |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed

Commit Message

Tom Tromey Nov. 1, 2023, 5:09 p.m. UTC
  This adds the method block::function_block, to easily access a block's
enclosing function block.
---
 gdb/block.c | 13 +++++++++++++
 gdb/block.h |  6 ++++++
 2 files changed, 19 insertions(+)
  

Patch

diff --git a/gdb/block.c b/gdb/block.c
index 6ada69c388f..e588a68aa2f 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -378,6 +378,19 @@  block::global_block () const
 
 /* See block.h.  */
 
+const struct block *
+block::function_block () const
+{
+  const block *block = this;
+
+  while (block != nullptr && block->function () == nullptr)
+    block = block->superblock ();
+
+  return block;
+}
+
+/* See block.h.  */
+
 void
 block::set_compunit_symtab (struct compunit_symtab *cu)
 {
diff --git a/gdb/block.h b/gdb/block.h
index 9fccbe02b99..a29298517b0 100644
--- a/gdb/block.h
+++ b/gdb/block.h
@@ -273,6 +273,12 @@  struct block : public allocate_on_obstack
   bool is_global_block () const
   { return superblock () == nullptr; }
 
+  /* Return the function block for this block.  Returns nullptr if
+     there is no enclosing function, i.e., if this block is a static
+     or global block.  */
+
+  const struct block *function_block () const;
+
   /* Set the compunit of this block, which must be a global block.  */
 
   void set_compunit_symtab (struct compunit_symtab *);