From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id EbIrMKin9GkcGwkAWB0awg (envelope-from ) for ; Fri, 01 May 2026 09:16:24 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=iAYQSUvs; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=9GHmAABQ; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=VvmWmeBr; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Mq6MGwdS; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id BFE791E0BA; Fri, 01 May 2026 09:16:24 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (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 082211E067 for ; Fri, 01 May 2026 09:16:24 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 76A2444115C8 for ; Fri, 1 May 2026 13:16:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 76A2444115C8 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=iAYQSUvs; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=9GHmAABQ; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=VvmWmeBr; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Mq6MGwdS Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id B3C8B4A968FA for ; Fri, 1 May 2026 13:15:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B3C8B4A968FA Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B3C8B4A968FA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777641356; cv=none; b=gP+ISS4p+1lc6Jw2UrCjsDbcHKFtSQ8pNTNQ9lihkDhjFEh9zdkDt+u5hjoWaMlRL02gjVUhvBiYnPnWipl2y3Ya2CDsR9CogclWWrInfjTIu8Mry43uM7as9fds6Vtf3+T3qNISmgR1YcfMoLS58Bd/HE+jF0gtMblzG1/Mgfc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777641356; c=relaxed/simple; bh=o3EUqCj1ZNCSi3w1cWeM2cHxyFD81QNsJne0xs+vT7Y=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature: Message-ID:Date:MIME-Version:Subject:To:From; b=knalo9NIBpdPQBY1yJNgQ0fE/7uCwv9qghUx/tA8HotmkrqDbL2uNjKxHl9VE3W5ivhoWNNsQ2jKavgI9eoxYI86H7Sw4ims8uxq45RhzMFadPdvQ2hYLmnoR0dSwRVQZRE23k6JsOkT6/PNsqeWA8JAI5/fErj+cse9cbuYQsw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B3C8B4A968FA Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 316BA5BCCE; Fri, 1 May 2026 13:15:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1777641355; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ooZAu9uIQ93K72SqAHzqpidqNltU0R6DzXuPgENgAIQ=; b=iAYQSUvsiksyvfcxu8yBhxzOUKE/P9rjbaTBlaiEwv/BE3PEpVxWuHKLTuaxpWY5reo0ZP 83i/sbOXmopkC7/5K63d+rGTu0p2tNdooFmouHgs3vk8tzY5hZGi6SPk1WvoNz/CgAnezr rikFd/ItPlGbP3kvWUe4G00pIUFOIIg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1777641355; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ooZAu9uIQ93K72SqAHzqpidqNltU0R6DzXuPgENgAIQ=; b=9GHmAABQSdm4VJsIYXW6x9LVofsZXe3+QzZqvZZex3x5iO9MDClWwCyEP7oi1W09N7RcB3 cyKgfz00cXmRNEDA== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=VvmWmeBr; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=Mq6MGwdS DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1777641354; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ooZAu9uIQ93K72SqAHzqpidqNltU0R6DzXuPgENgAIQ=; b=VvmWmeBrro0FlTitDIUVj48uNEE/vpqMJJ+uOHvEpeNgzlcQm+1IEARFe9OsFjog7OoMpv Diea+6e7hwo73F63+pmqzxZeSDFIwzJgZaXKF/nmfSp6iIn3UmsMQwr38kK/+Rk7lbJhe/ EI6HgY0FVqqKG8fFjpGNmEeijik5eXQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1777641354; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ooZAu9uIQ93K72SqAHzqpidqNltU0R6DzXuPgENgAIQ=; b=Mq6MGwdS34dXCwuE885SM8ui0DBYWWdQ4w3/2pW7Quuj8VoM4OIp1MHviOxkS169nZe0qx KWyxf4lv7lrvPgDA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 1BB0E593B0; Fri, 1 May 2026 13:15:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id a3WIBYqn9GlZBgAAD6G6ig (envelope-from ); Fri, 01 May 2026 13:15:54 +0000 Message-ID: <31946953-b76b-4495-8cf0-bcb29b9aa930@suse.de> Date: Fri, 1 May 2026 15:15:53 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 3/7] [gdbsupport] Factor out base_next_iterator To: Simon Marchi , gdb-patches@sourceware.org References: <20260423063530.1074175-1-tdevries@suse.de> <20260423063530.1074175-4-tdevries@suse.de> <52ebd2ce-a27b-4cf6-81f4-ad3fa3537ee1@simark.ca> Content-Language: en-US From: Tom de Vries In-Reply-To: <52ebd2ce-a27b-4cf6-81f4-ad3fa3537ee1@simark.ca> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spamd-Result: default: False [-4.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RCVD_TLS_ALL(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,sourceware.org:url,suse.de:dkim,suse.de:mid]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:104:10:150:64:97:from]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Queue-Id: 316BA5BCCE 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 On 4/30/26 6:24 PM, Simon Marchi wrote: > On 4/23/26 2:35 AM, Tom de Vries wrote: >> diff --git a/gdbsupport/next-iterator.h b/gdbsupport/next-iterator.h >> index 0c90428d349..1dee941a252 100644 >> --- a/gdbsupport/next-iterator.h >> +++ b/gdbsupport/next-iterator.h >> @@ -21,27 +21,43 @@ >> >> #include "gdbsupport/iterator-range.h" >> >> -/* An iterator that uses the 'next' field of a type to iterate. This >> - can be used with various GDB types that are stored as linked >> - lists. */ >> +/* An iterator base class for iterating over a field of a type. In order to >> + form a functioning iterator, classes inheriting this should define an >> + operator++, which determines the actual field that is iterated over. >> + >> + Instead of factoring out a base class, we could use something like this: >> + >> + template >> + struct next_iterator >> + { >> + ... >> + self_type &operator++ () >> + { >> + m_item = m_item->*F; >> + return *this; >> + } >> + ... >> + } >> + >> + but that has the drawback that it doesn't work with incomplete T. */ > Hi Simon, thanks for the review. > I'm of the opinion that this information is not really relevant here, it > belongs to the commit message. > Ack, I've moved that to the commit message in a v1 ( https://sourceware.org/pipermail/gdb-patches/2026-May/227066.html ). > I was initially skeptic that the version with the pointer-to-member > didn't work, so I tried it for myself and indeed, I don't think it would > work with the block and superblock_iterator relationship (at least, if > we want to have a method of block returning a > superblock_iterator/range). > That was not what I was getting at. The problem is that the gdb build breaks with the pointer-to-member approach because we exploit this incomplete type behavior in the sources. > While next_iterator is "iterate using the raw field `next`", > base_next_iterator is more generic just for "iterating over a field of a > type". It looks like you defined a pretty generic class where the > derived class only needs to fill in operator++ (and perhaps a bit more > boilerplate). But operator++ doesn't have to just follow a field, it > can have any logic in there, as function_block_iterator proves, which is > nice. Following the raw `next` field (or another raw field of any other > name) is just one specific case. > > Given that all the concrete iterate needs to provide is "given a > reference to the current element, give me the next element", I think we > could reduce the boilerplate needed at each site by having the concrete > iterator provide a functor that does the increment (much like you > defined an std::map by providing a "hash" functor, not by deriving from > std::map). > Tom Tromey suggested using CRTP, and doing so has I think brought it closer to what you suggest here. > Rather than copy paste what I mean here, I pushed what I think it could > look like to the users/simark/next-iterator branch. > > https://sourceware.org/git/?p=binutils-gdb.git;a=shortlog;h=refs/heads/users/simark/next-iterator > https://sourceware.org/cgit/binutils-gdb/log/?h=users/simark/next-iterator > > But just to illustrate here is how the function block iterator and > range are implemented: > > /* Iterator and range type to iterate over this block and its superblocks > within a function. */ > > struct function_block_incrementer > { > const block *operator() (const block &b) const noexcept > { > /* If the current item is the function-defining block, we're done. */ > if (b.function () != nullptr) > return nullptr; > > return b.superblock (); > } > }; > > using function_block_iterator > = base_next_iterator; > using function_block_range = iterator_range; > > I kept the name `base_next_iterator`, we could perhaps find a better > name, since it's not realted to `next_iterator` more than any other > concrete instance. Perhaps `base_iterator`, or `simple_iterator`? > Yeah, agreed. I kept it as is in v1 thought. >> @@ -61,15 +77,34 @@ struct next_iterator >> return m_item != other.m_item; >> } >> >> - self_type &operator++ () >> +protected: >> + >> + T *m_item; >> +}; >> + >> +/* An iterator that uses the 'next' field of a type to iterate. This >> + can be used with various GDB types that are stored as linked >> + lists. */ >> + >> +template >> +struct next_iterator : base_next_iterator { >> + typedef next_iterator self_type; >> + typedef T *value_type; >> + typedef T *&reference; >> + typedef T **pointer; > > I think we should use `using` instead of typedef everywhere now. > I've added a patch to the series doing this transformation in next-iterator.h and one other file. >> + >> + explicit next_iterator (T *item) >> + : base_next_iterator (item) >> { >> - m_item = m_item->next; >> - return *this; >> } >> >> -private: >> + next_iterator () = default; > > Just noting that instead of those two constructors, you can use: > > using base_next_iterator::base_next_iterator; Yeah, that's neat, thanks, I've used that in the v1. Thanks, - Tom