public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Guinevere Larsen <blarsen@redhat.com>
To: gdb-patches@sourceware.org
Cc: Guinevere Larsen <blarsen@redhat.com>
Subject: [PATCH v3 3/4] gdb/testsuite: fix testing gdb.reverse/step-reverse.exp with clang
Date: Mon, 14 Aug 2023 12:48:19 +0200	[thread overview]
Message-ID: <20230814104819.207097-5-blarsen@redhat.com> (raw)
In-Reply-To: <20230814104819.207097-2-blarsen@redhat.com>

When testing using reverse-stepi to fully step through a function, the
code checks for an infinite loop by seeing if we land on the line that
contains the return statement multiple times. This assumption only works
if there is only one instruction associated with that line, which is how
GCC handles line information, but other compilers may handle it differently.
Clang-15, for instance, associates 6. Because of this, the inferior used
to get seriously out of sync with the test expectations, and result in 13
spurious failures. The same issue occurs with gdb.reverse/step-precsave.exp.

This commit changes the test so that we check for PC instead of line
number. The test still only happens when the same line is detected, to
simplify the resulting log. With this change, no new failures are
emitted when using clang.

It also adds a new parameter to get_hexadecimal_valueof, so that we can
use it without generating new passes, otherwise we'd get multiple
duplicate test names. This change shouldn't affect any other test using
this proc.
---
 gdb/testsuite/gdb.reverse/step-precsave.exp | 10 +++++++++-
 gdb/testsuite/gdb.reverse/step-reverse.exp  | 12 +++++++++++-
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/gdb/testsuite/gdb.reverse/step-precsave.exp b/gdb/testsuite/gdb.reverse/step-precsave.exp
index 19cd5d9930e..e2971621c57 100644
--- a/gdb/testsuite/gdb.reverse/step-precsave.exp
+++ b/gdb/testsuite/gdb.reverse/step-precsave.exp
@@ -209,11 +209,19 @@ gdb_test_multiple "stepi" "$test_message" {
 
 # stepi backward out of a function call
 
+set start_pc [get_hexadecimal_valueof "\$pc" 0 "getting PC at start of stepi backwards"]
+set step_count 0
 set stepi_location  [gdb_get_line_number "STEPI TEST" "$srcfile"]
 set test_message "reverse stepi from a function call"
 gdb_test_multiple "stepi" "$test_message" {
     -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
-	fail "$test_message (start statement)"
+	incr step_count
+	if { [get_hexadecimal_valueof "\$pc" 0 "getting PC after $step_count steps"] == $start_pc } {
+	    fail "$test_message (start statement)"
+	} else {
+	    send_gdb "stepi\n"
+	    exp_continue
+	}
     }
     -re "ENTER CALLEE.*$gdb_prompt $" {
 	send_gdb "stepi\n" 
diff --git a/gdb/testsuite/gdb.reverse/step-reverse.exp b/gdb/testsuite/gdb.reverse/step-reverse.exp
index 4b78a8f8fb7..b7d00fb4bd3 100644
--- a/gdb/testsuite/gdb.reverse/step-reverse.exp
+++ b/gdb/testsuite/gdb.reverse/step-reverse.exp
@@ -174,11 +174,21 @@ gdb_test_multiple "stepi" "$test_message" {
 
 # stepi backward out of a function call
 
+# When testing stepi, we dont want to infinitely step if we're not moving
+# so we store the starting PC, in case we land on the same line as above
+set start_pc [get_hexadecimal_valueof "\$pc" 0 "get PC at start"]
+set get_pc_count 0
 set stepi_location  [gdb_get_line_number "STEPI TEST" "$srcfile"]
 set test_message "reverse stepi from a function call"
 gdb_test_multiple "stepi" "$test_message" {
     -re "ARRIVED IN CALLEE.*$gdb_prompt $" {
-	fail "$test_message (start statement)"
+	incr get_pc_count
+	if { [get_hexadecimal_valueof "\$pc" 0 "get PC again $get_pc_count"] == $start_pc } {
+	    fail "$test_message (start statement)"
+	} else {
+	    send_gdb "stepi\n"
+	    exp_continue
+	}
     }
     -re "ENTER CALLEE.*$gdb_prompt $" {
 	send_gdb "stepi\n" 
-- 
2.41.0


  parent reply	other threads:[~2023-08-14 10:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-14 10:48 [PATCH v3 0/4] Many fixes to gdb.reverse tests when testing Guinevere Larsen
2023-08-14 10:48 ` [PATCH v3 1/4] gdb/testsuite: Fix many errors in gdb.reverse with clang Guinevere Larsen
2023-08-14 10:48 ` [PATCH v3 2/4] gdb/testsuite: fix gdb.reverse/solib-*.exp tests when using clang Guinevere Larsen
2023-08-14 10:48 ` Guinevere Larsen [this message]
2023-08-18 18:56   ` [PATCH v3 3/4] gdb/testsuite: fix testing gdb.reverse/step-reverse.exp with clang Tom Tromey
2023-08-21  7:23     ` Guinevere Larsen
2023-08-14 10:48 ` [PATCH v3 4/4] gdb/testsuite: Multiple improvements for gdb.reverse/insn-reverse.exp Guinevere Larsen

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=20230814104819.207097-5-blarsen@redhat.com \
    --to=blarsen@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /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).