Re: [PATCH 2/2] gdb/block: add assert in block_iterator::compunit_symtab

Andrew Burgess
2026-02-06T16:37:14Z

simon.marchi@polymtl.ca writes:

> From: Simon Marchi <simon.marchi@efficios.com>
>
> Verify that the compunit is only accessed when the iterator is in the
> mode where that field makes sense.
>
> We could also set compunit_symtab_ even in "single block" mode, it
> wouldn't hurt, but it would not be useful either.

Approved-By: Andrew Burgess <aburgess@redhat.com>

Thanks,
Andrew

>
> Change-Id: I237db16bb485148f9e906b2e7238159e9f0a8585
> ---
> gdb/block.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/gdb/block.c b/gdb/block.c
> index 5aa58545393b..730e4580a5b7 100644
> --- a/gdb/block.c
> +++ b/gdb/block.c
> @@ -442,6 +442,10 @@ initialize_block_iterator (const struct block *block,
> compunit_symtab *
> block_iterator::compunit_symtab () const
> {
> + /* The compunit field is only used when iterating over global or static
> + blocks. */
> + gdb_assert (this->which != FIRST_LOCAL_BLOCK);
> +
> if (this->idx == -1)
> return this->compunit_symtab_;
>
> --
> 2.52.0