From patchwork Fri Jan 20 21:45:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 63524 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 D2E3F3889E3C for ; Fri, 20 Jan 2023 21:47:39 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from outbound-ss-820.bluehost.com (outbound-ss-820.bluehost.com [69.89.24.241]) by sourceware.org (Postfix) with ESMTPS id BDDE53858C5E for ; Fri, 20 Jan 2023 21:46:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BDDE53858C5E 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 cmgw14.mail.unifiedlayer.com (unknown [10.0.90.129]) by progateway2.mail.pro1.eigbox.com (Postfix) with ESMTP id C3E631004854D for ; Fri, 20 Jan 2023 21:46:32 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id IzDUpNXUAmt0LIzDUptiya; Fri, 20 Jan 2023 21:46:32 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=N6rsq0xB c=1 sm=1 tr=0 ts=63cb0bb8 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=0ydof0_9mls9fT3IddIA: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=O/0DxLVET0zhguCzx8I5tuNawImrh1P2uRz766UW1z8=; b=FGxiudDvclwUc2wr7nqkJSlBT/ IuYsQ+nxCYQMUXkY6NpROnXH9MQKp5Xb6wqV7ZnqkSeXX0ohonxWeNnRYDrczFBEWt2N8o5a/z5er 6kZhP9T+/+o5SmHxHnA0VvHN+; Received: from 97-122-76-186.hlrn.qwest.net ([97.122.76.186]:36374 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 1pIzDU-001G7B-Gr; Fri, 20 Jan 2023 14:46:32 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 06/27] Don't allow NULL as an argument to block_global_block Date: Fri, 20 Jan 2023 14:45:57 -0700 Message-Id: <20230120214618.3236224-7-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: 1pIzDU-001G7B-Gr X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-76-186.hlrn.qwest.net (localhost.localdomain) [97.122.76.186]:36374 X-Source-Auth: tom+tromey.com X-Email-Count: 7 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" block_global_block has special behavior when the block is NULL. Remove this and patch up the callers instead. --- gdb/block.c | 6 +----- gdb/cp-support.c | 15 ++++++++------- gdb/symtab.c | 5 +++-- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/gdb/block.c b/gdb/block.c index d21729f069d..5751a6b6f84 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -378,15 +378,11 @@ block_static_block (const struct block *block) return block; } -/* Return the static block associated to BLOCK. Return NULL if block - is NULL. */ +/* Return the static block associated to BLOCK. */ const struct block * block_global_block (const struct block *block) { - if (block == NULL) - return NULL; - while (block->superblock () != NULL) block = block->superblock (); diff --git a/gdb/cp-support.c b/gdb/cp-support.c index 08f7c2b4140..38225a6d9ba 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -1308,14 +1308,15 @@ 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); - if (block) - add_symbol_overload_list_block (name, block, overload_list); - - /* Look in the global block. */ - block = block_global_block (block); - if (block) - add_symbol_overload_list_block (name, block, overload_list); + if (block != nullptr) + { + add_symbol_overload_list_block (name, block, overload_list); + /* Look in the global block. */ + block = block_global_block (block); + if (block) + add_symbol_overload_list_block (name, block, overload_list); + } } /* Search the namespace of the given type and namespace of and public diff --git a/gdb/symtab.c b/gdb/symtab.c index 0e522b2c7f9..924bd5d8ec0 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2623,7 +2623,8 @@ lookup_global_symbol (const char *name, /* If a block was passed in, we want to search the corresponding global block first. This yields "more expected" behavior, and is needed to support 'FILENAME'::VARIABLE lookups. */ - const struct block *global_block = block_global_block (block); + const struct block *global_block + = block == nullptr ? nullptr : block_global_block (block); symbol *sym = NULL; if (global_block != nullptr) { @@ -5861,7 +5862,7 @@ default_collect_symbol_completion_matches_break_on b = get_selected_block (0); surrounding_static_block = b == nullptr ? nullptr : block_static_block (b); - surrounding_global_block = block_global_block (b); + surrounding_global_block = b == nullptr : nullptr : block_global_block (b); if (surrounding_static_block != NULL) while (b != surrounding_static_block) {