From patchwork Wed Jan 8 07:23:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 104317 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 0DD763858C32 for ; Wed, 8 Jan 2025 07:26:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0DD763858C32 Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=tibcwr3q X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta40.uswest2.a.cloudfilter.net (omta40.uswest2.a.cloudfilter.net [35.89.44.39]) by sourceware.org (Postfix) with ESMTPS id 12AF93858C51 for ; Wed, 8 Jan 2025 07:23:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 12AF93858C51 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 12AF93858C51 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736321007; cv=none; b=bbe5TlvrMAt6uohY28I3CyNPlfLgEzZHfywCNcP4334uUJzFVvzBFgYTZoTikqDIOitvP5wE4/ebMkej2qG6Qq70wCob3Z0pi4w5oRUOzSeEg8iOu6K8fzDsMXNX3PqNAonNuhIqrzOOhXikxWGnjJ0LXVhCK7dcp7xIC6FHoys= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736321007; c=relaxed/simple; bh=RxnvsvI+4EPqnGa5Ua4RYLVr6dSm+y5um5LZehm8ObM=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=WwFjcVoqxKVkPo7YiebjYDq+0CdbGxcLRwHk+lWzF5fBIhcrTck+qv3k6FOB5/GW4d/PqGn5RC3oH8wIc8+2YVMau9/gBRovtkHzRpjiS1Bvmd24Bx6cg5Lcn61Y2MdCu4f7Q8/PCfKd6jDxYJAB8RgA8umTirpd/3u7iRmcV4Y= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 12AF93858C51 Received: from eig-obgw-6006a.ext.cloudfilter.net ([10.0.30.182]) by cmsmtp with ESMTPS id VG6qtCKXOfC5ZVQPWtcxS9; Wed, 08 Jan 2025 07:23:26 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id VQPVtYzIxhhqDVQPVtXrR1; Wed, 08 Jan 2025 07:23:25 +0000 X-Authority-Analysis: v=2.4 cv=XeiPzp55 c=1 sm=1 tr=0 ts=677e27ed a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=VdSt8ZQiCzkA:10 a=ItBw4LHWJt0A:10 a=9OoM-kX4OdzaEwLqyBkA:9 a=QEXdDO2ut3YA:10 a=6Ogn3jAGHLSNbaov7Orx:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To: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=dbztsH6Udag2KvrvRIiyHc/GSC5voaCW9NPIQhF2H68=; b=tibcwr3qcHepEjPuMhYFmqTIa1 5nNjaUFV2xwbEZw/tRqB6BZUw4v+89HoX4nHAKJV0lmzxoPr/lyx6UHgUwxvhX6GaoQlg3ww79WrP NLXHtnfy/M7VkkLZu6a1EANVL; Received: from 97-118-36-154.hlrn.qwest.net ([97.118.36.154]:56396 helo=prentzel.local) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1tVQPU-001pZ1-2M; Wed, 08 Jan 2025 00:23:24 -0700 From: Tom Tromey Date: Wed, 08 Jan 2025 00:23:21 -0700 Subject: [PATCH 1/6] Add constructor and destructor to linespec_state MIME-Version: 1.0 Message-Id: <20250108-linespec-state-cxx-v1-1-a721e95ee050@tromey.com> References: <20250108-linespec-state-cxx-v1-0-a721e95ee050@tromey.com> In-Reply-To: <20250108-linespec-state-cxx-v1-0-a721e95ee050@tromey.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.14.2 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.118.36.154 X-Source-L: No X-Exim-ID: 1tVQPU-001pZ1-2M X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-118-36-154.hlrn.qwest.net (prentzel.local) [97.118.36.154]:56396 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfHHOvIncJFRRyqJ3zyyFSwZsdS9uFaHynwlGYSbpT7tujfL4dM+XCF6In/XIcCx9B/i5QJd1Qgnp/BvTGacbp20bFFG7QNeRH8fh7eKJ2z4HEActFj7l i+zamD1j/sXtCeWXdRkU6Bc8WlGsWJpnDHd22joqczi0LF1DgctClhSfHzYgPZuKb87MBMq7eCi7VaJG4jIUq8KlYUPypRYTcyA= X-Spam-Status: No, score=-3019.2 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.30 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 This changes linespec_state to have real constructors and a destructor. --- gdb/linespec.c | 132 +++++++++++++++++++++++++-------------------------------- 1 file changed, 58 insertions(+), 74 deletions(-) diff --git a/gdb/linespec.c b/gdb/linespec.c index d70008778e29abd13b89c889f48aeffb13f1f31b..b9c918b048eb0a4404104cddb9b161ac7c09a709 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -132,12 +132,64 @@ struct linespec_canonical_name struct symtab *symtab; }; +/* A hash function for address_entry. */ + +static hashval_t +hash_address_entry (const void *p) +{ + const struct address_entry *aep = (const struct address_entry *) p; + hashval_t hash; + + hash = iterative_hash_object (aep->pspace, 0); + return iterative_hash_object (aep->addr, hash); +} + +/* An equality function for address_entry. */ + +static int +eq_address_entry (const void *a, const void *b) +{ + const struct address_entry *aea = (const struct address_entry *) a; + const struct address_entry *aeb = (const struct address_entry *) b; + + return aea->pspace == aeb->pspace && aea->addr == aeb->addr; +} + /* An instance of this is used to keep all state while linespec operates. This instance is passed around as a 'this' pointer to the various implementation methods. */ struct linespec_state { + linespec_state (int flags, const struct language_defn *language, + struct program_space *search_pspace, + struct symtab *default_symtab, + int default_line, + struct linespec_result *canonical) + : language (language), + program_space (current_program_space), + search_pspace (search_pspace), + default_symtab (default_symtab), + default_line (default_line), + funfirstline ((flags & DECODE_LINE_FUNFIRSTLINE) ? 1 : 0), + list_mode ((flags & DECODE_LINE_LIST_MODE) ? 1 : 0), + canonical (canonical), + addr_set (htab_create_alloc (10, hash_address_entry, eq_address_entry, + xfree, xcalloc, xfree)) + { + } + + explicit linespec_state (const struct language_defn *language) + : linespec_state (0, language, nullptr, nullptr, 0, nullptr) + { + } + + ~linespec_state () + { + htab_delete (addr_set); + xfree (canonical_names); + } + /* The language in use during linespec processing. */ const struct language_defn *language; @@ -165,14 +217,14 @@ struct linespec_state struct linespec_result *canonical; /* Canonical strings that mirror the std::vector result. */ - struct linespec_canonical_name *canonical_names; + struct linespec_canonical_name *canonical_names = nullptr; /* This is a set of address_entry objects which is used to prevent duplicate symbols from being entered into the result. */ htab_t addr_set; /* Are we building a linespec? */ - int is_linespec; + int is_linespec = 0; }; /* This is a helper object that is used when collecting symbols into a @@ -284,8 +336,6 @@ struct linespec_parser int default_line, struct linespec_result *canonical); - ~linespec_parser (); - DISABLE_COPY_AND_ASSIGN (linespec_parser); /* Lexer internal data */ @@ -305,7 +355,7 @@ struct linespec_parser int is_quote_enclosed = 0; /* The state of the parse. */ - struct linespec_state state {}; + struct linespec_state state; /* The result of the parse. */ linespec result; @@ -1086,29 +1136,6 @@ add_sal_to_sals (struct linespec_state *self, } } -/* A hash function for address_entry. */ - -static hashval_t -hash_address_entry (const void *p) -{ - const struct address_entry *aep = (const struct address_entry *) p; - hashval_t hash; - - hash = iterative_hash_object (aep->pspace, 0); - return iterative_hash_object (aep->addr, hash); -} - -/* An equality function for address_entry. */ - -static int -eq_address_entry (const void *a, const void *b) -{ - const struct address_entry *aea = (const struct address_entry *) a; - const struct address_entry *aeb = (const struct address_entry *) b; - - return aea->pspace == aeb->pspace && aea->addr == aeb->addr; -} - /* Check whether the address, represented by PSPACE and ADDR, is already in the set. If so, return 0. Otherwise, add it and return 1. */ @@ -2667,30 +2694,6 @@ parse_linespec (linespec_parser *parser, const char *arg, } -/* A constructor for linespec_state. */ - -static void -linespec_state_constructor (struct linespec_state *self, - int flags, const struct language_defn *language, - struct program_space *search_pspace, - struct symtab *default_symtab, - int default_line, - struct linespec_result *canonical) -{ - memset (self, 0, sizeof (*self)); - self->language = language; - self->funfirstline = (flags & DECODE_LINE_FUNFIRSTLINE) ? 1 : 0; - self->list_mode = (flags & DECODE_LINE_LIST_MODE) ? 1 : 0; - self->search_pspace = search_pspace; - self->default_symtab = default_symtab; - self->default_line = default_line; - self->canonical = canonical; - self->program_space = current_program_space; - self->addr_set = htab_create_alloc (10, hash_address_entry, eq_address_entry, - xfree, xcalloc, xfree); - self->is_linespec = 0; -} - /* Initialize a new linespec parser. */ linespec_parser::linespec_parser (int flags, @@ -2699,30 +2702,13 @@ linespec_parser::linespec_parser (int flags, struct symtab *default_symtab, int default_line, struct linespec_result *canonical) + : state (flags, language, search_pspace, default_symtab, + default_line, canonical) { lexer.current.type = LSTOKEN_CONSUMED; result.explicit_loc.func_name_match_type = symbol_name_match_type::WILD; result.explicit_loc.line_offset.sign = LINE_OFFSET_UNKNOWN; - linespec_state_constructor (&state, flags, language, - search_pspace, - default_symtab, default_line, canonical); -} - -/* A destructor for linespec_state. */ - -static void -linespec_state_destructor (struct linespec_state *self) -{ - htab_delete (self->addr_set); - xfree (self->canonical_names); -} - -/* Delete a linespec parser. */ - -linespec_parser::~linespec_parser () -{ - linespec_state_destructor (&state); } /* See description in linespec.h. */ @@ -3753,10 +3739,8 @@ symbol_searcher::find_all_symbols (const std::string &name, struct program_space *search_pspace) { symbol_searcher_collect_info info; - struct linespec_state state; + struct linespec_state state (language); - memset (&state, 0, sizeof (state)); - state.language = language; info.state = &state; info.result.symbols = &m_symbols; From patchwork Wed Jan 8 07:23:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 104315 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 18FF03858C60 for ; Wed, 8 Jan 2025 07:25:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 18FF03858C60 Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=tX76T8RB X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta036.useast.a.cloudfilter.net (omta036.useast.a.cloudfilter.net [44.202.169.35]) by sourceware.org (Postfix) with ESMTPS id 099483858D28 for ; Wed, 8 Jan 2025 07:23:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 099483858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 099483858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.35 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736321007; cv=none; b=MoxiiPTPWtqeyDTq9eQL/CckifQ2zCFMH5wJApP6Ud88qX890Q0SO+V0qpt3/5evO2XNgMr4+Tt2a6oKdar+Ob/njcLSe10tSer3XpE9jRqHo3b7nseVzcKEfh9HgCDeeCuxlqrlC+CHQgWT0nkJNv3pRMHWN9V7tBuq22nIGn0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736321007; c=relaxed/simple; bh=HjzYQbas75HLmxIUZRrFfKQVmicGk1+f1Bjxz1x6Cb8=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=BkWzgrYtmM0fM8bnnPW150SZ3PAYtkDZ7RzYMblFCV3uTckV4e+S4o6wa0O/pwhJmeRVmnQfwx3G/UvtHsFcFiMIU9M+JFK605x3y4O79NAMeQyH8iZovJBgX3lfBEc9l4yChBNL9cwMtFPliNcpgbwDU4OEAE5KIZP2QSVb0VU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 099483858D28 Received: from eig-obgw-6002a.ext.cloudfilter.net ([10.0.30.222]) by cmsmtp with ESMTPS id VB3utIrX7xoE1VQPWtsH3P; Wed, 08 Jan 2025 07:23:26 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id VQPVtU55VelOWVQPVtniTu; Wed, 08 Jan 2025 07:23:26 +0000 X-Authority-Analysis: v=2.4 cv=ZOQcmm7b c=1 sm=1 tr=0 ts=677e27ee a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=VdSt8ZQiCzkA:10 a=ItBw4LHWJt0A:10 a=GO2AoQChXo-ZJFrGiZMA:9 a=QEXdDO2ut3YA:10 a=6Ogn3jAGHLSNbaov7Orx:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To: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=flOozqDkpPo5XWBqfBJEM9PH8BdR96jZnR++ofSt3f4=; b=tX76T8RBPvsnQFUpPyl2dPQQ/z bVK8Qz7jJb0kWqb0Id2RiH45cjLvBPomW4Nr2vQOUPXWzRbVPi/5X7z5t4tc7M3s1gHnN/VZhr12b jPDoTz5UsUCWOIXBIdLncC7em; Received: from 97-118-36-154.hlrn.qwest.net ([97.118.36.154]:56396 helo=prentzel.local) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1tVQPV-001pZ1-04; Wed, 08 Jan 2025 00:23:25 -0700 From: Tom Tromey Date: Wed, 08 Jan 2025 00:23:22 -0700 Subject: [PATCH 2/6] Use gdb::unordered_set in linespec_state MIME-Version: 1.0 Message-Id: <20250108-linespec-state-cxx-v1-2-a721e95ee050@tromey.com> References: <20250108-linespec-state-cxx-v1-0-a721e95ee050@tromey.com> In-Reply-To: <20250108-linespec-state-cxx-v1-0-a721e95ee050@tromey.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.14.2 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.118.36.154 X-Source-L: No X-Exim-ID: 1tVQPV-001pZ1-04 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-118-36-154.hlrn.qwest.net (prentzel.local) [97.118.36.154]:56396 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfA4o8YQhz/ykx8O5jrtKuo9utXyIvuGl/j85go7KkQ0gaEmBY2lPu9B8wj+Sl/7QcT6a8NaNvrgixGEmKfCsmAva5EnlGj6qpJHxTfVxrCIlULDGImYs jb/xw2pJn1ep00AjwjAUxxi4pGKgz1BMT1q8oeE2tUjldQhqMYZ3AUruUiLj7514gudDf/omnfx6P6mScvShB06wb4e5k8ci9Xs= X-Spam-Status: No, score=-3019.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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.30 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 This patch changes linespec_state to use gdb::unordered_set. This simplifies the code a little and removes some manual management. --- gdb/linespec.c | 82 +++++++++++++++++++++++----------------------------------- 1 file changed, 33 insertions(+), 49 deletions(-) diff --git a/gdb/linespec.c b/gdb/linespec.c index b9c918b048eb0a4404104cddb9b161ac7c09a709..689a8791d8561098a435262a32cc6883bfd38abf 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -134,26 +134,25 @@ struct linespec_canonical_name /* A hash function for address_entry. */ -static hashval_t -hash_address_entry (const void *p) +struct address_entry_hash { - const struct address_entry *aep = (const struct address_entry *) p; - hashval_t hash; - - hash = iterative_hash_object (aep->pspace, 0); - return iterative_hash_object (aep->addr, hash); -} + std::size_t operator() (const address_entry &aep) const noexcept + { + hashval_t hash = iterative_hash_object (aep.pspace, 0); + return iterative_hash_object (aep.addr, hash); + } +}; /* An equality function for address_entry. */ -static int -eq_address_entry (const void *a, const void *b) +struct address_entry_eq { - const struct address_entry *aea = (const struct address_entry *) a; - const struct address_entry *aeb = (const struct address_entry *) b; - - return aea->pspace == aeb->pspace && aea->addr == aeb->addr; -} + bool operator() (const address_entry &aea, const address_entry &aeb) + const noexcept + { + return aea.pspace == aeb.pspace && aea.addr == aeb.addr; + } +}; /* An instance of this is used to keep all state while linespec operates. This instance is passed around as a 'this' pointer to @@ -173,9 +172,7 @@ struct linespec_state default_line (default_line), funfirstline ((flags & DECODE_LINE_FUNFIRSTLINE) ? 1 : 0), list_mode ((flags & DECODE_LINE_LIST_MODE) ? 1 : 0), - canonical (canonical), - addr_set (htab_create_alloc (10, hash_address_entry, eq_address_entry, - xfree, xcalloc, xfree)) + canonical (canonical) { } @@ -186,10 +183,17 @@ struct linespec_state ~linespec_state () { - htab_delete (addr_set); xfree (canonical_names); } + /* Add ADDR to the address set. Return true if this is a new + entry. */ + bool add_address (program_space *pspace, CORE_ADDR addr) + { + address_entry entry { pspace, addr }; + return addr_set.insert (entry).second; + } + /* The language in use during linespec processing. */ const struct language_defn *language; @@ -219,12 +223,15 @@ struct linespec_state /* Canonical strings that mirror the std::vector result. */ struct linespec_canonical_name *canonical_names = nullptr; - /* This is a set of address_entry objects which is used to prevent - duplicate symbols from being entered into the result. */ - htab_t addr_set; - /* Are we building a linespec? */ int is_linespec = 0; + +private: + + /* This is a set of address_entry objects which is used to prevent + duplicate symbols from being entered into the result. */ + gdb::unordered_set addr_set; }; /* This is a helper object that is used when collecting symbols into a @@ -1136,29 +1143,6 @@ add_sal_to_sals (struct linespec_state *self, } } -/* Check whether the address, represented by PSPACE and ADDR, is - already in the set. If so, return 0. Otherwise, add it and return - 1. */ - -static int -maybe_add_address (htab_t set, struct program_space *pspace, CORE_ADDR addr) -{ - struct address_entry e, *p; - void **slot; - - e.pspace = pspace; - e.addr = addr; - slot = htab_find_slot (set, &e, INSERT); - if (*slot) - return 0; - - p = XNEW (struct address_entry); - memcpy (p, &e, sizeof (struct address_entry)); - *slot = p; - - return 1; -} - /* A helper that walks over all matching symtabs in all objfiles and calls CALLBACK for each symbol matching NAME. If SEARCH_PSPACE is not NULL, then the search is restricted to just that program @@ -2240,7 +2224,7 @@ convert_linespec_to_sals (struct linespec_state *state, linespec *ls) = sym.symbol->symtab ()->compunit ()->objfile ()->pspace (); if (symbol_to_sal (&sal, state->funfirstline, sym.symbol) - && maybe_add_address (state->addr_set, pspace, sal.pc)) + && state->add_address (pspace, sal.pc)) add_sal_to_sals (state, &sals, &sal, sym.symbol->natural_name (), 0); } @@ -2305,7 +2289,7 @@ convert_linespec_to_sals (struct linespec_state *state, linespec *ls) { symtab_and_line sal; if (symbol_to_sal (&sal, state->funfirstline, sym.symbol) - && maybe_add_address (state->addr_set, pspace, sal.pc)) + && state->add_address (pspace, sal.pc)) add_sal_to_sals (state, &sals, &sal, sym.symbol->natural_name (), 0); } @@ -4154,7 +4138,7 @@ minsym_found (struct linespec_state *self, struct objfile *objfile, sal.section = msymbol->obj_section (objfile); - if (maybe_add_address (self->addr_set, objfile->pspace (), sal.pc)) + if (self->add_address (objfile->pspace (), sal.pc)) add_sal_to_sals (self, result, &sal, msymbol->natural_name (), 0); } From patchwork Wed Jan 8 07:23:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 104316 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 0524E3858402 for ; Wed, 8 Jan 2025 07:26:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0524E3858402 Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=IMlqKtKN X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta034.useast.a.cloudfilter.net (omta034.useast.a.cloudfilter.net [44.202.169.33]) by sourceware.org (Postfix) with ESMTPS id F24C23858D21 for ; Wed, 8 Jan 2025 07:23:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F24C23858D21 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F24C23858D21 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736321007; cv=none; b=OCMe3mwAslcMpoEiNS2S3eSB6kW1V6hQMmmRPcyL3mtONVT7HNiRmI5aOTVAzWGu+GFcgwgPSbPTK82VialHQfNMOA2xLAqz8XQmZphS9gtwNBqal3/C1yl4d7WHzXRN9Apt8dSfjeV3EVtRPCPC8euHHgKaQ5XNUdqYbZWbOjs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736321007; c=relaxed/simple; bh=FQOzdK7rtwFaHaV6OGj8neasfxy0ZFMLe/44+8WGl8k=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=m0vR1V/wWOgmXLPzgltScnH9Kt5XoZdlDyjbArWOGLbFEbRCFtTBdKTpEc11atJZWFLx9c+oilmAthbp8ZqmQvbnxyJL7mYRfZ94oyQElz/+8JI+85idU4aU/NMsxxQ/lxwZUbUHFCPO3rRplETV+hbeCKx6hoUQ3pX5xhqKs7c= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F24C23858D21 Received: from eig-obgw-5001a.ext.cloudfilter.net ([10.0.29.139]) by cmsmtp with ESMTPS id VNXQtpoqDrKrbVQPWteJjI; Wed, 08 Jan 2025 07:23:26 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id VQPVt1WK4yGKBVQPWt1HGv; Wed, 08 Jan 2025 07:23:26 +0000 X-Authority-Analysis: v=2.4 cv=CYXD56rl c=1 sm=1 tr=0 ts=677e27ee a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=VdSt8ZQiCzkA:10 a=ItBw4LHWJt0A:10 a=_MR1hBvuMjvGZjrAFSIA:9 a=QEXdDO2ut3YA:10 a=6Ogn3jAGHLSNbaov7Orx:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To: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=huFUf5xlqie3mtGXJ9pdci/GTPnRWzSLhq23zpEGPxs=; b=IMlqKtKNvi3i0jcFPc+GlymDwk Fs8zTXaVqac5jtkoMmUa7R1FohrkMGdAFw1W7yrSi4azrwItAwnLGoxsOZwJsAH94ik3wfdy1xsE/ nEEfS8bwgQcAJ9d92awGIrYr4; Received: from 97-118-36-154.hlrn.qwest.net ([97.118.36.154]:56396 helo=prentzel.local) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1tVQPV-001pZ1-1H; Wed, 08 Jan 2025 00:23:25 -0700 From: Tom Tromey Date: Wed, 08 Jan 2025 00:23:23 -0700 Subject: [PATCH 3/6] Use std::vector in linespec_state MIME-Version: 1.0 Message-Id: <20250108-linespec-state-cxx-v1-3-a721e95ee050@tromey.com> References: <20250108-linespec-state-cxx-v1-0-a721e95ee050@tromey.com> In-Reply-To: <20250108-linespec-state-cxx-v1-0-a721e95ee050@tromey.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.14.2 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.118.36.154 X-Source-L: No X-Exim-ID: 1tVQPV-001pZ1-1H X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-118-36-154.hlrn.qwest.net (prentzel.local) [97.118.36.154]:56396 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfA8aC2umkAcD238N+DmEmOjAnrrXW3d621Wm0H86m7XUNelAj1GjmLsComsrFPExvKOFaa2APF8IQMDCKtWZ2RoxcAoAEIQcHbWujBp7zfxQoEhQ5JmZ v+9UbE1TwZQA0bVwZNzbbqAlhI+UGkfC4/TfrdyJ1Xc0qdGo/rA4eg6TO9/2w/FMWEuBRq7whHCxwvGviemNajXgJTt2MYfmVlU= X-Spam-Status: No, score=-3019.2 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.30 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 This changes linespec_state to use a std::vector, and changes linespec_canonical_name to use std::string. This removes some manual memory management, including some odd cleanup code in in decode_line_full. --- gdb/linespec.c | 38 +++++++++++--------------------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/gdb/linespec.c b/gdb/linespec.c index 689a8791d8561098a435262a32cc6883bfd38abf..053af6f9bb595294bc9a512a9f465ddc3ff73f65 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -126,7 +126,7 @@ struct linespec struct linespec_canonical_name { /* Remaining text part of the linespec string. */ - char *suffix; + std::string suffix; /* If NULL then SUFFIX is the whole linespec string. */ struct symtab *symtab; @@ -181,11 +181,6 @@ struct linespec_state { } - ~linespec_state () - { - xfree (canonical_names); - } - /* Add ADDR to the address set. Return true if this is a new entry. */ bool add_address (program_space *pspace, CORE_ADDR addr) @@ -221,7 +216,7 @@ struct linespec_state struct linespec_result *canonical; /* Canonical strings that mirror the std::vector result. */ - struct linespec_canonical_name *canonical_names = nullptr; + std::vector canonical_names; /* Are we building a linespec? */ int is_linespec = 0; @@ -1111,9 +1106,7 @@ add_sal_to_sals (struct linespec_state *self, { struct linespec_canonical_name *canonical; - self->canonical_names = XRESIZEVEC (struct linespec_canonical_name, - self->canonical_names, - sals->size ()); + self->canonical_names.resize (sals->size ()); canonical = &self->canonical_names[sals->size () - 1]; if (!literal_canonical && sal->symtab) { @@ -1124,20 +1117,20 @@ add_sal_to_sals (struct linespec_state *self, the time being. */ if (symname != NULL && sal->line != 0 && self->language->la_language == language_ada) - canonical->suffix = xstrprintf ("%s:%d", symname, - sal->line).release (); + canonical->suffix = string_printf ("%s:%d", symname, + sal->line); else if (symname != NULL) - canonical->suffix = xstrdup (symname); + canonical->suffix = symname; else - canonical->suffix = xstrprintf ("%d", sal->line).release (); + canonical->suffix = string_printf ("%d", sal->line); canonical->symtab = sal->symtab; } else { if (symname != NULL) - canonical->suffix = xstrdup (symname); + canonical->suffix = symname; else - canonical->suffix = xstrdup (""); + canonical->suffix = ""; canonical->symtab = NULL; } } @@ -1333,7 +1326,7 @@ canonical_to_fullform (const struct linespec_canonical_name *canonical) return canonical->suffix; else return string_printf ("%s:%s", symtab_to_fullname (canonical->symtab), - canonical->suffix); + canonical->suffix.c_str ()); } /* Given FILTERS, a list of canonical names, filter the sals in RESULT @@ -1444,7 +1437,6 @@ decode_line_2 (struct linespec_state *self, std::string displayform; canonical = &self->canonical_names[i]; - gdb_assert (canonical->suffix != NULL); std::string fullform = canonical_to_fullform (canonical); @@ -1456,7 +1448,7 @@ decode_line_2 (struct linespec_state *self, fn_for_display = symtab_to_filename_for_display (canonical->symtab); displayform = string_printf ("%s:%s", fn_for_display, - canonical->suffix); + canonical->suffix.c_str ()); } items.emplace_back (std::move (fullform), std::move (displayform), @@ -3156,14 +3148,6 @@ decode_line_full (struct location_spec *locspec, int flags, gdb_assert (result.size () == 1 || canonical->pre_expanded); canonical->pre_expanded = 1; - /* Arrange for allocated canonical names to be freed. */ - std::vector> hold_names; - for (int i = 0; i < result.size (); ++i) - { - gdb_assert (state->canonical_names[i].suffix != NULL); - hold_names.emplace_back (state->canonical_names[i].suffix); - } - if (select_mode == NULL) { if (top_level_interpreter ()->interp_ui_out ()->is_mi_like_p ()) From patchwork Wed Jan 8 07:23:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 104319 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 89894385843D for ; Wed, 8 Jan 2025 07:28:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 89894385843D Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=p9HPL8xK X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta34.uswest2.a.cloudfilter.net (omta34.uswest2.a.cloudfilter.net [35.89.44.33]) by sourceware.org (Postfix) with ESMTPS id EDC923858C60 for ; Wed, 8 Jan 2025 07:23:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EDC923858C60 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EDC923858C60 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736321008; cv=none; b=lxWcNzOG+4+6cqH5onNms2zvbK8uqkSwqAfMaQNanrHXyIfiNA6pWOh2yh1vmaA5FpgVjigTyupxcXrlAgZ4Ab3MEEErpobtrhho1tDmDD2TR91rHQ14TmB+qAUMKIidhGaO36BmVStHh4Ru8y/iE4+qy8iu8rRiFhB1OjBXzhs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736321008; c=relaxed/simple; bh=s1LtRTu5v31chKnyJhrH33DtOybwfwtcCDaN6Spt8xc=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=lYm+pJX3liURWl6vaA7Kxl/bCxDq9DTCTLGnE2kytGG0URejI1GjqVUZ/wqhh64wzTWLAQA3ECfoxc0FdXE4h/89UjlysZjZnRW7xQRjpK65Rp+HVEDZJ9LsHoySv53ELvyIXLV/n0FWL81hTxffi02LmE1/g0z79GdNXXda7CA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EDC923858C60 Received: from eig-obgw-6004a.ext.cloudfilter.net ([10.0.30.197]) by cmsmtp with ESMTPS id VLMatJ6kh09RnVQPXtyGi0; Wed, 08 Jan 2025 07:23:27 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id VQPWtjbBW1nbEVQPWtpp5T; Wed, 08 Jan 2025 07:23:26 +0000 X-Authority-Analysis: v=2.4 cv=EO7N0EZC c=1 sm=1 tr=0 ts=677e27ee a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=VdSt8ZQiCzkA:10 a=ItBw4LHWJt0A:10 a=lT97ZhyhDVa61FYwSFUA:9 a=QEXdDO2ut3YA:10 a=6Ogn3jAGHLSNbaov7Orx:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To: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=xvZL5/1xEdATQ6OwLRhjwlVeXszMzwX8wj7l7/xBzXE=; b=p9HPL8xKNsgC2lhTHMESuvitSE wEjnph2R5nAm2SjeIRdFvIYWaTgSN1PbHwVPvDCrvE6AyI/K7/zPiA4+sEsDpnWqSqUa0gNEb2aZ8 3i6EJ6cc4oNufUlSWB/oKfd1j; Received: from 97-118-36-154.hlrn.qwest.net ([97.118.36.154]:56396 helo=prentzel.local) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1tVQPV-001pZ1-2c; Wed, 08 Jan 2025 00:23:25 -0700 From: Tom Tromey Date: Wed, 08 Jan 2025 00:23:24 -0700 Subject: [PATCH 4/6] Minor cleanup in linespec.c:add_minsym MIME-Version: 1.0 Message-Id: <20250108-linespec-state-cxx-v1-4-a721e95ee050@tromey.com> References: <20250108-linespec-state-cxx-v1-0-a721e95ee050@tromey.com> In-Reply-To: <20250108-linespec-state-cxx-v1-0-a721e95ee050@tromey.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.14.2 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.118.36.154 X-Source-L: No X-Exim-ID: 1tVQPV-001pZ1-2c X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-118-36-154.hlrn.qwest.net (prentzel.local) [97.118.36.154]:56396 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfMe78/MYngRWPnJIIY3xzEgNiqFNawSuYGqyF+eM+5bRDEd+KODi/WZR+a4th0TeBXFsO5DHeNPHa6cOzzg7sClz2UZfT8Sj8b/75XhyJvDv0dUrpk9e R6GYY6T0UT4c9xGHwzaMi8hhSZ7I/vvwFTKXFhNEjSUkHDEqVdouhpbdYofgEZL1ux21ogb3cKra/IpBKwRynzXh6w8pasoImSg= X-Spam-Status: No, score=-3017.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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.30 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 This cleans up a 'return' in linespec.c:add_minsym. --- gdb/linespec.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/gdb/linespec.c b/gdb/linespec.c index 053af6f9bb595294bc9a512a9f465ddc3ff73f65..4f80a42484fef33bed5b4c9f36e78486bbd4f97d 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -4149,11 +4149,8 @@ add_minsym (struct minimal_symbol *minsym, struct objfile *objfile, } /* Exclude data symbols when looking for breakpoint locations. */ - if (!list_mode && !msymbol_is_function (objfile, minsym)) - return; - - msyms->emplace_back (minsym, objfile); - return; + if (list_mode || msymbol_is_function (objfile, minsym)) + msyms->emplace_back (minsym, objfile); } /* Search for minimal symbols called NAME. If SEARCH_PSPACE From patchwork Wed Jan 8 07:23:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 104318 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 4ECAE3858C60 for ; Wed, 8 Jan 2025 07:27:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4ECAE3858C60 Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=aHtHpOiC X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta36.uswest2.a.cloudfilter.net (omta36.uswest2.a.cloudfilter.net [35.89.44.35]) by sourceware.org (Postfix) with ESMTPS id 4CC303858C32 for ; Wed, 8 Jan 2025 07:23:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4CC303858C32 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4CC303858C32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.35 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736321008; cv=none; b=EksY7RAUJIuTPhZcEqE7JhB7jlXHfe6hkW1DG5C+ROM/HvRBTwvv1vHo2Fll+mRx24+z1bVa1oF2GJy7SLn6RjpkAYFg1Hgnhgkj//T6t/veN4FuQNDszNYBE4hVDMOOyD97xyGjJZ09YuiFCk2BoUDmUbOkvEchSFn6WwUGl0A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736321008; c=relaxed/simple; bh=32vJXpDtuXDfkVeJs+AnO9mL6cvuYq3V18CFQgAC9SM=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=U5Rjv06QOV6QpWpSpnIt5tMFciY9yGeyJAeH0Iw1dvNTGKUmMgp5VcMO/hMJ49ZDkr1Exa4XEXErWTOfu8U+WUtl72/dVlu72BudDvRx6mO8klIleQrXyMRI/9ch+ms2rLr7WdkmFLNJuOgKHG7jgemTp7TqEIKP0JkGutXIVJs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4CC303858C32 Received: from eig-obgw-6005a.ext.cloudfilter.net ([10.0.30.201]) by cmsmtp with ESMTPS id VL1CtQlEjYpSZVQPXt6AA5; Wed, 08 Jan 2025 07:23:27 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id VQPWtG6S8IQeVVQPWtzZ1H; Wed, 08 Jan 2025 07:23:27 +0000 X-Authority-Analysis: v=2.4 cv=cLYrsUeN c=1 sm=1 tr=0 ts=677e27ef a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=VdSt8ZQiCzkA:10 a=ItBw4LHWJt0A:10 a=EuqcBZHCz_egLTRmhbYA:9 a=QEXdDO2ut3YA:10 a=6Ogn3jAGHLSNbaov7Orx:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To: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=1pdZSoqkOa4xZ4KubkmGpPReg8BhZ4U72UkuUtbHlvA=; b=aHtHpOiCTHOWpMZVonq080YHRF 3rctoO6/r0YkKNKwchy1yO3PcInmiYoUjOK7fvj1blN5avkp91tgecobgn3U77uIGas5Zf8M1OWu3 Q9nucUmsP38FghEbfzGY8CMx2; Received: from 97-118-36-154.hlrn.qwest.net ([97.118.36.154]:56396 helo=prentzel.local) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1tVQPW-001pZ1-0m; Wed, 08 Jan 2025 00:23:26 -0700 From: Tom Tromey Date: Wed, 08 Jan 2025 00:23:25 -0700 Subject: [PATCH 5/6] Hoist lambda in linespec.c:add_matching_symbols_to_info MIME-Version: 1.0 Message-Id: <20250108-linespec-state-cxx-v1-5-a721e95ee050@tromey.com> References: <20250108-linespec-state-cxx-v1-0-a721e95ee050@tromey.com> In-Reply-To: <20250108-linespec-state-cxx-v1-0-a721e95ee050@tromey.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.14.2 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.118.36.154 X-Source-L: No X-Exim-ID: 1tVQPW-001pZ1-0m X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-118-36-154.hlrn.qwest.net (prentzel.local) [97.118.36.154]:56396 X-Source-Auth: tom+tromey.com X-Email-Count: 6 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfBp3unaHRd7J3ygSz+gUNwNUwAVa+Iy05CGgFLm1gDnGb7odeRhIuX3SgqLzWcW9tqFm/Af92LXwNOlsTPLia4Glskj6Af8tImHNPAF5VqEC5LmDCqmx jkw96IeTfgMa8uaOvWBsny5eFTdWXyDJP8r7fYENbUaIb++GgrnFI0IkIwgoeO+XiuhLDgHJQzcMmJSVg44XhcfLf17OJqs4N5A= X-Spam-Status: No, score=-3019.3 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.30 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 I noticed that two parts of linespec.c:add_matching_symbols_to_info use the same lambda, and hoisting this seems slightly more efficient. --- gdb/linespec.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/gdb/linespec.c b/gdb/linespec.c index 4f80a42484fef33bed5b4c9f36e78486bbd4f97d..9b1e1856eff349d567d4f918b85a79e8323e247f 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -4277,6 +4277,11 @@ add_matching_symbols_to_info (const char *name, { lookup_name_info lookup_name (name, name_match_type); + auto add_symbol = [&] (block_symbol *bsym) + { + return info->add_symbol (bsym); + }; + for (const auto &elt : *info->file_symtabs) { if (elt == nullptr) @@ -4284,8 +4289,7 @@ add_matching_symbols_to_info (const char *name, iterate_over_all_matching_symtabs (info->state, lookup_name, domain_search_flags, pspace, true, - [&] (block_symbol *bsym) - { return info->add_symbol (bsym); }); + add_symbol); search_minsyms_for_name (info, lookup_name, pspace, NULL); } else if (pspace == NULL || pspace == elt->compunit ()->objfile ()->pspace ()) @@ -4297,9 +4301,7 @@ add_matching_symbols_to_info (const char *name, program_space *elt_pspace = elt->compunit ()->objfile ()->pspace (); gdb_assert (!elt_pspace->executing_startup); set_current_program_space (elt_pspace); - iterate_over_file_blocks (elt, lookup_name, SEARCH_VFT, - [&] (block_symbol *bsym) - { return info->add_symbol (bsym); }); + iterate_over_file_blocks (elt, lookup_name, SEARCH_VFT, add_symbol); /* If no new symbols were found in this iteration and this symtab is in assembler, we might actually be looking for a label for From patchwork Wed Jan 8 07:23:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 104320 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 6DC713858C2B for ; Wed, 8 Jan 2025 07:29:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6DC713858C2B Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=LQ1XHxMi X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta036.useast.a.cloudfilter.net (omta036.useast.a.cloudfilter.net [44.202.169.35]) by sourceware.org (Postfix) with ESMTPS id 423603858C2B for ; Wed, 8 Jan 2025 07:23:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 423603858C2B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 423603858C2B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.35 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736321008; cv=none; b=QVPL9wbkcGsfQNOA8sXi3fb7/T2sRJenwS+yRJIxBCjc9H1ufT5mifCLl49YnJfqaVtRNtiYSpFY53MDUdOgAaP781Rd/S/NI1L4Ce5mENTUEETShEjhTbMFg7+dGjpey8wLB5+PUn4yxxed/8PwXDBoVNzKKkIkoF/IceZRVwU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736321008; c=relaxed/simple; bh=XlyO6lF4P940Oc/o6HgApPJH+Qr9JkS/qCymaAUzwjk=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=GQrMVHJqt3s5atrG0W85JJa73JBX4wJN60PnYkvP1c9M2QhkMWR3oH2VDQXb5XZB8xXTG/65HNQEkh2tWgHP3/Ut8R1gmTtAJQF/sA5OM8+ichjsC5HYNbT9JflBjpaibEFYDUOMQb+QdA2Y8PcDCmxtO/1f9mLE5kmK/QRtxiI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 423603858C2B Received: from eig-obgw-5002a.ext.cloudfilter.net ([10.0.29.215]) by cmsmtp with ESMTPS id VLButLdKzxoE1VQPYtsH3s; Wed, 08 Jan 2025 07:23:28 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id VQPWtE86TAWQ3VQPXtNsDe; Wed, 08 Jan 2025 07:23:27 +0000 X-Authority-Analysis: v=2.4 cv=KKiRD0Fo c=1 sm=1 tr=0 ts=677e27ef a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=VdSt8ZQiCzkA:10 a=ItBw4LHWJt0A:10 a=yqVGEpWH_T9SaNXiONsA:9 a=QEXdDO2ut3YA:10 a=6Ogn3jAGHLSNbaov7Orx:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To: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=pE8N7g0eDet1QOLZZ+y9eTM+o57QibWU0yrDarK0V8A=; b=LQ1XHxMi1AjVsMbKs1Z5lFgUGf X99FzzFopgxpQF/uE610YWY9Ta1NswH0uyP2ilo6D1JJAVRG2aCEKf9ifXH4ZtafE2zTIWivyPAqZ BHEEJHVQR9JfoHf/5A6/ndHXn; Received: from 97-118-36-154.hlrn.qwest.net ([97.118.36.154]:56396 helo=prentzel.local) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1tVQPW-001pZ1-1s; Wed, 08 Jan 2025 00:23:26 -0700 From: Tom Tromey Date: Wed, 08 Jan 2025 00:23:26 -0700 Subject: [PATCH 6/6] Use bool in linespec MIME-Version: 1.0 Message-Id: <20250108-linespec-state-cxx-v1-6-a721e95ee050@tromey.com> References: <20250108-linespec-state-cxx-v1-0-a721e95ee050@tromey.com> In-Reply-To: <20250108-linespec-state-cxx-v1-0-a721e95ee050@tromey.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.14.2 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.118.36.154 X-Source-L: No X-Exim-ID: 1tVQPW-001pZ1-1s X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-118-36-154.hlrn.qwest.net (prentzel.local) [97.118.36.154]:56396 X-Source-Auth: tom+tromey.com X-Email-Count: 7 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfNqAYRQBqMDW3BWf6PGqSKeyLU2zpKiZKiuc4s66zCOeeHV2DgMiSm0hLr9YTRNbpUh5aJwmCJe/QpR3PQWuSaDR1wbyTxIKkw1qrDWUn2sip5ry34pL LSn/w4d024utjRdNeKN3bpWC9Ahk562Q8tuwT3pcGyC5FZliduASOFQ+rzQe9pusgl6WqWRTGam/G65MKvuERZe5oYHCIJ7ko3g= X-Spam-Status: No, score=-3015.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_SOMETLD_ARE_BAD_TLD, PDS_OTHER_BAD_TLD, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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.30 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 This changes various spots in linespec to use a bool rather than an int. --- gdb/linespec.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/gdb/linespec.c b/gdb/linespec.c index 9b1e1856eff349d567d4f918b85a79e8323e247f..6ee12ea56a8d5cb780614cac92a06d75fbcfb8f0 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -170,8 +170,8 @@ struct linespec_state search_pspace (search_pspace), default_symtab (default_symtab), default_line (default_line), - funfirstline ((flags & DECODE_LINE_FUNFIRSTLINE) ? 1 : 0), - list_mode ((flags & DECODE_LINE_LIST_MODE) ? 1 : 0), + funfirstline ((flags & DECODE_LINE_FUNFIRSTLINE) ? true : false), + list_mode ((flags & DECODE_LINE_LIST_MODE) ? true : false), canonical (canonical) { } @@ -207,10 +207,10 @@ struct linespec_state /* The 'funfirstline' value that was passed in to decode_line_1 or decode_line_full. */ - int funfirstline; + bool funfirstline; /* Nonzero if we are running in 'list' mode; see decode_line_list. */ - int list_mode; + bool list_mode; /* The 'canonical' value passed to decode_line_full, or NULL. */ struct linespec_result *canonical; @@ -219,7 +219,7 @@ struct linespec_state std::vector canonical_names; /* Are we building a linespec? */ - int is_linespec = 0; + bool is_linespec = false; private: @@ -354,7 +354,7 @@ struct linespec_parser } lexer {}; /* Is the entire linespec quote-enclosed? */ - int is_quote_enclosed = 0; + bool is_quote_enclosed = false; /* The state of the parse. */ struct linespec_state state; @@ -422,8 +422,8 @@ static struct line_offset linespec_parse_variable (struct linespec_state *self, const char *variable); -static int symbol_to_sal (struct symtab_and_line *result, - int funfirstline, struct symbol *sym); +static bool symbol_to_sal (struct symtab_and_line *result, + bool funfirstline, struct symbol *sym); static void add_matching_symbols_to_info (const char *name, symbol_name_match_type name_match_type, @@ -2013,7 +2013,7 @@ static std::vector create_sals_line_offset (struct linespec_state *self, linespec *ls) { - int use_default = 0; + bool use_default = false; /* This is where we need to make sure we have good defaults. We must guarantee that this section of code is never executed @@ -2032,7 +2032,7 @@ create_sals_line_offset (struct linespec_state *self, ls->file_symtabs = collect_symtabs_from_filename (self->default_symtab->filename, self->search_pspace); - use_default = 1; + use_default = true; } symtab_and_line val; @@ -2488,7 +2488,7 @@ parse_linespec (linespec_parser *parser, const char *arg, /* A special case to start. It has become quite popular for IDEs to work around bugs in the previous parser by quoting the entire linespec, so we attempt to deal with this nicely. */ - parser->is_quote_enclosed = 0; + parser->is_quote_enclosed = false; if (parser->completion_tracker == NULL && !is_ada_operator (arg) && *arg != '\0' @@ -2500,7 +2500,7 @@ parse_linespec (linespec_parser *parser, const char *arg, /* Here's the special case. Skip ARG past the initial quote. */ ++arg; - parser->is_quote_enclosed = 1; + parser->is_quote_enclosed = true; } } @@ -2870,7 +2870,7 @@ linespec_complete (completion_tracker &tracker, const char *text, parser.lexer.stream = text; parser.completion_tracker = &tracker; - parser.state.is_linespec = 1; + parser.state.is_linespec = true; /* Parse as much as possible. parser.completion_word will hold furthest completion point we managed to parse to. */ @@ -3061,7 +3061,7 @@ location_spec_to_sals (linespec_parser *parser, case LINESPEC_LOCATION_SPEC: { const linespec_location_spec *ls = as_linespec_location_spec (locspec); - parser->state.is_linespec = 1; + parser->state.is_linespec = true; result = parse_linespec (parser, ls->spec_string.get (), ls->match_type); } @@ -4131,7 +4131,7 @@ minsym_found (struct linespec_state *self, struct objfile *objfile, static void add_minsym (struct minimal_symbol *minsym, struct objfile *objfile, - struct symtab *symtab, int list_mode, + struct symtab *symtab, bool list_mode, std::vector *msyms) { if (symtab != NULL) @@ -4319,14 +4319,14 @@ add_matching_symbols_to_info (const char *name, /* Now come some functions that are called from multiple places within decode_line_1. */ -static int +static bool symbol_to_sal (struct symtab_and_line *result, - int funfirstline, struct symbol *sym) + bool funfirstline, struct symbol *sym) { if (sym->aclass () == LOC_BLOCK) { *result = find_function_start_sal (sym, funfirstline); - return 1; + return true; } else { @@ -4339,7 +4339,7 @@ symbol_to_sal (struct symtab_and_line *result, result->pc = sym->value_address (); result->pspace = result->symtab->compunit ()->objfile ()->pspace (); result->explicit_pc = 1; - return 1; + return true; } else if (funfirstline) { @@ -4354,11 +4354,11 @@ symbol_to_sal (struct symtab_and_line *result, result->line = sym->line (); result->pc = sym->value_address (); result->pspace = result->symtab->compunit ()->objfile ()->pspace (); - return 1; + return true; } } - return 0; + return false; } linespec_result::~linespec_result ()