From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id C86853858430; Thu, 10 Nov 2022 16:33:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C86853858430 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1668098035; bh=/tg2gP64e5NgqyIX6f2kUvgpV4OmFLHNg/bC0ov95Yw=; h=From:To:Subject:Date:From; b=gyaansjAHlyEB584GkyPG5SOkWp2BJJzYDji9sKDDS7ODkKqvprqsx5XQuYdePBBd EuZ6VGUVuZ7KSMSElxUp+l8szuQSKAUbuxvR9XmsgxnvRCnOx0U9FwMIkH8qlHn7r9 D4Fss9YEmVAp3+XgbdSGbgckj0/KGZ5YPh5yq0jY= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Simon Marchi To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: add prepare_reinflate/reinflate around print_frame_args in info_frame_command_core X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: 70f479c6f8bf976ca680fd53d655ccec56b3f12e X-Git-Newrev: 3dc9dde26d1c279e888d1fd0361f720e5a3721f3 Message-Id: <20221110163355.C86853858430@sourceware.org> Date: Thu, 10 Nov 2022 16:33:55 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D3dc9dde26d1c= 279e888d1fd0361f720e5a3721f3 commit 3dc9dde26d1c279e888d1fd0361f720e5a3721f3 Author: Simon Marchi Date: Mon Nov 7 09:55:23 2022 -0500 gdb: add prepare_reinflate/reinflate around print_frame_args in info_fr= ame_command_core =20 I noticed this crash: =20 $ ./gdb --data-directory=3Ddata-directory -nx -q \ testsuite/outputs/gdb.python/pretty-print-call-by-hand/pretty= -print-call-by-hand \ -x testsuite/outputs/gdb.python/pretty-print-call-by-hand/pre= tty-print-call-by-hand.py \ -ex "b g" -ex r (gdb) info frame Stack level 0, frame at 0x7fffffffdd80: rip =3D 0x555555555160 in g (/home/simark/src/binutils-gdb/gdb/testsuite/gdb.python/pretty-= print-call-by-hand.c:41); saved rip =3D 0x5555555551a3 called by frame at 0x7fffffffdda0 source language c. Arglist at 0x7fffffffdd70, args: mt=3Dmytype is 0x555555556004 "he= llo world", depth=3D10 =20 Fatal signal: Segmentation fault =20 This is another case of frame_info being invalidated under a function's feet. The stack trace when the frame_info get invalidated looks like: =20 ... many frames to pretty print the arg, that eventually invalidate= the frame_infos ... #35 0x00005568d0a8ab24 in print_frame_arg (fp_opts=3D..., arg=3D0x7= ffc3216bcb0) at /home/simark/src/binutils-gdb/gdb/stack.c:489 #36 0x00005568d0a8cc75 in print_frame_args (fp_opts=3D..., func=3D0= x621000233210, frame=3D..., num=3D-1, stream=3D0x60b000000300) at /home/simark/src/binutils-gdb/gdb/stack.c:898 #37 0x00005568d0a9536d in info_frame_command_core (fi=3D..., select= ed_frame_p=3Dtrue) at /home/simark/src/binutils-gdb/gdb/stack.c:1682 =20 print_frame_args knows that print_frame_arg can invalidate frame_info objects, and therefore calls prepare_reinflate/reinflate. However, info_frame_command_core has a separate frame_info_ptr instance (it is passed by value / copy). So info_frame_command_core needs to know that print_frame_args can invalidate frame_info objects, and therefore needs to prepare_reinflate/reinflate as well. Add those calls, and enhance the gdb.python/pretty-print-call-by-hand.exp test to test that command. =20 Reviewed-By: Bruno Larsen Change-Id: I9edaae06d62e97ffdb30938d364437737238a960 Diff: --- gdb/stack.c | 4 ++++ gdb/testsuite/gdb.python/pretty-print-call-by-hand.exp | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/gdb/stack.c b/gdb/stack.c index 653251c200b..4e2342c2a8d 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -1679,8 +1679,12 @@ info_frame_command_core (frame_info_ptr fi, bool sel= ected_frame_p) else gdb_printf (" %d args: ", numargs); } + + fi.prepare_reinflate (); print_frame_args (user_frame_print_options, func, fi, numargs, gdb_stdout); + fi.reinflate (); + gdb_puts ("\n"); } } diff --git a/gdb/testsuite/gdb.python/pretty-print-call-by-hand.exp b/gdb/t= estsuite/gdb.python/pretty-print-call-by-hand.exp index 0aeb2218f91..eb3fc9e35fa 100644 --- a/gdb/testsuite/gdb.python/pretty-print-call-by-hand.exp +++ b/gdb/testsuite/gdb.python/pretty-print-call-by-hand.exp @@ -98,6 +98,14 @@ with_test_prefix "frame print" { "backtrace test" } } + +# Test the "info frame" command +with_test_prefix "info frame" { + if { [start_test "TAG: first frame"] =3D=3D 0 } { + gdb_test "info frame" "mytype is $hex \"hello world\".*" + } +} + # Testing the down command. with_test_prefix "frame movement down" { if { [start_test "TAG: first frame"] =3D=3D 0 } {