From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id bwdOMrRxsGi2Ww4AWB0awg (envelope-from ) for ; Thu, 28 Aug 2025 11:11:48 -0400 Received: by simark.ca (Postfix, from userid 112) id 9B25F1E08D; Thu, 28 Aug 2025 11:11:48 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=no autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 343DC1E047 for ; Thu, 28 Aug 2025 11:11:47 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8F3223858401 for ; Thu, 28 Aug 2025 15:11:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8F3223858401 Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 0B3873858422 for ; Thu, 28 Aug 2025 15:11:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0B3873858422 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0B3873858422 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756393863; cv=none; b=oK1/uZbnQzmgH5YLSHvy5Y65Ou7DvSEtAdgCKVxSFLohqq5aBE6r4ROfWUF5OBsVWuBdKBl1MV/Hk3bv8YJmbr3NjSWd7DXGTfzgFznd+Xb1XWV8nS8/oOMRmoKV+xm8tf0gr8ecu7rI7yBhhuESR3+Eq2L056vUKvCHYwGOP3I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756393863; c=relaxed/simple; bh=J3+RxaWK0shH8DpRaG2VN2gBzvqvPAlhMAnErejvo9U=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=BnD9pJyxZnUCkvxL9iLlIrSUSiklXrJIxIkV4d4a5KWf83jC3OyWgSr24Pg54KfLSYGNxXsarzte+kT2+KK7dko55cwg8Sicf21/yQH8yCrj9W+cHkteWxFddq2TTUKTVXbNtwPdlhxWxBVFtgvU+RhsJsTHw6EsyvbfvlscFEY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0B3873858422 Received: by simark.ca (Postfix) id 5F1661E04C; Thu, 28 Aug 2025 11:11:02 -0400 (EDT) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 3/3] gdb/objfiles: use filtered_iterator as objfile::section_iterator Date: Thu, 28 Aug 2025 11:10:51 -0400 Message-ID: <20250828151100.84594-3-simon.marchi@efficios.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250828151100.84594-1-simon.marchi@efficios.com> References: <20250828151100.84594-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org objfile::section_iterator looks like a good candidate to be implemented with filtered_iterator. Following the enhancements to filtered_iterator in the previous patch, it's pretty straighforward. I removed the non-const version of objfile::sections, because it didn't seem useful to have the two methods returning the exact same type and value. Having just the const version achieves the same thing. Change-Id: I2f29c2fb3f95605cb816cc1ff8935c10e0496052 --- gdb/objfiles.h | 59 +++++++------------------------------------------- 1 file changed, 8 insertions(+), 51 deletions(-) diff --git a/gdb/objfiles.h b/gdb/objfiles.h index fe7a2ac91fda..2711d4dcb06f 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -657,61 +657,18 @@ struct objfile : intrusive_list_node this->section_offsets[idx] = offset; } - class section_iterator + /* Filter function for section_iterator. */ + struct filter_out_null_bfd_section { - public: - section_iterator (const section_iterator &) = default; - section_iterator (section_iterator &&) = default; - section_iterator &operator= (const section_iterator &) = default; - section_iterator &operator= (section_iterator &&) = default; - - using self_type = section_iterator; - using reference = obj_section &; - - reference operator* () - { return *m_iter; } - - section_iterator &operator++ () - { - ++m_iter; - skip_null (); - return *this; - } - - bool operator== (const section_iterator &other) const - { return m_iter == other.m_iter && m_end == other.m_end; } - - bool operator!= (const section_iterator &other) const - { return !(*this == other); } - - private: - - friend class objfile; - - section_iterator (obj_section *iter, obj_section *end) - : m_iter (iter), - m_end (end) - { - skip_null (); - } - - void skip_null () - { - while (m_iter < m_end && m_iter->the_bfd_section == nullptr) - ++m_iter; - } - - obj_section *m_iter; - obj_section *m_end; + bool operator() (const obj_section &sec) const noexcept + { return sec.the_bfd_section != nullptr; } }; - iterator_range sections () - { - return (iterator_range - (section_iterator (sections_start, sections_end), - section_iterator (sections_end, sections_end))); - } + using section_iterator = filtered_iterator; + /* Return an iterable that yields the "non-null" sections of this objfile. + That is, the sections for which obj_section::the_bfd_section is + non-nullptr. */ iterator_range sections () const { return (iterator_range -- 2.51.0