From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id GXU2BetvjGr6yDwAWB0awg (envelope-from ) for ; Mon, 24 Aug 2026 12:23:07 -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=A3/aMBzo; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 0E9101E167; Mon, 24 Aug 2026 12:23:07 -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 036001E09E for ; Mon, 24 Aug 2026 12:23:05 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C25434BAE7FA for ; Mon, 24 Aug 2026 16:23:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C25434BAE7FA 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=A3/aMBzo Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id C535A4BAE7E3 for ; Mon, 24 Aug 2026 16:22:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C535A4BAE7E3 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 C535A4BAE7E3 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1787588553; cv=none; b=mojJz30eVEPXDr3GxKnwn/R/cuQKbT2TTVGeuTqms0vEDSEP9Ngn1eDHJnTW7yt4lFMrcFkmJZbz2qaDbWl9kVkf2ws3vxWWZ8IBKReyOWSPyJz2dXWUNqFx3kMN04WMBbJBYd7VPh6d0xL+crCdcfk6tLgY4cYSYlCqmLpM9zw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1787588553; c=relaxed/simple; bh=8sSeWQKo8RmETcUILaKT+yD5NJbUXd1s7/pcUjMs+FY=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=i/io+HGwFRaUWYMnSLhU84JBv0YrDGBdnWq2kLr0EgGxM+4v7F3dX5Y0wNQ21KT8ew+lgQv7ajL43Fnjed8SboAWFEGdbU5tiyTbyNLhpmMs/pCq9aMKa+gmMwonVRGCW8kwjxrkRag6XsT+xxfS9aGK6cvbCOE13KoopqKF13A= 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=A3/aMBzo DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C535A4BAE7E3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787588553; 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=039hyNkpQeohu1q4h77el7Fz3otd+5WRaUwulj4Lo1U=; b=A3/aMBzoH23Gd7lNyui44xi8Ok+OGbAj/0pZ8jUno/BEeKJxJYhfx0WNnJPGohI/Xu1sBR 15lvcYsnGfM5AqEd8YGBROouIhZUpRsByfSC/JVB5ljU+kKfuhjMxxn0qwFxHwBfKeH0p+ xFzmV6Zo1bFWtB7IUlPOSKAJULl/oNY= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-325-zrEXBgvKNQ2lAPBuN5-yWA-1; Mon, 24 Aug 2026 12:22:32 -0400 X-MC-Unique: zrEXBgvKNQ2lAPBuN5-yWA-1 X-Mimecast-MFC-AGG-ID: zrEXBgvKNQ2lAPBuN5-yWA_1787588551 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-482a5e9400eso2532988f8f.2 for ; Mon, 24 Aug 2026 09:22:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787588551; x=1788193351; 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:content-type; bh=039hyNkpQeohu1q4h77el7Fz3otd+5WRaUwulj4Lo1U=; b=c+dpQjyPPjcCfQd8RB4rt8aEXovoB+UdwnFQ7OWOoY3mvVu6uNzLP7801hQ+3xDT4d UIV0iWoFnTflUs0gotrJaUrNzg/vdLDR9aMKeL3nfDveOpRqnM7jKdwVnCRUscwqQTBw HPmePEJC/SxNCd/AUDxTBp2Y/l1jhE5mReGaZC5XWaVK+VBqL7v5sNmko59CYIhmu4wC ss2pOlzoRRtRNBulRu5OMmxztU60nzagke8ArNO9BDNq3M8VXWH2YfwPredLAQM1Qz30 7jahwVGtBOBcuBfRmsjLLEXBmX7PJD8KQUBT4m2JjOGGJ/weGV5TKRNz/fd5/LVbRgX+ B2QA== X-Gm-Message-State: AFuF++lynEQ6eH1zuO1U87sdrct0sRNxLw03u4OL3YnjvsOKJhITEqJ5 8e09yigtDqyoG2RO7p3sBMnsSP3VRrr2MUVE6asFdZCUeBwatB990Why3E38PxjKpibdJ1wzCP8 e5jJmCIla8BCvxn2h2IhHBn3qY4Ndc+ntvalfdiIaQiNd8GmaiaS7xaJzsAvK51hug/WJgFd1mX LZZ7395yVxJVEM1jnZiPYi6XeDgeWjkmoY6Rq13B8CO0uOyNs= X-Gm-Gg: AR+sD10ib0pD936nRhODRtWkVjgod6eln5Na+LIRjFUlbV/uWSQfQnPZ8ZNlRsmcXCn HapKAkpE8W32VaCe5HMlAvxiOu9ahc/ADAukdq8op6XQUI19WDwGNRsBl3Cy6EhRpsIaKvDMaxl z/q0mFSUa2ov7uM0Q8JumtpAw2o8ecfN/3/rHLBMF8c8D1lQ/EKhuYsm4CbAtcnO9BdIiqzpN8i bOnwEqyUw5aWj5KOY7wcWss6BCbdoTKJc2zKLoW3KfiSuKi8u5ml+HwSA++cm5m19spxx4Ji8mf 8fhvE55DtbP445OoE7TjBUHY9/IaaqiBcOWvG1HEBXOHOWuo9k3crO7EKYJ7AsrqFoVqNZTnDQX nSmHTnXjoJgVogv0ZP+i61QJDNZ8= X-Received: by 2002:a05:6000:25fe:b0:47f:86af:8fe7 with SMTP id ffacd0b85a97d-482c0ba220fmr40350379f8f.22.1787588551089; Mon, 24 Aug 2026 09:22:31 -0700 (PDT) X-Received: by 2002:a05:6000:25fe:b0:47f:86af:8fe7 with SMTP id ffacd0b85a97d-482c0ba220fmr40350217f8f.22.1787588550537; Mon, 24 Aug 2026 09:22:30 -0700 (PDT) Received: from localhost (128.223.159.143.dyn.plus.net. [143.159.223.128]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-482c9b78ebfsm8748469f8f.12.2026.08.24.09.22.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2026 09:22:28 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Simon Marchi , Andrew Burgess Subject: [PATCHv9 4/4] gdb: cache program space entry point information Date: Mon, 24 Aug 2026 17:22:19 +0100 Message-Id: <72b4024c8e485f7786dcb7c29aa2e6c6397d12aa.1787588386.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: l0pLASTVy0bBz__3BJZm6dEw-j-c1WEHioup0B_qsJw_1787588551 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, 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. 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 2e0b6e4b825..b219acdf380 100644 --- a/gdb/progspace.c +++ b/gdb/progspace.c @@ -289,9 +289,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 (); + 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,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"); + 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 69e70a1de6a..12bf116eb99 100644 --- a/gdb/progspace.h +++ b/gdb/progspace.h @@ -370,7 +370,13 @@ 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. */ @@ -463,6 +469,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