public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [pushed 1/3] [gdb/testsuite] Set completions to unlimited in get_set_option_choices
@ 2022-11-14 11:13 Tom de Vries
  2022-11-14 11:13 ` [pushed 2/3] [gdb/testsuite] Handle with_set arch Tom de Vries
  2022-11-14 11:13 ` [pushed 3/3] [gdb/testsuite] Run gdb.arch/ppc64-symtab-cordic.exp for --enable-targets=all Tom de Vries
  0 siblings, 2 replies; 3+ messages in thread
From: Tom de Vries @ 2022-11-14 11:13 UTC (permalink / raw)
  To: gdb-patches

In some test-case I tried to use get_set_option_choices "set architecture" and
ran into max-completions:
...
set architecture simple^M
set architecture tomcat^M
set architecture xscale^M
set architecture  *** List may be truncated, max-completions reached. ***^M
(gdb) PASS: gdb.base/foo.exp: complete set architecture
...

There's only one test-case using this currently: gdb.base/parse_number.exp,
and it locally sets max-completions to unlimited.

Fix this by:
- factoring out a new proc with_set out of proc with_complaints, and
- using it to temporarily set max-completions to unlimited in
  get_set_option_choice.

Tested on x86_64-linux, by running test-cases that excercise
get_set_option_choice and with_complaints.
---
 gdb/testsuite/gdb.base/parse_number.exp | 10 ++---
 gdb/testsuite/lib/gdb.exp               | 54 ++++++++++++++-----------
 2 files changed, 35 insertions(+), 29 deletions(-)

diff --git a/gdb/testsuite/gdb.base/parse_number.exp b/gdb/testsuite/gdb.base/parse_number.exp
index 70b0ad065d7..06bf1cd1714 100644
--- a/gdb/testsuite/gdb.base/parse_number.exp
+++ b/gdb/testsuite/gdb.base/parse_number.exp
@@ -346,18 +346,16 @@ proc test_parse_numbers {arch} {
 
 clean_restart
 
-gdb_test_no_output "set language unknown"
-gdb_test "p/x 0" \
-	"expression parsing not implemented for language \"Unknown\""
-
-gdb_test_no_output "set max-completions unlimited"
-
 set supported_archs [get_set_option_choices "set architecture"]
 # There should be at least one more than "auto".
 gdb_assert {[llength $supported_archs] > 1} "at least one architecture"
 
 set all_languages [get_set_option_choices "set language"]
 
+gdb_test_no_output "set language unknown"
+gdb_test "p/x 0" \
+	"expression parsing not implemented for language \"Unknown\""
+
 # If 1, test each arch.  If 0, test one arch for each sizeof
 # short/int/long/longlong configuration.
 # For a build with --enable-targets=all, full_arch_testing == 0 takes 15s,
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 1240c2ef6f3..40a7c7728d1 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -5911,34 +5911,31 @@ proc gdb_load { arg } {
 }
 
 #
-# with_complaints -- Execute BODY and set complaints temporary to N for the
+# with_set -- Execute BODY and set VAR temporary to VAL for the
 # duration.
 #
-proc with_complaints { n body } {
-    global decimal
-
-    # Save current setting of complaints.
+proc with_set { var val body } {
     set save ""
-    set show_complaints_re \
-	"Max number of complaints about incorrect symbols is ($decimal)\\."
-    gdb_test_multiple "show complaints" "" {
-	-re -wrap $show_complaints_re {
+    set show_re \
+	"is (\[^\r\n\]+)\\."
+    gdb_test_multiple "show $var" "" {
+	-re -wrap $show_re {
 	    set save $expect_out(1,string)
 	}
     }
 
     if { $save == "" } {
-	perror "Did not manage to set complaints"
+	perror "Did not manage to set $var"
     } else {
-	# Set complaints.
-	gdb_test_no_output -nopass "set complaints $n"
+	# Set var.
+	gdb_test_no_output -nopass "set $var $val"
     }
 
     set code [catch {uplevel 1 $body} result]
 
-    # Restore saved setting of complaints.
+    # Restore saved setting.
     if { $save != "" } {
-	gdb_test_no_output -nopass "set complaints $save"
+	gdb_test_no_output -nopass "set $var $save"
     }
 
     if {$code == 1} {
@@ -5949,6 +5946,14 @@ proc with_complaints { n body } {
     }
 }
 
+#
+# with_complaints -- Execute BODY and set complaints temporary to N for the
+# duration.
+#
+proc with_complaints { n body } {
+    return [uplevel [list with_set complaints $n $body]]
+}
+
 #
 # gdb_load_no_complaints -- As gdb_load, but in addition verifies that
 # loading caused no symbol reading complaints.
@@ -9108,20 +9113,23 @@ gdb_caching_proc has_hw_wp_support {
 # Return a list of all the accepted values of the set command SET_CMD.
 
 proc get_set_option_choices {set_cmd} {
-    global gdb_prompt
-
     set values {}
 
+    set cmd "complete $set_cmd "
     set test "complete $set_cmd"
-    gdb_test_multiple "complete $set_cmd " "$test" {
-	-re "$set_cmd (\[^\r\n\]+)\r\n" {
-	    lappend values $expect_out(1,string)
-	    exp_continue
-	}
-	-re "$gdb_prompt " {
-	    pass $test
+
+    with_set max-completions unlimited {
+	gdb_test_multiple $cmd $test {
+	    -re "\r\n$set_cmd (\[^\r\n\]+)" {
+		lappend values $expect_out(1,string)
+		exp_continue
+	    }
+	    -re -wrap "" {
+		pass $gdb_test_name
+	    }
 	}
     }
+
     return $values
 }
 

base-commit: fadfefbf159291a685c9849ebf597c1d4d7f75dc
-- 
2.35.3


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

* [pushed 2/3] [gdb/testsuite] Handle with_set arch
  2022-11-14 11:13 [pushed 1/3] [gdb/testsuite] Set completions to unlimited in get_set_option_choices Tom de Vries
@ 2022-11-14 11:13 ` Tom de Vries
  2022-11-14 11:13 ` [pushed 3/3] [gdb/testsuite] Run gdb.arch/ppc64-symtab-cordic.exp for --enable-targets=all Tom de Vries
  1 sibling, 0 replies; 3+ messages in thread
From: Tom de Vries @ 2022-11-14 11:13 UTC (permalink / raw)
  To: gdb-patches

I realized that the more irregular output of show arch:
...
(gdb) show arch^M
The target architecture is set to "auto" (currently "i386").^M
...
would be a problem for something like:
...
with_set arch powerpc:common64 {}
...
and indeed:
...
(gdb) set arch powerpc:common64^M
The target architecture is set to "powerpc:common64".^M
(gdb) FAIL: gdb.base/foo.exp: set arch powerpc:common64
...
and:
...
(gdb) set arch set to "auto" (currently "i386")^M
Undefined item: "set".^M
...

Fix this in with_set by handling this type of output.

Tested on x86_64-linux.
---
 gdb/testsuite/lib/gdb.exp | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 40a7c7728d1..bdb8da9daf9 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -5924,18 +5924,36 @@ proc with_set { var val body } {
 	}
     }
 
+    # Handle 'set to "auto" (currently "i386")'.
+    set save [regsub {^set to} $save ""]
+    set save [regsub {\([^\r\n]+\)$} $save ""]
+    set save [string trim $save]
+    set save [regsub -all {^"|"$} $save ""]
+
     if { $save == "" } {
 	perror "Did not manage to set $var"
     } else {
 	# Set var.
-	gdb_test_no_output -nopass "set $var $val"
+	set cmd "set $var $val"
+	gdb_test_multiple $cmd "" {
+	    -re -wrap "^$cmd" {
+	    }
+	    -re -wrap " is set to \"?$val\"?\\." {
+	    }
+	}
     }
 
     set code [catch {uplevel 1 $body} result]
 
     # Restore saved setting.
     if { $save != "" } {
-	gdb_test_no_output -nopass "set $var $save"
+	set cmd "set $var $save"
+	gdb_test_multiple $cmd "" {
+	    -re -wrap "^$cmd" {
+	    }
+	    -re -wrap "is set to \"?$save\"?( \\(\[^)\]*\\))?\\." {
+	    }
+	}
     }
 
     if {$code == 1} {
-- 
2.35.3


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

* [pushed 3/3] [gdb/testsuite] Run gdb.arch/ppc64-symtab-cordic.exp for --enable-targets=all
  2022-11-14 11:13 [pushed 1/3] [gdb/testsuite] Set completions to unlimited in get_set_option_choices Tom de Vries
  2022-11-14 11:13 ` [pushed 2/3] [gdb/testsuite] Handle with_set arch Tom de Vries
@ 2022-11-14 11:13 ` Tom de Vries
  1 sibling, 0 replies; 3+ messages in thread
From: Tom de Vries @ 2022-11-14 11:13 UTC (permalink / raw)
  To: gdb-patches

While looking at test-case gdb.arch/ppc64-symtab-cordic.exp I realized that
the test-case is too restrictive here:
...
if {![istarget "powerpc*"] || ![is_lp64_target]} {
    verbose "Skipping powerpc64 separate debug file symtab test."
    return
}
...
and can also be run on x86_64-linux, if "set arch powerpc:common64" is
supported, which is the case if we've build gdb with --enable-targets=all.

Fix this by instead checking if powerpc:common64 is in the completion list for
"set arch".

This allows us to remove the 'untested "powerpc:common64 is not supported"'.

While we're at it, clean up the test-case by using clean_restart.

Tested on x86_64-linux.
---
 gdb/testsuite/gdb.arch/ppc64-symtab-cordic.exp | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/gdb/testsuite/gdb.arch/ppc64-symtab-cordic.exp b/gdb/testsuite/gdb.arch/ppc64-symtab-cordic.exp
index 9d02da739d6..5d2e1255d45 100644
--- a/gdb/testsuite/gdb.arch/ppc64-symtab-cordic.exp
+++ b/gdb/testsuite/gdb.arch/ppc64-symtab-cordic.exp
@@ -13,7 +13,10 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-if {![istarget "powerpc*"] || ![is_lp64_target]} {
+clean_restart
+
+set supported_archs [get_set_option_choices "set architecture"]
+if { [lsearch -exact $supported_archs "powerpc:common64"] == -1 } {
     verbose "Skipping powerpc64 separate debug file symtab test."
     return
 }
@@ -34,10 +37,6 @@ if {[catch "system \"bzip2 -dc ${kodebugbz2file} >${kodebugfile}\""] != 0} {
     return -1
 }
 
-gdb_exit
-gdb_start
-gdb_reinitialize_dir $srcdir/$subdir
-
 # This test won't work properly if system debuginfo is installed.
 # Test message is suppressed by "" as otherwise we could print PASS+UNTESTED
 # result to gdb.sum making a false feeling the issue has been tested.
@@ -50,7 +49,4 @@ gdb_test_multiple $test $test {
     -re "\r\nThe target architecture is set to \"auto\" \\(currently \"powerpc:common64\"\\)\.\r\n$gdb_prompt $" {
 	pass $test
     }
-    -re "\r\nThe target architecture is set to \"auto\" \\(currently \".*\"\\)\.\r\n$gdb_prompt $" {
-	untested "powerpc:common64 is not supported"
-    }
 }
-- 
2.35.3


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

end of thread, other threads:[~2022-11-14 11:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-14 11:13 [pushed 1/3] [gdb/testsuite] Set completions to unlimited in get_set_option_choices Tom de Vries
2022-11-14 11:13 ` [pushed 2/3] [gdb/testsuite] Handle with_set arch Tom de Vries
2022-11-14 11:13 ` [pushed 3/3] [gdb/testsuite] Run gdb.arch/ppc64-symtab-cordic.exp for --enable-targets=all Tom de Vries

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