mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-26 09:08:59 +00:00
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>
This commit is contained in:
48
gdb/block.h
48
gdb/block.h
@@ -264,25 +264,26 @@ struct block : public allocate_on_obstack<block>
|
||||
return sup->is_global_block ();
|
||||
}
|
||||
|
||||
/* Return the static block associated with block. */
|
||||
/* Return the global block associated with block. */
|
||||
|
||||
const struct block *global_block () const;
|
||||
const struct global_block *global_block () const;
|
||||
|
||||
/* Return true if this block is a global block. */
|
||||
|
||||
bool is_global_block () const
|
||||
{ return superblock () == nullptr; }
|
||||
|
||||
/* Return this block as a global_block. This block must be a global
|
||||
block. */
|
||||
struct global_block *as_global_block ();
|
||||
const struct global_block *as_global_block () const;
|
||||
|
||||
/* Return the function block for this block. Returns nullptr if
|
||||
there is no enclosing function, i.e., if this block is a static
|
||||
or global block. */
|
||||
|
||||
const struct block *function_block () const;
|
||||
|
||||
/* Set the compunit of this block, which must be a global block. */
|
||||
|
||||
void set_compunit_symtab (struct compunit_symtab *);
|
||||
|
||||
/* Return a property to evaluate the static link associated to this
|
||||
block.
|
||||
|
||||
@@ -346,13 +347,31 @@ private:
|
||||
};
|
||||
|
||||
/* The global block is singled out so that we can provide a back-link
|
||||
to the compunit symtab. */
|
||||
to the compunit. */
|
||||
|
||||
struct global_block : public block
|
||||
{
|
||||
/* This holds a pointer to the compunit symtab holding this block. */
|
||||
/* Set the compunit of this global block.
|
||||
|
||||
struct compunit_symtab *compunit_symtab = nullptr;
|
||||
The compunit must not have been set previously. */
|
||||
void set_compunit (compunit_symtab *cu)
|
||||
{
|
||||
gdb_assert (m_compunit == nullptr);
|
||||
m_compunit = cu;
|
||||
}
|
||||
|
||||
/* Return the compunit of this global block.
|
||||
|
||||
The compunit must have been set previously. */
|
||||
compunit_symtab *compunit () const
|
||||
{
|
||||
gdb_assert (m_compunit != nullptr);
|
||||
return m_compunit;
|
||||
}
|
||||
|
||||
private:
|
||||
/* This holds a pointer to the compunit holding this block. */
|
||||
compunit_symtab *m_compunit = nullptr;
|
||||
};
|
||||
|
||||
struct blockvector
|
||||
@@ -394,12 +413,15 @@ struct blockvector
|
||||
{ return m_num_blocks; }
|
||||
|
||||
/* Return the global block of this blockvector. */
|
||||
struct block *global_block ()
|
||||
{ return this->block (GLOBAL_BLOCK); }
|
||||
struct global_block *global_block ()
|
||||
{ return static_cast<struct global_block *> (this->block (GLOBAL_BLOCK)); }
|
||||
|
||||
/* Const version of the above. */
|
||||
const struct block *global_block () const
|
||||
{ return this->block (GLOBAL_BLOCK); }
|
||||
const struct global_block *global_block () const
|
||||
{
|
||||
return static_cast<const struct global_block *>
|
||||
(this->block (GLOBAL_BLOCK));
|
||||
}
|
||||
|
||||
/* Return the static block of this blockvector. */
|
||||
struct block *static_block ()
|
||||
|
||||
Reference in New Issue
Block a user