gdb/testsuite: remove global gcc_compiled from gdb.exp

After this commit the gcc_compiled global is no longer exported from
lib/gdb.exp.  In theory we could switch over all uses of gcc_compiled
to instead call test_compiler_info directly, however, I have instead
added a new proc to gdb.exp: 'is_c_compiler_gcc'.  I've then updated
the testsuite to call this proc instead of using the global.

Having a new proc specifically for this task means that we have a
single consistent pattern for detecting gcc.  By wrapping this logic
within a proc that calls test_compiler_info, rather than using the
global, means that test scripts don't need to call get_compiler_info
before they read the global, simply calling the new proc does
everything in one go.

As a result I've been able to remove the get_compiler_info calls from
all the test scripts that I've touched in this commit.

In some of the tests e.g. gdb.dwarf2/*.exp, the $gcc_compiled flag was
being checked at the top of the script to decide if the whole script
should be skipped or not.  In these cases I've called the new proc
directly and removed all uses of gcc_compiled.

In other cases, e.g. most of the gdb.base scripts, there were many
uses of gcc_compiled.  In these cases I set a new global gcc_compiled
near the top of the script, and leave the rest of the script
unchanged.

There should be no changes in what is tested after this commit.
This commit is contained in:
Andrew Burgess
2022-06-09 15:21:37 +01:00
parent e83907ff5f
commit ef7a6b977b
37 changed files with 54 additions and 177 deletions

View File

@ -20,6 +20,9 @@ if [skip_ctf_tests] {
return 0 return 0
} }
# Some tests require GCC.
set gcc_compiled [is_c_compiler_gcc]
standard_testfile .c standard_testfile .c
# Using `-gctf` generates full-fledged CTF debug information. # Using `-gctf` generates full-fledged CTF debug information.
@ -30,12 +33,6 @@ if { [prepare_for_testing "failed to prepare" ${testfile} \
return 0 return 0
} }
# Create and source the file that provides information about the compiler
# used to compile the test case.
if [get_compiler_info] {
return -1
}
# Test ptype of unnamed enumeration members before any action causes # Test ptype of unnamed enumeration members before any action causes
# the partial symbol table to be expanded to full symbols. This fails # the partial symbol table to be expanded to full symbols. This fails
# with stabs compilers which fail to use a nameless stab (such as # with stabs compilers which fail to use a nameless stab (such as

View File

@ -18,17 +18,13 @@
standard_testfile standard_testfile
set gcc_compiled [is_c_compiler_gcc]
set compile_flags {debug nowarnings quiet} set compile_flags {debug nowarnings quiet}
if [support_complex_tests] { if [support_complex_tests] {
lappend compile_flags "additional_flags=-DTEST_COMPLEX" lappend compile_flags "additional_flags=-DTEST_COMPLEX"
} }
# Create and source the file that provides information about the compiler
# used to compile the test case.
if [get_compiler_info] {
return -1
}
set skip_float_test [gdb_skip_float_test] set skip_float_test [gdb_skip_float_test]
if {[prepare_for_testing "failed to prepare" $testfile $srcfile $compile_flags]} { if {[prepare_for_testing "failed to prepare" $testfile $srcfile $compile_flags]} {

View File

@ -30,11 +30,6 @@ set execsrc "${srcdir}/${subdir}/${srcfile}"
remote_exec build "rm -f ${binfile}" remote_exec build "rm -f ${binfile}"
# get the value of gcc_compiled
if [get_compiler_info] {
return -1
}
if { [gdb_compile_shlib $libsrc $libobj {debug}] != "" if { [gdb_compile_shlib $libsrc $libobj {debug}] != ""
|| [gdb_compile $execsrc ${binfile} executable \ || [gdb_compile $execsrc ${binfile} executable \
[list debug shlib=${libobj}]] != "" } { [list debug shlib=${libobj}]] != "" } {

View File

@ -30,13 +30,8 @@ if {[prepare_for_testing "failed to prepare" ${testfile} \
set oldtimeout $timeout set oldtimeout $timeout
set timeout 10 set timeout 10
# Some tests require GCC.
set gcc_compiled [is_c_compiler_gcc]
# Create and source the file that provides information about the compiler
# used to compile the test case.
if [get_compiler_info] {
return -1
}
gdb_test_multiple "b -qualified langs0" "break on nonexistent function in langs.exp" { gdb_test_multiple "b -qualified langs0" "break on nonexistent function in langs.exp" {
-re "Function \"langs0\" not defined\..*Make breakpoint pending on future shared library load.*y or .n.. $" { -re "Function \"langs0\" not defined\..*Make breakpoint pending on future shared library load.*y or .n.. $" {

View File

@ -13,12 +13,9 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
if [get_compiler_info] { if {![is_c_compiler_gcc]} {
return -1 unsupported "gcc compiler is required"
} return
if {$gcc_compiled == 0} {
return -1
} }
standard_testfile standard_testfile

View File

@ -15,15 +15,11 @@
# This file was written by Fred Fish. (fnf@cygnus.com) # This file was written by Fred Fish. (fnf@cygnus.com)
# Create and source the file that provides information about the compiler
# used to compile the test case.
if [get_compiler_info] {
return -1
}
standard_testfile opaque0.c opaque1.c standard_testfile opaque0.c opaque1.c
# Some tests require GCC.
set gcc_compiled [is_c_compiler_gcc]
if {[prepare_for_testing "failed to prepare" $testfile \ if {[prepare_for_testing "failed to prepare" $testfile \
[list $srcfile $srcfile2] debug]} { [list $srcfile $srcfile2] debug]} {
return -1 return -1

View File

@ -23,11 +23,8 @@ if { ![isnative] || [is_remote host] || [skip_shlib_tests]} {
return return
} }
if [get_compiler_info] { if {![is_c_compiler_gcc]} {
return -1 unsupported "gcc compiler is required"
}
if {$gcc_compiled == 0} {
return -1 return -1
} }

View File

@ -26,11 +26,8 @@ if {[prepare_for_testing "failed to prepare" ${testfile} \
return -1 return -1
} }
# Create and source the file that provides information about the compiler # Some tests require GCC.
# used to compile the test case. set gcc_compiled [is_c_compiler_gcc]
if [get_compiler_info] {
return -1
}
# Test ptype of unnamed enumeration members before any action causes # Test ptype of unnamed enumeration members before any action causes
# the partial symbol table to be expanded to full symbols. This fails # the partial symbol table to be expanded to full symbols. This fails

View File

@ -26,12 +26,6 @@
standard_testfile standard_testfile
# Create and source the file that provides information about the compiler
# used to compile the test case.
if [get_compiler_info] {
return -1
}
if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
return -1 return -1
} }
@ -395,7 +389,7 @@ set timeout $prev_timeout
# Test printing of enumeration bitfields. # Test printing of enumeration bitfields.
# GNU C supports them, some other compilers don't. # GNU C supports them, some other compilers don't.
if {$gcc_compiled} then { if {[is_c_compiler_gcc]} then {
gdb_test "print sef.field=sm1" ".*.\[0-9\]* = sm1" gdb_test "print sef.field=sm1" ".*.\[0-9\]* = sm1"
gdb_test "print sef.field" ".*.\[0-9\]* = sm1" "print sef.field (sm1)" gdb_test "print sef.field" ".*.\[0-9\]* = sm1" "print sef.field (sm1)"
gdb_test "print sef.field=s1" ".*.\[0-9\]* = s1" gdb_test "print sef.field=s1" ".*.\[0-9\]* = s1"

View File

@ -28,11 +28,6 @@ set execsrc "${srcdir}/${subdir}/${srcfile}"
remote_exec build "rm -f ${binfile}" remote_exec build "rm -f ${binfile}"
# get the value of gcc_compiled
if [get_compiler_info] {
return -1
}
if { [gdb_compile_shlib $libsrc $libobj {debug}] != "" if { [gdb_compile_shlib $libsrc $libobj {debug}] != ""
|| [gdb_compile $execsrc ${binfile} executable \ || [gdb_compile $execsrc ${binfile} executable \
[list debug shlib=${libobj}]] != "" } { [list debug shlib=${libobj}]] != "" } {

View File

@ -84,12 +84,8 @@ if {![dwarf2_support]} {
return 0 return 0
} }
if [get_compiler_info] {
return -1
}
# The DWARF assembler requires the gcc compiler. # The DWARF assembler requires the gcc compiler.
if {!$gcc_compiled} { if {![is_c_compiler_gcc]} {
unsupported "gcc is required for this test" unsupported "gcc is required for this test"
return 0 return 0
} }

View File

@ -25,6 +25,9 @@ if [target_info exists no_long_long] {
set exec_opts [list debug] set exec_opts [list debug]
} }
# Some tests require GCC.
set gcc_compiled [is_c_compiler_gcc]
standard_testfile .c standard_testfile .c
# Define a procedure to set up an xfail for all targets that put out a # Define a procedure to set up an xfail for all targets that put out a

View File

@ -24,6 +24,9 @@ if [target_info exists no_long_long] {
set exec_opts [list debug] set exec_opts [list debug]
} }
# Some tests require GCC.
set gcc_compiled [is_c_compiler_gcc]
standard_testfile whatis.c standard_testfile whatis.c
# Using `-gctf` generates full-fledged CTF debug information. # Using `-gctf` generates full-fledged CTF debug information.
@ -34,12 +37,6 @@ if { [prepare_for_testing "failed to prepare" ${testfile} \
return 0 return 0
} }
# Create and source the file that provides information about the compiler
# used to compile the test case.
if [get_compiler_info] {
return -1
}
# test print command with functions return type # test print command with functions return type
set void "(void|)" set void "(void|)"
gdb_test "print v_char_func" \ gdb_test "print v_char_func" \

View File

@ -30,10 +30,7 @@ if {![dwarf2_support]} {
} }
# The .c files use __attribute__. # The .c files use __attribute__.
if [get_compiler_info] { if ![is_c_compiler_gcc] {
return -1
}
if !$gcc_compiled {
return 0 return 0
} }

View File

@ -58,10 +58,7 @@ if {![dwarf2_support]} {
} }
# The .c files use __attribute__. # The .c files use __attribute__.
if [get_compiler_info] { if ![is_c_compiler_gcc] {
return -1
}
if !$gcc_compiled {
return 0 return 0
} }

View File

@ -53,10 +53,7 @@ if {![dwarf2_support]} {
} }
# The .c files use __attribute__. # The .c files use __attribute__.
if [get_compiler_info] { if ![is_c_compiler_gcc] {
return -1
}
if !$gcc_compiled {
return 0 return 0
} }

View File

@ -42,10 +42,7 @@ if {![dwarf2_support]} {
} }
# The .c files use __attribute__. # The .c files use __attribute__.
if [get_compiler_info] { if ![is_c_compiler_gcc] {
return -1
}
if !$gcc_compiled {
return 0 return 0
} }

View File

@ -31,10 +31,7 @@ if {![dwarf2_support]} {
} }
# The .c files use __attribute__. # The .c files use __attribute__.
if [get_compiler_info] { if ![is_c_compiler_gcc] {
return -1
}
if !$gcc_compiled {
return 0 return 0
} }

View File

@ -32,10 +32,7 @@ if {![dwarf2_support]} {
} }
# The .c files use __attribute__. # The .c files use __attribute__.
if [get_compiler_info] { if ![is_c_compiler_gcc] {
return -1
}
if !$gcc_compiled {
return 0 return 0
} }

View File

@ -31,10 +31,7 @@ if {![dwarf2_support]} {
} }
# The .c files use __attribute__. # The .c files use __attribute__.
if [get_compiler_info] { if ![is_c_compiler_gcc] {
return -1
}
if !$gcc_compiled {
return 0 return 0
} }

View File

@ -31,10 +31,7 @@ if {![dwarf2_support]} {
} }
# The .c files use __attribute__. # The .c files use __attribute__.
if [get_compiler_info] { if ![is_c_compiler_gcc] {
return -1
}
if !$gcc_compiled {
return 0 return 0
} }

View File

@ -31,10 +31,7 @@ if {![dwarf2_support]} {
} }
# The .c files use __attribute__. # The .c files use __attribute__.
if [get_compiler_info] { if ![is_c_compiler_gcc] {
return -1
}
if !$gcc_compiled {
return 0 return 0
} }

View File

@ -21,10 +21,7 @@ if {![dwarf2_support]} {
} }
# The .c files use __attribute__. # The .c files use __attribute__.
if [get_compiler_info] { if ![is_c_compiler_gcc] {
return -1
}
if !$gcc_compiled {
verbose "Skipping $gdb_test_file_name." verbose "Skipping $gdb_test_file_name."
return 0 return 0
} }

View File

@ -25,10 +25,7 @@ if {![dwarf2_support]} {
} }
# The .c files use __attribute__. # The .c files use __attribute__.
if [get_compiler_info] { if ![is_c_compiler_gcc] {
return -1
}
if !$gcc_compiled {
verbose "Skipping $gdb_test_file_name." verbose "Skipping $gdb_test_file_name."
return 0 return 0
} }

View File

@ -25,10 +25,7 @@ if {![dwarf2_support]} {
} }
# The .c files use __attribute__. # The .c files use __attribute__.
if [get_compiler_info] { if ![is_c_compiler_gcc] {
return -1
}
if !$gcc_compiled {
verbose "Skipping $gdb_test_file_name." verbose "Skipping $gdb_test_file_name."
return 0 return 0
} }

View File

@ -24,10 +24,7 @@ if {![dwarf2_support]} {
} }
# The .c files use __attribute__. # The .c files use __attribute__.
if [get_compiler_info] { if ![is_c_compiler_gcc] {
return -1
}
if !$gcc_compiled {
verbose "Skipping $gdb_test_file_name." verbose "Skipping $gdb_test_file_name."
return 0 return 0
} }

View File

@ -22,10 +22,7 @@ if {![dwarf2_support]} {
return 0 return 0
} }
if [get_compiler_info] { if ![is_c_compiler_gcc] {
return -1
}
if !$gcc_compiled {
unsupported "gcc required for this test" unsupported "gcc required for this test"
return 0 return 0
} }

View File

@ -28,10 +28,7 @@ if {![dwarf2_support]} {
} }
# The .c files use __attribute__. # The .c files use __attribute__.
if [get_compiler_info] { if ![is_c_compiler_gcc] {
return -1
}
if !$gcc_compiled {
verbose "Skipping $gdb_test_file_name." verbose "Skipping $gdb_test_file_name."
return 0 return 0
} }

View File

@ -23,10 +23,7 @@ if {![dwarf2_support]} {
return 0 return 0
} }
if [get_compiler_info] { if ![is_c_compiler_gcc] {
return -1
}
if !$gcc_compiled {
unsupported "gcc required for this test" unsupported "gcc required for this test"
return 0 return 0
} }

View File

@ -24,10 +24,7 @@ if {![dwarf2_support]} {
} }
# The .c files use __attribute__. # The .c files use __attribute__.
if [get_compiler_info] { if ![is_c_compiler_gcc] {
return -1
}
if !$gcc_compiled {
verbose "Skipping $gdb_test_file_name." verbose "Skipping $gdb_test_file_name."
return 0 return 0
} }

View File

@ -34,10 +34,7 @@ if {![dwarf2_support]} {
} }
# The .c files use __attribute__. # The .c files use __attribute__.
if [get_compiler_info] { if ![is_c_compiler_gcc] {
return -1
}
if !$gcc_compiled {
verbose "Skipping $gdb_test_file_name." verbose "Skipping $gdb_test_file_name."
return 0 return 0
} }

View File

@ -21,10 +21,7 @@ if {![dwarf2_support]} {
} }
# The .c files use __attribute__. # The .c files use __attribute__.
if [get_compiler_info] { if ![is_c_compiler_gcc] {
return -1
}
if !$gcc_compiled {
verbose "Skipping $gdb_test_file_name." verbose "Skipping $gdb_test_file_name."
return 0 return 0
} }

View File

@ -23,10 +23,7 @@ if {![dwarf2_support]} {
} }
# The .c files use __attribute__. # The .c files use __attribute__.
if [get_compiler_info] { if ![is_c_compiler_gcc] {
return -1
}
if !$gcc_compiled {
return 0 return 0
} }

View File

@ -23,12 +23,6 @@ set binfile_lib [standard_output_file ${libfile}.so]
remote_exec build "rm -f ${binfile}" remote_exec build "rm -f ${binfile}"
# get the value of gcc_compiled
if [get_compiler_info] {
return -1
}
if { [gdb_compile_shlib_pthreads ${srcdir}/${subdir}/${srcfile_lib} ${binfile_lib} {debug}] != "" if { [gdb_compile_shlib_pthreads ${srcdir}/${subdir}/${srcfile_lib} ${binfile_lib} {debug}] != ""
|| [gdb_compile_pthreads ${srcdir}/${subdir}/${srcfile} ${binfile} executable [list debug shlib=${binfile_lib}]] != ""} { || [gdb_compile_pthreads ${srcdir}/${subdir}/${srcfile} ${binfile} executable [list debug shlib=${binfile_lib}]] != ""} {
return -1 return -1

View File

@ -22,12 +22,6 @@ set srcfile_lib ${libfile}.c
set binfile_lib [standard_output_file ${libfile}.so] set binfile_lib [standard_output_file ${libfile}.so]
# get the value of gcc_compiled
if [get_compiler_info] {
return -1
}
if { [gdb_compile_shlib_pthreads ${srcdir}/${subdir}/${srcfile_lib} ${binfile_lib} {debug}] != "" if { [gdb_compile_shlib_pthreads ${srcdir}/${subdir}/${srcfile_lib} ${binfile_lib} {debug}] != ""
|| [gdb_compile_pthreads ${srcdir}/${subdir}/${srcfile} ${binfile} executable [list debug shlib=${binfile_lib}]] != ""} { || [gdb_compile_pthreads ${srcdir}/${subdir}/${srcfile} ${binfile} executable [list debug shlib=${binfile_lib}]] != ""} {
return -1 return -1

View File

@ -27,9 +27,6 @@
TODO: make compiler_info a local variable for get_compiler_info and TODO: make compiler_info a local variable for get_compiler_info and
test_compiler_info. test_compiler_info.
TODO: all clients should use test_compiler_info and should not
use gcc_compiled.
*/ */
set compiler_info "unknown" set compiler_info "unknown"

View File

@ -4043,8 +4043,6 @@ if [info exists compiler_info] {
unset compiler_info unset compiler_info
} }
set gcc_compiled 0
# Figure out what compiler I am using. # Figure out what compiler I am using.
# The result is cached so only the first invocation runs the compiler. # The result is cached so only the first invocation runs the compiler.
# #
@ -4178,16 +4176,6 @@ proc get_compiler_info {{language "c"}} {
set compiler_info_cache($language) $compiler_info set compiler_info_cache($language) $compiler_info
# Set the legacy symbol gcc_compiled.
if { $language == "c" } {
# Legacy global data symbols.
gdb_persistent_global gcc_compiled
set gcc_compiled 0
regexp "^gcc-(\[0-9\]+)-" "$compiler_info" matchall gcc_compiled
}
# Log what happened. # Log what happened.
verbose -log "get_compiler_info: $compiler_info" verbose -log "get_compiler_info: $compiler_info"
@ -4220,6 +4208,15 @@ proc test_compiler_info { {compiler ""} {language "c"} } {
return [string match $compiler $compiler_info_cache($language)] return [string match $compiler $compiler_info_cache($language)]
} }
# Return true if the C compiler is GCC, otherwise, return false.
proc is_c_compiler_gcc {} {
set compiler_info [test_compiler_info]
set gcc_compiled false
regexp "^gcc-(\[0-9\]+)-" "$compiler_info" matchall gcc_compiled
return $gcc_compiled
}
# Return the gcc major version, or -1. # Return the gcc major version, or -1.
# For gcc 4.8.5, the major version is 4.8. # For gcc 4.8.5, the major version is 4.8.
# For gcc 7.5.0, the major version 7. # For gcc 7.5.0, the major version 7.