From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id GaHaIJlkOmqJvhQAWB0awg (envelope-from ) for ; Tue, 23 Jun 2026 06:48:57 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=W4fd/idI; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 823021E024; Tue, 23 Jun 2026 06:48:57 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,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 [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 8FDA31E024 for ; Tue, 23 Jun 2026 06:48:55 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B54594BA2E07 for ; Tue, 23 Jun 2026 10:48:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B54594BA2E07 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=W4fd/idI Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 847AA4BA2E29 for ; Tue, 23 Jun 2026 10:47:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 847AA4BA2E29 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 847AA4BA2E29 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782211649; cv=none; b=q11Gzy/d73EUoewLzjHF2RvEsO2cWL4rdiOPOW7t2OMQpCoD/XA48+4UzuTnNV5DqcKmuKbpcwgbrx3nlO7l0vHp7IAWV/VZmx5/l5MiwgQuciA5LcB18rSXP6Mi2zszNfKh8+6Q9vNbCJaBu8EFTkD2Iw5iwl8nhKExzvdHZDo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782211649; c=relaxed/simple; bh=7KbwyrzId5VYBv2EdA1WQEdeHSCSPxyDjvLAJ3BSFBc=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=EppAr/jjWo3fzNfH4V0MQrt0nU0KAi+rvxEOPML/7gwXHAqTipDiGeSxN0qGnvigewGZz2V3tV3a/fVLSZ2PoXLkN9CKBEeIuWpFxkchx9jURzYiWI4Z93VolhLlZojkt6pfVFIC62PGnxXskumHxAMYJJKAuSB/RRlBDOoAOe4= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=W4fd/idI DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 847AA4BA2E29 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782211649; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rLat32RNcLZ9IL3YYhv79dFILnly0vhJ0cJeRpybIBs=; b=W4fd/idIefvOL13CFxMRUjfyhhBZiSlXHiKiXFlLED9fAC7H5fd2bC8XBVnQ0TcufhRRwH pYTR6dq6C4aplJMmNW+b9yFc7Zmm61pzfeV8qUqNlj/vqmuyQXH6msNTZ5nCa7YefjsSB3 dCdDxkEo0Vq4sOZfLN0+pIO8KoKcE1o= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-528-yMYGWskWPyC8kQS0KA9XwA-1; Tue, 23 Jun 2026 06:47:28 -0400 X-MC-Unique: yMYGWskWPyC8kQS0KA9XwA-1 X-Mimecast-MFC-AGG-ID: yMYGWskWPyC8kQS0KA9XwA_1782211647 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-46010392f89so4528755f8f.2 for ; Tue, 23 Jun 2026 03:47:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782211647; x=1782816447; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=rLat32RNcLZ9IL3YYhv79dFILnly0vhJ0cJeRpybIBs=; b=dThOY+EmfhVWVeXASFpoloOhR86pd3gIBR37gcskt8pUXaWNqEz2osROthWOdC9wsv 0BzoFjJgQUAifwSOl+QN4kUQS5WrYz9vq/gvy4G8T3S7is8fhJEuJCBU17MzlkmpqSwb ug6KX7GtAdWADqOobe0EiXk9p2JDHuIXxwa6IYv6owf1dF9c0sxvhqf/r+Fimwqrph+n xYgaAeq747oTTxb0rC/90LSQHtX6pa6ghw9Zf6kLc3/mxCBsKIdaBnVDnUZbSCVhr68W 0Nkm/R4O6qeV4Wo+wmemoqo3OC4/5MJEGnPmruz8DB1/aTCi9gqkhhaw2PzIumEx3mk7 VTSw== X-Gm-Message-State: AOJu0Yzl/SlTskGNa8Zx5Q178xV8Ja5NmJpnNG1/w8Aosqvs8OvjjgJI 5KAxq0Ol8Uk6EPhcV7xZEFxziAkGlz1zcn7hRklnBLE61It7w6/y+cPHhCgUfVSEFQOfFxkU4zT qrWMdXyGEEMCOnstdB452AmGuK7RVBXNILcCJh7UEzq/FL3mdxLc5CPZPSESzTwnK1M0+uIKJqB 6T2x91O0FSsbmvqFT8GLJEIuq/ASpJz16TX9ywm4ZT4SHPP/Y= X-Gm-Gg: AfdE7ckbk1lyWkfTMOvdmYFzun+owFRBQNezIaPoZTEveMFeNEo2k+E0rTIKowO7SZp /hGCCIjxBphgCr9r4rvxEBkU8hQd8E4HnHkDcqfU4bg5P6tcQ866zIXCU9iNH1nPbYa9AaYBaOE gZyaV5Dsm0AU6us0vJQssVNnxABRKB8AOYTeaq/yHJ5su+JjuuHPvnFWj51C+nuh80B8CJYB/cq BGJiLo8pZyA8D3X/Id6jaj+mhdcYdVuhRYrZNgL8uGt8J3DTRneQrfAbCNxpWKgpGmlDbO1fVrZ HdC8QKgDr99Kv/QRlvkcgFlLmXlQmdjE14pthLyMKbYOWSsNiXiD+TCQutaJP2oi9oXNxmOT2k9 b5v0thxPJueuhf43tAcJhE9t3r2wx+w== X-Received: by 2002:a05:6000:220c:b0:465:5627:79e8 with SMTP id ffacd0b85a97d-46adabe30bcmr3430640f8f.22.1782211646900; Tue, 23 Jun 2026 03:47:26 -0700 (PDT) X-Received: by 2002:a05:6000:220c:b0:465:5627:79e8 with SMTP id ffacd0b85a97d-46adabe30bcmr3430599f8f.22.1782211646403; Tue, 23 Jun 2026 03:47:26 -0700 (PDT) Received: from localhost (19.81.93.209.dyn.plus.net. [209.93.81.19]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-46667221da1sm34890945f8f.36.2026.06.23.03.47.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jun 2026 03:47:25 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , Pedro Alves Subject: [PATCHv4 4/4] gdb: cache program space entry point information Date: Tue, 23 Jun 2026 11:47:16 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: s3YCtm4gLIvuDL3-BAOcKMqqGkr4PdycqTm2zxP0lng_1782211647 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true 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 After the previous two patches, every time that GDB unwinds a frame there are now two places where we check if the frame is an entry point frame, these are in get_prev_frame and get_prev_frame_always, look for the calls to `inside_entry_func`, which then calls program_space::get_entry_point_info. The calls to program_space::get_entry_point_info are not crazy expensive, but they are not free either, there are reads from target memory to read the auxv vector and the entry address offset, so on remote targets this could introduce a small delay, especially as this occurs twice per frame now. However, the information returned by program_space::get_entry_point_info is not expected to change from one call to the next. This information should be a property of the executable and libraries, so we really only need to figure it out once. This commit caches the entry point information within program_space, clearing it whenever an inferior starts or exits, or whenever the executable is updated. After clearing GDB will compute, and cache the updated information the next time it is needed, which will be whenever GDB needs to unwind a frame. It will be possible to observe this change by, for example, monitoring the remote target packets, but as far as the normal GDB output is concerned, there should be no user visible changes after this commit. --- gdb/progspace.c | 34 +++++++++++++++++++++++++++++++--- gdb/progspace.h | 9 ++++++++- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/gdb/progspace.c b/gdb/progspace.c index 26e16cae8d0..c1f3044f4c5 100644 --- a/gdb/progspace.c +++ b/gdb/progspace.c @@ -289,9 +289,12 @@ program_space::exec_entry_point_address () const /* See progspace.h. */ -program_space::entry_point_info +const program_space::entry_point_info & program_space::get_entry_point_info () const { + if (m_entry_point_info.has_value ()) + return m_entry_point_info.value (); + std::optional exec_entry_address = this->exec_entry_point_address_if_available (); @@ -299,8 +302,9 @@ program_space::get_entry_point_info () const if (m_solib_ops != nullptr) inferior_entry_address = m_solib_ops->inferior_entry_point_address (); - return entry_point_info (std::move (inferior_entry_address), - std::move (exec_entry_address)); + m_entry_point_info.emplace (std::move (inferior_entry_address), + std::move (exec_entry_address)); + return m_entry_point_info.value (); } /* Implement the 'maint info entry-address' command. */ @@ -538,11 +542,35 @@ program_space::clear_solib_cache () deleted_solibs.clear (); } +/* Clear cached entry point information in the program space of INF. */ + +static void +clear_cached_entry_point_info_for_inferior (inferior *inf) +{ + inf->pspace->clear_cached_entry_point_info (); +} + +/* Clear cached entry point information in the program space PSPACE. */ + +static void +clear_cached_entry_point_info_for_pspace (program_space *pspace, + bool /* reload */) +{ + pspace->clear_cached_entry_point_info (); +} + /* See progspace.h. */ void initialize_progspace () { + gdb::observers::inferior_created.attach + (clear_cached_entry_point_info_for_inferior, "program-space"); + gdb::observers::inferior_exit.attach + (clear_cached_entry_point_info_for_inferior, "program-space"); + gdb::observers::executable_changed.attach + (clear_cached_entry_point_info_for_pspace, "program-space"); + add_cmd ("program-spaces", class_maintenance, maintenance_info_program_spaces_command, _("Info about currently known program spaces."), diff --git a/gdb/progspace.h b/gdb/progspace.h index d75379fe621..407d2595136 100644 --- a/gdb/progspace.h +++ b/gdb/progspace.h @@ -369,7 +369,11 @@ struct program_space /* Return information about the entry point in the main executable, and the entry point for the inferior, which might be different from the main executable. */ - entry_point_info get_entry_point_info () const; + const entry_point_info &get_entry_point_info () const; + + /* Clear any cached entry point information. */ + void clear_cached_entry_point_info () + { m_entry_point_info.reset (); } /* If there is a valid and known entry point in the main executable of this program space, return it. Otherwise return an empty optional. */ @@ -462,6 +466,9 @@ struct program_space /* See `exec_filename`. */ gdb::unique_xmalloc_ptr m_exec_filename; + + /* Cached entry point information. See get_entry_point_info. */ + mutable std::optional m_entry_point_info; }; /* The list of all program spaces. There's always at least one. */ -- 2.25.4