From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id cfzVJpOoMWrBzAoAWB0awg (envelope-from ) for ; Tue, 16 Jun 2026 15:48:35 -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=DP7SNZlR; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 9A2AA1E098; Tue, 16 Jun 2026 15:48:35 -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 ECDD71E070 for ; Tue, 16 Jun 2026 15:48:34 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 900E248A0801 for ; Tue, 16 Jun 2026 19:48:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 900E248A0801 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=DP7SNZlR 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 8C2C648A081E for ; Tue, 16 Jun 2026 19:47:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8C2C648A081E 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 8C2C648A081E 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=1781639253; cv=none; b=TJoM86u2fO8sLRhsk0s/Vkdmt33bKf7ls0HGCm0vR1SmE5xh8ie/vQ33+z75hq5dJkSxqUyOsDgducJRY+hIVhzjikZ0ysOlFWjNB2qyAu/+ThQOCfeo3oHu+g9clirPKHcRv6UC4MDnV7Rh5U49q8AH6jHid6kHFUhxXKluIAg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1781639253; c=relaxed/simple; bh=7KbwyrzId5VYBv2EdA1WQEdeHSCSPxyDjvLAJ3BSFBc=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Wy3lIP82lwK6FudmkGV//PgB9xDumROCi8XCFyPBfKD0NCW5w3IPOBs2j4g9H5xKlSAO/k7rzn+UQBzs+YlNtzOEnm7OYiRrQIqCYExLPHO1RFQEW/oFYoppz/mHUsBZLMbXSeoOPSnnTCofGb1XZ0D+h8Q2n2OZSQi/A56cDxY= 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=DP7SNZlR DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8C2C648A081E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1781639253; 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=DP7SNZlRB0F5FpMzMR4d/s+W27nuoot11NG3NtFdorunvqzgKNRNJC/VGA2wByFJ0a1Ihq GzpHfZCWkiq9zpfUiBl9OMMLDIFLI/BE2rs1GZ9n44/O4CUd2stNUai7xtp5TkIX/7wDIH hSmZhYK49b7PmhGS6L7Tyi3raM8nPXo= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-680-G1Z9QccGOdONYTEinbiu0g-1; Tue, 16 Jun 2026 15:47:32 -0400 X-MC-Unique: G1Z9QccGOdONYTEinbiu0g-1 X-Mimecast-MFC-AGG-ID: G1Z9QccGOdONYTEinbiu0g_1781639251 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-490ab3f6e55so28812875e9.0 for ; Tue, 16 Jun 2026 12:47:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781639251; x=1782244051; 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=ClYNWMpr1GTl8o1FEVfdihmnhsV+zDIEKT/6TPQv1E2HmTu7jiVm4GGeixBHVd+csi 7xf+fKcCgkKCvkU+ZchKh1GAV9fZCCW4e8VSfAfjF4mLnbDKV01PUydS4pQZQ0gCmffC QpsoZNi62QqTXBxkdWnjSMjrAOFJk2d4Ni3Ysd2nvX2gzUfTfqgBkr5LsdTpzOecqvIm JoNv/UJcW5qxuRgAIYcrUaIqiPrfbR95stULaD+xR5wT2P5iBYOHYrISeDCLqPakqMTd iUD0TDNZYXpvMtSbdH8h0cDTpwnxXKP8wp/verrxXkVjzWz8ZR1LvnDN+apPTGCitknT ARzg== X-Gm-Message-State: AOJu0Yy7OUmEVhYu9QUKZDES8N2ZWktVjbuD/UPP0KA9+DnoCrn5yyqf Yop/QlsMHPv6f5fefT3tybWuxc/Q6yBXWCp+x7/FT8SaxGO9TClxbSWbwvpi/6lJBXz9vT0g6gg hchNnsF3tFDzafNvbFZCG6992Sbnifm7+9f4qm/iE2313kTmi81YeXiZDmzK0sjp8ELR+oPRgxu m2GRKhdh4p4jkzbS10orX3pdk0PL9X7OptT8QP5AQR2d0IcPg= X-Gm-Gg: Acq92OFYqKCgM7gW0g4mXq3rpMb6keWT16f8ZqOcJNvwYr8DiKpISVZJdCfPw9OI8x2 W9TtqyO8PjRSiiS3XUoQrc8JssLmwPxS7P+gZ9zTrX9BWq+kapkWmX8j40CEUMiHDC3VhLJByf8 lFmxOViwkxEe9Im9Oh4pl1l/IXVybXuNxsliUDsT34mASDOBlx8H4GVQA3raw0Ppj52vfPPx9ff xVXUi4sAOcz/+LqZK8wEfOOO70B6fYBFB4+lTaRpkHI00MKQZvZoON/WyKeQ0jUqcOWrdycj8eg qmcw8ItNhmWyYAmmZkx43qBUeOvufj6PCmTSZfYd1h49FaXWcL/8cRiEVlZr9zGyEqFbDpvvz7T JYdtSF1+kejcakI5alAqQ5UyZ5A17U0JRVGWLUcbDIK0= X-Received: by 2002:a05:600c:a30c:b0:488:b187:3c with SMTP id 5b1f17b1804b1-492333bf7bamr13944645e9.14.1781639251000; Tue, 16 Jun 2026 12:47:31 -0700 (PDT) X-Received: by 2002:a05:600c:a30c:b0:488:b187:3c with SMTP id 5b1f17b1804b1-492333bf7bamr13944255e9.14.1781639250456; Tue, 16 Jun 2026 12:47:30 -0700 (PDT) Received: from localhost (92.40.184.41.threembb.co.uk. [92.40.184.41]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4922fa47da9sm124851455e9.5.2026.06.16.12.47.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jun 2026 12:47:30 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Guinevere Larsen , Pedro Alves , Andrew Burgess Subject: [PATCHv3 4/4] gdb: cache program space entry point information Date: Tue, 16 Jun 2026 20:47:17 +0100 Message-Id: <597e613711f25828ecea28da0bc05f7ffaef794e.1781638570.git.aburgess@redhat.com> 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: fD67B2-BVxewBjP0XujH47e13zRsZN3ZXzHieK6wCeY_1781639251 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