Files
binutils-gdb/gdb/testsuite/gdb.base/info_sources_2.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

191 lines
5.6 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 'info sources' when the test file makes use of a shared
# library.
require allow_shlib_tests
set is_remote_target [is_remote target]
standard_testfile -test.c -lib.c
set solib_name [standard_output_file ${testfile}-lib.so]
if { [build_executable "build shlib" $solib_name $srcfile2 {debug shlib}] != 0 } {
return
}
if { [prepare_for_testing "prepare" $testfile $srcfile \
[list debug shlib=${solib_name} ]] != 0} {
return
}
set solib_name [gdb_load_shlib $solib_name]
if {![runto foo]} {
untested "failed to run to function foo"
return -1
}
# Invoke 'info sources EXTRA_ARGS' and extract the results.
# The results are then compared to the list ARGS.
#
# The list ARGS should consist of pairs of values, the first item being the
# path to an object file, and the second item being the name of a source file.
# This proc checks that source file was listed as being a source file for the
# given object file.
#
# If the name of the source file starts with the character "!" (exclamation
# character, without the quotes) then the check is inverted, that the source
# file is NOT listed for the given object file.
proc run_info_sources { extra_args args } {
global gdb_prompt srcdir subdir
global is_remote_target
with_test_prefix "args: ${extra_args}" {
# The results of running info sources will be placed into this local.
array set info_sources {}
# The command we are going to run.
set cmd "info sources ${extra_args}"
set command_regex [string_to_regexp $cmd]
# Run the command and extract the results into INFO_SOURCES.
set objfile_name ""
set source_files {}
set files {}
# Note below we sanitize paths so we can compare against the
# host_file_normalize'd paths later. Note we sanitize, but
# don't normalize here, as the latter would turn a relative
# path into an absolute path, and this testcase wants to make
# sure that GDB prints the absolute path.
gdb_test_multiple $cmd "" {
-re "${command_regex}\r\n" {
exp_continue
}
-re "^(\[^\r\n\]+):\r\n" {
set objfile_name [host_file_sanitize $expect_out(1,string)]
if { $is_remote_target } {
set objfile_name [file tail $objfile_name]
}
exp_continue
}
-re "^\\(Full debug information has not yet been read for this file\\.\\)\r\n" {
exp_continue
}
-re "^\\(Objfile has no debug information\\.\\)\r\n" {
exp_continue
}
-re "^\r\n" {
exp_continue
}
-re "^$gdb_prompt $" {
pass $gdb_test_name
}
-re "^(\[^,\r\n\]+), " {
set f [host_file_sanitize $expect_out(1,string)]
lappend files $f
exp_continue
}
-re "^(\[^\r\n\]+)\r\n" {
if { $objfile_name == "" } {
fail "${gdb_test_name} (no objfile name)"
return
}
set f [host_file_sanitize $expect_out(1,string)]
lappend files $f
set info_sources($objfile_name) $files
set $objfile_name ""
set files {}
exp_continue
}
}
# Now check ARGS against the values held in INFO_SOURCES map.
foreach {objfile sourcefile} $args {
# First, figure out if we're expecting SOURCEFILE to be present,
# or not.
set present True
set match_type "is"
if {[string index $sourcefile 0] == "!"} {
set present False
set match_type "is not"
set sourcefile [string range $sourcefile 1 end]
}
# Figure out the path for SOURCEFILE that we're looking for.
set sourcepath [host_file_normalize ${srcdir}/${subdir}/${sourcefile}]
if { $is_remote_target } {
set objfile [file tail $objfile]
}
# Make sure we handle the case where there are no source files
# associated with a particular objfile.
set source_list {}
if {[info exists info_sources($objfile)]} {
set source_list $info_sources($objfile)
}
# Now perform the search, and check the results.
set idx [lsearch -exact $source_list $sourcepath]
gdb_assert {($present && $idx >= 0) || (!$present && $idx == -1)} \
"source file '$sourcefile' ${match_type} present for '[file tail $objfile]'"
}
}
}
# The actual tests.
set host_binfile [host_file_normalize $binfile$EXEEXT]
run_info_sources "" \
${host_binfile} ${srcfile} \
${host_binfile} ${testfile}-header.h \
${solib_name} ${srcfile2} \
${solib_name} ${testfile}-header.h
run_info_sources "-basename info_sources_2" \
${host_binfile} ${srcfile} \
${host_binfile} ${testfile}-header.h \
${solib_name} ${srcfile2} \
${solib_name} ${testfile}-header.h
run_info_sources "-basename \\.c" \
${host_binfile} ${srcfile} \
${host_binfile} !${testfile}-header.h \
${solib_name} ${srcfile2} \
${solib_name} !${testfile}-header.h
run_info_sources "-basename -- -test\\.c" \
${host_binfile} ${srcfile} \
${host_binfile} !${testfile}-header.h \
${solib_name} !${srcfile2} \
${solib_name} !${testfile}-header.h
run_info_sources "-basename -- -lib\\.c" \
${host_binfile} !${srcfile} \
${host_binfile} !${testfile}-header.h \
${solib_name} ${srcfile2} \
${solib_name} !${testfile}-header.h