From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 4fVXJzvwXWqP6RkAWB0awg (envelope-from ) for ; Mon, 20 Jul 2026 05:54:03 -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=gx4SGw//; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 95B8C1E099; Mon, 20 Jul 2026 05:54:03 -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 B61151E099 for ; Mon, 20 Jul 2026 05:54:01 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B0CA34BA9005 for ; Mon, 20 Jul 2026 09:53:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B0CA34BA9005 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=gx4SGw// 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 3A7294BA79BC for ; Mon, 20 Jul 2026 09:52:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3A7294BA79BC 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 3A7294BA79BC 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=1784541153; cv=none; b=Z64jnjbGG5/Fx17yWwBMsBE+84o4Fps+m2hOtmD1xRGWZ9Etwdf3hjJh3Z+xEZoK3ykAJRA2a3zNSjzsdS08uqM1c3QZ6bWtv0/YHVF7evxy06srp4/kFrPTlvBsOVl+F8E1nTMguk3jK2YP8TzFH9B2cBZj+dOOyOUfoDIoDzw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784541153; c=relaxed/simple; bh=E559PCXMHBvlkL2Hj5g9BTLjCmjUj7a1vXOjaaEw3Bc=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=XRzYioqbqtQPZez2rg5Ixj+K6Y3p1NTuXcM5qpFTMnvmgzPOdUMEz0uZB2qzi6qYSxdWHqkYgvt43PUrNcRNefvwjahfOeYY9HuFaDvfVUBoIksTey1nJlR8+o2uT3R3S8PgE+GZZEDC7mmWCVCOrl6v76YMP3xIRvZn/tT03xo= 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=gx4SGw// DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3A7294BA79BC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784541152; 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=E6bGTTuM2DB6Z5Hdq9hN7uMgujM/n3iJsYtWHHY3YEM=; b=gx4SGw//NtW5sFU+1suKBoqz4ieRGRp5Kpav7SmNgvfK/3MZZxAh85fPK2N7/GfpqIPlm4 e58k0KQ81mSxHczFEOEkE4g+/J/L4U8D3/lCFpQPAkzkhe5/KFTZoz/WU/rMjx+DYizOLN O34VwXXcEG2r8zTZCAg+5sKZQtJhI6s= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-539-rgzKLGdNOJu44rr5CIfzFg-1; Mon, 20 Jul 2026 05:52:31 -0400 X-MC-Unique: rgzKLGdNOJu44rr5CIfzFg-1 X-Mimecast-MFC-AGG-ID: rgzKLGdNOJu44rr5CIfzFg_1784541151 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4955fd77c18so3507455e9.2 for ; Mon, 20 Jul 2026 02:52:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784541150; x=1785145950; 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=E6bGTTuM2DB6Z5Hdq9hN7uMgujM/n3iJsYtWHHY3YEM=; b=NFc3yQME2MapWnfO0/ak/WWS3pGHGkQ+HSHoWqbfYcR6TiPwXx00Lqk32DUvOWOgX4 xC9JSGSsMUOrvMMlKiN5jWkOodd//m+XC9A4mfYyPxqGmk1mopOZ5WMJmGI6bbQ5s+6p cgCQWFBs9eNPCNvgKm4qT51+NkkS1vilq2Cz9PI/D9STk1t+DeAj1glBnHtz7jcTzciM 0+caTxSoQCaRHQia7sXDMXvZ37beaAkbZc2KDlfv1wzqLr0+/VJ/4yRtOY+5MrpTjHQC 66Al5COIVLhRtkV6WXjw17wmKrVrV/7uWCzY3uk+E49i4fFH4pXZMP14HHalsit18XR4 9w2g== X-Gm-Message-State: AOJu0YwkazpAfircaoqTUxavQ3eSeP3QECB4pAq/vp7Z/XTdfQapZDr+ bc5Qxk62x4dJrxCvUSQOfrEt8Leb1RJLp2BHzeekRfPiofeqcjHYebCUIXjj933u3e0isMCod7G pPNt/DHKgU5CUH478uFtKbPcugOMBgCnTdJzt5w/tHtr5ZIv0oqL1XYnnxwHFMdAp6+wCmpadtx q+KaE+b56ldTiwlNHUQgZfEQBPq8+lkmmCw7xeNH+Nu/q/3Zw= X-Gm-Gg: AfdE7ckeM2RHYCVp8WDgRJkCZb6VyDxJmZxY8QyyYLbFQlze6bxMZSvvePHNsRayM3i V9JUmNN19/OJhhhPRVRgb3pBGpcq/rW1b0ExepfLmnWs0bGb6x1wV3n4V7ji81xDJbDNilFT4FM C6/g7C2QZJgC9FUlPR7HpOwtwO+kAQ3aq3ZtgT1Vv+yT1Yii3whpYI0m/61s47wRTK3xTaDKXJ4 Xb9k4PvfMb/ItBnFnrz1dosZ7X+KGwfRk56/902siGwXO9ujRq3Sde9m5nMvTGQci86ZaItDHFj iJuHAaGmiDXFSQcbcYzc6eX1EPvMVHSHHhKSNhuRoFLXMCXScnKAWJOmKqaZQr0o7x2MOpWi X-Received: by 2002:a05:600c:3589:b0:495:641a:fffe with SMTP id 5b1f17b1804b1-495641b01acmr1169445e9.39.1784541150493; Mon, 20 Jul 2026 02:52:30 -0700 (PDT) X-Received: by 2002:a05:600c:3589:b0:495:641a:fffe with SMTP id 5b1f17b1804b1-495641b01acmr1168985e9.39.1784541149939; Mon, 20 Jul 2026 02:52:29 -0700 (PDT) Received: from localhost ([31.111.209.233]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-495499d1d4asm175426015e9.2.2026.07.20.02.52.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2026 02:52:29 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv8 4/4] gdb: cache program space entry point information Date: Mon, 20 Jul 2026 10:52:20 +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: ktp2Dhlwvax2awfleoa1jUU92EhKM9gyWXw7tOYN-V0_1784541151 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, 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 | 45 ++++++++++++++++++++++++++++++++++++++++++--- gdb/progspace.h | 9 ++++++++- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/gdb/progspace.c b/gdb/progspace.c index 4de32bc522f..b1e313f97ff 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 be2d3f7e88c..bfe0e5ec36f 100644 --- a/gdb/progspace.h +++ b/gdb/progspace.h @@ -370,7 +370,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. */ @@ -463,6 +467,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