From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id D13523858D28; Wed, 25 Jan 2023 12:27:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D13523858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674649626; bh=qjoS5t6rbkkWa5Ee59cWYqv5FI4T5xOcAxzFtnp6gW8=; h=From:To:Subject:Date:From; b=Qzj+Q9mrj/378Wi2RxtduazzCvlGATDgkqSwxeX73wq1Mzd0fX7iau7SGVSs9pNio VlxWCNkW9G7DVSvAuVQbxEKNd/9BSRlV2HdipU56ebP548cLoR2mOjyy2YOEJpNWPU V0I8KGNX3lG58LHYlyVPhG0lDj9qIzavqvTPfv0U= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb/testsuite] Improve leaf fn in gdb.base/unwind-on-each-insn.exp X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: 2e10cefd83b6a5b0b3745da1134d35a4924db6c5 X-Git-Newrev: 5f6ec13ffe8ae4db04419bf66868e082df73634d Message-Id: <20230125122706.D13523858D28@sourceware.org> Date: Wed, 25 Jan 2023 12:27:06 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D5f6ec13ffe8a= e4db04419bf66868e082df73634d commit 5f6ec13ffe8ae4db04419bf66868e082df73634d Author: Tom de Vries Date: Wed Jan 25 13:27:03 2023 +0100 [gdb/testsuite] Improve leaf fn in gdb.base/unwind-on-each-insn.exp =20 In test-case gdb.base/unwind-on-each-insn.exp, we stepi through functio= n foo to check various invariants at each insn, in particular hoping to excer= cise insns that modify stack and frame pointers. =20 For x86_64-linux, we have a reasonably complex foo (and similar for -m3= 2): ... 4004bc: 55 push %rbp 4004bd: 48 89 e5 mov %rsp,%rbp 4004c0: 90 nop 4004c1: 5d pop %rbp 4004c2: c3 ret ... Both stack pointer (%rsp) and frame pointer (%rbp) are modified. =20 Also for s390x-linux (and similar for -m31): ... 0000000001000668 : 1000668: e3 b0 f0 58 00 24 stg %r11,88(%r15) 100066e: b9 04 00 bf lgr %r11,%r15 1000672: e3 b0 b0 58 00 04 lg %r11,88(%r11) 1000678: 07 fe br %r14 ... Frame pointer (%r11) is modified. =20 Likewise for powerpc64le-linux: ... 00000000100006c8 : 100006c8: f8 ff e1 fb std r31,-8(r1) 100006cc: d1 ff 21 f8 stdu r1,-48(r1) 100006d0: 78 0b 3f 7c mr r31,r1 100006d4: 00 00 00 60 nop 100006d8: 30 00 3f 38 addi r1,r31,48 100006dc: f8 ff e1 eb ld r31,-8(r1) 100006e0: 20 00 80 4e blr ... Both stack pointer (r1) and frame pointer (r31) are modified. =20 But for aarch64-linux, we have: ... 00000000004005fc : 4005fc: d503201f nop 400600: d65f03c0 ret ... There's no insn that modifies stack or frame pointer. =20 Fix this by making foo more complex, adding an (unused) argument: ... 0000000000400604 : 400604: d10043ff sub sp, sp, #0x10 400608: f90007e0 str x0, [sp, #8] 40060c: d503201f nop 400610: 910043ff add sp, sp, #0x10 400614: d65f03c0 ret ... such that the stack pointer (sp) is modified. =20 [ Note btw that we're seeing the effects of -momit-leaf-frame-pointer, = with -mno-omit-leaf-frame-pointer we have instead: ... 0000000000400604 : 400604: a9be7bfd stp x29, x30, [sp, #-32]! 400608: 910003fd mov x29, sp 40060c: f9000fa0 str x0, [x29, #24] 400610: d503201f nop 400614: a8c27bfd ldp x29, x30, [sp], #32 400618: d65f03c0 ret ... such that also the frame pointer (x29) is modified. ] =20 Having made foo more complex, we now run into the following fail on x86_64/-m32: ... FAIL: gdb.base/unwind-on-each-insn.exp: instruction 1: $sp_value =3D=3D= $main_sp .... =20 The problem is that the stack pointer has changed inbetween the samplin= g of main_sp and *foo, in particular by the push insn: ... 804841a: 68 c0 84 04 08 push $0x80484c0 804841f: e8 10 00 00 00 call 8048434 ... =20 Fix this by updating main_sp. =20 On powerpc64le-linux, with gcc 7.5.0 I now run into PR tdep/30021: ... FAIL: gdb.base/unwind-on-each-insn.exp: insn 7: $fba_value =3D=3D $main= _fba FAIL: gdb.base/unwind-on-each-insn.exp: insn 7: [string equal $fid $mai= n_fid] ... but I saw the same failure before this commit with gcc 4.8.5. =20 Tested on: - x86_64-linux (-m64 and -m32) - s390x-linux (-m64 and -m31) - powerpc64le-linux - aarch64-linux =20 Also I've checked that the test-case still functions as regression test= for PR record/16678 on x86_64. Diff: --- gdb/testsuite/gdb.base/unwind-on-each-insn-foo.c | 2 +- gdb/testsuite/gdb.base/unwind-on-each-insn.c | 4 ++-- gdb/testsuite/gdb.base/unwind-on-each-insn.exp | 7 ++++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/gdb/testsuite/gdb.base/unwind-on-each-insn-foo.c b/gdb/testsui= te/gdb.base/unwind-on-each-insn-foo.c index af9fc11ddab..635aa44135e 100644 --- a/gdb/testsuite/gdb.base/unwind-on-each-insn-foo.c +++ b/gdb/testsuite/gdb.base/unwind-on-each-insn-foo.c @@ -16,7 +16,7 @@ along with this program. If not, see . = */ =20 void -foo () +foo (const char *s) { /* Nothing. */ } diff --git a/gdb/testsuite/gdb.base/unwind-on-each-insn.c b/gdb/testsuite/g= db.base/unwind-on-each-insn.c index 60bc83a6d4f..821df375115 100644 --- a/gdb/testsuite/gdb.base/unwind-on-each-insn.c +++ b/gdb/testsuite/gdb.base/unwind-on-each-insn.c @@ -15,11 +15,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . = */ =20 -extern void foo (); +extern void foo (const char *); =20 int main () { - foo (); + foo ("foo"); return 0; } diff --git a/gdb/testsuite/gdb.base/unwind-on-each-insn.exp b/gdb/testsuite= /gdb.base/unwind-on-each-insn.exp index fc48bf5c061..6e68b24af9c 100644 --- a/gdb/testsuite/gdb.base/unwind-on-each-insn.exp +++ b/gdb/testsuite/gdb.base/unwind-on-each-insn.exp @@ -113,7 +113,12 @@ for { set i_count 1 } { true } { incr i_count } { # Check we can unwind the stack-pointer and the frame base # address correctly. lassign [get_sp_and_fba "for main"] sp_value fba_value - gdb_assert { $sp_value =3D=3D $main_sp } + if { $i_count =3D=3D 1 } { + # The stack-pointer may have changed while running to *foo. + set main_sp $sp_value + } else { + gdb_assert { $sp_value =3D=3D $main_sp } + } gdb_assert { $fba_value =3D=3D $main_fba } =20 # Check we have a consistent value for main's frame-id.