gdb: make user-created frames reinflatable
authorSimon Marchi <simon.marchi@polymtl.ca>
Wed, 14 Dec 2022 03:34:39 +0000 (22:34 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Fri, 20 Jan 2023 19:48:57 +0000 (14:48 -0500)
commit836a8d3710462596bb4184617999a9507adc3629
treeda76674260e0c55130bfe6931918cfd6a6b8e643
parentbc2cbe815bdbac3bd027bf4acc94c554c29b0189
gdb: make user-created frames reinflatable

This patch teaches frame_info_ptr to reinflate user-created frames
(frames created through create_new_frame, with the "select-frame view"
command).

Before this patch, frame_info_ptr doesn't support reinflating
user-created frames, because it currently reinflates by getting the
current target frame (for frame 0) or frame_find_by_id (for other
frames).  To reinflate a user-created frame, we need to call
create_new_frame, to make it lookup an existing user-created frame, or
otherwise create one.

So, in prepare_reinflate, get the frame id even if the frame has level
0, if it is user-created.  In reinflate, if the saved frame id is user
create it, call create_new_frame.

In order to test this, I initially enhanced the gdb.base/frame-view.exp
test added by the previous patch by setting a pretty-printer for the
type of the function parameters, in which we do an inferior call.  This
causes print_frame_args to not reinflate its frame (which is a
user-created one) properly.  On one machine (my Arch Linux one), it
properly catches the bug, as the frame is not correctly restored after
printing the first parameter, so it messes up the second parameter:

    frame
    #0  baz (z1=hahaha, z2=<error reading variable: frame address is not available.>) at /home/simark/src/binutils-gdb/gdb/testsuite/gdb.base/frame-view.c:40
    40        return z1.m + z2.n;
    (gdb) FAIL: gdb.base/frame-view.exp: with_pretty_printer=true: frame
    frame
    #0  baz (z1=hahaha, z2=<error reading variable: frame address is not available.>) at /home/simark/src/binutils-gdb/gdb/testsuite/gdb.base/frame-view.c:40
    40        return z1.m + z2.n;
    (gdb) FAIL: gdb.base/frame-view.exp: with_pretty_printer=true: frame again

However, on another machine (my Ubuntu 22.04 one), it just passes fine,
without the appropriate fix.  I then thought about writing a selftest
for that, it's more reliable.  I left the gdb.base/frame-view.exp pretty
printer test there, it's already written, and we never know, it might
catch some unrelated issue some day.

Change-Id: I5849baf77991fc67a15bfce4b5e865a97265b386
Reviewed-By: Bruno Larsen <blarsen@redhat.com>
gdb/Makefile.in
gdb/frame.c
gdb/frame.h
gdb/testsuite/gdb.base/frame-view.c
gdb/testsuite/gdb.base/frame-view.exp
gdb/testsuite/gdb.base/frame-view.py [new file with mode: 0644]
gdb/unittests/frame_info_ptr-selftests.c [new file with mode: 0644]