From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 1FInOcxXTmrcZiwAWB0awg (envelope-from ) for ; Wed, 08 Jul 2026 09:59:40 -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=chAdqbAW; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id D886E1E098; Wed, 08 Jul 2026 09:59:40 -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 C33A91E024 for ; Wed, 08 Jul 2026 09:59:39 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3CE8B4BA2E3E for ; Wed, 8 Jul 2026 13:59:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3CE8B4BA2E3E 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=chAdqbAW 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 5C8B84BA2E0D for ; Wed, 8 Jul 2026 13:59:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5C8B84BA2E0D 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 5C8B84BA2E0D 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=1783519147; cv=none; b=kGP6BnIQKBlf1LpW0w6OxiVMJ9YfaZNf9wjiH2eYsJ/XozwUE2sn6pT1sTtZF4UU7SQkDv5Yt77jfVDwtBhYVE+GK2L5LSbVrWMgGoMscq63aPw0LGdjOjfOi4fxUzVdUNnAeVzRQJvH5ZAScrmACIGaKXa+H5COlEaAezt596Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783519147; c=relaxed/simple; bh=kvPkUusyAVbJOnNKz2eakC9mpkFftu4y5Q4I1X1ShQw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=VzTgDvWCO35hWBLgktNtY7PDmg2eB7bADw/PKym54bjsodSgk7L3sM79WkATKXfyMO0Zjk0USTEMkIUf93wR8pM3VnSjGOzJpIPfuojbXQrGXUK1BnwWPMU5AbcQ6GIBQVWnpK3AKHNgNlmTbvTMJtvlF9EKSR58lDKV0S5oy2Y= 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=chAdqbAW DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5C8B84BA2E0D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783519147; 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: in-reply-to:in-reply-to:references:references; bh=urO4VDUUkC1xa2p1bg7Pny9NqLwaEHG4K+SktDgxxJU=; b=chAdqbAWeu2bJ3ClL34ngThZfXkEZ3dEr6gWrT8BBIUXEGxNgx9n3Cy9oImsLHL3as/MJj lklM+ZkqSZwLio7BO/oDKToe2oLiWt1hzWiN7H/B8GUj1afUyH76MYYpPiVAteYJJSCGiC UwsjFrvQI/5bEZOGNvXOJPaqERbygH8= 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-638-DnQbGJvcNUeQbJanVdssRg-1; Wed, 08 Jul 2026 09:59:06 -0400 X-MC-Unique: DnQbGJvcNUeQbJanVdssRg-1 X-Mimecast-MFC-AGG-ID: DnQbGJvcNUeQbJanVdssRg_1783519145 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-493b0a5e636so10518855e9.3 for ; Wed, 08 Jul 2026 06:59:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783519145; x=1784123945; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=urO4VDUUkC1xa2p1bg7Pny9NqLwaEHG4K+SktDgxxJU=; b=O4sy4DSbuup61On2dt8BoXFLwFMJvJf7KIgSi3SRSNmqVSVoEc06RhMRBM5AgXXuVT Y8PFKenwTkaTSXt6SJiClZCtt8Hraf43OrCoz9d40bBhcbZuto0FhRCkXkruOI3r/L/9 zMvRV9flLFt7kUzd2EpW8evT/oWvXGEwQhaUnsIFVddNjjoCGiZe5tFnSYQmtZOOOl5c 0roQTTTic5mrMatHIfHlbN8IaZLmC+niQ5DXLFd1NL2eDcWz95FbK50wkATXaUSTEgu7 rX8qLKsFYiEK6A9wQECbixZZPO1j61BksxP7P9b9atfdmScQlthbIDi2gj3+BgWj5Shh 0g1Q== X-Gm-Message-State: AOJu0YyKPvEI/L4Zoy6jt1C43A3Mby04jakY/4+NEd5xsRgMpcMT1d7t aJ90CCEmMWDKlxebxEdLCPkouZgL/WMc3CLaAMZ3PoDvJORwXasjVXG2AAN+JPxFqc5e/V86A9O qSXCHUHmM/517zU0VJ68H8sVeCJS+BDqXQuBJBj98seUsc2xcCXg///plZiWffGuMVeIGHnA= X-Gm-Gg: AfdE7ck7DpBUhbsgQqUvzS9rPUMHarNMIdHKHPVQUbGs6gVFvl+82B5/i9+5nFoffGt WO0JkD/KeLMvHen8eSV46bYLD79dDnVfmwcPfy0+8s9Rjih2nbkC0Yx/P40YEvCF/JJuhT/iUdJ MboUREU7LGIxlKOS/3JuD1+/lKauIz3RUcNCHGB9FzdFaADgtkTB4s+PXy+4OdF9vSi3l2XJxey 6r4z3XIkEKgYkQ79eWKuB5wIOsI7IABistjRpQB2m4DnTSsoOnh/Co0S4Bqp8LjkgmrplsNr9Xz oHYvybaYeK4c/lWahYI3vmOgF/G0f7uCidOEgMF9jXevOQUe4IZT0vC8qlXA0R+KahZmqmIdTob sCsq5I7E= X-Received: by 2002:a05:600c:8284:b0:493:e504:cbef with SMTP id 5b1f17b1804b1-493e68508f0mr30281265e9.0.1783519144379; Wed, 08 Jul 2026 06:59:04 -0700 (PDT) X-Received: by 2002:a05:600c:8284:b0:493:e504:cbef with SMTP id 5b1f17b1804b1-493e68508f0mr30280925e9.0.1783519143903; Wed, 08 Jul 2026 06:59:03 -0700 (PDT) Received: from localhost ([31.111.209.233]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493e0f50418sm127732735e9.11.2026.07.08.06.59.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2026 06:59:03 -0700 (PDT) From: Andrew Burgess To: "Rohr, Stephan" Cc: "gdb-patches@sourceware.org" , Tom Tromey Subject: RE: [PATCH 1/1] gdb: set the cache information in 'get_prev_frame_maybe_check_cycle' In-Reply-To: References: <20260625145850.3104079-1-stephan.rohr@intel.com> <20260625145850.3104079-2-stephan.rohr@intel.com> <87se69wdbt.fsf@tromey.com> <87zf04tawh.fsf@redhat.com> <87ldbmu6py.fsf@redhat.com> Date: Wed, 08 Jul 2026 14:59:01 +0100 Message-ID: <87h5m9fuqi.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Rlw0KrnURMxc8vOWm56taU2lwDPP4GSc8H7uafvGoWw_1783519145 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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 "Rohr, Stephan" writes: > HI Andrew, > > Thanks for sharing. The patch itself looks good. > > I have a few comments regarding the commit message, see below. Thanks Stephan. Below is an updated patch with an improved commit message. I also tweaked some of the comments in the actual code as, upon re-reading, I found some of them not ideal. Let me know what you think. Thanks, Andrew --- commit cec35caa5c173de5e98a9ac6cbc0b8ee8e15d912 Author: Andrew Burgess Date: Thu Jun 25 14:58:50 2026 +0000 gdb: set frame_info_ptr::m_cached_id during invalidation Currently frame_info_ptr caches the frame_id at construction time, see frame_info_ptr::frame_info_ptr in frame.c. The problem with this is that a frame's frame-id might not be known at this point. Consider get_prev_frame_maybe_check_cycle, this calls get_prev_frame_raw to create the previous frame, placing the result into a frame_info_ptr PREV_FRAME. Then (for frames other than frame 0) compute_frame_id is called, however, this only computes the frame_id for the frame_info object pointed to by the frame_info_ptr, the cached frame_id within the frame_info_ptr itself is not updated. What this means is that in get_prev_frame_maybe_check_cycle, the PREV_FRAME local has no cached frame-id. If we consider the call stack: get_selected_frame lookup_selected_frame frame_find_by_id get_prev_frame get_prev_frame_always get_prev_frame_always_1 get_prev_frame_maybe_check_cycle Then what we see is that the frame_info_ptr created in get_prev_frame_maybe_check_cycle, which lacks a cached frame_id, can be passed all the way back to lookup_selected_frame, where it will be stored in the SELECTED_FRAME global by a call to select_frame. The outer get_selected_frame call (in the above backtrace) will then return the SELECTED_FRAME global, which lacks a cached frame-id. If GDB ever tries to reinflate the SELECTED_FRAME frame_info_ptr (or a copy of it), then we will trigger the assert: `gdb_assert (frame_id_p (m_cached_id));` which can be found in `frame_info_ptr::reinflate` in frame.c. An example of how this can be triggered is included in the updated test case: - The 'up' command sets the selected frame to a frame with level > 0. - An inferior call invalidates the selected frame. - The selected frame is rebuilt following the call-stack above. The wrapping frame_info_ptr object doesn't cache the frame-id. - The 'frame' command invokes another inferior call for the pretty printer, which flushes the frame cache. - The frame_info_ptr is reinflated, e.g., to print the next argument, and this hits the assertion mentioned above. The problem is that frames don't always know their frame-id when they are placed into a frame_info_ptr, but they always do (for frames other than #0) after get_prev_frame_maybe_check_cycle has finished. This commit defers caching the frame-id in the frame_info_ptr until the frame cache is being flushed, at which point the frame-id is known. Co-Authored-By: Rohr, Stephan diff --git a/gdb/frame.c b/gdb/frame.c index cefdde5ed1e..a0a982dc866 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -2190,15 +2190,18 @@ reinit_frame_cache (void) sentinel_frame = nullptr; } + /* Invalidation copies the frame-id from the managed frame_info object + into the frame_info_ptr, so this must run before the frame_info + objects are freed (via obstack_free). */ + for (frame_info_ptr &iter : frame_info_ptr::frame_list) + iter.invalidate (); + frame_stash_invalidate (); /* Since we can't really be sure what the first object allocated was. */ obstack_free (&frame_cache_obstack, 0); obstack_init (&frame_cache_obstack); - for (frame_info_ptr &iter : frame_info_ptr::frame_list) - iter.invalidate (); - frame_debug_printf ("generation=%d", frame_cache_generation); } @@ -3436,9 +3439,24 @@ frame_info_ptr::frame_info_ptr (struct frame_info *ptr) return; m_cached_level = ptr->level; +} +void +frame_info_ptr::invalidate () +{ + if (m_ptr == nullptr) + return; + + gdb_assert (m_cached_level == m_ptr->level); + + /* If a frame_info_ptr is invalidated multiple times (with a reinflate + call between) then we will end up updating m_cached_id multiple times. + This should be harmless as the underlying frame_id should never + change. */ if (m_cached_level != 0 || m_ptr->this_id.value.user_created_p) m_cached_id = m_ptr->this_id.value; + + m_ptr = nullptr; } /* See frame-info-ptr.h. */ diff --git a/gdb/frame.h b/gdb/frame.h index f6553fb7b6d..b386303d895 100644 --- a/gdb/frame.h +++ b/gdb/frame.h @@ -327,10 +327,7 @@ class frame_info_ptr : public intrusive_list_node } /* Invalidate this pointer. */ - void invalidate () - { - m_ptr = nullptr; - } + void invalidate (); private: /* We sometimes need to construct frame_info_ptr objects around the diff --git a/gdb/testsuite/gdb.python/pretty-print-call-by-hand.exp b/gdb/testsuite/gdb.python/pretty-print-call-by-hand.exp index 52162fc9952..a2a29c4d0f8 100644 --- a/gdb/testsuite/gdb.python/pretty-print-call-by-hand.exp +++ b/gdb/testsuite/gdb.python/pretty-print-call-by-hand.exp @@ -108,6 +108,8 @@ with_test_prefix "frame movement down" { with_test_prefix "frame movement up" { if { [start_test "TAG: final frame"] == 0 } { gdb_test "up" [multi_line "#1 .*in g \\(mt=mytype is .*\\, depth=1\\).*" ".*first frame.*"] + gdb_test "p f ()" " = 2" + gdb_test "frame" [multi_line "#1 .*in g \\(mt=mytype is .*\\, depth=1\\).*" ".*first frame.*"] } }