aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/py-block.c
diff options
context:
space:
mode:
authorJan Vrany <jan.vrany@labware.com>2025-02-04 13:56:49 +0000
committerJan Vrany <jan.vrany@labware.com>2025-02-04 13:56:49 +0000
commit5166ed9c9c6f60859295d932b65c5c5a19984dfd (patch)
tree874e1421f9a70922c7d1a66da7bdff26f6ac6233 /gdb/python/py-block.c
parent96a02b669eb4e5483bc820cc2cc8acfff8b8ae23 (diff)
downloadbinutils-5166ed9c9c6f60859295d932b65c5c5a19984dfd.zip
binutils-5166ed9c9c6f60859295d932b65c5c5a19984dfd.tar.gz
binutils-5166ed9c9c6f60859295d932b65c5c5a19984dfd.tar.bz2
gdb/python: add subblocks property to gdb.Block
This commit adds new propery "subblocks" to gdb.Block objects. This allows Python to traverse block tree starting with global block. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-By: Andrew Burgess <aburgess@redhat.com>
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 */
};