binutils-gdb/gdb/python
Andrew Burgess 6383eda55a gdb/python: remove frame_object::frame_id_is_next as unnecessary
Remove the frame_object::frame_id_is_next field.  This has been part
of how Python handles frames since this code was first added in commit
f8f6f20b6e back in 2009.  The motivation
for this field can be found in a couple of comments, there's this one
on frame_id_is_next:

  /* Marks that the FRAME_ID member actually holds the ID of the frame next
     to this, and not this frames' ID itself.  This is a hack to permit Python
     frame objects which represent invalid frames (i.e., the last frame_info
     in a corrupt stack).  The problem arises from the fact that this code
     relies on FRAME_ID to uniquely identify a frame, which is not always true
     for the last "frame" in a corrupt stack (it can have a null ID, or the same
     ID as the  previous frame).  Whenever get_prev_frame returns NULL, we
     record the frame_id of the next frame and set FRAME_ID_IS_NEXT to 1.  */

And this one in frame_info_to_frame_object:

  /* Try to get the previous frame, to determine if this is the last frame
    in a corrupt stack.  If so, we need to store the frame_id of the next
    frame and not of this one (which is possibly invalid).  */

This field is dealing with a problem that was present in older
versions of GDB where not every stack frame had a valid frame-id, if
the stack was corrupted in some way then the last frame might have an
invalid frame-id.  However, that is no longer the case.  With current
GDB there is a promise that every frame has a valid frame-id.  I don't
have a single commit to point to where this became the reality, but it
is my understanding of current GDB.

As an example, the frame-id of every frame (except #0) is computed as
the frame is created, any frames with a  duplicate frame-id, or any
errors during computation of the frame-id, and the new frame is
discarded.

Additionally, our frame_info_ptr::reinflate mechanism relies on unique
and valid frame-ids.

The problem with the existing code is that the last frame in a
corrupted stack will hold the frame-id of the next frame, that is, the
more inner frame.  This means we have two frames holding the same
frame-id, and the only difference is the frame_id_is_next flag.

However, the frapy_str function, which prints a string representation
of the frame, doesn't take frame_id_is_next into account, so printing
the last two frames in a corrupted stack, will print the same
frame-id.

We could fix this in frapy_str and also frapy_repr by checking the
frame_id_is_next flag and then fetching the previous frame-id, but
this would still assume that the previous frame has a valid-id, so we
might as well just drop the frame_id_is_next flag and make everything
simpler.

There's a new test which exposes the incorrectly printed frame-id
problem.

While testing I needed to "fix" the results for two existing tests.

In frame_info_to_frame_object, in order to figure out if we should use
the next frame, we called get_prev_frame.  This would cause GDB to
always unwind 1 extra level of the stack.

What this means is that, if there is an error, or some diagnostic
output, when unwinding frame #1, then this will show up when trying to
access frame #0 via the Python API as frame_info_to_frame_object on
frame #0 would call get_prev_frame, which would then unwind frame #1.

After this commit this is no longer the case.  We only see
output (either errors, or diagnostic output) associated with frame #1
when we actually try to unwind to frame #1.  The two tests that needed
updating were expecting output associated with frame #1 while printing
frame #0.  This is now fixed and the output for frame #1 occurs later
on.  I think this is an improvement.
2026-07-08 10:39:39 +01:00
..
lib/gdb Update use of deque in _frame_iterator 2026-06-22 16:15:08 -06:00
py-all-events.def gdb/python: new events.corefile_changed event 2026-04-20 22:15:26 +01:00
py-arch.c gdb/python: fix memory leak in gdb_py_tp_name 2026-06-04 15:09:54 +01:00
py-auto-load.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-block.c gdb/python: fix memory leak in gdb_py_tp_name 2026-06-04 15:09:54 +01:00
py-bpevent.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-breakpoint.c [gdb/build] Fix Wnon-pod-varargs in bppy_repr 2026-06-05 23:03:42 +02:00
py-cmd.c gdb/python: add type traits check for all PyObject sub-classes 2026-05-16 12:44:37 +01:00
py-color.c gdb/python: add type traits check for all PyObject sub-classes 2026-05-16 12:44:37 +01:00
py-color.h Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-connection.c gdb/python: fix memory leak in gdb_py_tp_name 2026-06-04 15:09:54 +01:00
py-continueevent.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-corefile.c gdb/python: fix memory leak in gdb_py_tp_name 2026-06-04 15:09:54 +01:00
py-dap.c Rewrite output redirection and logging 2026-02-09 08:15:44 -07:00
py-disasm.c gdb/python: fix memory leak in gdb_py_tp_name 2026-06-04 15:09:54 +01:00
py-event-types.def gdb/python: new events.corefile_changed event 2026-04-20 22:15:26 +01:00
py-event.c gdb/python: add accessor helpers for __dict__ in Python extension objects 2026-03-14 13:21:06 +00:00
py-event.h gdb: new setters and getters for __dict__, and attributes 2026-01-29 16:46:14 +00:00
py-events.h gdb/python: add type traits check for all PyObject sub-classes 2026-05-16 12:44:37 +01:00
py-evtregistry.c [gdb/python] Remove Py_RETURN_{NONE,TRUE,FALSE,NOTIMPLEMENTED} 2026-05-15 21:38:12 +02:00
py-evts.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-exitedevent.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-finishbreakpoint.c [gdb/python] Use py_{none,notimplemented} more often 2026-05-15 21:38:12 +02:00
py-frame.c gdb/python: remove frame_object::frame_id_is_next as unnecessary 2026-07-08 10:39:39 +01:00
py-framefilter.c [gdb/python] Remove Py_RETURN_{NONE,TRUE,FALSE,NOTIMPLEMENTED} 2026-05-15 21:38:12 +02:00
py-function.c gdb: switch tuple object helpers to Python limited API equivalents 2026-03-04 15:38:11 +00:00
py-gdb-readline.c Python limited API: migrate Py_CompileStringExFlags and PyRun_SimpleString 2026-01-28 09:41:25 +00:00
py-inferior.c [gdb/python] Use py_{none,false} more often 2026-05-15 21:38:12 +02:00
py-infevents.c Return gdbpy_ref<> from frame_info_to_frame_object 2026-02-23 05:29:12 -07:00
py-infthread.c gdb/python: fix memory leak in gdb_py_tp_name 2026-06-04 15:09:54 +01:00
py-instruction.c gdb/python: add type traits check for all PyObject sub-classes 2026-05-16 12:44:37 +01:00
py-instruction.h Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-lazy-string.c gdb/python: add type traits check for all PyObject sub-classes 2026-05-16 12:44:37 +01:00
py-linetable.c gdb: make symtab::compunit return a reference 2026-06-19 10:04:11 -04:00
py-membuf.c gdb/python: add type traits check for all PyObject sub-classes 2026-05-16 12:44:37 +01:00
py-mi.c gdb/python: fix memory leak in gdb_py_tp_name 2026-06-04 15:09:54 +01:00
py-micmd.c gdb/python: fix memory leak in gdb_py_tp_name 2026-06-04 15:09:54 +01:00
py-newobjfileevent.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-obj-type.c gdb_py_tp_name: remove redundant PyErr_Clear 2026-06-09 10:58:21 +01:00
py-obj-type.h gdb/python: fix memory leak in gdb_py_tp_name 2026-06-04 15:09:54 +01:00
py-objfile.c [gdb/python] Remove Py_RETURN_{NONE,TRUE,FALSE,NOTIMPLEMENTED} 2026-05-15 21:38:12 +02:00
py-param.c Remove ARI 2026-06-26 09:17:29 -06:00
py-prettyprint.c gdb/python: add type traits check for all PyObject sub-classes 2026-05-16 12:44:37 +01:00
py-progspace.c [gdb/python] Remove Py_RETURN_{NONE,TRUE,FALSE,NOTIMPLEMENTED} 2026-05-15 21:38:12 +02:00
py-record-btrace.c gdb/python: add type traits check for all PyObject sub-classes 2026-05-16 12:44:37 +01:00
py-record-btrace.h Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-record-full.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-record-full.h Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-record.c gdb/python: add type traits check for all PyObject sub-classes 2026-05-16 12:44:37 +01:00
py-record.h gdb/python: add type traits check for all PyObject sub-classes 2026-05-16 12:44:37 +01:00
py-ref.h gdb/python: add type traits check for all PyObject sub-classes 2026-05-16 12:44:37 +01:00
py-registers.c [gdb] Use using instead of typedef 2026-06-11 08:54:34 +02:00
py-signalevent.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-stopevent.c Return gdbpy_ref<> from value_to_value_object 2026-02-23 05:29:11 -07:00
py-stopevent.h Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-style.c gdb/python: fix memory leak in gdb_py_tp_name 2026-06-04 15:09:54 +01:00
py-symbol.c gdb/python: fix memory leak in gdb_py_tp_name 2026-06-04 15:09:54 +01:00
py-symtab.c gdb: make symtab::compunit return a reference 2026-06-19 10:04:11 -04:00
py-threadevent.c [gdb/python] Use py_{none,false} more often 2026-05-15 21:38:12 +02:00
py-tui.c gdb/python: add type traits check for all PyObject sub-classes 2026-05-16 12:44:37 +01:00
py-type.c gdb/python: fix memory leak in gdb_py_tp_name 2026-06-04 15:09:54 +01:00
py-uiout.h Remove m_applied_style from ui_file 2026-02-09 08:15:29 -07:00
py-unwind.c gdb/python: fix memory leak in gdb_py_tp_name 2026-06-04 15:09:54 +01:00
py-utils.c gdb/python: fix memory leak in gdb_py_tp_name 2026-06-04 15:09:54 +01:00
py-value.c gdb/python: add type traits check for all PyObject sub-classes 2026-05-16 12:44:37 +01:00
py-varobj.c Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00
py-xmethods.c [gdb/python] Remove Py_RETURN_{NONE,TRUE,FALSE,NOTIMPLEMENTED} 2026-05-15 21:38:12 +02:00
python-config.py
python-internal.h [gdb] Use using instead of typedef 2026-06-11 08:54:34 +02:00
python-limited-api-missing.h [gdb] Use using instead of typedef 2026-06-11 08:54:34 +02:00
python-traits.h gdb/python: add type traits check for all PyObject sub-classes 2026-05-16 12:44:37 +01:00
python.c gdb/python: fix memory leak in gdb_py_tp_name 2026-06-04 15:09:54 +01:00
python.h Update copyright dates to include 2026 2026-01-05 13:16:46 -07:00