From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id oQX6I6mg9GmM9AgAWB0awg (envelope-from ) for ; Fri, 01 May 2026 08:46:33 -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=Ejd01ZTs; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=8ve20BPQ; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=Ejd01ZTs; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=8ve20BPQ; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 8E4831E0BA; Fri, 01 May 2026 08:46:33 -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 61A4B1E067 for ; Fri, 01 May 2026 08:46:31 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id F403446A9CD2 for ; Fri, 1 May 2026 12:46:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F403446A9CD2 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=Ejd01ZTs; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=8ve20BPQ; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=Ejd01ZTs; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=8ve20BPQ Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id E1DB846A9CE4 for ; Fri, 1 May 2026 12:45:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E1DB846A9CE4 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 E1DB846A9CE4 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777639558; cv=none; b=eE/8OV/p7A8vY7JI3XuvZwOqoeacfF7H+JHlW0nDTbXBenEgoja1TXozKxEDAdGglUSyl4HgqWsiIHAharCV0aGdH7mg52PteRs/8SrjkB0jU7Wws1xA0ebQcRwxNVeaHCQceacPhJV99g+lON8xjVTpv32GDrU7KMK3o2a6NfI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777639558; c=relaxed/simple; bh=FmcRzGcecpQTOPCcDELA9uUBUSGv+GIvVJjDbbeZ1Y4=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=snGC9S+WLGzzgO+ul/FYNHVp7XY1LaMa2J4cpOu6u0Zbvws0QR4+oMatfjxCUQ4ItyjDDpv38QxybOHvrPCT2tLxUKo0hBqtniEFGCpr9EITsMEfOXZe/YClr1cgnhE77SpZvz/wEqjexKeja7htqULIKUC6gz3tuAJ4pClLIzk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E1DB846A9CE4 Received: from imap1.dmz-prg2.suse.org (unknown [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 E2A4B5BD72 for ; Fri, 1 May 2026 12:45:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1777639506; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1C4mzazulZTMwFeqbPEnDgBgpmU4MvoHp4/97s9T0F0=; b=Ejd01ZTsAv3gDagsJkChirSf9AvbsBOTUTZ7TSHHYkZASab8IJeQ5QUFWMNDUoqrT4nzWs xmow5V15zZ8p8nHv+S8F0BFCxdA3o2Lb83Bh3neZVj8NFknosQ+pMbpCd3ntBYged0FaIv vXh5u97Ae1stHHG5RBhMrOw3C+7rA70= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1777639506; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1C4mzazulZTMwFeqbPEnDgBgpmU4MvoHp4/97s9T0F0=; b=8ve20BPQpZb4EKt5Hivpz9OoACVPBvhvFkwMUCMKb+/+SRxqVl42RgM8hXqi9Se7hkc1ib zwrvBIog6h5L2BCg== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1777639506; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1C4mzazulZTMwFeqbPEnDgBgpmU4MvoHp4/97s9T0F0=; b=Ejd01ZTsAv3gDagsJkChirSf9AvbsBOTUTZ7TSHHYkZASab8IJeQ5QUFWMNDUoqrT4nzWs xmow5V15zZ8p8nHv+S8F0BFCxdA3o2Lb83Bh3neZVj8NFknosQ+pMbpCd3ntBYged0FaIv vXh5u97Ae1stHHG5RBhMrOw3C+7rA70= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1777639506; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1C4mzazulZTMwFeqbPEnDgBgpmU4MvoHp4/97s9T0F0=; b=8ve20BPQpZb4EKt5Hivpz9OoACVPBvhvFkwMUCMKb+/+SRxqVl42RgM8hXqi9Se7hkc1ib zwrvBIog6h5L2BCg== 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 C96B5593B0 for ; Fri, 1 May 2026 12:45:06 +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 CGatL1Kg9Gn5ZwAAD6G6ig (envelope-from ) for ; Fri, 01 May 2026 12:45:06 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH 09/10] [gdb] Add block::block_and_superblocks_in_fn Date: Fri, 1 May 2026 14:45:03 +0200 Message-ID: <20260501124504.2233495-10-tdevries@suse.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260501124504.2233495-1-tdevries@suse.de> References: <20260501124504.2233495-1-tdevries@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[99.99%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:mid]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCVD_TLS_ALL(0.00)[] 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 Add a function block::block_and_superblocks_in_fn that can be used to transform: ... while (block != NULL) { ... if (block->function () != nullptr) break; block = block->superblock (); } ... into: ... for (auto b : block::block_and_superblocks_in_fn (block)) { ... } ... In fact the new loop is somewhat stricter, because it systematically ignores the static and global blocks. This means that the transformation is not strictly semantics-preserving. I'm still on the fence about whether this is a good idea. My assumption here is that these loops are written assuming a well-formed block hierarchy: ... global block <- static block <- function block <- in-function block ... as well as assuming that the starting block is not the static or global block. And for such loops, the stricter static/global blocks skipping behavior doesn't matter. --- gdb/block.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/gdb/block.h b/gdb/block.h index ff5203ae4c6..c39425185aa 100644 --- a/gdb/block.h +++ b/gdb/block.h @@ -127,7 +127,42 @@ struct block : public allocate_on_obstack } }; + /* Variant of next_iterator using the superblock field instead of next. */ + struct function_block_iterator + : base_next_iterator + { + typedef function_block_iterator self_type; + + explicit function_block_iterator (value_type item) + : base_next_iterator (item->is_global_block () || item->is_static_block () + ? nullptr : item) + { + } + + function_block_iterator () = default; + + value_type next () + { + if (m_item->function () != nullptr) + return nullptr; + + value_type next = m_item->superblock (); + if (next->is_global_block () || next->is_static_block ()) + { + /* This shouldn't be reachable in well-formed block hierarchies, given + that we avoid global and static block in the constructor, and + stop iterating when encountering a function. But let's try to be + robust and ensure that this iterator never points to a static or + global block. */ + return nullptr; + } + + return next; + } + }; + using superblock_range = iterator_range; + using function_block_range = iterator_range; /* Return this block's start address. */ CORE_ADDR start () const @@ -352,6 +387,27 @@ struct block : public allocate_on_obstack return b->block_and_superblocks (); } + /* Return a range adapter that iterates over this block and its + superblocks in the same function. */ + + function_block_range block_and_superblocks_in_fn () const + { + function_block_range::iterator begin (this); + + return function_block_range (std::move (begin)); + } + + /* Return a range adapter that iterates over B and its superblocks in the + same function. */ + + static function_block_range block_and_superblocks_in_fn (const block *b) + { + if (b == nullptr) + return function_block_range (); + + return b->block_and_superblocks_in_fn (); + } + /* Return true if block A is lexically nested within this block, or if A and this block have the same pc range. Return false otherwise. If ALLOW_NESTED is true, then block A is considered -- 2.51.0