From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id SVk/C0osoWp9XDkAWB0awg (envelope-from ) for ; Wed, 09 Sep 2026 05:52:10 -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=tsjsuLxo; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=QnlDV5wu; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=sfxj5xDZ; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=jOnX4Zb5; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 29F381E09E; Wed, 09 Sep 2026 05:52:10 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.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 autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::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 5D0671E091 for ; Wed, 09 Sep 2026 05:52:09 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B1A8A4B9DB62 for ; Wed, 9 Sep 2026 09:52:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B1A8A4B9DB62 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=tsjsuLxo; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=QnlDV5wu; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=sfxj5xDZ; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=jOnX4Zb5 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 23A0F4BB3BA4 for ; Wed, 9 Sep 2026 09:49:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 23A0F4BB3BA4 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 23A0F4BB3BA4 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788947348; cv=none; b=Fm1aWRT15x5XPxZKV7+G0q/UQOsm63suHykWHX0GQZmCq7CfZmQRKj5Z0h+0PRLOdQq+O0ayqe9JyqeKdbQCl5aqUt34m6AdZUyLzS56Tk6bEiP8nB4X8WQiOD3rqijChfs4Msoztk2P1gkhhDqQKMaf+hi7vjAP+i49hcRWXH8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788947348; c=relaxed/simple; bh=CWC/K4VxDULohVXg2majcJvYhXLI7T4jwy/VaS/hT/M=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=CphI0i8gEJihARK9BYgAd2Vhn1gXH3+R/d3Q+PM4FnSsmkc/KQVWAZJc4NQLK43P6Tpf0zNvmf5uIp3SXXq5LwerD75/X7bB0OPy/BRGeD93QjydCLq+SkmXh37W7EG6AHJRRRqodN9PXZ3cRMxnx4yPWmG9zYwqR432e7hREew= ARC-Authentication-Results: i=1; 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=tsjsuLxo; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=QnlDV5wu; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=sfxj5xDZ; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=jOnX4Zb5 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 23A0F4BB3BA4 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-out1.suse.de (Postfix) with ESMTPS id 1768521AF9 for ; Wed, 9 Sep 2026 09:48:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1788947343; 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=FtL0sdbrc3wefcNg+Rfx8qhMQMXkHEZ9PmN2XyHSMmw=; b=tsjsuLxohIJAdQM5m2XV2XuqbVJFg1n594Mn8lCUZytSaqQLqem6m6qzQPinSX3qzxOx5H XhpesvT+zTeiy2Qm9aMR/Xkyiijw7HXIOx6yreFW2+rV8uJlzLL40fUwJmAnUmXeiLc+xY 6CD87/Yovcb//1VoI1hVtqI4YkY9q9E= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1788947343; 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=FtL0sdbrc3wefcNg+Rfx8qhMQMXkHEZ9PmN2XyHSMmw=; b=QnlDV5wu4K0HdXq976pnXQVELtaiKJWCV3aJ0Pa22Td2V9Iuz8RVOz9c/z/tcnSBgOLkny 51A2NHE+bA3XwPAQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1788947339; 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=FtL0sdbrc3wefcNg+Rfx8qhMQMXkHEZ9PmN2XyHSMmw=; b=sfxj5xDZOVVIRxRDI0kZI8jijYIkZCRu+rI7F4mhjUW0WbD9Ez5pVm/OcJP75vTxvAVHt1 STX8HHxUwILdA/HBATWl3+zbRYkA9r3P4nMCzmmv4rgKska44t3HOygtaSpkPCzd7Fr0sb yRoCrC/dLSQFc3upf0aCTfirossHbvA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1788947339; 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=FtL0sdbrc3wefcNg+Rfx8qhMQMXkHEZ9PmN2XyHSMmw=; b=jOnX4Zb5NrCd2WM0TQ6A2dboBA96CikEQOH5H+SmkNkYLEw7kuFCs2YZYlh2MMb3k/5dcJ DlHrK2WGSLxk4qCQ== 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 F41881366F for ; Wed, 9 Sep 2026 09:48:50 +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 YBoUOoIroWpJBAAAD6G6ig (envelope-from ) for ; Wed, 09 Sep 2026 09:48:50 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v2 5/7] [gdb] Add prev/next params to find_pc_section Date: Wed, 9 Sep 2026 11:48:47 +0200 Message-ID: <20260909094849.2745086-6-tdevries@suse.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260909094849.2745086-1-tdevries@suse.de> References: <20260909094849.2745086-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%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.996]; MIME_GOOD(-0.10)[text/plain]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid,imap1.dmz-prg2.suse.org:helo]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; 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 Now that we're using std::lower_bound to find sections in find_pc_section, extend find_pc_section to return the previous and next section in case it returns nullptr. --- gdb/objfiles.c | 32 ++++++++++++++++++++++++++++++-- gdb/objfiles.h | 4 +++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 066d1af9b9e..3871ef1670f 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -912,14 +912,22 @@ update_section_map (struct program_space *pspace, *pmap_size = map_size; } -/* Returns a section whose range includes PC or NULL if none found. */ +/* Returns a section whose range includes PC or nullptr if none found. + On returning nullptr, set PREV_PTR and NEXT_PTR to point to the sections + before and after PC, if any. */ struct obj_section * -find_pc_section (CORE_ADDR pc) +find_pc_section (CORE_ADDR pc, struct obj_section **prev_ptr, + struct obj_section **next_ptr) { struct objfile_pspace_info *pspace_info; struct obj_section *s; + if (prev_ptr != nullptr) + *prev_ptr = nullptr; + if (next_ptr != nullptr) + *next_ptr = nullptr; + /* Check for mapped overlay section first. */ s = find_pc_mapped_section (pc); if (s) @@ -964,6 +972,26 @@ find_pc_section (CORE_ADDR pc) && (*it)->addr () <= pc && pc < (*it)->endaddr ()) return *it; + struct obj_section *prev = nullptr, *next = nullptr; + auto prev_it = (it == data.cbegin () + ? data.cend () + : it - 1); + if (prev_it != data.cend ()) + { + prev = *prev_it; + gdb_assert (prev->endaddr () <= pc); + } + if (it != data.cend ()) + { + next = *it; + gdb_assert (pc < next->addr ()); + } + + if (prev_ptr != nullptr) + *prev_ptr = prev; + if (next_ptr != nullptr) + *next_ptr = next; + return NULL; } diff --git a/gdb/objfiles.h b/gdb/objfiles.h index fa265f83b79..d23e2b3046e 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -954,7 +954,9 @@ extern void objfile_purge_solibs (program_space *pspace); /* Functions for dealing with the minimal symbol table, really a misc address<->symbol mapping for things we don't have debug symbols for. */ -extern struct obj_section *find_pc_section (CORE_ADDR pc); +extern struct obj_section *find_pc_section (CORE_ADDR pc, + struct obj_section **prev = nullptr, + struct obj_section **next = nullptr); /* Return true if PC is in a section called NAME. */ extern bool pc_in_section (CORE_ADDR, const char *); -- 2.51.0