From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id sMGcHbDR5GrbpRgAWB0awg (envelope-from ) for ; Fri, 30 Oct 2026 13:19:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1793380784; bh=43yhBhIG+mc04v0p5fuMUb16KhD/Gpl8Xfz3nOJgzM8=; h=Date:Subject:To:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=PAEUUXyjpdb+Px5Gz4vVEIQLHrB8v0DLkNyvKDcSp/vOPZxvO+h5r5YEyFKnn6WBY kKGvemvXdDLHGDYdVahIgS9OrnHspyXnvINdOlZL7subriye8YX24k7O740ie2UDor SOnUrqM/47h/FgDWmBWq2Rubeik0lvPu3jtQ8MPQ= Received: by simark.ca (Postfix, from userid 112) id 5E4C5378002; Fri, 30 Oct 2026 13:19:44 -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_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=gXjrUr/5; dkim-atps=neutral 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 8CEDF378002 for ; Fri, 30 Oct 2026 13:19:43 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 196804BAE7D2 for ; Fri, 30 Oct 2026 17:19:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 196804BAE7D2 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=gXjrUr/5 Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id E1BED4BA799C for ; Fri, 30 Oct 2026 17:19:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E1BED4BA799C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E1BED4BA799C Authentication-Results: sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793380758; cv=none; b=etFsUFyzeOHOVNYULwP8rCJVGDctZDVlabf1F091dh72ZscDOm4dQK3WZrUJKe/b6AZjajDsb3sC+MercIOxtgu+E2cQv7W/tfXosKj4qfaRblFbfXr52UlyKD0PCyRZIHirq+T75ZRCWQErYw7WfwOeCIlLfcOcENX7/DHvK+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793380758; c=relaxed/simple; bh=43yhBhIG+mc04v0p5fuMUb16KhD/Gpl8Xfz3nOJgzM8=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=j152ar/kHRXKp8OdC/ASBU5cjlqNgGUNnfZqdElzurXGC20GwiTn1lAoEZo/uzrAFPtx7YomSYJSTcs4Pq9DRrz2muHFCEmuUMVWUPxkqegSnByEu9l2Zk/C3UI1pcQP5W3aS4eaI7hlkYZT+dOwjtp/W0GD3Q94Gf/ty0taI1Q= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=gXjrUr/5 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E1BED4BA799C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1793380756; bh=43yhBhIG+mc04v0p5fuMUb16KhD/Gpl8Xfz3nOJgzM8=; h=Date:Subject:To:References:From:In-Reply-To:From; b=gXjrUr/5ButhjExLhnJtl0iY4OSZBg8Edu21HY5kj7o3QF/TvtIrRZkDUVqaXRrBy 8a6GTl+nJLrOunmDnzq5oSUfQOobXc+dLNwkrnSDjkGCqIbS6MghgDqb7J006wmiUr hBg4QB5YzFdBYlb6K3Ajof8CxihqwDDcp1rWwbtA= Received: by simark.ca (Postfix) id 4504C378002; Fri, 30 Oct 2026 13:19:16 -0400 (EDT) Message-ID: Date: Fri, 30 Oct 2026 13:19:15 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCHv10 5/5] gdb: cache program space entry point information To: Andrew Burgess , gdb-patches@sourceware.org References: <2c9ddc321a22311a9848f5482a0f27881aa74e7f.1793268860.git.aburgess@redhat.com> Content-Language: fr From: Simon Marchi In-Reply-To: <2c9ddc321a22311a9848f5482a0f27881aa74e7f.1793268860.git.aburgess@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 10/29/26 6:20 AM, Andrew Burgess wrote: > After the previous two patches, there are now two places where we > check if a frame is an entry point frame, these are in get_prev_frame > and frame_unwind_caller_frame. Both of these locations call > inside_entry_func, which then calls program_space::get_entry_point_info. Slightly outdated now that there is get_prev_frame_with_entry_frame_check, but the idea remains the same. > 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. > > However, the result from 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, whenever the > executable is updated, or whenever the inferior execs. 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 | 45 ++++++++++++++++++++++++++++++++++++++++++--- > gdb/progspace.h | 11 ++++++++++- > 2 files changed, 52 insertions(+), 4 deletions(-) > > diff --git a/gdb/progspace.c b/gdb/progspace.c > index 3347eb7dacc..b7282b6fd64 100644 > --- a/gdb/progspace.c > +++ b/gdb/progspace.c > @@ -371,9 +371,12 @@ program_space::exec_entry_point_address () const > > /* See progspace.h. */ > > -entry_point_info > +const entry_point_info & > program_space::get_entry_point_info () const > { > + if (m_entry_point_info.has_value ()) > + return m_entry_point_info.value (); We typically use: return *m_entry_point_info; > + > std::optional exec_entry_address > = this->exec_entry_point_address_if_available (); > > @@ -389,8 +392,9 @@ program_space::get_entry_point_info () const > break; > } > > - 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 (); Likewise. Also, same unnecessary std::moves comment as before. > } > > /* Implement the 'maint info entry-address' command. */ > @@ -628,11 +632,46 @@ 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 (); > +} > + > +/* Clear cached entry point information in the program space of EXEC_INF. */ > + > +static void > +clear_cached_entry_point_info_after_exec (inferior *exec_inf, > + inferior */* follow_inf */) > +{ > + exec_inf->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"); > + gdb::observers::inferior_execd.attach > + (clear_cached_entry_point_info_after_exec, "program-space"); A corner case spotted by Claude: if you use the symbol-file command to load a new main obfile, or get rid of the existing symbols, it potentially affects the answer of "what is the executable entry point", but none of the above observers is fired (executable_changed is only called when the "exec-file" changes). This could be fixed by listening to the new_objfile and free_objfile observers, clearing the cache is we see the objfile with OBJF_MAINLINE go by. Otherwise, LGTM. Approved-By: Simon Marchi Simon