From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1983) id ED60E3858D3C; Thu, 1 Dec 2022 19:42:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED60E3858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669923735; bh=b2gSDRf9yvujzEx9Pf/nonR2HsdXh+JiFX1ihESL3P8=; h=From:To:Subject:Date:From; b=nZJtQRD2l2BpNhQYh9g32BvCga8eeQ20fnFV0f0Ej3lmDEZE+koAP7WIb3eRRZzqK qWX2gHWGvTEsyXMV/BwdtHUXvAnvJUbwdr6yM3U3ayAgQ2mtvGZ+TXokUy4EgC7JIF 6ryR4TnUKoaEF0iAgMagBYvlmT2uowaqQSNU5nlI= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Carl Love To: gdb-cvs@sourceware.org Subject: [binutils-gdb] PowerPC, fix gdb.reverse/finish-reverse-bkpt.exp and gdb.reverse/next-reverse-bkpt-over-sr.exp X-Act-Checkin: binutils-gdb X-Git-Author: Carl Love X-Git-Refname: refs/heads/master X-Git-Oldrev: 4cb80f0e5bddc29cf50b08f0a4d2cca8ea330a23 X-Git-Newrev: c367d9e0cbfda0e32b7074c2719dfaee42c4cfb6 Message-Id: <20221201194215.ED60E3858D3C@sourceware.org> Date: Thu, 1 Dec 2022 19:42:15 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dc367d9e0cbfd= a0e32b7074c2719dfaee42c4cfb6 commit c367d9e0cbfda0e32b7074c2719dfaee42c4cfb6 Author: Carl Love Date: Thu Dec 1 14:39:45 2022 -0500 PowerPC, fix gdb.reverse/finish-reverse-bkpt.exp and gdb.reverse/next-r= everse-bkpt-over-sr.exp =20 The tests set a break point with the command break *func. This sets a breakpoint on the first instruction of the function. PowerPC uses Global Entry Points (GEP) and Local Entry Points (LEP). The first instruction in the function is the GEP. The GEP sets up register r2 before reaching the LEP. When the function is called with func() the function is entered via the LEP and the test fails because GDB does not see the breakpoint on the GEP. However, if the function is called via a function pointer, execution begins at the GEP as the test expects. =20 Currently finish-reverse-bkpt.exp uses source file finish-reverse.c and next-reverse-bpkt-over-sr.exp uses source file step-reverse.c A new source file was created for tests finish-reverse-bkpt.exp and next-reverse-bkpt-over-sr.exp. The new files use the new function pointer method to call the functions so the tests will work correctly on both PowerPC with a GEP and LEP as well as on other systems. The GEP is the same as the LEP on non PowerPC systems. =20 The expect files were changed to use the new source files and to set the initial break point for the rest of the test on the function pointer ca= ll for the function. =20 This patch fixes two PowerPC test failures in each of the tests gdb.reverse/finish-reverse-bkpt.exp and gdb.reverse/next-reverse-bkpt-over-sr.exp. =20 Patch tested on PowerPC and Intel X86-64 with no regressions. =20 Reviewed-By: Bruno Larsen Diff: --- gdb/testsuite/gdb.reverse/finish-reverse-bkpt.c | 39 ++++++++++++++++++= ++ gdb/testsuite/gdb.reverse/finish-reverse-bkpt.exp | 24 +++++++++++- .../gdb.reverse/next-reverse-bkpt-over-sr.c | 43 ++++++++++++++++++= ++++ .../gdb.reverse/next-reverse-bkpt-over-sr.exp | 31 +++++++++++++--- 4 files changed, 130 insertions(+), 7 deletions(-) diff --git a/gdb/testsuite/gdb.reverse/finish-reverse-bkpt.c b/gdb/testsuit= e/gdb.reverse/finish-reverse-bkpt.c new file mode 100644 index 00000000000..7a954179234 --- /dev/null +++ b/gdb/testsuite/gdb.reverse/finish-reverse-bkpt.c @@ -0,0 +1,39 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2008-2022 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . = */ + +/* Test gdb's "return" command in reverse. The code for this test is based + on the code in test finish-reverse.c. The code was modified to call the + function via a function pointer so the test will behave the same on all + platforms. See comments in finish-reverse-bkpt.exp. */ + +int void_test =3D 0; + +void +void_func () +{ + void_test =3D 1; /* VOID FUNC */ +} + +int +main (int argc, char **argv) +{ + int i; + void (*funp) (void) =3D void_func; + + funp (); + return 0; +} diff --git a/gdb/testsuite/gdb.reverse/finish-reverse-bkpt.exp b/gdb/testsu= ite/gdb.reverse/finish-reverse-bkpt.exp index 5bfe14788c6..3d98178a4c3 100644 --- a/gdb/testsuite/gdb.reverse/finish-reverse-bkpt.exp +++ b/gdb/testsuite/gdb.reverse/finish-reverse-bkpt.exp @@ -19,11 +19,32 @@ # the functions entry would be ignored. Make sure the bug doesn't # reappear. =20 +# The test sets a breakpoint with the command break *void_func to set a +# breakpoint on the first instruction of the function. The issue is on +# PowerPC it uses Global Entry Points (GEP) and Local Entry Points (LEP). +# The GEP is the first instruction in the function. It sets up register +# r2 and then reaches the LEP. +# +# : +# lis r2,4098 <- GEP +# addi r2,r2,32512 +# mflr r0 <- LEP +# std r0,16(r1) +# .... + +# +# The command break *void_func sets the breakpoint on the GEP. Calling +# the function with void_func() will enter the function via the LEP. So, +# this test needs to use a function pointer to call void_func() so the +# function will be entered via the GEP to work as designed on PowerPC in +# addition to non-PowerPC systems. On non-PowerPC systems, the GEP and LEP +# are the same. + if ![supports_reverse] { return } =20 -standard_testfile finish-reverse.c +standard_testfile =20 if { [prepare_for_testing "failed to prepare" "$testfile" $srcfile] } { return -1 @@ -38,6 +59,7 @@ if [supports_process_record] { gdb_test_no_output "record" "turn on process record" } =20 +# Start the test. set breakloc [gdb_get_line_number "VOID FUNC" "$srcfile"] gdb_test "tbreak void_func" \ "Temporary breakpoint $decimal at .*$srcfile, line $breakloc\." \ diff --git a/gdb/testsuite/gdb.reverse/next-reverse-bkpt-over-sr.c b/gdb/te= stsuite/gdb.reverse/next-reverse-bkpt-over-sr.c new file mode 100644 index 00000000000..6d0ed521fc3 --- /dev/null +++ b/gdb/testsuite/gdb.reverse/next-reverse-bkpt-over-sr.c @@ -0,0 +1,43 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2008-2022 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . = */ + +#include +#include + +/* Test reverse finish command. The code for this test is based on the co= de + in test step-reverse.c. The code was modified to call the function via + a function pointer so the test will behave the same on all platforms. + See comments in next-reverse-bkpt-over-sr.exp. */ + +int myglob =3D 0; + +int +callee() { + return myglob++; +} + +int +main () { + int (*funp) (void) =3D callee; + + /* Test next-reverse-bkpt-over-sr.exp needs to call function callee usi= ng + a function pointer to work correctly on PowerPC. See comments in + next-reverse-bkpt-over-sr.exp. */ + funp (); /* FUNCTION PTR CALL TO CALLEE */ + + exit (0); /* END OF MAIN */ +} diff --git a/gdb/testsuite/gdb.reverse/next-reverse-bkpt-over-sr.exp b/gdb/= testsuite/gdb.reverse/next-reverse-bkpt-over-sr.exp index 71d915d20a9..b8364e237b4 100644 --- a/gdb/testsuite/gdb.reverse/next-reverse-bkpt-over-sr.exp +++ b/gdb/testsuite/gdb.reverse/next-reverse-bkpt-over-sr.exp @@ -14,20 +14,37 @@ # along with this program. If not, see . */ =20 # This file is part of the GDB testsuite. It tests reverse stepping. -# Lots of code borrowed from "step-test.exp". - # # reverse-next over a function call sets a step-resume breakpoint at # callee's entry point, runs to it, and then does an extra single-step # to get at the callee's caller. Test that a user breakpoint set at # the same location as the step-resume breakpoint isn't ignored. # +# The test sets a breakpoint with the command break *callee to set a +# breakpoint on the first instruction of the function. The issue is on +# PowerPC it uses Global Entry Points (GEP) and Local Entry Points (LEP). +# The GEP is the first instruction in the function. It sets up register +# r2 and then reaches the LEP. +# +# : +# lis r2,4098 <- GEP +# addi r2,r2,32512 +# mflr r0 <- LEP +# std r0,16(r1) + +# +# The command break *callee sets the breakpoint on the GEP. Calling +# the function with callee() will enter the function via the LEP. So, +# this test needs to use a function pointer to call callee() so the +# function will be entered via the GEP to work as designed on PowerPC in +# addition to non-PowerPC systems. On non-PowerPC systems, the GEP and LEP +# are the same. =20 if ![supports_reverse] { return } =20 -standard_testfile step-reverse.c +standard_testfile =20 if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } { return -1 @@ -42,8 +59,10 @@ if [supports_process_record] { gdb_test_no_output "record" "turn on process record" } =20 -set lineno [gdb_get_line_number "STEP INTO THIS CALL"] -gdb_test "advance $lineno" ".*STEP INTO THIS CALL.*" "get past callee call" +# Stop after the function pointer call to test the reverse-next command. +set lineno [gdb_get_line_number "END OF MAIN"] +gdb_test "advance $lineno" ".*END OF MAIN.*" \ + "get past callee call" =20 gdb_test "b \*callee" "" "set breakpoint at callee's entry" =20 @@ -53,5 +72,5 @@ gdb_test "reverse-next" \ "reverse-next over call trips user breakpoint at function entry" =20 gdb_test "up" \ - ".*NEXT OVER THIS CALL.*" \ + ".*FUNCTION PTR CALL TO CALLEE.*" \ "stopped at the right callee call"