diff options
Diffstat (limited to 'gdb/python/py-block.c')
-rw-r--r-- | gdb/python/py-block.c | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c index 62e93d5..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 * @@ -493,19 +524,14 @@ static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION gdbpy_initialize_blocks (void) { block_object_type.tp_new = PyType_GenericNew; - if (PyType_Ready (&block_object_type) < 0) + if (gdbpy_type_ready (&block_object_type) < 0) return -1; block_syms_iterator_object_type.tp_new = PyType_GenericNew; - if (PyType_Ready (&block_syms_iterator_object_type) < 0) - return -1; - - if (gdb_pymodule_addobject (gdb_module, "Block", - (PyObject *) &block_object_type) < 0) + if (gdbpy_type_ready (&block_syms_iterator_object_type) < 0) return -1; - return gdb_pymodule_addobject (gdb_module, "BlockIterator", - (PyObject *) &block_syms_iterator_object_type); + return 0; } GDBPY_INITIALIZE_FILE (gdbpy_initialize_blocks); @@ -534,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 */ }; |