From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 8d9ZF7B7W2qsJhEAWB0awg (envelope-from ) for ; Sat, 18 Jul 2026 09:12:16 -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=Lxg4YEdB; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 554C21E09E; Sat, 18 Jul 2026 09:12:16 -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 [IPv6:2620:52:6:3111::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 5A25D1E099 for ; Sat, 18 Jul 2026 09:12:15 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1A0804BA2E1E for ; Sat, 18 Jul 2026 13:12:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1A0804BA2E1E 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=Lxg4YEdB 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 334BE4BA2E2F for ; Sat, 18 Jul 2026 13:11:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 334BE4BA2E2F 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 334BE4BA2E2F 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=1784380308; cv=none; b=sF7ZQwr75yEOzFPPKXNNtwwLOZTTGRj2EB0wP0aIhMUfL3yEv1QSLU2tE4pF9SqWqRMG6qmqsXqP1DmJDsLDGt51zEyTYMThKFus8jOvNEr9lJj+60ns6KfchSNG+b64Efp1GxBKq+0Kaha0xVWb7IWoUS7qhuJ3GrxOMVozBwc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784380308; c=relaxed/simple; bh=E559PCXMHBvlkL2Hj5g9BTLjCmjUj7a1vXOjaaEw3Bc=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Hoz771fM9cQ1jeteuTHc7jXFA7vclIJcwjuU8AaizNp+LjRV8QjhtgHnINO4dLLIc9dZB+jbr/LnZnONzYLD0UkyLEv3F2cJQCZE6pjxwZF6rKcII2LscjvE2a9Fu7ZtuNDbW38vn857NEM4npI/g8iBDGqSsj+vjdPqq9gL3yg= 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=Lxg4YEdB DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 334BE4BA2E2F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784380307; 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=Lxg4YEdBBNTcEDAV+XLgMZEDidSqn1mZjlN89SewaQHLJ+VF33rzaRslG4uiN7Gw7dabyC Y7pmWWGzv/uMmuuXll4u8zNeDeqzfxchPPhoA37wcubtNS6fzkfBBzdZfWkcJ9AK1KvRHi Uai7BPPegCtV4i/129FRhjViOh1Y1ss= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-587-DZANm9jtN9OXRzqkc_QD1g-1; Sat, 18 Jul 2026 09:11:46 -0400 X-MC-Unique: DZANm9jtN9OXRzqkc_QD1g-1 X-Mimecast-MFC-AGG-ID: DZANm9jtN9OXRzqkc_QD1g_1784380305 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-490a767b782so36654075e9.2 for ; Sat, 18 Jul 2026 06:11:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784380305; x=1784985105; 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=URFQdmAsZPkhdvxJtFVGDVijkS7i5D8q+3lf9AIhiGnLBPzrGWUCzZuF2O9BB7l/6U /pBBVB7D/fqH2RzJL1rvHXMVPgsFsiUrZ8+o+4vQNzwxlfdUmQqja3dUGBsvWAK1T5qg kq4Vjq/x5ohIeriYGxhhFAP8UYeMqQMhD59e46GTVVqF52H1dup/eKaLL/w4zo3ptc4h 03GUeggLKo1uhZDFzJ+N1PvNOZtzJGNaZ/BxD5Jjpt1VjvbiUtoXJneaF1RvfKxyEcrn ZICoZIF8cJoeQamKOZ91rM5T9Zcay1HKUt5faQW3O8fVWQtzByJdg1+ZqrH494W1f5xe cpZQ== X-Gm-Message-State: AOJu0Yym4etgLmhDoz5BKMdwl6bmcnEGdzsUOlMG7s0OafhqRMCIKdbX 4Sgg9CJGm4zNbQ+lRNRIKNsMojPscDsu4XjOl9xD7HggIM+Lp3kVbFqKkAxp051uPxejHOU7Ezt YXf7uq469EPQqnUOfI+JVWq69DQoNx8AKdgA4RVK7QaIaxMpnCfOwb8mRaUhuRoQQUY2n9Z7f/z 4U3b1keXT1DVDRHL4PaenZOZMyUsibLj9+zc22rIAA7habVV8= X-Gm-Gg: AfdE7clxFFA0I5LYW+eMJW1nYW8sgvB+Bb3nZMG7rR7K4PpLf01OxCEHjQH2VhlEGHO G/BiD4Cej/GuGZRCA/STRNoTNj3d+JApgdrDdwCt06zGZF8muwexsWarCof6+4r/xB68wOkGgkr hpYuMFESazY+vu04R2AdRw3brMoww50r+slTNXnFtlhwY8kvIgttN8hq8Xx/viME63yWsoWwQqW V6Ab1irT7FjxL27X2WxXMpnPdLcDOtZjPsKslbF6EsSFdSzjqa8j4uQ3OFOljb48JJvoNp5x5P7 cG4mna8gx3Wfs7Kp9uNSSQoNIr7zve4Jxao3ageFUsGvGUmMdH44ZYXpAt/k8jKenERY4gMPvQ= = X-Received: by 2002:a05:600c:63d4:b0:493:d21f:8f98 with SMTP id 5b1f17b1804b1-4954a4136bcmr53325895e9.36.1784380305260; Sat, 18 Jul 2026 06:11:45 -0700 (PDT) X-Received: by 2002:a05:600c:63d4:b0:493:d21f:8f98 with SMTP id 5b1f17b1804b1-4954a4136bcmr53325655e9.36.1784380304750; Sat, 18 Jul 2026 06:11:44 -0700 (PDT) Received: from localhost ([109.144.221.116]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4954a2a2504sm135712445e9.2.2026.07.18.06.11.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jul 2026 06:11:44 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv7 4/4] gdb: cache program space entry point information Date: Sat, 18 Jul 2026 14:11:27 +0100 Message-Id: <4e928877bd985e4aa30f06092c43759c9b763217.1784380038.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: lpr7HZRbmrsXcNgBvWZGamSTSAESWuaw564BTkzE5AI_1784380305 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