public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: Keith Seitz <keiths@redhat.com>,
	Keith Seitz via Gdb-patches <gdb-patches@sourceware.org>
Subject: [PATCH] Make gdb.fortran/{array-slices,lbound-ubound} work against gdbserver
Date: Mon, 7 Mar 2022 14:27:31 +0000	[thread overview]
Message-ID: <a057ae60-f8f1-ded8-aca1-79e58a6e4a1a@palves.net> (raw)
In-Reply-To: <e366be4b-c0a7-f2ff-ead5-c02962bd55a3@palves.net>

On 2022-03-03 20:02, Pedro Alves wrote:

> Well, the change is incorrect, because when testing with gdbserver we do have
> inferior output.  :-P  
> 
> We're not supposed to check whether the target is native.
> 
> Instead, we're supposed to use gdb_test_stdio & gdb_skip_stdio_test.

Keith mentioned he might be away this week, so I went ahead and played with this.  We
can't use gdb_test_stdio here, because that maps to gdb_test, and we want gdb_test_multiple
instead.  So we use inferior_spawn_id with gdb_test_multiple instead.

It took me some head scratching and staring at logs to figure out why the patch
wasn't working -- I was hitting a buglet in gdb.fortran/array-slices.f90, argh.
With that out of the way, both testcases now pass cleanly with gdbserver too.

Here's the proposed patch.  Any comments?

From cb3fadb145a5ac6a2ddd5714ec17374ef5254cba Mon Sep 17 00:00:00 2001
From: Pedro Alves <pedro@palves.net>
Date: Fri, 4 Mar 2022 17:34:18 +0000
Subject: [PATCH] Make gdb.fortran/{array-slices,lbound-ubound} work against
 gdbserver

gdb.fortran/array-slices.exp and gdb.fortran/lbound-ubound.exp were
recently disabled unless testing with the native target, because they
rely on inferior I/O.  However, when testing against gdbserver using
the native-gdbserver/native-extended-gdbserver boards, we do have
access to inferior I/O.

The right way to check whether the board can do I/O, is via checking
the gdb,noinferiorio board variable.  Switch to using that.

And then, tweak the testcases to expect output to appear in
inferior_spawn_id, instead of gdb_spawn_id.  When testing against the
native target, inferior_spawn_id is the same as gdb_spawn_id.  When
testing against gdbserver, it maps to gdbserver_spawn_id.

This exposed a buglet in gdb.fortran/array-slices.f90's show_1d
subroutine -- it was missing printing newline at the end of the
"Expected GDB Output" text, leading to a test timeout.  All other
subroutines end with advance=yes, except this one.  Fix it by using
advance=yes here too.

Change-Id: I4640729f334431cfc24b0917e7d3977b677c6ca5
---
 gdb/testsuite/gdb.fortran/array-slices.exp  | 30 +++++++++++++++------
 gdb/testsuite/gdb.fortran/array-slices.f90  |  2 +-
 gdb/testsuite/gdb.fortran/lbound-ubound.exp | 28 ++++++++++++++-----
 3 files changed, 45 insertions(+), 15 deletions(-)

diff --git a/gdb/testsuite/gdb.fortran/array-slices.exp b/gdb/testsuite/gdb.fortran/array-slices.exp
index 8f9c012e399..a38276c67e4 100644
--- a/gdb/testsuite/gdb.fortran/array-slices.exp
+++ b/gdb/testsuite/gdb.fortran/array-slices.exp
@@ -35,6 +35,11 @@
 
 if {[skip_fortran_tests]} { return -1 }
 
+# This test relies on output from the inferior.
+if [target_info exists gdb,noinferiorio] {
+    return -1
+}
+
 standard_testfile ".f90"
 load_lib fortran.exp
 
@@ -62,12 +67,6 @@ proc run_test { repack } {
 	return -1
     }
 
-    # This test relies on output from the inferior and is not supported on
-    # remote targets.
-    if {![gdb_is_target_native]} {
-	return 0
-    }
-
     # Avoid libc symbols, in particular the 'array' type.
     gdb_test_no_output "nosharedlibrary"
 
@@ -97,11 +96,19 @@ proc run_test { repack } {
 	    set found_final_breakpoint false
 	    set expected_result ""
 	    set func_name ""
+	    set found_prompt false
 	    gdb_test_multiple "continue" "continue" {
+		-i $::inferior_spawn_id
+
 		-re ".*GDB = (\[^\r\n\]+)\r\n" {
 		    set expected_result $expect_out(1,string)
-		    exp_continue
+		    if {!$found_prompt} {
+			exp_continue
+		    }
 		}
+
+		-i $::gdb_spawn_id
+
 		-re "! Display Element" {
 		    set func_name "show_elem"
 		    exp_continue
@@ -119,7 +126,14 @@ proc run_test { repack } {
 		    exp_continue
 		}
 		-re "$gdb_prompt $" {
-		    # We're done.
+		    set found_prompt true
+
+		    if {$found_final_breakpoint
+			|| ($expected_result != "" && $func_name != "")} {
+			# We're done.
+		    } else {
+			exp_continue
+		    }
 		}
 	    }
 
diff --git a/gdb/testsuite/gdb.fortran/array-slices.f90 b/gdb/testsuite/gdb.fortran/array-slices.f90
index ff3964ffb6b..1eaee82b7b7 100644
--- a/gdb/testsuite/gdb.fortran/array-slices.f90
+++ b/gdb/testsuite/gdb.fortran/array-slices.f90
@@ -61,7 +61,7 @@ subroutine show_1d (array)
      end if
      write(*, fmt="(I0)", advance="no") array (i)
   end do
-  write(*, fmt="(A)", advance="no") ")"
+  write(*, fmt="(A)", advance="yes") ")"
 
   print *, ""	! Display Array Slice 1D
 end subroutine show_1d
diff --git a/gdb/testsuite/gdb.fortran/lbound-ubound.exp b/gdb/testsuite/gdb.fortran/lbound-ubound.exp
index 671b251c799..709b74a69e8 100644
--- a/gdb/testsuite/gdb.fortran/lbound-ubound.exp
+++ b/gdb/testsuite/gdb.fortran/lbound-ubound.exp
@@ -32,9 +32,8 @@ if ![fortran_runto_main] {
     return -1
 }
 
-# This test relies on output from the inferior and is not supported on
-# remote targets.
-if {![gdb_is_target_native]} {
+# This test relies on output from the inferior.
+if [target_info exists gdb,noinferiorio] {
    return 0
 }
 
@@ -55,15 +54,25 @@ while { $test_count < 500 } {
 
 	set expected_lbound ""
 	set expected_ubound ""
+	set found_prompt false
 	gdb_test_multiple "continue" "continue" {
+	    -i $::inferior_spawn_id
+
 	    -re ".*LBOUND = (\[^\r\n\]+)\r\n" {
 		set expected_lbound $expect_out(1,string)
-		exp_continue
+		if {!$found_prompt} {
+		    exp_continue
+		}
 	    }
 	    -re ".*UBOUND = (\[^\r\n\]+)\r\n" {
 		set expected_ubound $expect_out(1,string)
-		exp_continue
+		if {!$found_prompt} {
+		    exp_continue
+		}
 	    }
+
+	    -i $::gdb_spawn_id
+
 	    -re "! Test Breakpoint" {
 		set func_name "show_elem"
 		exp_continue
@@ -73,7 +82,14 @@ while { $test_count < 500 } {
 		exp_continue
 	    }
 	    -re "$gdb_prompt $" {
-		# We're done.
+		set found_prompt true
+
+		if {$found_final_breakpoint
+		    || ($expected_lbound != "" && $expected_ubound != "")} {
+		    # We're done.
+		} else {
+		    exp_continue
+		}
 	    }
 	}
 

base-commit: 0daa5af85a9b5548a1bd7e8085a326162b41fd6f
-- 
2.26.2


  reply	other threads:[~2022-03-07 14:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-24 17:41 [PATCH] Fix gdb.fortran "failed to extract expected results" errors Keith Seitz
2022-02-25 16:40 ` Tom Tromey
2022-02-25 16:48   ` Simon Marchi
2022-02-28 15:35     ` Keith Seitz
2022-03-03 20:02       ` Pedro Alves
2022-03-07 14:27         ` Pedro Alves [this message]
2022-03-09 17:21           ` [PATCH] Make gdb.fortran/{array-slices,lbound-ubound} work against gdbserver Tom Tromey

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=a057ae60-f8f1-ded8-aca1-79e58a6e4a1a@palves.net \
    --to=pedro@palves.net \
    --cc=gdb-patches@sourceware.org \
    --cc=keiths@redhat.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).