binutils-gdb/gdb/testsuite/lib/gdb-guile.exp
Pedro Alves cce0ae568c gdb: Fix DUPLICATE and PATH regressions throughout
The previous patch to add -prompt/-lbl to gdb_test introduced a
regression: Before, you could specify an explicit empty message to
indicate you didn't want to PASS, like so:

  gdb_test COMMAND PATTERN ""

After said patch, gdb_test no longer distinguishes
no-message-specified vs empty-message, so tests that previously would
be silent on PASS, now started emitting PASS messages based on
COMMAND.  This in turn introduced a number of PATH/DUPLICATE
violations in the testsuite.

This commit fixes all the regressions I could see.

This patch uses the new -nopass feature introduced in the previous
commit, but tries to avoid it if possible.  Most of the patch fixes
DUPLICATE issues the usual way, of using with_test_prefix or explicit
unique messages.

See previous commit's log for more info.

In addition to looking for DUPLICATEs, I also looked for cases where
we would now end up with an empty message in gdb.sum, due to a
gdb_test being passed both no message and empty command.  E.g., this
in gdb.ada/bp_reset.exp:

 gdb_run_cmd
 gdb_test "" "Breakpoint $decimal, foo\\.nested_sub \\(\\).*"

was resulting in this in gdb.sum:

 PASS: gdb.ada/bp_reset.exp:

I fixed such cases by passing an explicit message.  We may want to
make such cases error out.

Tested on x86_64 GNU/Linux, native and native-extended-gdbserver.  I
see zero PATH cases now.  I get zero DUPLICATEs with native testing
now.  I still see some DUPLICATEs with native-extended-gdbserver, but
those were preexisting, unrelated to the gdb_test change.

Change-Id: I5375f23f073493e0672190a0ec2e847938a580b2
2022-05-25 13:44:12 +01:00

110 lines
3.5 KiB
Plaintext

# Copyright 2010-2022 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/>.
# Utilities for Guile-scripting related tests.
# Guile doesn't print the 0x prefix on hex numbers.
set ghex {[0-9a-f]+}
# Return a 1 for configurations that do not support Guile scripting.
proc skip_guile_tests {} {
global gdb_prompt
gdb_test_multiple "guile (display \"test\\n\")" "verify guile support" {
-re "Undefined command.*$gdb_prompt $" {
unsupported "Guile not supported."
return 1
}
-re "not supported.*$gdb_prompt $" {
unsupported "Guile support is disabled."
return 1
}
-re "$gdb_prompt $" {}
}
return 0
}
# Run a command in GDB, and report a failure if a Scheme exception is thrown.
# If report_pass is true, report a pass if no exception is thrown.
# This also catches the "Undefined command" error that happens if the user
# passes, e.g., "(print foo)" instead of "guile (print foo)".
proc gdb_scm_test_silent_cmd { cmd name {report_pass 1} } {
global gdb_prompt
gdb_test_multiple $cmd $name {
-re "Backtrace.*$gdb_prompt $" { fail $name }
-re "ERROR.*$gdb_prompt $" { fail $name }
-re "Undefined command: .*$gdb_prompt $" { fail $name }
-re "$gdb_prompt $" { if $report_pass { pass $name } }
}
}
# Load Scheme file FILE_NAME.
# TEST_NAME can be used to specify the name of the test,
# otherwise a standard test name is provided.
#
# Note: When Guile loads something and auto-compilation is enabled
# (which is useful and the default), then the first time a file is loaded
# Guile will compile the file and store the result somewhere
# (e.g., $HOME/.cache/guile). Output of the compilation process will
# appear in gdb.log. But since Guile only does this when necessary
# don't be confused if you don't always see it - Guile just skipped it
# because it thought it was unnecessary.
proc gdb_scm_load_file { file_name {test_name ""} } {
if { $test_name == "" } {
set test_name "guile (load \"[file tail $file_name]\")"
}
# Note: This can produce output if Guile compiles the file.
gdb_scm_test_silent_cmd "guile (load \"$file_name\")" $test_name
}
# Install various utilities in Guile to simplify tests.
#
# print - combination of display + newline
proc gdb_install_guile_utils { } {
# Define utilities in Guile to save needing (newline) all the time,
# and in the case of "print" add a prefix to help erroneous passes.
#
gdb_test_no_output -nopass \
"guile (define (print x) (format #t \"= ~A\" x) (newline))"
gdb_test_no_output -nopass \
"guile (define (raw-print x) (format #t \"= ~S\" x) (newline))"
}
# Install the gdb module.
proc gdb_install_guile_module { } {
gdb_test_no_output -nopass "guile (use-modules (gdb))"
}
# Wrapper around runto_main that installs the guile utils and module.
# The result is the same as for runto_main.
proc gdb_guile_runto_main { } {
if ![runto_main] {
return 0
}
gdb_install_guile_utils
gdb_install_guile_module
return 1
}