From patchwork Fri Jan 20 21:46:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 63531 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3E3A538AA262 for ; Fri, 20 Jan 2023 21:48:21 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from gproxy3-pub.mail.unifiedlayer.com (gproxy3-pub.mail.unifiedlayer.com [69.89.30.42]) by sourceware.org (Postfix) with ESMTPS id A2B353858C36 for ; Fri, 20 Jan 2023 21:46:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A2B353858C36 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw10.mail.unifiedlayer.com (unknown [10.0.90.125]) by progateway5.mail.pro1.eigbox.com (Postfix) with ESMTP id 1249C1004A27F for ; Fri, 20 Jan 2023 21:46:37 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id IzDYpicodFqSRIzDZp2cBD; Fri, 20 Jan 2023 21:46:37 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=c6Ru/Txl c=1 sm=1 tr=0 ts=63cb0bbd a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=RvmDmJFTN0MA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=Ss0_TLysQ42YSIft7JYA:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=2c53lFiY+YwV5Vj67iRdkB08cPGLWlgu0UePneFvdJM=; b=PSiMSC4fzt/Oq34A3aX0HfcjZa VfJP/a2XYRV+mjFZoZihj6RzaQgw1o3xqARCMGeEz4HC8zoqjwfmX+CYRE1cK4ZxawGmx1RtTP0ak 7UyiT9SbAWcHccmqhR/rfRF7I; Received: from 97-122-76-186.hlrn.qwest.net ([97.122.76.186]:60138 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pIzDY-001GGF-Iu; Fri, 20 Jan 2023 14:46:36 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 10/27] Convert more block functions to methods Date: Fri, 20 Jan 2023 14:46:01 -0700 Message-Id: <20230120214618.3236224-11-tom@tromey.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230120214618.3236224-1-tom@tromey.com> References: <20230120214618.3236224-1-tom@tromey.com> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.76.186 X-Source-L: No X-Exim-ID: 1pIzDY-001GGF-Iu X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-76-186.hlrn.qwest.net (localhost.localdomain) [97.122.76.186]:60138 X-Source-Auth: tom+tromey.com X-Email-Count: 11 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3027.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This converts block_scope, block_set_scope, block_using, and block_set_using to be methods. These are all done at once to make it easier to also convert block_initialize_namespace at the same time. This was mostly written by script. --- gdb/ada-lang.c | 2 +- gdb/block.c | 63 +++++++++++++++++++--------------------------- gdb/block.h | 48 +++++++++++++++++++++-------------- gdb/buildsym.c | 9 +++---- gdb/cp-namespace.c | 6 ++--- gdb/cp-support.c | 2 +- gdb/d-namespace.c | 4 +-- gdb/dbxread.c | 4 +-- gdb/dwarf2/read.c | 4 +-- gdb/rust-lang.c | 2 +- gdb/rust-lang.h | 2 +- gdb/rust-parse.c | 2 +- gdb/symtab.c | 2 +- 13 files changed, 74 insertions(+), 76 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 8fdf5fcef5a..7830fff6d8e 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -5428,7 +5428,7 @@ ada_add_block_renamings (std::vector &result, symbol_name_matcher_ftype *name_match = ada_get_symbol_name_matcher (lookup_name); - for (renaming = block_using (block); + for (renaming = block->get_using (); renaming != NULL; renaming = renaming->next) { diff --git a/gdb/block.c b/gdb/block.c index 574086aa4f6..fc523332a3d 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -285,40 +285,36 @@ block_for_pc (CORE_ADDR pc) /* Now come some functions designed to deal with C++ namespace issues. The accessors are safe to use even in the non-C++ case. */ -/* This returns the namespace that BLOCK is enclosed in, or "" if it - isn't enclosed in a namespace at all. This travels the chain of - superblocks looking for a scope, if necessary. */ +/* See block.h. */ const char * -block_scope (const struct block *block) +block::scope () const { - for (; block != NULL; block = block->superblock ()) + for (const block *block = this; + block != nullptr; + block = block->superblock ()) { - if (block->namespace_info () != NULL - && block->namespace_info ()->scope != NULL) - return block->namespace_info ()->scope; + if (block->m_namespace_info != nullptr + && block->m_namespace_info->scope != nullptr) + return block->m_namespace_info->scope; } return ""; } -/* If block->namespace_info () is NULL, allocate it via OBSTACK and - initialize its members to zero. */ +/* See block.h. */ -static void -block_initialize_namespace (struct block *block, struct obstack *obstack) +void +block::initialize_namespace (struct obstack *obstack) { - if (block->namespace_info () == NULL) - block->set_namespace_info (new (obstack) struct block_namespace_info ()); + if (m_namespace_info == nullptr) + m_namespace_info = new (obstack) struct block_namespace_info; } -/* Set BLOCK's scope member to SCOPE; if needed, allocate memory via - OBSTACK. (It won't make a copy of SCOPE, however, so that already - has to be allocated correctly.) */ +/* See block.h. */ void -block_set_scope (struct block *block, const char *scope, - struct obstack *obstack) +block::set_scope (const char *scope, struct obstack *obstack) { if (scope == nullptr || scope[0] == '\0') { @@ -326,31 +322,25 @@ block_set_scope (struct block *block, const char *scope, return; } - block_initialize_namespace (block, obstack); - - block->namespace_info ()->scope = scope; + initialize_namespace (obstack); + m_namespace_info->scope = scope; } -/* This returns the using directives list associated with BLOCK, if - any. */ +/* See block.h. */ struct using_direct * -block_using (const struct block *block) +block::get_using () const { - if (block->namespace_info () == NULL) - return NULL; + if (m_namespace_info == nullptr) + return nullptr; else - return block->namespace_info ()->using_decl; + return m_namespace_info->using_decl; } -/* Set BLOCK's using member to USING; if needed, allocate memory via - OBSTACK. (It won't make a copy of USING, however, so that already - has to be allocated correctly.) */ +/* See block.h. */ void -block_set_using (struct block *block, - struct using_direct *using_decl, - struct obstack *obstack) +block::set_using (struct using_direct *using_decl, struct obstack *obstack) { if (using_decl == nullptr) { @@ -358,9 +348,8 @@ block_set_using (struct block *block, return; } - block_initialize_namespace (block, obstack); - - block->namespace_info ()->using_decl = using_decl; + initialize_namespace (obstack); + m_namespace_info->using_decl = using_decl; } /* Return the static block associated to BLOCK. Return NULL if block diff --git a/gdb/block.h b/gdb/block.h index ab343b44698..680b7d0161e 100644 --- a/gdb/block.h +++ b/gdb/block.h @@ -147,14 +147,6 @@ struct block void set_multidict (multidictionary *multidict) { m_multidict = multidict; } - /* Return this block's namespace info. */ - block_namespace_info *namespace_info () const - { return m_namespace_info; } - - /* Set this block's namespace info. */ - void set_namespace_info (block_namespace_info *namespace_info) - { m_namespace_info = namespace_info; } - /* Return a view on this block's ranges. */ gdb::array_view ranges () { @@ -216,6 +208,29 @@ struct block bool inlined_p () const; + /* This returns the namespace that this block is enclosed in, or "" + if it isn't enclosed in a namespace at all. This travels the + chain of superblocks looking for a scope, if necessary. */ + + const char *scope () const; + + /* Set this block's scope member to SCOPE; if needed, allocate + memory via OBSTACK. (It won't make a copy of SCOPE, however, so + that already has to be allocated correctly.) */ + + void set_scope (const char *scope, struct obstack *obstack); + + /* This returns the using directives list associated with this + block, if any. */ + + struct using_direct *get_using () const; + + /* Set this block's using member to USING; if needed, allocate + memory via OBSTACK. (It won't make a copy of USING, however, so + that already has to be allocated correctly.) */ + + void set_using (struct using_direct *using_decl, struct obstack *obstack); + /* Addresses in the executable code that are in this block. */ CORE_ADDR m_start; @@ -248,6 +263,12 @@ struct block startaddr and endaddr above. */ struct blockranges *m_ranges; + +private: + + /* If the namespace_info is NULL, allocate it via OBSTACK and + initialize its members to zero. */ + void initialize_namespace (struct obstack *obstack); }; /* The global block is singled out so that we can provide a back-link @@ -373,17 +394,6 @@ extern const struct block *block_for_pc (CORE_ADDR); extern const struct block *block_for_pc_sect (CORE_ADDR, struct obj_section *); -extern const char *block_scope (const struct block *block); - -extern void block_set_scope (struct block *block, const char *scope, - struct obstack *obstack); - -extern struct using_direct *block_using (const struct block *block); - -extern void block_set_using (struct block *block, - struct using_direct *using_decl, - struct obstack *obstack); - extern const struct block *block_static_block (const struct block *block); extern const struct block *block_global_block (const struct block *block); diff --git a/gdb/buildsym.c b/gdb/buildsym.c index adab927235c..fd76e56599d 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -371,11 +371,10 @@ buildsym_compunit::finish_block_internal opblock = pblock; } - block_set_using (block, - (is_global - ? m_global_using_directives - : m_local_using_directives), - &m_objfile->objfile_obstack); + block->set_using ((is_global + ? m_global_using_directives + : m_local_using_directives), + &m_objfile->objfile_obstack); if (is_global) m_global_using_directives = NULL; else diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index 97b7a653e33..2d44b7bc047 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -413,7 +413,7 @@ cp_lookup_symbol_via_imports (const char *scope, /* Go through the using directives. If any of them add new names to the namespace we're searching in, see if we can find a match by applying them. */ - for (current = block_using (block); + for (current = block->get_using (); current != NULL; current = current->next) { @@ -769,7 +769,7 @@ cp_lookup_symbol_nonlocal (const struct language_defn *langdef, const domain_enum domain) { struct block_symbol sym; - const char *scope = block_scope (block); + const char *scope = block == nullptr ? "" : block->scope (); symbol_lookup_debug_printf ("cp_lookup_symbol_non_local (%s, %s (scope %s), %s)", @@ -1025,7 +1025,7 @@ cp_lookup_transparent_type (const char *name) /* If that doesn't work and we're within a namespace, look there instead. */ - scope = block_scope (get_selected_block (0)); + scope = get_selected_block (0)->scope (); if (scope[0] == '\0') return NULL; diff --git a/gdb/cp-support.c b/gdb/cp-support.c index be4a636336d..76407fdeb2f 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -1402,7 +1402,7 @@ add_symbol_overload_list_using (const char *func_name, for (block = get_selected_block (0); block != NULL; block = block->superblock ()) - for (current = block_using (block); + for (current = block->get_using (); current != NULL; current = current->next) { diff --git a/gdb/d-namespace.c b/gdb/d-namespace.c index aaef1dfae1f..6153e5b3239 100644 --- a/gdb/d-namespace.c +++ b/gdb/d-namespace.c @@ -375,7 +375,7 @@ d_lookup_symbol_imports (const char *scope, const char *name, the module we're searching in, see if we can find a match by applying them. */ - for (current = block_using (block); + for (current = block->get_using (); current != NULL; current = current->next) { @@ -511,7 +511,7 @@ d_lookup_symbol_nonlocal (const struct language_defn *langdef, const domain_enum domain) { struct block_symbol sym; - const char *scope = block == nullptr ? "" : block_scope (block); + const char *scope = block == nullptr ? "" : block->scope (); sym = lookup_module_scope (langdef, name, block, domain, scope, 0); if (sym.symbol != NULL) diff --git a/gdb/dbxread.c b/gdb/dbxread.c index ab0734f0218..dbfbf9a6574 100644 --- a/gdb/dbxread.c +++ b/gdb/dbxread.c @@ -2362,8 +2362,8 @@ cp_set_block_scope (const struct symbol *symbol, const char *name = symbol->demangled_name (); unsigned int prefix_len = cp_entire_prefix_len (name); - block_set_scope (block, obstack_strndup (obstack, name, prefix_len), - obstack); + block->set_scope (obstack_strndup (obstack, name, prefix_len), + obstack); } } diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index cd937f24ee7..9789f871eb9 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -12195,8 +12195,8 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) || cu->lang () == language_d || cu->lang () == language_rust) && cu->processing_has_namespace_info) - block_set_scope (block, determine_prefix (die, cu), - &objfile->objfile_obstack); + block->set_scope (determine_prefix (die, cu), + &objfile->objfile_obstack); /* If we have address ranges, record them. */ dwarf2_record_block_ranges (die, block, baseaddr, cu); diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index 6653f7a9c64..24fb514831f 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -58,7 +58,7 @@ rust_last_path_segment (const char *path) std::string rust_crate_for_block (const struct block *block) { - const char *scope = block_scope (block); + const char *scope = block->scope (); if (scope[0] == '\0') return std::string (); diff --git a/gdb/rust-lang.h b/gdb/rust-lang.h index 497342d4ef3..37a22e7a404 100644 --- a/gdb/rust-lang.h +++ b/gdb/rust-lang.h @@ -148,7 +148,7 @@ class rust_language : public language_defn { struct block_symbol result = {}; - const char *scope = block == nullptr ? "" : block_scope (block); + const char *scope = block == nullptr ? "" : block->scope (); symbol_lookup_debug_printf ("rust_lookup_symbol_non_local (%s, %s (scope %s), %s)", name, host_address_to_string (block), scope, diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c index 72b843ef40c..9074d651d85 100644 --- a/gdb/rust-parse.c +++ b/gdb/rust-parse.c @@ -375,7 +375,7 @@ rust_parser::super_name (const std::string &ident, unsigned int n_supers) { const char *scope = ""; if (pstate->expression_context_block != nullptr) - scope = block_scope (pstate->expression_context_block); + scope = pstate->expression_context_block->scope (); int offset; if (scope[0] == '\0') diff --git a/gdb/symtab.c b/gdb/symtab.c index 530de418e53..71b9ebe9efc 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2184,7 +2184,7 @@ lookup_local_symbol (const char *name, struct symbol *sym; const struct block *static_block = block_static_block (block); - const char *scope = block_scope (block); + const char *scope = block->scope (); /* Check if it's a global block. */ if (static_block == nullptr)