aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2023-10-24 07:53:29 -0600
committerTom Tromey <tromey@adacore.com>2023-11-14 08:49:55 -0700
commit43f2540a8e6e628da567faf671e2f2925afea56a (patch)
tree566c2c778969d1d4c42b8cee8ca1d2d6317227fc /gdb
parent18a2a7470f7e944957c4c5b8ae7cf2fd6544ac8b (diff)
downloadgdb-43f2540a8e6e628da567faf671e2f2925afea56a.zip
gdb-43f2540a8e6e628da567faf671e2f2925afea56a.tar.gz
gdb-43f2540a8e6e628da567faf671e2f2925afea56a.tar.bz2
Add block::function_block
This adds the method block::function_block, to easily access a block's enclosing function block. (cherry picked from commit ba707cadae18a7cc8bb47a736d3d0438d44262a9)
Diffstat (limited to 'gdb')
-rw-r--r--gdb/block.c13
-rw-r--r--gdb/block.h6
2 files changed, 19 insertions, 0 deletions
diff --git a/gdb/block.c b/gdb/block.c
index 6ada69c..e588a68 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 9fccbe0..a292985 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 *);