From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id weDVBgosoWp9XDkAWB0awg (envelope-from ) for ; Wed, 09 Sep 2026 05:51:06 -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=y4iR81Jk; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=CzYpw/hV; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=q+r9ntFQ; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=rM77GUUr; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 160401E091; Wed, 09 Sep 2026 05:51:06 -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 348EC1E091 for ; Wed, 09 Sep 2026 05:51:05 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 260564BA23FC for ; Wed, 9 Sep 2026 09:51:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 260564BA23FC 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=y4iR81Jk; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=CzYpw/hV; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=q+r9ntFQ; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=rM77GUUr Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id 7ECEA4BA23FB for ; Wed, 9 Sep 2026 09:49:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7ECEA4BA23FB 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 7ECEA4BA23FB Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788947340; cv=none; b=RZbXJ4k0+yJZtxc5Xx1UyDKUHREFrKjFJd45PfOn2SzIJ3R01UIgEDqbC2/mONcoX8NjJAjnqfDk7NxX9VUsAZpBo76Bgc2l9F3v9qIxZT8PEp+c/gS7Tr53aVZ84UfeY5QpX6jLzCr4MT+PSRs5wavBxaU8Vtuirj/djTGhkEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788947340; c=relaxed/simple; bh=gT7Wh9OcJqAKOISigeYEf8wjZjude9C1GzQVcQ79hE0=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=wXbxjmPypU/MP11OTYW3m+bCZuM73SwHYbaXwomCFoxfkg/XBOOCuL8LgPGP0bqcKOL7jxuuVBiAciO5sct37M9x1g3u2r8XL+H8ex5O5l/AazYCsCi0OMTrhVbA2u17kntPmyjjcO9CkT0j/PfVPQpllF23Cv7Czw7mC8y33zk= 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=y4iR81Jk; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=CzYpw/hV; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=q+r9ntFQ; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=rM77GUUr DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7ECEA4BA23FB 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 31D9221B27 for ; Wed, 9 Sep 2026 09:48:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1788947335; 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=+bVBSieO84sitE14NkA/XTyBE5X7iOLxZS/qf79ydOs=; b=y4iR81JkhlNLRx5ms5YZGD14FzG2j/4uINpC5lggLxeKLS0ievKlxpxo3Ih+32B3XLTqd7 IGO6EfjKuTVDJ8RgvWdTOmuPO9FYYgEXYR7JVfzUIMUglAwF8QfOIQckvNqyAJ30gz2vNT MOu5xRCzWQCqGbGEe7voZvbW9RDG+lA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1788947335; 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=+bVBSieO84sitE14NkA/XTyBE5X7iOLxZS/qf79ydOs=; b=CzYpw/hVzXdYiCXzzlbMtHwo7PCdYwUsU2ugFioow2ZS6o11R6iJRma2p5UJGbyTbIiW48 DXJUPP0nlvhoY/AQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1788947331; 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=+bVBSieO84sitE14NkA/XTyBE5X7iOLxZS/qf79ydOs=; b=q+r9ntFQYhwaHudyTJEABLGWc/KwtH3msEdHorQZRUCS6DhMB24BnLXUXh85kH5R73pN3k xKqhK1SuFtuhS65IhHIH4w7Sba9EC5iKKABlbytrSwsXpAny/Ma41K2+Xh9hU4Bmj0TdX4 3WrOsiZ+klmP9jWCagPsWbikj2k0l9A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1788947331; 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=+bVBSieO84sitE14NkA/XTyBE5X7iOLxZS/qf79ydOs=; b=rM77GUUrdmHqt1B6kmpwoJ2g6nYlDMWiLJvA6mEscJv1ojEUt7B7KcjnP2ZS3g7+U6UiP7 R8xJCxeyQtO/zWCQ== 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 D6E7D13668 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 0IAcM4IroWpJBAAAD6G6ig (envelope-from ) for ; Wed, 09 Sep 2026 09:48:50 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v2 4/7] [gdb] replace bsearch with std::lower_bound in find_pc_section Date: Wed, 9 Sep 2026 11:48:46 +0200 Message-ID: <20260909094849.2745086-5-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 In find_pc_section, we use bsearch to find a matching section. This works fine, but in case the pc matches a section hole, it returns nullptr, with no information about where the section hole is. Instead, use std::lower_bound. No functional changes. --- gdb/objfiles.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 408ddf1ff83..066d1af9b9e 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -912,28 +912,13 @@ update_section_map (struct program_space *pspace, *pmap_size = map_size; } -/* Bsearch comparison function. */ - -static int -bsearch_cmp (const void *key, const void *elt) -{ - const CORE_ADDR pc = *(CORE_ADDR *) key; - const struct obj_section *section = *(const struct obj_section **) elt; - - if (pc < section->addr ()) - return -1; - if (pc < section->endaddr ()) - return 0; - return 1; -} - /* Returns a section whose range includes PC or NULL if none found. */ struct obj_section * find_pc_section (CORE_ADDR pc) { struct objfile_pspace_info *pspace_info; - struct obj_section *s, **sp; + struct obj_section *s; /* Check for mapped overlay section first. */ s = find_pc_mapped_section (pc); @@ -963,13 +948,22 @@ find_pc_section (CORE_ADDR pc) return NULL; } - sp = (struct obj_section **) bsearch (&pc, - pspace_info->sections, - pspace_info->num_sections, - sizeof (*pspace_info->sections), - bsearch_cmp); - if (sp != NULL) - return *sp; + gdb::array_view data + = gdb::make_array_view (pspace_info->sections, pspace_info->num_sections); + auto section_before_pc + = [] (obj_section *sect, CORE_ADDR pc_) -> bool + { + /* Return true if SECT is ordered before PC. */ + return sect->endaddr () <= pc_; + }; + auto it + = std::lower_bound (data.cbegin (), data.cend (), pc, section_before_pc); + /* The std::lower_bound call returns the first section which is not ordered + before pc. That section may or may not contain pc. */ + if (it != data.cend () + && (*it)->addr () <= pc && pc < (*it)->endaddr ()) + return *it; + return NULL; } -- 2.51.0