Files
binutils-gdb/gdb/testsuite/gdb.base/dprintf-execution-x-script.exp
Andrew Burgess 25902bd0ba gdb/testsuite: make more use of clean_restart's argument
Commits:

  commit aaad5a3254
  Author: Tom de Vries <tdevries@suse.de>
  Date:   Fri Sep 5 15:36:23 2025 +0200

      [gdb/testsuite] Fix clean_restart <absolute filename> in gdb.base, part 3

  commit 2e61486fce
  Author: Tom de Vries <tdevries@suse.de>
  Date:   Fri Sep 5 15:36:23 2025 +0200

      [gdb/testsuite] Fix clean_restart <absolute filename> in gdb.base, part 2

  commit 202beb3fee
  Author: Tom de Vries <tdevries@suse.de>
  Date:   Fri Sep 5 15:36:23 2025 +0200

      [gdb/testsuite] Fix clean_restart <absolute filename> in gdb.base, part 1

were made to work around the changes to clean_restart in commit:

  commit cba778b944
  Date:   Sun Sep 7 11:53:30 2025 +0200

      [gdb/testsuite] Error out on clean_restart <absolute filename>

These commits added a lot of calls to gdb_load which can be removed in
many cases by passing $testfile to clean_restart, or by switching to
use prepare_for_testing to compile the test executable.

In this commit I've gone through the gdb.base/ directory and removed
as many of the gdb_load calls as possible.  I was only looking for
places where the gdb_load call immediately follows the call to
clean_restart.  And I did skip a few where it was not as simple as
just passing $testfile.

Where possible I've updated tests to use calls to prepare_for_testing,
and simply removed the clean_restart call altogether (this is done as
part of prepare_for_testing).  This is, I think, the best solution.

In other cases I've removed the gdb_load call, and passed $testfile to
clean_restart.  I've preferred $::testfile to adding a 'global'
declaration, and in some cases switching to testfile has allowed me to
remove the 'global binfile' as an additional cleanup.

I ran the complete set of tests that I touched and I didn't see any
regressions, so I don't believe I broke anything.

I know that there are probably gdb_load calls that can be cleaned up
in other testsuite sub-directories, if/when this patch is merged I'll
take a look at those too.

Reviewed-By: Tom de Vries <tdevries@suse.de>
2025-12-01 14:00:47 +00:00

104 lines
4.0 KiB
Plaintext

# Copyright 2021-2025 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/>. */
# Test that commands in a GDB script file run via GDB's -x flag work
# as expected. Specifically, the script creates a dprintf breakpoint
# as well as a normal breakpoint that has "continue" in its command
# list, and then does "run". Correct output from GDB is checked as
# part of this test.
# Bail out if the target can't use the 'run' command.
require target_can_use_run_cmd
standard_testfile
if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
return -1
}
# This is the name of the GDB script to load.
set x_file ${srcdir}/${subdir}/$testfile.gdb
# Create context in which the global, GDBFLAGS, will be restored at
# the end of the block. All commands run within the block are
# actually run in the outer context. (This is why 'res' is available
# outside of the save_vars block.)
save_vars { GDBFLAGS } {
# Set flags with which to start GDB.
append GDBFLAGS " -x \"$x_file\""
append GDBFLAGS " --args \"$binfile\""
# Start GDB with above flags.
set res [gdb_spawn]
}
set test "load and run script with -x"
if { $res != 0} {
fail $test
return -1
}
# The script loaded via -x contains a run command; while running, GDB
# is expected to print three messages from dprintf breakpoints along
# with three interspersed messages from an ordinary breakpoint (which
# was set up with a continue command). Set up pattern D to match
# output from hitting the dprintf breakpoint and B for the ordinary
# breakpoint. Then set PAT to contain the entire pattern of expected
# output from the interspersed dprintf and ordinary breakpoints along
# with some (additional) expected output from the dprintf breakpoints,
# i.e. 0, 1, and 2.
set d "dprintf in increment.., vi="
set b "Breakpoint ., inc_vi"
set pat "${d}0.*?$b.*?${d}1.*?$b.*?${d}2.*?$b.*?"
proc do_test {cmd test} {
gdb_test_multiple $cmd $test {
-re "$::pat$::inferior_exited_re normally.*$::gdb_prompt $" {
pass $test
}
-re "Don't know how to run.*$::gdb_prompt $" {
# Even though we bailed out at the beginning of this test case
# for targets which can't use the "run" command, there are
# still targets, e.g. native-extended-gdbserver, which can
# run, but will still print the "Don't know how to run"
# message. In the case of native-extended-gdbserver, it would
# first need to connect to the target in order to run. For
# that particular target, the very first test which attempts
# to use the "run" command from a command line script is
# the one that is unsupported. The other two tests will
# pass because, after reaching the (gdb) prompt, a gdbserver
# is spawned and then connected to. (The command line which
# spawns GDB for this target has a "-iex set
# auto-connect-native-target off" which prevents it from
# attempting to "run" using the native target.)
unsupported $test
}
}
}
# Check output from running script with -x
do_test "" $test
# Restart GDB and 'source' the script; this will (still) run the program
# due to the 'run' command in the script.
clean_restart $testfile
do_test "source $x_file" "load and run script using source command"
# This should leave us at the gdb prompt; Run program again using
# already established breakpoints, i.e. those loaded from the
# script. Prior to fixing PR 28308, this was the only test that
# would pass.
do_test "run" "run again"