From patchwork Fri Jan 20 21:46:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 63525 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 D32393893679 for ; Fri, 20 Jan 2023 21:47:44 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from alt-proxy28.mail.unifiedlayer.com (alt-proxy28.mail.unifiedlayer.com [74.220.216.123]) by sourceware.org (Postfix) with ESMTPS id 5E806385735E for ; Fri, 20 Jan 2023 21:46:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5E806385735E 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 cmgw12.mail.unifiedlayer.com (unknown [10.0.90.127]) by progateway1.mail.pro1.eigbox.com (Postfix) with ESMTP id D35221003FD9D for ; Fri, 20 Jan 2023 21:46:37 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id IzDZp994SiOW0IzDZpygDm; Fri, 20 Jan 2023 21:46:37 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=S5kcfKgP 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=Ab0uQ1DXlzr8lSvP7hYA: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=ythRX9FoGLofUMOb+YfVzqKQcqqxgBjqd/tLhHJlEl4=; b=WeNnVM60Yw4tzpHKFCuTPu6hO5 EzBu8xKQnjyNnngZ5Jaqtb3S3X//hf4v1wxg4aoByRPClD4Y8W9rqDI/WgkdwRXVoRsO2+s1HfpNe q14G0O+4w9C6OtzdiheG4YVaz; 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 1pIzDZ-001GGF-Ej; Fri, 20 Jan 2023 14:46:37 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 13/27] Convert block_static_block and block_global_block to methods Date: Fri, 20 Jan 2023 14:46:04 -0700 Message-Id: <20230120214618.3236224-14-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: 1pIzDZ-001GGF-Ej 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: 14 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_static_block and block_global_block to be methods. This was mostly written by script. It was simpler to convert them at the same time because they're often used near each other. --- gdb/ada-lang.c | 2 +- gdb/block.c | 18 ++++++++++-------- gdb/block.h | 13 +++++++++---- gdb/compile/compile-c-symbols.c | 6 +++--- gdb/compile/compile-cplus-symbols.c | 4 ++-- gdb/cp-namespace.c | 2 +- gdb/cp-support.c | 8 ++++---- gdb/findvar.c | 6 +++--- gdb/guile/scm-block.c | 4 ++-- gdb/python/py-block.c | 4 ++-- gdb/rust-parse.c | 2 +- gdb/symtab.c | 10 +++++----- 12 files changed, 43 insertions(+), 36 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 2602700e0ce..57676f0de95 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -13818,7 +13818,7 @@ class ada_language : public language_defn sym = ada_lookup_symbol (name, (block == nullptr ? nullptr - : block_static_block (block)), + : block->static_block ()), domain); if (sym.symbol != NULL) return sym; diff --git a/gdb/block.c b/gdb/block.c index 31916ce48dc..c0d6ed7da97 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -47,7 +47,7 @@ block::objfile () const if (function () != nullptr) return function ()->objfile (); - global_block = (struct global_block *) block_global_block (this); + global_block = (struct global_block *) this->global_block (); return global_block->compunit_symtab->objfile (); } @@ -349,26 +349,28 @@ block::set_using (struct using_direct *using_decl, struct obstack *obstack) m_namespace_info->using_decl = using_decl; } -/* Return the static block associated to BLOCK. Return NULL if block - is a global block. */ +/* See block.h. */ const struct block * -block_static_block (const struct block *block) +block::static_block () const { - if (block->superblock () == NULL) - return NULL; + if (superblock () == nullptr) + return nullptr; + const block *block = this; while (block->superblock ()->superblock () != NULL) block = block->superblock (); return block; } -/* Return the static block associated to BLOCK. */ +/* See block.h. */ const struct block * -block_global_block (const struct block *block) +block::global_block () const { + const block *block = this; + while (block->superblock () != NULL) block = block->superblock (); diff --git a/gdb/block.h b/gdb/block.h index 9f1ba935abb..9ce8ef51945 100644 --- a/gdb/block.h +++ b/gdb/block.h @@ -245,6 +245,15 @@ struct block struct symbol *containing_function () const; + /* Return the static block associated with this block. Return NULL + if block is a global block. */ + + const struct block *static_block () const; + + /* Return the static block associated with block. */ + + const struct block *global_block () const; + /* Addresses in the executable code that are in this block. */ CORE_ADDR m_start; @@ -404,10 +413,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 struct block *block_static_block (const struct block *block); - -extern const struct block *block_global_block (const struct block *block); - extern struct block *allocate_block (struct obstack *obstack); extern struct block *allocate_global_block (struct obstack *obstack); diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c index 79490b811c3..678cbcd5c44 100644 --- a/gdb/compile/compile-c-symbols.c +++ b/gdb/compile/compile-c-symbols.c @@ -228,7 +228,7 @@ convert_symbol_sym (compile_c_instance *context, const char *identifier, const struct block *static_block = nullptr; if (sym.block != nullptr) - static_block = block_static_block (sym.block); + static_block = sym.block->static_block (); /* STATIC_BLOCK is NULL if FOUND_BLOCK is the global block. */ is_local_symbol = (sym.block != static_block && static_block != NULL); if (is_local_symbol) @@ -239,7 +239,7 @@ convert_symbol_sym (compile_c_instance *context, const char *identifier, /* If the outer symbol is in the static block, we ignore it, as it cannot be referenced. */ if (global_sym.symbol != NULL - && global_sym.block != block_static_block (global_sym.block)) + && global_sym.block != global_sym.block->static_block ()) { if (compile_debug) gdb_printf (gdb_stdlog, @@ -617,7 +617,7 @@ generate_c_for_variable_locations (compile_instance *compiler, if (block == nullptr) return {}; - const struct block *static_block = block_static_block (block); + const struct block *static_block = block->static_block (); /* If we're already in the static or global block, there is nothing to write. */ diff --git a/gdb/compile/compile-cplus-symbols.c b/gdb/compile/compile-cplus-symbols.c index 45a76eef303..eff04406fb5 100644 --- a/gdb/compile/compile-cplus-symbols.c +++ b/gdb/compile/compile-cplus-symbols.c @@ -241,7 +241,7 @@ convert_symbol_sym (compile_cplus_instance *instance, const struct block *static_block = nullptr; if (sym.block != nullptr) - static_block = block_static_block (sym.block); + static_block = sym.block->static_block (); /* STATIC_BLOCK is NULL if FOUND_BLOCK is the global block. */ bool is_local_symbol = (sym.block != static_block && static_block != nullptr); if (is_local_symbol) @@ -252,7 +252,7 @@ convert_symbol_sym (compile_cplus_instance *instance, /* If the outer symbol is in the static block, we ignore it, as it cannot be referenced. */ if (global_sym.symbol != nullptr - && global_sym.block != block_static_block (global_sym.block)) + && global_sym.block != global_sym.block->static_block ()) { if (compile_debug) gdb_printf (gdb_stdlog, diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c index 2d44b7bc047..14d807694b7 100644 --- a/gdb/cp-namespace.c +++ b/gdb/cp-namespace.c @@ -141,7 +141,7 @@ cp_basic_lookup_symbol (const char *name, const struct block *block, but should be treated as local to a single file nonetheless. So we only search the current file's global block. */ - const struct block *global_block = block_global_block (block); + const struct block *global_block = block->global_block (); if (global_block != NULL) { diff --git a/gdb/cp-support.c b/gdb/cp-support.c index 76407fdeb2f..cdaf5fd3e8e 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -1307,13 +1307,13 @@ add_symbol_overload_list_namespace (const char *func_name, /* Look in the static block. */ block = get_selected_block (0); - block = block == nullptr ? nullptr : block_static_block (block); + block = block == nullptr ? nullptr : block->static_block (); if (block != nullptr) { add_symbol_overload_list_block (name, block, overload_list); /* Look in the global block. */ - block = block_global_block (block); + block = block->global_block (); if (block) add_symbol_overload_list_block (name, block, overload_list); } @@ -1457,10 +1457,10 @@ add_symbol_overload_list_qualified (const char *func_name, b = b->superblock ()) add_symbol_overload_list_block (func_name, b, overload_list); - surrounding_static_block = block_static_block (get_selected_block (0)); + surrounding_static_block = get_selected_block (0); surrounding_static_block = (surrounding_static_block == nullptr ? nullptr - : block_static_block (surrounding_static_block)); + : surrounding_static_block->static_block ()); /* Go through the symtabs and check the externs and statics for symbols which match. */ diff --git a/gdb/findvar.c b/gdb/findvar.c index 656f982be2d..586ceb9dc72 100644 --- a/gdb/findvar.c +++ b/gdb/findvar.c @@ -460,8 +460,8 @@ get_hosting_frame (struct symbol *var, const struct block *var_block, tests that embed global/static symbols with null location lists. We want to get instead of when evaluating them so return a frame instead of raising an error. */ - else if (var_block == block_global_block (var_block) - || var_block == block_static_block (var_block)) + else if (var_block == var_block->global_block () + || var_block == var_block->static_block ()) return frame; /* We have to handle the "my_func::my_local_var" notation. This requires us @@ -486,7 +486,7 @@ get_hosting_frame (struct symbol *var, const struct block *var_block, /* If we failed to find the proper frame, fallback to the heuristic method below. */ - else if (frame_block == block_global_block (frame_block)) + else if (frame_block == frame_block->global_block ()) { frame = NULL; break; diff --git a/gdb/guile/scm-block.c b/gdb/guile/scm-block.c index 02cd3ff9a43..c9d847a4d60 100644 --- a/gdb/guile/scm-block.c +++ b/gdb/guile/scm-block.c @@ -438,7 +438,7 @@ gdbscm_block_global_block (SCM self) const struct block *block = b_smob->block; const struct block *global_block; - global_block = block_global_block (block); + global_block = block->global_block (); return bkscm_scm_from_block (global_block, b_smob->objfile); } @@ -458,7 +458,7 @@ gdbscm_block_static_block (SCM self) if (block->superblock () == NULL) return SCM_BOOL_F; - static_block = block_static_block (block); + static_block = block->static_block (); return bkscm_scm_from_block (static_block, b_smob->objfile); } diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c index c399a01c4fb..bd2ce7fc181 100644 --- a/gdb/python/py-block.c +++ b/gdb/python/py-block.c @@ -188,7 +188,7 @@ blpy_get_global_block (PyObject *self, void *closure) BLPY_REQUIRE_VALID (self, block); - global_block = block_global_block (block); + global_block = block->global_block (); return block_to_block_object (global_block, self_obj->objfile); @@ -210,7 +210,7 @@ blpy_get_static_block (PyObject *self, void *closure) if (block->superblock () == NULL) Py_RETURN_NONE; - static_block = block_static_block (block); + static_block = block->static_block (); return block_to_block_object (static_block, self_obj->objfile); } diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c index 9074d651d85..545d0141183 100644 --- a/gdb/rust-parse.c +++ b/gdb/rust-parse.c @@ -421,7 +421,7 @@ munge_name_and_block (const char **name, const struct block **block) if (startswith (*name, "::")) { *name += 2; - *block = block_static_block (*block); + *block = (*block)->static_block (); } } diff --git a/gdb/symtab.c b/gdb/symtab.c index 71b9ebe9efc..dd9cc7d5163 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2183,7 +2183,7 @@ lookup_local_symbol (const char *name, return {}; struct symbol *sym; - const struct block *static_block = block_static_block (block); + const struct block *static_block = block->static_block (); const char *scope = block->scope (); /* Check if it's a global block. */ @@ -2489,7 +2489,7 @@ lookup_symbol_in_static_block (const char *name, if (block == nullptr) return {}; - const struct block *static_block = block_static_block (block); + const struct block *static_block = block->static_block (); struct symbol *sym; if (static_block == NULL) @@ -2624,7 +2624,7 @@ lookup_global_symbol (const char *name, global block first. This yields "more expected" behavior, and is needed to support 'FILENAME'::VARIABLE lookups. */ const struct block *global_block - = block == nullptr ? nullptr : block_global_block (block); + = block == nullptr ? nullptr : block->global_block (); symbol *sym = NULL; if (global_block != nullptr) { @@ -5861,8 +5861,8 @@ default_collect_symbol_completion_matches_break_on visible from current context. */ b = get_selected_block (0); - surrounding_static_block = b == nullptr ? nullptr : block_static_block (b); - surrounding_global_block = b == nullptr : nullptr : block_global_block (b); + surrounding_static_block = b == nullptr ? nullptr : b->static_block (); + surrounding_global_block = b == nullptr ? nullptr : b->global_block (); if (surrounding_static_block != NULL) while (b != surrounding_static_block) {