From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 2OQ+GK36qGYMkzYAWB0awg (envelope-from ) for ; Tue, 30 Jul 2024 10:37:33 -0400 Received: by simark.ca (Postfix, from userid 112) id 5D3091E0D0; Tue, 30 Jul 2024 10:37:33 -0400 (EDT) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 4785D1E030 for ; Tue, 30 Jul 2024 10:37:31 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E3D9F3858C56 for ; Tue, 30 Jul 2024 14:37:30 +0000 (GMT) Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id B2F3C3858C56 for ; Tue, 30 Jul 2024 14:37:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B2F3C3858C56 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B2F3C3858C56 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722350230; cv=none; b=ocjCHeYkimPGpPUVpPJf9i3fRPYRZ87YQptThTf5PowJItqe0KFXqqTa4xOyPESc/cTIXxEH4Wu56S0L9Js6tGQGVQJn3f+KN9+5vN5g1o4o8NtGH9pQTV2n/aBac4MUEHNOjU1k6kzJHOmai5AxOWl9XHQUHIigAhPXtqLkPNs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722350230; c=relaxed/simple; bh=GeaCFOyLSpt/QWMqVnf512ZxARR6sLi6rlqH3kK+xMo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ibQztpHTaWWKRlHcqNgTV1o8wrSb23Nxgc1a33/YY5BLx9+jhdBmTC8QJNke658iZbgk3coEkD2g3508bdYeVl2uT0U7NK0lvjnn0zs0JCgFtlF2RJgXTVz0j/MaFnM8Xwb476HjAVHfda0W5MX22cPUFCM1S7chWmavaUBmF24= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from smarchi-efficios.internal.efficios.com (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 59D021E030; Tue, 30 Jul 2024 10:37:06 -0400 (EDT) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH] gdb: some global_block improvements Date: Tue, 30 Jul 2024 10:37:01 -0400 Message-ID: <20240730143705.39618-1-simon.marchi@efficios.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3496.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org 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, 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 --- gdb/block.c | 75 ++++++++++++++++++++------------------------------ gdb/block.h | 48 +++++++++++++++++++++++--------- gdb/buildsym.c | 6 +--- gdb/jit.c | 3 +- 4 files changed, 68 insertions(+), 64 deletions(-) diff --git a/gdb/block.c b/gdb/block.c index 511689c9738f..95fa1f237e91 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -41,13 +41,10 @@ struct block_namespace_info : public allocate_on_obstack 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(this); +} - return block; +/* See block.h. */ + +const struct global_block * +block::as_global_block () const +{ + gdb_assert (this->is_global_block ()); + + return static_cast(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 = nullptr) { 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) diff --git a/gdb/block.h b/gdb/block.h index ae676c4ba673..c3babad52f3f 100644 --- a/gdb/block.h +++ b/gdb/block.h @@ -264,25 +264,26 @@ struct block : public allocate_on_obstack 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 @@ struct block : public allocate_on_obstack }; /* 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. + + 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. - struct compunit_symtab *compunit_symtab = nullptr; + 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 (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 + (this->block (GLOBAL_BLOCK)); + } /* Return the static block of this blockvector. */ struct block *static_block () diff --git a/gdb/buildsym.c b/gdb/buildsym.c index 1c762ad81bfd..02d6848f3a4a 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -951,11 +951,7 @@ buildsym_compunit::end_compunit_symtab_with_blockvector cu->set_producer (m_producer); cu->set_blockvector (blockvector); - { - struct block *b = blockvector->global_block (); - - b->set_compunit_symtab (cu); - } + blockvector->global_block ()->set_compunit (cu); cu->set_macro_table (release_macros ()); diff --git a/gdb/jit.c b/gdb/jit.c index 2744d03f8f8d..d5e3804e7f06 100644 --- a/gdb/jit.c +++ b/gdb/jit.c @@ -613,6 +613,7 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile) new_block = new (&objfile->objfile_obstack) global_block; else new_block = new (&objfile->objfile_obstack) block; + new_block->set_multidict (mdict_create_linear (&objfile->objfile_obstack, NULL)); new_block->set_superblock (block_iter); @@ -624,7 +625,7 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile) bv->set_block (i, new_block); if (i == GLOBAL_BLOCK) - new_block->set_compunit_symtab (cust); + new_block->as_global_block ()->set_compunit (cust); } /* Fill up the superblock fields for the real blocks, using the base-commit: b1da98a74656685087b0afd97af8080edc78d995 -- 2.45.2