aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorPedro Alves <pedro@palves.net>2025-09-11 13:14:16 +0100
committerPedro Alves <pedro@palves.net>2025-09-15 19:49:43 +0100
commitd09eba07ca013e6b95eeafd67d79c32ebf6f28eb (patch)
tree9cd5e4a6b544bb415e13799b1b5408d43081e71c /gdb
parentbd21dd6807893c76b94da522b6af14c6b8c745a8 (diff)
downloadfsf-binutils-gdb-master.zip
fsf-binutils-gdb-master.tar.gz
fsf-binutils-gdb-master.tar.bz2
Make get_compiler_info use gdb_caching_procHEADmaster
While running tests on Windows with: $ make check-parallel RUNTESTFLAGS="-v" I noticed that get_compiler_info was invoking the compiler over and over for each testcase, even though the result is supposed to be cached. This isn't normally very visible in gdb.log, because we suppress it there: # Run $ifile through the right preprocessor. # Toggle gdb.log to keep the compiler output out of the log. set saved_log [log_file -info] log_file ... I'm not sure it's a good idea to do that suppression, BTW. I was very confused when I couldn't find the compiler invocation in gdb.log, and it took me a while to notice that code. The reason get_compiler_info in parallel mode isn't hitting the cache is that in that mode each testcase runs under its own expect/dejagnu process, and the way get_compiler_info caches results currently doesn't handle that -- the result is simply cached in a global variable, which is private to each expect. So improve this by switching get_compiler_info's caching mechanism to gdb_caching_proc instead, so that results are cached across parallel invocations of dejagnu. On an x86-64 GNU/Linux run with "make check-parallel -j32", before the patch I get 2223 calls to get_compiler_info that result in a compiler invocation. After the patch, I get 7. On GNU/Linux, those compiler invocations don't cost much, but on Windows, they add up. On my machine each invocation takes around 500ms to 700ms. Here is one representative run: $ time x86_64-w64-mingw32-gcc \ /c/msys2/home/alves/gdb/build-testsuite/temp/14826/compiler.c \ -fdiagnostics-color=never -E ... real 0m0.639s user 0m0.061s sys 0m0.141s This reference to a 'compiler_info' global: # N.B. compiler_info is intended to be local to this file. # Call test_compiler_info with no arguments to fetch its value. # Yes, this is counterintuitive when there's get_compiler_info, # but that's the current API. if [info exists compiler_info] { unset compiler_info } is outdated, even before this patch, as "compiler_info" is a local variable in get_compiler_info. Remove all that code. Since test_compiler_info now calls get_compiler_info directly, the "Requires get_compiler_info" comments in skip_inline_frame_tests and skip_inline_var_tests are no longer accurate. Remove them. test_compiler_info's intro comment is also outdated; improve it. Changing the return value of get_compiler_info to be the 'compiler_info' string directly instead of 0/-1 was simpler. It would be possible to support the current 0/-1 interface by making get_compiler_info_1 still return the 'compiler_info' string, and then having the get_compiler_info wrapper convert to 0/-1, and I considered doing that. But the only caller of get_compiler_info outside gdb.exp is gdb.python/py-event-load.exp, and it seems that one simply crossed wires with: commit 9704b8b4bc58f4f464961cca97d362fd33740ce8 gdb/testsuite: remove unneeded calls to get_compiler_info as the test as added at roughly the same time as that commit. So simply remove that call in gdb.python/py-event-load.exp, otherwise we get something like: ERROR: ------------------------------------------- ERROR: in testcase src/gdb/testsuite/gdb.python/py-event-load.exp ERROR: expected boolean value but got "gcc-13-3-0" ERROR: tcl error code TCL VALUE NUMBER ERROR: tcl error info: expected boolean value but got "gcc-13-3-0" Approved-By: Tom Tromey <tom@tromey.com> Change-Id: Ia3d3dc34f7cdcf9a2013f1054128c62a108eabfb
Diffstat (limited to 'gdb')
-rw-r--r--gdb/testsuite/gdb.python/py-event-load.exp6
-rw-r--r--gdb/testsuite/lib/gdb.exp52
2 files changed, 24 insertions, 34 deletions
diff --git a/gdb/testsuite/gdb.python/py-event-load.exp b/gdb/testsuite/gdb.python/py-event-load.exp
index a09a946..dbb225f 100644
--- a/gdb/testsuite/gdb.python/py-event-load.exp
+++ b/gdb/testsuite/gdb.python/py-event-load.exp
@@ -20,12 +20,6 @@ load_lib gdb-python.exp
require allow_shlib_tests allow_python_tests
-if {[get_compiler_info]} {
- warning "Could not get compiler info"
- untested "no compiler info"
- return -1
-}
-
standard_testfile .c
if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
executable {debug shlib_load}] != ""} {
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 3c19f71..1780e37 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -5351,7 +5351,7 @@ gdb_caching_proc allow_ifunc_tests {} {
}
# Return whether we should skip tests for showing inlined functions in
-# backtraces. Requires get_compiler_info and get_debug_format.
+# backtraces. Requires get_debug_format.
proc skip_inline_frame_tests {} {
# GDB only recognizes inlining information in DWARF.
@@ -5370,7 +5370,7 @@ proc skip_inline_frame_tests {} {
}
# Return whether we should skip tests for showing variables from
-# inlined functions. Requires get_compiler_info and get_debug_format.
+# inlined functions. Requires get_debug_format.
proc skip_inline_var_tests {} {
# GDB only recognizes inlining information in DWARF.
@@ -5642,14 +5642,6 @@ gdb_caching_proc target_is_gdbserver {} {
return $is_gdbserver
}
-# N.B. compiler_info is intended to be local to this file.
-# Call test_compiler_info with no arguments to fetch its value.
-# Yes, this is counterintuitive when there's get_compiler_info,
-# but that's the current API.
-if [info exists compiler_info] {
- unset compiler_info
-}
-
# Figure out what compiler I am using.
# The result is cached so only the first invocation runs the compiler.
#
@@ -5701,8 +5693,18 @@ if [info exists compiler_info] {
# I didn't get desperate enough to try this.
#
# -- chastain 2004-01-06
+#
+# Returns "unsupported" if LANGUAGE is not supported, and "unknown" if
+# LANGUAGE is supported but extracting the information out of the
+# compiler for LANGUAGE failed. Otherwise returns the compiler we're
+# using for LANGUAGE.
proc get_compiler_info {{language "c"}} {
+ # Split to a helper procedure because gdb_caching_proc does not
+ # support optional arguments.
+ return [get_compiler_info_1 $language]
+}
+gdb_caching_proc get_compiler_info_1 {language} {
# For compiler.c, compiler.cc and compiler.F90.
global srcdir
@@ -5711,13 +5713,8 @@ proc get_compiler_info {{language "c"}} {
global outdir
global tool
- # These come from compiler.c, compiler.cc or compiler.F90.
- gdb_persistent_global compiler_info_cache
-
- if [info exists compiler_info_cache($language)] {
- # Already computed.
- return 0
- }
+ # 'compiler_info' comes from evaluating the result of
+ # preprocessing compiler.c, compiler.cc or compiler.F90.
# Choose which file to preprocess.
if { $language == "c++" } {
@@ -5728,7 +5725,7 @@ proc get_compiler_info {{language "c"}} {
set ifile "${srcdir}/lib/compiler.c"
} else {
perror "Unable to fetch compiler version for language: $language"
- return -1
+ return "unsupported"
}
# Run $ifile through the right preprocessor.
@@ -5790,22 +5787,21 @@ proc get_compiler_info {{language "c"}} {
set compiler_info "unknown"
}
- set compiler_info_cache($language) $compiler_info
-
# Log what happened.
verbose -log "get_compiler_info: $compiler_info"
- return 0
+ return $compiler_info
}
-# Return the compiler_info string if no arg is provided.
-# Otherwise the argument is a glob-style expression to match against
-# compiler_info.
+# Return the compiler_info string if COMPILER is not provided.
+# Otherwise COMPILER is a glob-style expression to match against
+# compiler_info, and this returns true/false depending on whether the
+# expression matches or not.
proc test_compiler_info { {compiler ""} {language "c"} } {
- gdb_persistent_global compiler_info_cache
+ set compiler_info [get_compiler_info $language]
- if [get_compiler_info $language] {
+ if {$compiler_info == "unsupported"} {
# An error will already have been printed in this case. Just
# return a suitable result depending on how the user called
# this function.
@@ -5818,10 +5814,10 @@ proc test_compiler_info { {compiler ""} {language "c"} } {
# If no arg, return the compiler_info string.
if [string match "" $compiler] {
- return $compiler_info_cache($language)
+ return $compiler_info
}
- return [string match $compiler $compiler_info_cache($language)]
+ return [string match $compiler $compiler_info]
}
# Return true if the C compiler is GCC, otherwise, return false.