aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/py-block.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/python/py-block.c')
-rw-r--r--gdb/python/py-block.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c
index aeb9acb..fa7dd19 100644
--- a/gdb/python/py-block.c
+++ b/gdb/python/py-block.c
@@ -1,6 +1,6 @@
/* Python interface to blocks.
- Copyright (C) 2008-2024 Free Software Foundation, Inc.
+ Copyright (C) 2008-2025 Free Software Foundation, Inc.
This file is part of GDB.
@@ -149,6 +149,37 @@ blpy_get_superblock (PyObject *self, void *closure)
Py_RETURN_NONE;
}
+/* Implement gdb.Block.subblocks attribute. Return a list of gdb.Block
+ objects that are direct children of this block. */
+
+static PyObject *
+blpy_get_subblocks (PyObject *self, void *closure)
+{
+ const struct block *block;
+
+ BLPY_REQUIRE_VALID (self, block);
+
+ gdbpy_ref<> list (PyList_New (0));
+ if (list == nullptr)
+ return nullptr;
+
+ compunit_symtab *cu = block->global_block ()->compunit ();
+
+ for (const struct block *each : cu->blockvector ()->blocks ())
+ {
+ if (each->superblock () == block)
+ {
+ gdbpy_ref<> item (block_to_block_object (each, cu->objfile ()));
+
+ if (item.get () == nullptr
+ || PyList_Append (list.get (), item.get ()) == -1)
+ return nullptr;
+ }
+ }
+
+ return list.release ();
+}
+
/* Return the global block associated to this block. */
static PyObject *
@@ -529,6 +560,8 @@ static gdb_PyGetSetDef block_object_getset[] = {
"Whether this block is a static block.", NULL },
{ "is_global", blpy_is_global, NULL,
"Whether this block is a global block.", NULL },
+ { "subblocks", blpy_get_subblocks, nullptr,
+ "List of blocks contained in this block.", nullptr },
{ NULL } /* Sentinel */
};