public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Carl Love <cel@us.ibm.com>
To: Bruno Larsen <blarsen@redhat.com>,
	"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>,
	cel@us.ibm.com
Cc: Ulrich Weigand <Ulrich.Weigand@de.ibm.com>,
	Will Schmidt <will_schmidt@vnet.ibm.com>
Subject: RE: [PATCH] PowerPC, fix gdb.reverse/finish-reverse-bkpt.exp and gdb.reverse/next-reverse-bkpt-over-sr.exp
Date: Tue, 22 Nov 2022 08:53:19 -0800	[thread overview]
Message-ID: <ace89c525e06240c9bdc08377e1830d818a5988e.camel@us.ibm.com> (raw)
In-Reply-To: <c396f9fb-d9a7-66b9-a3df-09896fff7553@redhat.com>

GDB maintainers, Bruno:

On Tue, 2022-11-22 at 10:42 +0100, Bruno Larsen wrote:
> On 14/11/2022 22:05, Carl Love wrote:
> > Bruno, GDB maintainers:
> > 
> > 
<snip>
> > 
> > Patch tested on PowerPC and Intel X86-64 with no regressions.
> 
> Hi Carl,
> 
> This was a great approach to solve the problem, but the location of
> the 
> funcp() call in step-reverse.c is generating regressions on my
> machine.
> 
> Currently, GDB can't record memset calls in x86_64 (at least using 
> gcc-12.2.1), due to the instruction 0xc5.

OK, my x86_64 box has gcc version 11.3.0 which would explain why I
didn't see an issue.

> 
> Moving the funcp and callee calls above the block that contains
> memset 
> fixes the regression and should still fix the PowerPC issue.

I moved the calls up as described.  So, the latest version should now
work on your system.  
> 
> Also, style nits inlined.

Fixed the three nits.
> 

I have updated the patch, below.  If you could take a quick look and
make sure it works on your system that would be great.  Assuming it is
OK, hopefully we can get a maintainer to bless it and we will get the
patch committed.

Thanks.

                        Carl 
----------------------------------------------------------------------
PowerPC, fix gdb.reverse/finish-reverse-bkpt.exp and gdb.reverse/next-reverse-bkpt-over-sr.exp

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.

The tests were modified to call the function with a function pointer so
the test 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.

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.

Patch tested on PowerPC and Intel X86-64 with no regressions.
---
 .../gdb.reverse/finish-reverse-bkpt.exp       | 30 +++++++++++++++++++
 gdb/testsuite/gdb.reverse/finish-reverse.c    |  4 +++
 .../gdb.reverse/next-reverse-bkpt-over-sr.exp | 29 ++++++++++++++++--
 gdb/testsuite/gdb.reverse/step-precsave.exp   |  1 +
 gdb/testsuite/gdb.reverse/step-reverse.c      |  9 ++++++
 gdb/testsuite/gdb.reverse/step-reverse.exp    |  1 +
 6 files changed, 71 insertions(+), 3 deletions(-)

diff --git a/gdb/testsuite/gdb.reverse/finish-reverse-bkpt.exp b/gdb/testsuite/gdb.reverse/finish-reverse-bkpt.exp
index 2a204748d98..94bcf41dc67 100644
--- a/gdb/testsuite/gdb.reverse/finish-reverse-bkpt.exp
+++ b/gdb/testsuite/gdb.reverse/finish-reverse-bkpt.exp
@@ -19,6 +19,27 @@
 # the functions entry would be ignored.  Make sure the bug doesn't
 # reappear.
 
+# 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.
+#
+#   <void_func>:
+#  	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
 }
@@ -38,6 +59,15 @@ if [supports_process_record] {
     gdb_test_no_output "record" "turn on process record"
 }
 
+# Move to the function pointer call to void_func so we will use the GEP
+# to enter void_func and break.
+set breakloc [gdb_get_line_number "FUNCTION PTR" "$srcfile"]
+gdb_test "break $breakloc" \
+    "Breakpoint $decimal at .*$srcfile, line $breakloc\." \
+    "set breakpoint on funp"
+gdb_continue_to_breakpoint "funp call" ".*$srcfile:$breakloc.*"
+
+# 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/finish-reverse.c b/gdb/testsuite/gdb.reverse/finish-reverse.c
index 316d6f6aa7e..163a028f394 100644
--- a/gdb/testsuite/gdb.reverse/finish-reverse.c
+++ b/gdb/testsuite/gdb.reverse/finish-reverse.c
@@ -89,6 +89,7 @@ int main (int argc, char **argv)
   float float_resultval;
   double double_resultval;
   int i;
+  void (*funp) (void) = void_func;
 
   /* A "test load" that will insure that the function really returns 
      a ${type} (as opposed to just a truncated or part of a ${type}).  */
@@ -123,6 +124,9 @@ int main (int argc, char **argv)
   testval.double_testval = 3.14159265358979323846; /* float_checkpoint */
   double_resultval    = double_func ();		
   main_test = 1;				/* double_checkpoint */
+
+  /* This call is used with finish-reverse-bkpt.exp.  */
+  funp ();                              /* FUNCTION PTR call to void_func */
   return 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 6ef56d30e7b..d78c6ac490e 100644
--- a/gdb/testsuite/gdb.reverse/next-reverse-bkpt-over-sr.exp
+++ b/gdb/testsuite/gdb.reverse/next-reverse-bkpt-over-sr.exp
@@ -22,6 +22,25 @@
 # 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.
+#
+#  <callee>:
+#   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.
 
 if ![supports_reverse] {
     return
@@ -42,8 +61,12 @@ if [supports_process_record] {
     gdb_test_no_output "record" "turn on process record"
 }
 
-set lineno [gdb_get_line_number "STEP INTO THIS CALL"]
-gdb_test "advance $lineno" ".*STEP INTO THIS CALL.*" "get past callee call"
+# Move to the function pointer call to the callee call after the function
+# pointer call to callee to begin the test.  The function pointer call to
+# callee will use the Global Entry Point on Power.
+set lineno [gdb_get_line_number "STEP INTO CALL AFTER FUNP CALL"]
+gdb_test "advance $lineno" ".*STEP INTO CALL AFTER FUNP CALL.*" \
+    "get past callee call"
 
 gdb_test "b \*callee" "" "set breakpoint at callee's entry"
 
@@ -53,5 +76,5 @@ gdb_test "reverse-next" \
     "reverse-next over call trips user breakpoint at function entry"
 
 gdb_test "up" \
-    ".*NEXT OVER THIS CALL.*" \
+    ".*FUNCTION PTR CALL TO CALLEE.*" \
     "stopped at the right callee call"
diff --git a/gdb/testsuite/gdb.reverse/step-precsave.exp b/gdb/testsuite/gdb.reverse/step-precsave.exp
index 3279b6ce879..602dd7e6976 100644
--- a/gdb/testsuite/gdb.reverse/step-precsave.exp
+++ b/gdb/testsuite/gdb.reverse/step-precsave.exp
@@ -76,6 +76,7 @@ gdb_test "record restore $precsave" \
 
 # plain vanilla step/next (no count)
 
+gdb_test "next" ".*BREAK AT MAIN.*" "next past funp declaration"
 gdb_test "next" ".*NEXT TEST 1.*" "next test 1"
 gdb_test "step" ".*STEP TEST 1.*" "step test 1"
 
diff --git a/gdb/testsuite/gdb.reverse/step-reverse.c b/gdb/testsuite/gdb.reverse/step-reverse.c
index 809c7d16dc9..83704b42b6b 100644
--- a/gdb/testsuite/gdb.reverse/step-reverse.c
+++ b/gdb/testsuite/gdb.reverse/step-reverse.c
@@ -54,6 +54,7 @@ large_struct_by_value (struct rhomboidal r)
 int main () {
    int w,x,y,z;
    int a[10], b[10];
+   int (*funp) (void) = callee;
 
    /* Test "next" and "step" */
    w = 0;	/* BREAK AT MAIN */
@@ -83,6 +84,14 @@ int main () {
 
    y = w + z;
 
+   /* Test next-reverse-bkpt-over-sr.exp needs to call function callee using
+      a function pointer to work correctly on PowerPC.  See comments in
+      next-reverse-bkpt-over-sr.exp.  */
+   funp ();       /* FUNCTION PTR CALL TO CALLEE */
+
+   /* Test that "step" doesn't */
+   callee ();	/* STEP INTO CALL AFTER FUNP CALL */
+
    {
      struct rhomboidal r;
      memset (r.rather_large, 0, sizeof (r.rather_large));
diff --git a/gdb/testsuite/gdb.reverse/step-reverse.exp b/gdb/testsuite/gdb.reverse/step-reverse.exp
index d2975cffb5c..bce137a97ad 100644
--- a/gdb/testsuite/gdb.reverse/step-reverse.exp
+++ b/gdb/testsuite/gdb.reverse/step-reverse.exp
@@ -40,6 +40,7 @@ if [supports_process_record] {
 
 # plain vanilla step/next (no count)
 
+gdb_test "next" ".*BREAK AT MAIN.*" "next past funp declaration"
 gdb_test "next" ".*NEXT TEST 1.*" "next test 1"
 gdb_test "step" ".*STEP TEST 1.*" "step test 1"
 
-- 
2.37.2



  reply	other threads:[~2022-11-22 16:53 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-27 16:14 [PATCH] Fix test next-reverse-bkpt-over-sr.exp Carl Love
2022-09-28  7:35 ` Bruno Larsen
2022-11-14 21:05   ` [PATCH] PowerPC, fix gdb.reverse/finish-reverse-bkpt.exp and gdb.reverse/next-reverse-bkpt-over-sr.exp Carl Love
2022-11-21 16:36     ` [PING] " Carl Love
2022-11-22  9:42     ` Bruno Larsen
2022-11-22 16:53       ` Carl Love [this message]
2022-11-23  8:44         ` Bruno Larsen
2022-11-23 17:56         ` Ulrich Weigand
2022-11-23 23:33           ` Carl Love
2022-11-28 18:52           ` Carl Love
2022-11-29  8:52             ` Bruno Larsen
2022-11-29 16:50               ` Carl Love
2022-11-29 16:57               ` [PATCH V4] " Carl Love
2022-11-30 11:30                 ` Ulrich Weigand
2022-12-01  1:33                   ` Carl Love
2022-12-01 15:50                     ` [PATCH V5] " Carl Love
2022-12-01 16:02                       ` Ulrich Weigand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ace89c525e06240c9bdc08377e1830d818a5988e.camel@us.ibm.com \
    --to=cel@us.ibm.com \
    --cc=Ulrich.Weigand@de.ibm.com \
    --cc=blarsen@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=will_schmidt@vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).