aboutsummaryrefslogtreecommitdiff
path: root/gdb/block.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2024-07-30 10:37:01 -0400
committerSimon Marchi <simon.marchi@efficios.com>2024-08-21 15:38:11 -0400
commit57a91ca28fa903375bfc829d8f6ad3fb8f34e1b0 (patch)
treecd4778b4594348bf7fe93b38cced367f0155b658 /gdb/block.c
parent5d683ae3dadd78fa88c243310404480555555246 (diff)
downloadgdb-57a91ca28fa903375bfc829d8f6ad3fb8f34e1b0.zip
gdb-57a91ca28fa903375bfc829d8f6ad3fb8f34e1b0.tar.gz
gdb-57a91ca28fa903375bfc829d8f6ad3fb8f34e1b0.tar.bz2
gdb: some global_block improvements
Some refactors around struct global_block, all in one patch because they all tie in together and are relatively trivial. - Make block::global_block() and blockvector::global_block() return `global_block *`, instead of `block *`. There is no cost in doing so, and it's a bit more precise. Callers of these methods that need a `global_block *` won't need to cast themselves. - Add some block::as_global_block methods, as a way to get a `global_block *` from a `block *` when you know it's a global block. This is basically a static cast with an assert. - Move set_compunit_symtab to global_block, since it requires the block to be a global block anyway. Rename to just `set_compunit` (I think that compunit_symtab should just be renamed compunit...). - Move the get_block_compunit_symtab free function to be a method of global_block. - Make global_block::compunit_symtab private and rename. - Simplify initialize_block_iterator. Change-Id: I1667a86b5c1a02d0d460cfad55b5d3d48867583d Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/block.c')
-rw-r--r--gdb/block.c75
1 files changed, 30 insertions, 45 deletions
diff --git a/gdb/block.c b/gdb/block.c
index acf21e2..d4baaae 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -41,13 +41,10 @@ struct block_namespace_info : public allocate_on_obstack<block_namespace_info>
struct objfile *
block::objfile () const
{
- const struct global_block *global_block;
-
if (function () != nullptr)
return function ()->objfile ();
- global_block = (struct global_block *) this->global_block ();
- return global_block->compunit_symtab->objfile ();
+ return this->global_block ()->compunit ()->objfile ();
}
/* See block. */
@@ -364,7 +361,7 @@ block::static_block () const
/* See block.h. */
-const struct block *
+const struct global_block *
block::global_block () const
{
const block *block = this;
@@ -372,33 +369,40 @@ block::global_block () const
while (block->superblock () != NULL)
block = block->superblock ();
- return block;
+ return block->as_global_block ();
}
/* See block.h. */
-const struct block *
-block::function_block () const
+struct global_block *
+block::as_global_block ()
{
- const block *block = this;
+ gdb_assert (this->is_global_block ());
- while (block != nullptr && block->function () == nullptr)
- block = block->superblock ();
+ return static_cast<struct global_block *>(this);
+}
- return block;
+/* See block.h. */
+
+const struct global_block *
+block::as_global_block () const
+{
+ gdb_assert (this->is_global_block ());
+
+ return static_cast<const struct global_block *>(this);
}
/* See block.h. */
-void
-block::set_compunit_symtab (struct compunit_symtab *cu)
+const struct block *
+block::function_block () const
{
- struct global_block *gb;
+ const block *block = this;
- gdb_assert (superblock () == NULL);
- gb = (struct global_block *) this;
- gdb_assert (gb->compunit_symtab == NULL);
- gb->compunit_symtab = cu;
+ while (block != nullptr && block->function () == nullptr)
+ block = block->superblock ();
+
+ return block;
}
/* See block.h. */
@@ -416,21 +420,6 @@ block::static_link () const
return (struct dynamic_prop *) objfile_lookup_static_link (objfile, this);
}
-/* Return the compunit of the global block. */
-
-static struct compunit_symtab *
-get_block_compunit_symtab (const struct block *block)
-{
- struct global_block *gb;
-
- gdb_assert (block->superblock () == NULL);
- gb = (struct global_block *) block;
- gdb_assert (gb->compunit_symtab != NULL);
- return gb->compunit_symtab;
-}
-
-
-
/* Initialize a block iterator, either to iterate over a single block,
or, for static and global blocks, all the included symtabs as
well. */
@@ -441,30 +430,26 @@ initialize_block_iterator (const struct block *block,
const lookup_name_info *name)
{
enum block_enum which;
- struct compunit_symtab *cu;
iter->idx = -1;
iter->name = name;
- if (block->superblock () == NULL)
- {
- which = GLOBAL_BLOCK;
- cu = get_block_compunit_symtab (block);
- }
- else if (block->superblock ()->superblock () == NULL)
- {
- which = STATIC_BLOCK;
- cu = get_block_compunit_symtab (block->superblock ());
- }
+ if (block->is_global_block ())
+ which = GLOBAL_BLOCK;
+ else if (block->is_static_block ())
+ which = STATIC_BLOCK;
else
{
iter->d.block = block;
+
/* A signal value meaning that we're iterating over a single
block. */
iter->which = FIRST_LOCAL_BLOCK;
return;
}
+ compunit_symtab *cu = block->global_block ()->compunit ();
+
/* If this is an included symtab, find the canonical includer and
use it instead. */
while (cu->user != NULL)