[gdb/testsuite] test a function call by hand from pretty printer
authorBruno Larsen <blarsen@redhat.com>
Tue, 22 Feb 2022 14:44:44 +0000 (11:44 -0300)
committerBruno Larsen <blarsen@redhat.com>
Mon, 21 Mar 2022 12:08:55 +0000 (09:08 -0300)
commitdaaf7acf47a12d10459060dca5500b63273cd683
tree2588c3b660987ba49b11cc62674594ab73b0a81b
parent9170b70c41064a0ba197dc7e2d6ecb940d2272bb
[gdb/testsuite] test a function call by hand from pretty printer

The test case added here is testing the bug gdb/28856, where calling a
function by hand from a pretty printer makes GDB crash. There are 6
mechanisms to trigger this crash in the current test, using the commands
backtrace, up, down, finish, step and continue. Since the failure happens
because of use-after-free (more details below) the tests will always
have a chance of passing through sheer luck, but anecdotally they seem
to fail all of the time.

The reason GDB is crashing is a use-after-free problem. The above
mentioned functions save a pointer to the current frame's information,
then calls the pretty printer, and uses the saved pointer for different
reasons, depending on the function. The issue happens because
call_function_by_hand needs to reset the obstack to get the current
frame, invalidating the saved pointer.
gdb/testsuite/gdb.python/pretty-print-call-by-hand.c [new file with mode: 0644]
gdb/testsuite/gdb.python/pretty-print-call-by-hand.exp [new file with mode: 0644]
gdb/testsuite/gdb.python/pretty-print-call-by-hand.py [new file with mode: 0644]