public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 2/3] gdb/testsuite: kfail some tests if using broken gcc
  2019-12-04 11:41 [PATCH 0/3] Testsuite Fixes For GCC 8/9 Andrew Burgess
@ 2019-12-04 11:41 ` Andrew Burgess
  2019-12-06 19:47   ` Pedro Alves
  2019-12-04 11:41 ` [PATCH 3/3] gdb/fortran: Improve output pattern in gdb.mi/mi-fortran-modules.exp Andrew Burgess
  2019-12-04 11:41 ` [PATCH 1/3] gdb/testsuite/fortran: Fix info-modules/info-types for gfortran 8+ Andrew Burgess
  2 siblings, 1 reply; 7+ messages in thread
From: Andrew Burgess @ 2019-12-04 11:41 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

In some cases the Fortran stride information generated by GCC is wrong
with versions of GCC after 7.x.x.  This commit adds kfails for the
tests in question with known bad versions of gcc.

The bug has been reported to GCC here:

  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92775

gdb/testsuite/ChangeLog:

	* gdb.fortran/derived-type-striding.exp: KFAIL if we are using a
	broken version of GCC.

Change-Id: Iaef08e5e2c87ab3d6983b88f749d40e01aea2bc6
---
 gdb/testsuite/ChangeLog                             | 5 +++++
 gdb/testsuite/gdb.fortran/derived-type-striding.exp | 6 ++++++
 2 files changed, 11 insertions(+)

diff --git a/gdb/testsuite/gdb.fortran/derived-type-striding.exp b/gdb/testsuite/gdb.fortran/derived-type-striding.exp
index a2590a9ab2f..dc5ef96b3bc 100644
--- a/gdb/testsuite/gdb.fortran/derived-type-striding.exp
+++ b/gdb/testsuite/gdb.fortran/derived-type-striding.exp
@@ -20,6 +20,10 @@ if {[skip_fortran_tests]} { return -1 }
 
 standard_testfile ".f90"
 
+# Unfortunately recent versions of GCC broke the stride information in
+# the DEBUG so tests in this file will fail.
+set gcc_with_broken_stride [test_compiler_info {gcc-[89]-*}]
+
 if {[prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \
 	 {debug f90}]} {
     return -1
@@ -31,7 +35,9 @@ if {![runto [gdb_get_line_number "post_init"]]} then {
 }
 
 # Test homogeneous derived type.
+if { $gcc_with_broken_stride } { setup_kfail *-*-* gcc/92775 }
 gdb_test "p point_dimension" "= \\\(2, 2, 2, 2, 2, 2, 2, 2, 2\\\)"
 
 # Test mixed type derived type.
+if { $gcc_with_broken_stride } { setup_kfail *-*-* gcc/92775 }
 gdb_test "p point_mixed_dimension" "= \\\(3, 3, 3, 3\\\)"
-- 
2.14.5

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] gdb/testsuite/fortran: Fix info-modules/info-types for gfortran 8+
  2019-12-04 11:41 [PATCH 0/3] Testsuite Fixes For GCC 8/9 Andrew Burgess
  2019-12-04 11:41 ` [PATCH 2/3] gdb/testsuite: kfail some tests if using broken gcc Andrew Burgess
  2019-12-04 11:41 ` [PATCH 3/3] gdb/fortran: Improve output pattern in gdb.mi/mi-fortran-modules.exp Andrew Burgess
@ 2019-12-04 11:41 ` Andrew Burgess
  2019-12-06 19:46   ` Pedro Alves
  2 siblings, 1 reply; 7+ messages in thread
From: Andrew Burgess @ 2019-12-04 11:41 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

The gdb.fortran/info-modules.exp and gdb.fortran/info-types.exp tests
are failing on versions of gfortran after 7.3 due to the inclusion of
extra "system" modules and type that were not being matched by the
current test patterns.

Rather than building increasingly complex patterns that would always
be at risk of breaking with future versions of GCC I have instead
added a new library that parses the output of the following commands:

  info types
  info variables
  info functions
  info modules
  info module functions
  info module variables

into a data structure, the test can than run checks against the
contents of this data structure.

The benefit is that we can simply ignore extra results that we don't
care about.

There is a small risk that a bug in GDB might allow us to start
reporting incorrect results in such a way that the new library will
not spot the error.  However, I have tried to mitigate this risk by
adding extra procedures into the test library (see check_no_entry) and
we can add more in future if we wanted to be even more defensive.

I tested this test file with gFortran 7.3.1, 8.3.0, and 9.2.0, I now
see 100% pass in all cases.

gdb/testsuite/ChangeLog:

	* gdb.fortran/info-modules.exp: Rewrite to make use of new
	sym-info-cmds library.
	* gdb.fortran/info-types.exp: Likewise.
	* lib/sym-info-cmds.exp: New file.

Change-Id: Iff81624f51b5afb6c95393932f3d94472d7c2970
---
 gdb/testsuite/ChangeLog                    |   7 +
 gdb/testsuite/gdb.fortran/info-modules.exp | 261 +++++++--------
 gdb/testsuite/gdb.fortran/info-types.exp   |  13 +
 gdb/testsuite/lib/sym-info-cmds.exp        | 517 +++++++++++++++++++++++++++++
 4 files changed, 658 insertions(+), 140 deletions(-)
 create mode 100644 gdb/testsuite/lib/sym-info-cmds.exp

diff --git a/gdb/testsuite/gdb.fortran/info-modules.exp b/gdb/testsuite/gdb.fortran/info-modules.exp
index c57ac3ff569..cf20f0a54b0 100644
--- a/gdb/testsuite/gdb.fortran/info-modules.exp
+++ b/gdb/testsuite/gdb.fortran/info-modules.exp
@@ -17,6 +17,7 @@
 # module variables'.
 
 load_lib "fortran.exp"
+load_lib "sym-info-cmds.exp"
 
 if { [skip_fortran_tests] } { continue }
 
@@ -38,150 +39,130 @@ set real4 [fortran_real4]
 
 # Test 'info modules' command.
 
-gdb_test "info modules" \
-    [multi_line \
-	 "All defined modules:" \
-	 "" \
-	 "File .*${srcfile2}:" \
-	 "18:\[\t \]+mod2" \
-	 "" \
-	 "File .*${srcfile}:" \
-	 "16:\[\t \]+mod1" ]
-
-gdb_test "info modules 1" \
-    [multi_line \
-	 "All modules matching regular expression \"1\":" \
-	 "" \
-	 "File .*${srcfile}:" \
-	 "16:\[\t \]+mod1" ]
-
-gdb_test "info modules 2" \
-    [multi_line \
-	 "All modules matching regular expression \"2\":" \
-	 "" \
-	 "File .*${srcfile2}:" \
-	 "18:\[\t \]+mod2" ]
-
-gdb_test "info modules mod" \
-    [multi_line \
-	 "All modules matching regular expression \"mod\":" \
-	 "" \
-	 "File .*${srcfile2}:" \
-	 "18:\[\t \]+mod2" \
-	 "" \
-	 "File .*${srcfile}:" \
-	 "16:\[\t \]+mod1" ]
+GDBInfoSymbols::run_command "info modules"
+GDBInfoSymbols::check_header "All defined modules:"
+GDBInfoSymbols::check_entry "${srcfile2}" "18" "mod2"
+GDBInfoSymbols::check_entry "${srcfile}" "16" "mod1"
+GDBInfoSymbols::check_no_entry "${srcfile}"
+GDBInfoSymbols::check_no_entry "${srcfile2}"
+
+GDBInfoSymbols::run_command "info modules 1"
+GDBInfoSymbols::check_header \
+    "All modules matching regular expression \"1\":"
+GDBInfoSymbols::check_entry "${srcfile}" "16" "mod1"
+GDBInfoSymbols::check_no_entry "${srcfile}"
+GDBInfoSymbols::check_no_entry "${srcfile2}"
+
+GDBInfoSymbols::run_command "info modules 2"
+GDBInfoSymbols::check_header \
+    "All modules matching regular expression \"2\":"
+GDBInfoSymbols::check_entry "${srcfile2}" "18" "mod2"
+GDBInfoSymbols::check_no_entry "${srcfile}"
+GDBInfoSymbols::check_no_entry "${srcfile2}"
+
+GDBInfoSymbols::run_command "info modules mod"
+GDBInfoSymbols::check_header \
+    "All modules matching regular expression \"mod\":"
+GDBInfoSymbols::check_entry "${srcfile2}" "18" "mod2"
+GDBInfoSymbols::check_entry "${srcfile}" "16" "mod1"
+GDBInfoSymbols::check_no_entry "${srcfile}"
+GDBInfoSymbols::check_no_entry "${srcfile2}"
 
 # Test 'info module functions'.
 
-gdb_test "info module functions" \
-    [multi_line \
-	 "All functions in all modules:" \
-	 "" \
-	 "Module \"mod2\":" \
-	 "" \
-	 "File .*${srcfile2}:" \
-	 "22:\[\t \]+void mod2::sub_m2_a\\(${integer4}, ${logical4}\\);" \
-	 "30:\[\t \]+${logical4} mod2::sub_m2_b\\(${real4}\\);" \
-	 "" \
-	 "Module \"mod1\":" \
-	 "" \
-	 "File .*${srcfile}:" \
-	 "35:\[\t \]+void mod1::__copy_mod1_M1t1\\(Type m1t1, Type m1t1\\);" \
-	 "25:\[\t \]+void mod1::sub_m1_a\\(${integer4}\\);" \
-	 "31:\[\t \]+${integer4} mod1::sub_m1_b\\(void\\);" ]
-
-gdb_test "info module functions -m mod1" \
-    [multi_line \
-	 "All functions in all modules matching regular expression \"mod1\":" \
-	 "" \
-	 "Module \"mod1\":" \
-	 "" \
-	 "File .*:" \
-	 "35:\[\t \]+void mod1::__copy_mod1_M1t1\\(Type m1t1, Type m1t1\\);" \
-	 "25:\[\t \]+void mod1::sub_m1_a\\(${integer4}\\);" \
-	 "31:\[\t \]+${integer4} mod1::sub_m1_b\\(void\\);" ]
-
-gdb_test "info module functions -t integer" \
-    [multi_line \
-	 "All functions with type matching regular expression \"integer\" in all modules:" \
-	 "" \
-	 "Module \"mod2\":" \
-	 "" \
-	 "File .*${srcfile2}:" \
-	 "22:\[\t \]+void mod2::sub_m2_a\\(${integer4}, ${logical4}\\);" \
-	 "" \
-	 "Module \"mod1\":" \
-	 "" \
-	 "File .*${srcfile}:" \
-	 "25:\[\t \]+void mod1::sub_m1_a\\(${integer4}\\);" \
-	 "31:\[\t \]+${integer4} mod1::sub_m1_b\\(void\\);" ]
+GDBInfoModuleSymbols::run_command "info module functions"
+GDBInfoModuleSymbols::check_header "All functions in all modules:"
+GDBInfoModuleSymbols::check_entry "${srcfile2}" "mod2" "22" \
+    "void mod2::sub_m2_a\\(${integer4}, ${logical4}\\);"
+GDBInfoModuleSymbols::check_entry "${srcfile2}" "mod2" "30" \
+    "${logical4} mod2::sub_m2_b\\(${real4}\\);"
+GDBInfoModuleSymbols::check_entry "${srcfile}" "mod1" "35" \
+    "void mod1::__copy_mod1_M1t1\\(Type m1t1, Type m1t1\\);"
+GDBInfoModuleSymbols::check_entry "${srcfile}" "mod1" "25" \
+    "void mod1::sub_m1_a\\(${integer4}\\);"
+GDBInfoModuleSymbols::check_entry "${srcfile}" "mod1" "31" \
+    "${integer4} mod1::sub_m1_b\\(void\\);"
+GDBInfoModuleSymbols::check_no_entry "${srcfile}" ".*"
+GDBInfoModuleSymbols::check_no_entry "${srcfile2}" ".*"
+
+GDBInfoModuleSymbols::run_command "info module functions -m mod1"
+GDBInfoModuleSymbols::check_header \
+    "All functions in all modules matching regular expression \"mod1\":"
+GDBInfoModuleSymbols::check_entry "${srcfile}" "mod1" "35" \
+    "void mod1::__copy_mod1_M1t1\\(Type m1t1, Type m1t1\\);"
+GDBInfoModuleSymbols::check_entry "${srcfile}" "mod1" "25" \
+    "void mod1::sub_m1_a\\(${integer4}\\);"
+GDBInfoModuleSymbols::check_entry "${srcfile}" "mod1" "31" \
+    "${integer4} mod1::sub_m1_b\\(void\\);"
+GDBInfoModuleSymbols::check_no_entry "${srcfile}" ".*"
+GDBInfoModuleSymbols::check_no_entry "${srcfile2}" ".*"
+
+GDBInfoModuleSymbols::run_command "info module functions -t integer"
+GDBInfoModuleSymbols::check_header \
+    "All functions with type matching regular expression \"integer\" in all modules:"
+GDBInfoModuleSymbols::check_entry "${srcfile2}" "mod2" "22" \
+    "void mod2::sub_m2_a\\(${integer4}, ${logical4}\\);"
+GDBInfoModuleSymbols::check_entry "${srcfile}" "mod1" "25" \
+    "void mod1::sub_m1_a\\(${integer4}\\);"
+GDBInfoModuleSymbols::check_entry "${srcfile}" "mod1" "31" \
+    "${integer4} mod1::sub_m1_b\\(void\\);"
+GDBInfoModuleSymbols::check_no_entry "${srcfile}" ".*"
+GDBInfoModuleSymbols::check_no_entry "${srcfile2}" ".*"
 
 # Test 'info module variables'.
 
-gdb_test "info module variables" \
-    [multi_line \
-	 "All variables in all modules:" \
-	 "" \
-	 "Module \"mod2\":" \
-	 "" \
-	 "File .*${srcfile2}:" \
-	 "19:\[\t \]+${integer4} mod2::mod2_var_1;" \
-	 "20:\[\t \]+${real4} mod2::mod2_var_2;" \
-	 "" \
-	 "Module \"mod1\":" \
-	 "" \
-	 "File .*${srcfile}:" \
-	 "35:\[\t \]+Type m1t1 mod1::__def_init_mod1_M1t1;" \
-	 "35:\[\t \]+Type __vtype_mod1_M1t1 mod1::__vtab_mod1_M1t1;" \
-	 "21:\[\t \]+${real4} mod1::mod1_var_1;" \
-	 "22:\[\t \]+${integer4} mod1::mod1_var_2;" ]
-
-gdb_test "info module variables -t real" \
-    [multi_line \
-	 "All variables with type matching regular expression \"real\" in all modules:" \
-	 "" \
-	 "Module \"mod2\":" \
-	 "" \
-	 "File .*:" \
-	 "20:\[\t \]+${real4} mod2::mod2_var_2;" \
-	 "" \
-	 "Module \"mod1\":" \
-	 "" \
-	 "File .*:" \
-	 "21:\[\t \]+${real4} mod1::mod1_var_1;" ]
-
-gdb_test "info module variables -m mod2" \
-    [multi_line \
-	 "All variables in all modules matching regular expression \"mod2\":" \
-	 "" \
-	 "Module \"mod2\":" \
-	 "" \
-	 "File .*${srcfile2}:" \
-	 "19:\[\t \]+${integer4} mod2::mod2_var_1;" \
-	 "20:\[\t \]+${real4} mod2::mod2_var_2;" ]
-
-gdb_test "info module variables -m mod2 -t real" \
-    [multi_line \
-	 "All variables with type matching regular expression \"real\"" \
-	 "	in all modules matching regular expression \"mod2\":" \
-	 "" \
-	 "Module \"mod2\":" \
-	 "" \
-	 "File .*${srcfile2}:" \
-	 "20:\[\t \]+${real4} mod2::mod2_var_2;" ]
-
-gdb_test "info module variables _1" \
-    [multi_line \
-	 "All variables matching regular expression \"_1\" in all modules:" \
-	 "" \
-	 "Module \"mod2\":" \
-	 "" \
-	 "File .*:" \
-	 "19:\[\t \]+${integer4} mod2::mod2_var_1;" \
-	 "" \
-	 "Module \"mod1\":" \
-	 "" \
-	 "File .*:" \
-	 "21:\[\t \]+${real4} mod1::mod1_var_1;" ]
+GDBInfoModuleSymbols::run_command "info module variables"
+GDBInfoModuleSymbols::check_header "All variables in all modules:"
+GDBInfoModuleSymbols::check_entry "${srcfile2}" "mod2" "19" \
+    "${integer4} mod2::mod2_var_1;"
+GDBInfoModuleSymbols::check_entry "${srcfile2}" "mod2" "20" \
+    "${real4} mod2::mod2_var_2;"
+GDBInfoModuleSymbols::check_entry "${srcfile}" "mod1" "35" \
+    "Type m1t1 mod1::__def_init_mod1_M1t1;"
+GDBInfoModuleSymbols::check_entry "${srcfile}" "mod1" "35" \
+    "Type __vtype_mod1_M1t1 mod1::__vtab_mod1_M1t1;"
+GDBInfoModuleSymbols::check_entry "${srcfile}" "mod1" "21" \
+    "${real4} mod1::mod1_var_1;"
+GDBInfoModuleSymbols::check_entry "${srcfile}" "mod1" "22" \
+    "${integer4} mod1::mod1_var_2;"
+GDBInfoModuleSymbols::check_no_entry "${srcfile}" ".*"
+GDBInfoModuleSymbols::check_no_entry "${srcfile2}" ".*"
+
+GDBInfoModuleSymbols::run_command "info module variables -t real"
+GDBInfoModuleSymbols::check_header \
+    "All variables with type matching regular expression \"real\" in all modules:"
+GDBInfoModuleSymbols::check_entry "${srcfile2}" "mod2" "20" \
+    "${real4} mod2::mod2_var_2;"
+GDBInfoModuleSymbols::check_entry "${srcfile}" "mod1" "21" \
+    "${real4} mod1::mod1_var_1;"
+GDBInfoModuleSymbols::check_no_entry "${srcfile}" ".*"
+GDBInfoModuleSymbols::check_no_entry "${srcfile2}" ".*"
+
+GDBInfoModuleSymbols::run_command "info module variables -m mod2"
+GDBInfoModuleSymbols::check_header \
+    "All variables in all modules matching regular expression \"mod2\":"
+GDBInfoModuleSymbols::check_entry "${srcfile2}" "mod2" "19" \
+    "${integer4} mod2::mod2_var_1;"
+GDBInfoModuleSymbols::check_entry "${srcfile2}" "mod2" "20" \
+    "${real4} mod2::mod2_var_2;"
+GDBInfoModuleSymbols::check_no_entry "${srcfile}" ".*"
+GDBInfoModuleSymbols::check_no_entry "${srcfile2}" ".*"
+
+GDBInfoModuleSymbols::run_command "info module variables -m mod2 -t real"
+GDBInfoModuleSymbols::check_header \
+    "All variables with type matching regular expression \"real\" in all modules matching regular expression \"mod2\":"
+GDBInfoModuleSymbols::check_entry "${srcfile2}" "mod2" "20" \
+    "${real4} mod2::mod2_var_2;"
+GDBInfoModuleSymbols::check_no_entry "${srcfile}" ".*"
+GDBInfoModuleSymbols::check_no_entry "${srcfile2}" ".*"
+
+GDBInfoModuleSymbols::run_command "info module variables _1"
+GDBInfoModuleSymbols::check_header \
+    "All variables matching regular expression \"_1\" in all modules:"
+GDBInfoModuleSymbols::check_entry "${srcfile2}" "mod2" "19" \
+    "${integer4} mod2::mod2_var_1;"
+GDBInfoModuleSymbols::check_entry "${srcfile}" "mod1" "21" \
+    "${real4} mod1::mod1_var_1;"
+GDBInfoModuleSymbols::check_no_entry "${srcfile}" ".*"
+GDBInfoModuleSymbols::check_no_entry "${srcfile2}" ".*"
 
diff --git a/gdb/testsuite/gdb.fortran/info-types.exp b/gdb/testsuite/gdb.fortran/info-types.exp
index 324b4e01296..a99ac84f197 100644
--- a/gdb/testsuite/gdb.fortran/info-types.exp
+++ b/gdb/testsuite/gdb.fortran/info-types.exp
@@ -16,6 +16,7 @@
 # This file tests 'info types' for some Fortran types.
 
 load_lib "fortran.exp"
+load_lib "sym-info-cmds.exp"
 
 if { [skip_fortran_tests] } { continue }
 
@@ -37,6 +38,18 @@ set logical4 [fortran_logical4]
 set character1 [fortran_character1]
 set real4 [fortran_real4]
 
+GDBInfoSymbols::run_command "info types"
+GDBInfoSymbols::check_header "All defined types:"
+
+GDBInfoSymbols::check_entry "${srcfile}" "" "${character1}"
+GDBInfoSymbols::check_entry "${srcfile}" "" "${integer4}"
+GDBInfoSymbols::check_entry "${srcfile}" "" "${logical4}"
+GDBInfoSymbols::check_entry "${srcfile}" "$decimal" "Type m1t1;"
+GDBInfoSymbols::check_entry "${srcfile}" "" "${real4}"
+GDBInfoSymbols::check_entry "${srcfile}" "37" "Type s1;"
+
+return 0
+
 gdb_test "info types" \
     [multi_line \
 	 "All defined types:" \
diff --git a/gdb/testsuite/lib/sym-info-cmds.exp b/gdb/testsuite/lib/sym-info-cmds.exp
new file mode 100644
index 00000000000..d69be506288
--- /dev/null
+++ b/gdb/testsuite/lib/sym-info-cmds.exp
@@ -0,0 +1,517 @@
+# Copyright 2019 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 <http://www.gnu.org/licenses/>.
+
+# Make it easier to run the 'info modules' command (using
+# GDBInfoModules), and the 'info module ...' commands (using
+# GDBInfoModuleContents) and process the output.
+#
+# The difficulty we run into is that different versions of gFortran
+# include different helper modules which show up in the results.  The
+# procedures in this library help process those parts of the output we
+# actually want to check, while ignoring those parts that we don't
+# care about.
+#
+# For each namespace GDBInfoModules and GDBInfoModuleContents, there's
+# a run_command proc, use this to run a command and capture the
+# output.  Then make calls to check_header, check_entry, and
+# check_no_entry to ensure the output was as expected.
+
+namespace eval GDBInfoSymbols {
+
+    # A string that is the header printed by GDB immediately after the
+    # 'info [modules|types|functions|variables]' command has been issued.
+    variable _header
+
+    # A list of entries extracted from the output of the command.
+    # Each entry is a filename, a line number, and the rest of the
+    # text describing the entry.  If an entry has no line number then
+    # it is replaced with the text NONE.
+    variable _entries
+
+    # The string that is the complete last command run.
+    variable _last_command
+
+    # Add a new entry to the _entries list.
+    proc _add_entry { filename lineno text } {
+	variable _entries
+
+	set entry [list $filename $lineno $text]
+	lappend _entries $entry
+    }
+
+    # Run the 'info modules' command, passing ARGS as extra arguments
+    # to the command.  Process the output storing the results within
+    # the variables in this namespace.
+    #
+    # The results of any previous call to run_command are discarded
+    # when this is called.
+    proc run_command { cmd { testname "" } } {
+	global gdb_prompt
+
+	variable _header
+	variable _entries
+	variable _last_command
+
+	if {![regexp -- "^info (modules|types|variables|functions)" $cmd]} {
+	    perror "invalid command"
+	}
+
+	set _header ""
+	set _entries [list]
+	set _last_command $cmd
+
+	if { $testname == "" } {
+	    set testname $cmd
+	}
+
+	send_gdb "$cmd\n"
+	gdb_expect {
+	    -re "^$cmd\r\n" {
+		# Match the original command echoed back to us.
+	    }
+	    timeout {
+		fail "$testname (timeout)"
+		return 0
+	    }
+	}
+
+	gdb_expect {
+	    -re "^\r\n" {
+		# Found the blank line after the header, we're done
+		# parsing the header now.
+	    }
+	    -re "^\[ \t]*(\[^\r\n\]+)\r\n" {
+		set str $expect_out(1,string)
+		if { $_header == "" } {
+		    set _header $str
+		} else {
+		    set _header "$_header $str"
+		}
+		exp_continue
+	    }
+	    timeout {
+		fail "$testname (timeout)"
+		return 0
+	    }
+	}
+
+	set current_file ""
+	gdb_expect {
+	    -re "^File (\[^\r\n\]+):\r\n" {
+		set current_file $expect_out(1,string)
+		exp_continue
+	    }
+	    -re "^(\[0-9\]+):\[ \t\]+(\[^\r\n\]+)\r\n" {
+		set lineno $expect_out(1,string)
+		set text $expect_out(2,string)
+		if { $current_file == "" } {
+		    fail "$testname (missing filename)"
+		    return 0
+		}
+		_add_entry $current_file $lineno $text
+		exp_continue
+	    }
+	    -re "^\[ \t\]+(\[^\r\n\]+)\r\n" {
+		set lineno "NONE"
+		set text $expect_out(1,string)
+		if { $current_file == "" } {
+		    fail "$testname (missing filename)"
+		    return 0
+		}
+		_add_entry $current_file $lineno $text
+		exp_continue
+	    }
+	    -re "^\r\n" {
+		exp_continue
+	    }
+	    -re "^$gdb_prompt $" {
+		# All done.
+	    }
+	    timeout {
+		fail "$testname (timeout)"
+		return 0
+	    }
+	}
+
+	pass $testname
+	return 1
+    }
+
+    # Check that the header held in _header matches PATTERN.  Use
+    # TESTNAME as the name of the test, or create a suitable default
+    # test name based on the last command.
+    proc check_header { pattern { testname "" } } {
+	variable _header
+	variable _last_command
+
+	if { $testname == "" } {
+	    set testname "$_last_command: check header"
+	}
+
+	gdb_assert {[regexp -- $pattern $_header]} $testname
+    }
+
+    # Check that we have an entry in _entries matching FILENAME,
+    # LINENO, and TEXT.  If LINENO is the empty string it is replaced
+    # with the string NONE in order to match a similarly missing line
+    # number in the output of the command.
+    #
+    # TESTNAME is the name of the test, or a default will be created
+    # based on the last command run and the arguments passed here.
+    #
+    # If a matching entry is found then it is removed from the
+    # _entries list, this allows us to check for duplicates using the
+    # check_no_entry call.
+    proc check_entry { filename lineno text { testname "" } } {
+	variable _entries
+	variable _last_command
+
+	if { $testname == "" } {
+	    set testname \
+		"$_last_command: check for entry '$filename', '$lineno', '$text'"
+	}
+
+	if { $lineno == "" } {
+	    set lineno "NONE"
+	}
+
+	set new_entries [list]
+
+	set found_match 0
+	foreach entry $_entries {
+
+	    if {!$found_match} {
+		set f [lindex $entry 0]
+		set l [lindex $entry 1]
+		set t [lindex $entry 2]
+		if { [regexp -- $filename $f] \
+			 && [regexp -- $lineno $l] \
+			 && [regexp -- $text $t] } {
+		    set found_match 1
+		} else {
+		    lappend new_entries $entry
+		}
+	    } else {
+		lappend new_entries $entry
+	    }
+	}
+
+	set _entries $new_entries
+
+	if { $found_match } {
+	    pass $testname
+	} else {
+	    fail $testname
+	}
+    }
+
+    # Check that there is no entry in the _entries list matching
+    # FILENAME, LINENO, and TEXT.  The LINENO and TEXT are optional,
+    # and will be replaced with '.*' is missing.
+    #
+    # If LINENO is the empty string then it will be replaced with the
+    # string NONE in order to match against missing line numbers in
+    # the output of the command.
+    #
+    # TESTNAME is the name of the test, or a default will be built
+    # from the last command run and the arguments passed here.
+    #
+    # This can be used after a call to check_entry to ensure that
+    # there are no further matches for a particular file in the
+    # output.
+    proc check_no_entry { filename { lineno ".*" } { text ".*" } \
+			      { testname "" } } {
+	variable _entries
+	variable _last_command
+
+	if { $testname == "" } {
+	    set testname \
+		"$_last_command: check no matches for '$filename', $lineno', and '$text'"
+	}
+
+	if { $lineno == "" } {
+	    set lineno "NONE"
+	}
+
+	foreach entry $_entries {
+	    set f [lindex $entry 0]
+	    set l [lindex $entry 1]
+	    set t [lindex $entry 2]
+	    if { [regexp -- $filename $f] \
+		     && [regexp -- $lineno $l] \
+		     && [regexp -- $text $t] } {
+		fail $testname
+	    }
+	}
+
+	pass $testname
+    }
+}
+
+
+namespace eval GDBInfoModuleSymbols {
+
+    # A string that is the header printed by GDB immediately after the
+    # 'info modules (variables|functions)' command has been issued.
+    variable _header
+
+    # A list of entries extracted from the output of the command.
+    # Each entry is a filename, a module name, a line number, and the
+    # rest of the text describing the entry.  If an entry has no line
+    # number then it is replaced with the text NONE.
+    variable _entries
+
+    # The string that is the complete last command run.
+    variable _last_command
+
+    # Add a new entry to the _entries list.
+    proc _add_entry { filename module lineno text } {
+	variable _entries
+
+	set entry [list $filename $module $lineno $text]
+	lappend _entries $entry
+    }
+
+    # Run the 'info module ....' command, passing ARGS as extra
+    # arguments to the command.  Process the output storing the
+    # results within the variables in this namespace.
+    #
+    # The results of any previous call to run_command are discarded
+    # when this is called.
+    proc run_command { cmd { testname "" } } {
+	global gdb_prompt
+
+	variable _header
+	variable _entries
+	variable _last_command
+
+	if {![regexp -- "^info module (variables|functions)" $cmd]} {
+	    perror "invalid command: '$cmd'"
+	}
+
+	set _header ""
+	set _entries [list]
+	set _last_command $cmd
+
+	if { $testname == "" } {
+	    set testname $cmd
+	}
+
+	send_gdb "$cmd\n"
+	gdb_expect {
+	    -re "^$cmd\r\n" {
+		# Match the original command echoed back to us.
+	    }
+	    timeout {
+		fail "$testname (timeout)"
+		return 0
+	    }
+	}
+
+	gdb_expect {
+	    -re "^\r\n" {
+		# Found the blank line after the header, we're done
+		# parsing the header now.
+	    }
+	    -re "^\[ \t\]*(\[^\r\n\]+)\r\n" {
+		set str $expect_out(1,string)
+		if { $_header == "" } {
+		    set _header $str
+		} else {
+		    set _header "$_header $str"
+		}
+		exp_continue
+	    }
+	    timeout {
+		fail "$testname (timeout)"
+		return 0
+	    }
+	}
+
+	set current_module ""
+	set current_file ""
+	gdb_expect {
+	    -re "^Module \"(\[^\"\]+)\":\r\n" {
+		set current_module $expect_out(1,string)
+		exp_continue
+	    }
+	    -re "^File (\[^\r\n\]+):\r\n" {
+		if { $current_module == "" } {
+		    fail "$testname (missing module)"
+		    return 0
+		}
+		set current_file $expect_out(1,string)
+		exp_continue
+	    }
+	    -re "^(\[0-9\]+):\[ \t\]+(\[^\r\n\]+)\r\n" {
+		set lineno $expect_out(1,string)
+		set text $expect_out(2,string)
+		if { $current_module == "" } {
+		    fail "$testname (missing module)"
+		    return 0
+		}
+		if { $current_file == "" } {
+		    fail "$testname (missing filename)"
+		    return 0
+		}
+		_add_entry $current_file $current_module \
+		    $lineno $text
+		exp_continue
+	    }
+	    -re "^\[ \t\]+(\[^\r\n\]+)\r\n" {
+		set lineno "NONE"
+		set text $expect_out(1,string)
+		if { $current_module == "" } {
+		    fail "$testname (missing module)"
+		    return 0
+		}
+		if { $current_file == "" } {
+		    fail "$testname (missing filename)"
+		    return 0
+		}
+		_add_entry $current_file $current_module \
+		    $lineno $text
+		exp_continue
+	    }
+	    -re "^\r\n" {
+		exp_continue
+	    }
+	    -re "^$gdb_prompt $" {
+		# All done.
+	    }
+	    timeout {
+		fail "$testname (timeout)"
+		return 0
+	    }
+	}
+
+	pass $testname
+	return 1
+    }
+
+    # Check that the header held in _header matches PATTERN.  Use
+    # TESTNAME as the name of the test, or create a suitable default
+    # test name based on the last command.
+    proc check_header { pattern { testname "" } } {
+	variable _header
+	variable _last_command
+
+	if { $testname == "" } {
+	    set testname "$_last_command: check header"
+	}
+
+	gdb_assert {[regexp -- $pattern $_header]} $testname
+    }
+
+    # Check that we have an entry in _entries matching FILENAME,
+    # MODULE, LINENO, and TEXT.  If LINENO is the empty string it is
+    # replaced with the string NONE in order to match a similarly
+    # missing line number in the output of the command.
+    #
+    # TESTNAME is the name of the test, or a default will be created
+    # based on the last command run and the arguments passed here.
+    #
+    # If a matching entry is found then it is removed from the
+    # _entries list, this allows us to check for duplicates using the
+    # check_no_entry call.
+    proc check_entry { filename module lineno text { testname "" } } {
+	variable _entries
+	variable _last_command
+
+	if { $testname == "" } {
+	    set testname \
+		"$_last_command: check for entry '$filename', '$lineno', '$text'"
+	}
+
+	if { $lineno == "" } {
+	    set lineno "NONE"
+	}
+
+	set new_entries [list]
+
+	set found_match 0
+	foreach entry $_entries {
+
+	    if {!$found_match} {
+		set f [lindex $entry 0]
+		set m [lindex $entry 1]
+		set l [lindex $entry 2]
+		set t [lindex $entry 3]
+		if { [regexp -- $filename $f] \
+			 && [regexp -- $module $m] \
+			 && [regexp -- $lineno $l] \
+			 && [regexp -- $text $t] } {
+		    set found_match 1
+		} else {
+		    lappend new_entries $entry
+		}
+	    } else {
+		lappend new_entries $entry
+	    }
+	}
+
+	set _entries $new_entries
+
+	if { $found_match } {
+	    pass $testname
+	} else {
+	    fail $testname
+	}
+    }
+
+    # Check that there is no entry in the _entries list matching
+    # FILENAME, MODULE, LINENO, and TEXT.  The LINENO and TEXT are
+    # optional, and will be replaced with '.*' is missing.
+    #
+    # If LINENO is the empty string then it will be replaced with the
+    # string NONE in order to match against missing line numbers in
+    # the output of the command.
+    #
+    # TESTNAME is the name of the test, or a default will be built
+    # from the last command run and the arguments passed here.
+    #
+    # This can be used after a call to check_entry to ensure that
+    # there are no further matches for a particular file in the
+    # output.
+    proc check_no_entry { filename module { lineno ".*" } \
+			      { text ".*" } { testname "" } } {
+	variable _entries
+	variable _last_command
+
+	if { $testname == "" } {
+	    set testname \
+		"$_last_command: check no matches for '$filename', $lineno', and '$text'"
+	}
+
+	if { $lineno == "" } {
+	    set lineno "NONE"
+	}
+
+	foreach entry $_entries {
+	    set f [lindex $entry 0]
+	    set m [lindex $entry 1]
+	    set l [lindex $entry 2]
+	    set t [lindex $entry 3]
+	    if { [regexp -- $filename $f] \
+		     && [regexp -- $module $m] \
+		     && [regexp -- $lineno $l] \
+		     && [regexp -- $text $t] } {
+		fail $testname
+	    }
+	}
+
+	pass $testname
+    }
+}
-- 
2.14.5

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 0/3] Testsuite Fixes For GCC 8/9
@ 2019-12-04 11:41 Andrew Burgess
  2019-12-04 11:41 ` [PATCH 2/3] gdb/testsuite: kfail some tests if using broken gcc Andrew Burgess
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Andrew Burgess @ 2019-12-04 11:41 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

Some of the tests I have been adding or working on recently work fine
using GCC 7.x.x compilers, which is the default on my machine, but
fail when using GCC 8 or 9 due to slightly different output.

This small series addresses some recent issues I've introduced.

--

Andrew Burgess (3):
  gdb/testsuite/fortran: Fix info-modules/info-types for gfortran 8+
  gdb/testsuite: kfail some tests if using broken gcc
  gdb/fortran: Improve output pattern in gdb.mi/mi-fortran-modules.exp

 gdb/testsuite/ChangeLog                            |  17 +
 .../gdb.fortran/derived-type-striding.exp          |   6 +
 gdb/testsuite/gdb.fortran/info-modules.exp         | 261 +++++------
 gdb/testsuite/gdb.fortran/info-types.exp           |  13 +
 gdb/testsuite/gdb.mi/mi-fortran-modules.exp        |   6 +-
 gdb/testsuite/lib/sym-info-cmds.exp                | 517 +++++++++++++++++++++
 6 files changed, 679 insertions(+), 141 deletions(-)
 create mode 100644 gdb/testsuite/lib/sym-info-cmds.exp

-- 
2.14.5

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/3] gdb/fortran: Improve output pattern in gdb.mi/mi-fortran-modules.exp
  2019-12-04 11:41 [PATCH 0/3] Testsuite Fixes For GCC 8/9 Andrew Burgess
  2019-12-04 11:41 ` [PATCH 2/3] gdb/testsuite: kfail some tests if using broken gcc Andrew Burgess
@ 2019-12-04 11:41 ` Andrew Burgess
  2019-12-06 19:49   ` Pedro Alves
  2019-12-04 11:41 ` [PATCH 1/3] gdb/testsuite/fortran: Fix info-modules/info-types for gfortran 8+ Andrew Burgess
  2 siblings, 1 reply; 7+ messages in thread
From: Andrew Burgess @ 2019-12-04 11:41 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

Extend the output pattern in mi-fortran-modules.exp to skip some
system modules that appear with versions of GFortran after 7.x.x.

gdb/testsuite/ChangeLog:

	* gdb.mi/mi-fortran-modules.exp: Add pattern to skip system
	modules.

Change-Id: I64aaa395e554a32e8267ffa096faee53c19c0b9e
---
 gdb/testsuite/ChangeLog                     | 5 +++++
 gdb/testsuite/gdb.mi/mi-fortran-modules.exp | 6 +++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/gdb.mi/mi-fortran-modules.exp b/gdb/testsuite/gdb.mi/mi-fortran-modules.exp
index 640bb12642d..eec2fe75da8 100644
--- a/gdb/testsuite/gdb.mi/mi-fortran-modules.exp
+++ b/gdb/testsuite/gdb.mi/mi-fortran-modules.exp
@@ -33,8 +33,12 @@ if {[mi_gdb_start]} {
 
 mi_run_to_main
 
+
+# Pattern to skip optional system modules that appear with later versions of GFortran.
+set system_modules_pattern "\{filename=\"\[^\"\]+/ieee/\[^/\]+\.F90\",fullname=\"\[^\"\]+\",symbols=\\\[(\[^\]\]+)\\\]\},"
+
 mi_gdb_test "101-symbol-info-modules" \
-    "101\\^done,symbols=\{debug=\\\[\{filename=\"\[^\"\]+$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"16\",name=\"mod1\"\},\{line=\"27\",name=\"mod2\"\}\\\]\},\{filename=\"\[^\"\]+$srcfile\",fullname=\"\[^\"\]+$srcfile\",symbols=\\\[\{line=\"16\",name=\"mod3\"\},\{line=\"32\",name=\"modmany\"\},\{line=\"41\",name=\"moduse\"\}\\\]\}\\\]\}" \
+    "101\\^done,symbols=\{debug=\\\[($system_modules_pattern)*\{filename=\"\[^\"\]+$srcfile2\",fullname=\"\[^\"\]+$srcfile2\",symbols=\\\[\{line=\"16\",name=\"mod1\"\},\{line=\"27\",name=\"mod2\"\}\\\]\},\{filename=\"\[^\"\]+$srcfile\",fullname=\"\[^\"\]+$srcfile\",symbols=\\\[\{line=\"16\",name=\"mod3\"\},\{line=\"32\",name=\"modmany\"\},\{line=\"41\",name=\"moduse\"\}\\\]\}\\\]\}" \
     "-symbol-info-modules"
 
 mi_gdb_test "102-symbol-info-modules --name mod\[123\]" \
-- 
2.14.5

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] gdb/testsuite/fortran: Fix info-modules/info-types for gfortran 8+
  2019-12-04 11:41 ` [PATCH 1/3] gdb/testsuite/fortran: Fix info-modules/info-types for gfortran 8+ Andrew Burgess
@ 2019-12-06 19:46   ` Pedro Alves
  0 siblings, 0 replies; 7+ messages in thread
From: Pedro Alves @ 2019-12-06 19:46 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On 12/4/19 11:41 AM, Andrew Burgess wrote:

> Rather than building increasingly complex patterns that would always
> be at risk of breaking with future versions of GCC I have instead
> added a new library that parses the output of the following commands:
> 
>   info types
>   info variables
>   info functions
>   info modules
>   info module functions
>   info module variables
> 
> into a data structure, the test can than run checks against the
> contents of this data structure.

Looks like a good idea to me.

The patch LGTM.  Minor nits below.

> +	set _entries $new_entries
> +
> +	if { $found_match } {
> +	    pass $testname
> +	} else {
> +	    fail $testname
> +	}

Could be gdb_assert.

> +    }
> +
> +    # Check that there is no entry in the _entries list matching
> +    # FILENAME, MODULE, LINENO, and TEXT.  The LINENO and TEXT are
> +    # optional, and will be replaced with '.*' is missing.

Did you mean s/is missing/if missing/ ?  (likewise in the other
instances of this text.)

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] gdb/testsuite: kfail some tests if using broken gcc
  2019-12-04 11:41 ` [PATCH 2/3] gdb/testsuite: kfail some tests if using broken gcc Andrew Burgess
@ 2019-12-06 19:47   ` Pedro Alves
  0 siblings, 0 replies; 7+ messages in thread
From: Pedro Alves @ 2019-12-06 19:47 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On 12/4/19 11:41 AM, Andrew Burgess wrote:
> In some cases the Fortran stride information generated by GCC is wrong
> with versions of GCC after 7.x.x.  This commit adds kfails for the
> tests in question with known bad versions of gcc.
> 
> The bug has been reported to GCC here:
> 
>   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92775
> 
> gdb/testsuite/ChangeLog:
> 
> 	* gdb.fortran/derived-type-striding.exp: KFAIL if we are using a
> 	broken version of GCC.
OK.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] gdb/fortran: Improve output pattern in gdb.mi/mi-fortran-modules.exp
  2019-12-04 11:41 ` [PATCH 3/3] gdb/fortran: Improve output pattern in gdb.mi/mi-fortran-modules.exp Andrew Burgess
@ 2019-12-06 19:49   ` Pedro Alves
  0 siblings, 0 replies; 7+ messages in thread
From: Pedro Alves @ 2019-12-06 19:49 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On 12/4/19 11:41 AM, Andrew Burgess wrote:
> Extend the output pattern in mi-fortran-modules.exp to skip some
> system modules that appear with versions of GFortran after 7.x.x.
> 
> gdb/testsuite/ChangeLog:
> 
> 	* gdb.mi/mi-fortran-modules.exp: Add pattern to skip system
> 	modules.

OK.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-12-06 19:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-04 11:41 [PATCH 0/3] Testsuite Fixes For GCC 8/9 Andrew Burgess
2019-12-04 11:41 ` [PATCH 2/3] gdb/testsuite: kfail some tests if using broken gcc Andrew Burgess
2019-12-06 19:47   ` Pedro Alves
2019-12-04 11:41 ` [PATCH 3/3] gdb/fortran: Improve output pattern in gdb.mi/mi-fortran-modules.exp Andrew Burgess
2019-12-06 19:49   ` Pedro Alves
2019-12-04 11:41 ` [PATCH 1/3] gdb/testsuite/fortran: Fix info-modules/info-types for gfortran 8+ Andrew Burgess
2019-12-06 19:46   ` Pedro Alves

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).