From: Stephan Rohr <stephan.rohr@intel.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/1] gdb: set the cache information in 'get_prev_frame_maybe_check_cycle'
Date: Thu, 25 Jun 2026 14:58:50 +0000 [thread overview]
Message-ID: <20260625145850.3104079-2-stephan.rohr@intel.com> (raw)
In-Reply-To: <20260625145850.3104079-1-stephan.rohr@intel.com>
From: "Rohr, Stephan" <stephan.rohr@intel.com>
'get_prev_frame_maybe_check_cycle' retrieves the previous frame and
computes the frame id. At this point, the frame id is not cached yet,
which prevents the frame from being reinflated once the frane cache is
flushed. Explicitly update the cache information before returning
'prev_frame' so the frame can be reinflated properly.
The 'up' command invokes the following sequence.
1. Build the 'prev_frame' and eventually calls
'get_prev_frame_maybe_check_cycle'. The frame_id is only computed
for the raw frame pointer, the wrapping 'frame_info_ptr' it not
updated.
2. Printing the frame calls 'do_print_frame_info'.
3. If a pretty-printer runs an inferior call, the frame cache is
flushed.
4. This triggers the assertion when reinflating the frame_info_ptr.
Extend the 'gdb.python/pretty-print-call-by-hand.exp' testcase to cover
this use-case.
---
gdb/frame.c | 18 +++++++++++++++++-
gdb/frame.h | 4 ++++
.../gdb.python/pretty-print-call-by-hand.exp | 2 ++
3 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/gdb/frame.c b/gdb/frame.c
index 4137e1d5edd..1d4e231ea81 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -2332,6 +2332,12 @@ get_prev_frame_maybe_check_cycle (const frame_info_ptr &this_frame)
throw;
}
+ /* No cycle and the frame is added to the frame stash, update the cache
+ information to ensure the frame can be reinflated after the cache is
+ flushed. */
+ if (prev_frame)
+ prev_frame.update_cache ();
+
return prev_frame;
}
@@ -3431,7 +3437,17 @@ frame_info_ptr::frame_info_ptr (struct frame_info *ptr)
if (m_ptr == nullptr)
return;
- m_cached_level = ptr->level;
+ update_cache ();
+}
+
+/* See frame-info-ptr.h. */
+
+void
+frame_info_ptr::update_cache ()
+{
+ gdb_assert (m_ptr != nullptr);
+
+ m_cached_level = m_ptr->level;
if (m_cached_level != 0 || m_ptr->this_id.value.user_created_p)
m_cached_id = m_ptr->this_id.value;
diff --git a/gdb/frame.h b/gdb/frame.h
index f6553fb7b6d..897518371b2 100644
--- a/gdb/frame.h
+++ b/gdb/frame.h
@@ -332,6 +332,10 @@ class frame_info_ptr : public intrusive_list_node<frame_info_ptr>
m_ptr = nullptr;
}
+ /* Update the cached copies of frame_id and the frame level based on the
+ underlying pointer. */
+ void update_cache ();
+
private:
/* We sometimes need to construct frame_info_ptr objects around the
sentinel_frame, which has level -1. Therefore, make the invalid frame
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.*"]
}
}
--
2.43.0
Intel Deutschland GmbH
Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany
Tel: +49 89 991 430, www.intel.de
Managing Directors: Harry Demas, Jeffrey Schneiderman, Yin Chong Sorrell
Chairperson of the Supervisory Board: Nicole Lau
Registered Seat: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
next prev parent reply other threads:[~2026-06-25 15:01 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-25 14:58 [PATCH 0/1] " Stephan Rohr
2026-06-25 14:58 ` Stephan Rohr [this message]
2026-06-26 15:06 ` [PATCH 1/1] " Tom Tromey
2026-06-29 14:04 ` Rohr, Stephan
2026-07-06 15:06 ` Andrew Burgess
2026-07-07 7:57 ` Rohr, Stephan
2026-07-07 16:04 ` Andrew Burgess
2026-07-08 8:46 ` Rohr, Stephan
2026-07-08 13:59 ` Andrew Burgess
2026-07-08 15:18 ` Rohr, Stephan
2026-07-14 15:14 ` Andrew Burgess
2026-07-15 7:33 ` Rohr, Stephan
2026-07-18 11:57 ` Andrew Burgess
2026-07-20 17:39 ` Tom Tromey
2026-07-07 10:33 ` Andrew Burgess
2026-07-07 12:25 ` Rohr, Stephan
2026-07-07 15:04 ` Andrew Burgess
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260625145850.3104079-2-stephan.rohr@intel.com \
--to=stephan.rohr@intel.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox