From 8dc558a0724fa5f56f837144dd44012e211d176e Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 4 Jan 2021 11:43:59 -0500 Subject: [PATCH] gdb/testsuite: avoid reading files through the remote protocol in gdb.server/*.exp When I run some tests in gdb.server (fox example gdb.server/ext-attach.exp) on Ubuntu 20.04 with separate debug info for glibc installed, they often time out. This is because GDB reads the debug info through the remote protocol which is particularly slow: attach 316937 Attaching to program: /home/smarchi/build/binutils-gdb-all-targets/gdb/testsuite/outputs/gdb.server/ext-attach/ext-attach, process 316937 Reading /lib/x86_64-linux-gnu/libc.so.6 from remote target... warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead. Reading /lib64/ld-linux-x86-64.so.2 from remote target... Reading symbols from target:/lib/x86_64-linux-gnu/libc.so.6... Reading /lib/x86_64-linux-gnu/libc-2.31.so from remote target... Reading /lib/x86_64-linux-gnu/.debug/libc-2.31.so from remote target... Reading /usr/lib/debug//lib/x86_64-linux-gnu/libc-2.31.so from remote target... FAIL: gdb.server/ext-attach.exp: attach to remote program 1 (timeout) This is avoided in gdbserver boards by adding "set sysroot" to GDBFLAGS (see boards/local-board.exp), which makes GDB read files from the local filesystem. But gdb.server tests spawn GDBserver directly, so are ran even when using the default unix board, where the "set sysroot" isn't used. Modify these tests to append "set sysroot" to the GDBFLAGS, a bit like lib/local-board.exp does. One special case is gdb.server/sysroot.exp, whose intent is to test different "set sysroot" values. For this one, increase the timeout when testing the "target:" sysroot. gdb/testsuite/ChangeLog: * gdb.server/abspath.exp: Append "set sysroot" to GDBFLAGS. * gdb.server/connect-without-multi-process.exp: Likewise. * gdb.server/exit-multiple-threads.exp: Likewise. * gdb.server/ext-attach.exp: Likewise. * gdb.server/ext-restart.exp: Likewise. * gdb.server/ext-run.exp: Likewise. * gdb.server/ext-wrapper.exp: Likewise. * gdb.server/multi-ui-errors.exp: Likewise. * gdb.server/no-thread-db.exp: Likewise. * gdb.server/reconnect-ctrl-c.exp: Likewise. * gdb.server/run-without-local-binary.exp: Likewise. * gdb.server/server-kill.exp: Likewise. * gdb.server/server-run.exp: Likewise. * gdb.server/solib-list.exp: Likewise. * gdb.server/stop-reply-no-thread.exp: Likewise. * gdb.server/wrapper.exp: Likewise. * gdb.server/sysroot.exp: Increase timeout when testing the target: sysroot. Change-Id: I7451bcc737f90e2cd0b977e9f09da3710774b0bf --- gdb/testsuite/ChangeLog | 21 ++++++++ gdb/testsuite/gdb.server/abspath.exp | 13 ++++- .../connect-without-multi-process.exp | 12 ++++- .../gdb.server/exit-multiple-threads.exp | 12 ++++- gdb/testsuite/gdb.server/ext-attach.exp | 12 ++++- gdb/testsuite/gdb.server/ext-restart.exp | 12 ++++- gdb/testsuite/gdb.server/ext-run.exp | 10 +++- gdb/testsuite/gdb.server/ext-wrapper.exp | 12 ++++- gdb/testsuite/gdb.server/multi-ui-errors.exp | 12 ++++- gdb/testsuite/gdb.server/no-thread-db.exp | 10 +++- gdb/testsuite/gdb.server/reconnect-ctrl-c.exp | 13 ++++- .../gdb.server/run-without-local-binary.exp | 7 +++ gdb/testsuite/gdb.server/server-kill.exp | 11 +++- gdb/testsuite/gdb.server/server-run.exp | 10 +++- gdb/testsuite/gdb.server/solib-list.exp | 11 +++- .../gdb.server/stop-reply-no-thread.exp | 12 ++++- gdb/testsuite/gdb.server/sysroot.exp | 54 ++++++++++--------- gdb/testsuite/gdb.server/wrapper.exp | 12 ++++- 18 files changed, 208 insertions(+), 48 deletions(-) diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index ac4b6e1e55c..44afe3629b5 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,24 @@ +2021-01-04 Simon Marchi + + * gdb.server/abspath.exp: Append "set sysroot" to GDBFLAGS. + * gdb.server/connect-without-multi-process.exp: Likewise. + * gdb.server/exit-multiple-threads.exp: Likewise. + * gdb.server/ext-attach.exp: Likewise. + * gdb.server/ext-restart.exp: Likewise. + * gdb.server/ext-run.exp: Likewise. + * gdb.server/ext-wrapper.exp: Likewise. + * gdb.server/multi-ui-errors.exp: Likewise. + * gdb.server/no-thread-db.exp: Likewise. + * gdb.server/reconnect-ctrl-c.exp: Likewise. + * gdb.server/run-without-local-binary.exp: Likewise. + * gdb.server/server-kill.exp: Likewise. + * gdb.server/server-run.exp: Likewise. + * gdb.server/solib-list.exp: Likewise. + * gdb.server/stop-reply-no-thread.exp: Likewise. + * gdb.server/wrapper.exp: Likewise. + * gdb.server/sysroot.exp: Increase timeout when testing the + target: sysroot. + 2021-01-04 Simon Marchi * gdb.server/server-run.exp: Use clean_restart. diff --git a/gdb/testsuite/gdb.server/abspath.exp b/gdb/testsuite/gdb.server/abspath.exp index f14bd90b8b8..1ccdbe7ac1c 100644 --- a/gdb/testsuite/gdb.server/abspath.exp +++ b/gdb/testsuite/gdb.server/abspath.exp @@ -33,8 +33,17 @@ if { [is_remote target] } { return 0 } -if { [prepare_for_testing "failed to prepare" $testfile $srcfile debug] } { - return -1 +save_vars { GDBFLAGS } { + # If GDB and GDBserver are both running locally, set the sysroot to avoid + # reading files via the remote protocol (the `is_remote target` check is + # already done above). + if { ![is_remote host] } { + set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\"" + } + + if { [prepare_for_testing "failed to prepare" $testfile $srcfile debug] } { + return -1 + } } # Make sure we're disconnected, in case we're testing with an diff --git a/gdb/testsuite/gdb.server/connect-without-multi-process.exp b/gdb/testsuite/gdb.server/connect-without-multi-process.exp index c36bd9b82d9..9c03d1280e1 100644 --- a/gdb/testsuite/gdb.server/connect-without-multi-process.exp +++ b/gdb/testsuite/gdb.server/connect-without-multi-process.exp @@ -31,9 +31,17 @@ if {[build_executable "failed to prepare" $testfile $srcfile debug]} { # Test spawning gdbserver with a program, connect to it and run to # main, with both multiprocess extensions on and off. proc do_test {multiprocess} { - global binfile + global binfile GDBFLAGS - clean_restart $binfile + save_vars { GDBFLAGS } { + # If GDB and GDBserver are both running locally, set the sysroot to avoid + # reading files via the remote protocol. + if { ![is_remote host] && ![is_remote target] } { + set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\"" + } + + clean_restart $binfile + } # Make sure we're disconnected, in case we're testing with an # extended-remote board, therefore already connected. diff --git a/gdb/testsuite/gdb.server/exit-multiple-threads.exp b/gdb/testsuite/gdb.server/exit-multiple-threads.exp index c0db6e9cd67..a74f7d12449 100644 --- a/gdb/testsuite/gdb.server/exit-multiple-threads.exp +++ b/gdb/testsuite/gdb.server/exit-multiple-threads.exp @@ -39,7 +39,17 @@ standard_testfile # Places a breakpoint in function 'breakpt' and then continues to the # breakpoint, at which point it runs 'info threads'. proc prepare_for_test { executable disable_multi_process } { - clean_restart ${executable} + global GDBFLAGS + + save_vars { GDBFLAGS } { + # If GDB and GDBserver are both running locally, set the sysroot to avoid + # reading files via the remote protocol. + if { ![is_remote host] && ![is_remote target] } { + set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\"" + } + + clean_restart ${executable} + } # Make sure we're disconnected, in case we're testing with an # extended-remote board, therefore already connected. diff --git a/gdb/testsuite/gdb.server/ext-attach.exp b/gdb/testsuite/gdb.server/ext-attach.exp index 94695179dda..c9766e35317 100644 --- a/gdb/testsuite/gdb.server/ext-attach.exp +++ b/gdb/testsuite/gdb.server/ext-attach.exp @@ -30,8 +30,16 @@ if {![can_spawn_for_attach]} { return 0 } -if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { - return -1 +save_vars { GDBFLAGS } { + # If GDB and GDBserver are both running locally, set the sysroot to avoid + # reading files via the remote protocol. + if { ![is_remote host] && ![is_remote target] } { + set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\"" + } + + if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { + return -1 + } } # Make sure we're disconnected, in case we're testing with an diff --git a/gdb/testsuite/gdb.server/ext-restart.exp b/gdb/testsuite/gdb.server/ext-restart.exp index 33b13405391..8b175e75a77 100644 --- a/gdb/testsuite/gdb.server/ext-restart.exp +++ b/gdb/testsuite/gdb.server/ext-restart.exp @@ -25,8 +25,16 @@ if { [skip_gdbserver_tests] } { return 0 } -if { [prepare_for_testing "failed to prepare" $testfile $srcfile debug] } { - return -1 +save_vars { GDBFLAGS } { + # If GDB and GDBserver are both running locally, set the sysroot to avoid + # reading files via the remote protocol. + if { ![is_remote host] && ![is_remote target] } { + set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\"" + } + + if { [prepare_for_testing "failed to prepare" $testfile $srcfile debug] } { + return -1 + } } # Make sure we're disconnected, in case we're testing with an diff --git a/gdb/testsuite/gdb.server/ext-run.exp b/gdb/testsuite/gdb.server/ext-run.exp index 92aef141784..268f690949a 100644 --- a/gdb/testsuite/gdb.server/ext-run.exp +++ b/gdb/testsuite/gdb.server/ext-run.exp @@ -32,7 +32,15 @@ if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} { # gdb_skip_xml_test must be called while gdb is not running. set do_xml_test [expr ![gdb_skip_xml_test]] -clean_restart $binfile +save_vars { GDBFLAGS } { + # If GDB and GDBserver are both running locally, set the sysroot to avoid + # reading files via the remote protocol. + if { ![is_remote host] && ![is_remote target] } { + set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\"" + } + + clean_restart $binfile +} # Make sure we're disconnected, in case we're testing with an # extended-remote board, therefore already connected. diff --git a/gdb/testsuite/gdb.server/ext-wrapper.exp b/gdb/testsuite/gdb.server/ext-wrapper.exp index c6e7786af42..fc9a77f137c 100644 --- a/gdb/testsuite/gdb.server/ext-wrapper.exp +++ b/gdb/testsuite/gdb.server/ext-wrapper.exp @@ -27,8 +27,16 @@ if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} { return -1 } -if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { - return -1 +save_vars { GDBFLAGS } { + # If GDB and GDBserver are both running locally, set the sysroot to avoid + # reading files via the remote protocol. + if { ![is_remote host] && ![is_remote target] } { + set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\"" + } + + if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { + return -1 + } } # Make sure we're disconnected, in case we're testing with an diff --git a/gdb/testsuite/gdb.server/multi-ui-errors.exp b/gdb/testsuite/gdb.server/multi-ui-errors.exp index b89defc1ff4..073192f1971 100644 --- a/gdb/testsuite/gdb.server/multi-ui-errors.exp +++ b/gdb/testsuite/gdb.server/multi-ui-errors.exp @@ -28,8 +28,16 @@ if {[skip_gdbserver_tests]} { return 0 } -if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile}]} { - return -1 +save_vars { GDBFLAGS } { + # If GDB and GDBserver are both running locally, set the sysroot to avoid + # reading files via the remote protocol. + if { ![is_remote host] && ![is_remote target] } { + set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\"" + } + + if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile}]} { + return -1 + } } # Make sure we're disconnected, in case we're testing with an diff --git a/gdb/testsuite/gdb.server/no-thread-db.exp b/gdb/testsuite/gdb.server/no-thread-db.exp index 5dbb65469bb..19ec89a822f 100644 --- a/gdb/testsuite/gdb.server/no-thread-db.exp +++ b/gdb/testsuite/gdb.server/no-thread-db.exp @@ -33,7 +33,15 @@ if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executab return -1 } -clean_restart ${testfile} +save_vars { GDBFLAGS } { + # If GDB and GDBserver are both running locally, set the sysroot to avoid + # reading files via the remote protocol. + if { ![is_remote host] && ![is_remote target] } { + set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\"" + } + + clean_restart ${testfile} +} # Make sure we're disconnected, in case we're testing with an # extended-remote board, therefore already connected. diff --git a/gdb/testsuite/gdb.server/reconnect-ctrl-c.exp b/gdb/testsuite/gdb.server/reconnect-ctrl-c.exp index 9b5b7a83328..11aa5147c78 100644 --- a/gdb/testsuite/gdb.server/reconnect-ctrl-c.exp +++ b/gdb/testsuite/gdb.server/reconnect-ctrl-c.exp @@ -30,8 +30,17 @@ if [target_info exists gdb,nointerrupts] { } standard_testfile -if [prepare_for_testing "failed to prepare" $testfile $srcfile] { - return -1 + +save_vars { GDBFLAGS } { + # If GDB and GDBserver are both running locally, set the sysroot to avoid + # reading files via the remote protocol. + if { ![is_remote host] && ![is_remote target] } { + set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\"" + } + + if [prepare_for_testing "failed to prepare" $testfile $srcfile] { + return -1 + } } # Make sure we're disconnected, in case we're testing with an diff --git a/gdb/testsuite/gdb.server/run-without-local-binary.exp b/gdb/testsuite/gdb.server/run-without-local-binary.exp index 6bbdca278c6..395eddc9106 100644 --- a/gdb/testsuite/gdb.server/run-without-local-binary.exp +++ b/gdb/testsuite/gdb.server/run-without-local-binary.exp @@ -31,6 +31,13 @@ if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { # remote/21852. save_vars { GDBFLAGS } { set GDBFLAGS "" + + # If GDB and GDBserver are both running locally, set the sysroot to avoid + # reading files via the remote protocol. + if { ![is_remote host] && ![is_remote target] } { + set GDBFLAGS "-ex \"set sysroot\"" + } + gdb_exit gdb_start diff --git a/gdb/testsuite/gdb.server/server-kill.exp b/gdb/testsuite/gdb.server/server-kill.exp index ab82072138a..80d78f89738 100644 --- a/gdb/testsuite/gdb.server/server-kill.exp +++ b/gdb/testsuite/gdb.server/server-kill.exp @@ -36,8 +36,17 @@ if { [build_executable "failed to prepare" ${testfile}] } { proc prepare {} { global binfile gdb_prompt srcfile decimal global server_pid + global GDBFLAGS - clean_restart $binfile + save_vars { GDBFLAGS } { + # If GDB and GDBserver are both running locally, set the sysroot to avoid + # reading files via the remote protocol. + if { ![is_remote host] && ![is_remote target] } { + set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\"" + } + + clean_restart $binfile + } # Make sure we're disconnected, in case we're testing with an # extended-remote board, therefore already connected. diff --git a/gdb/testsuite/gdb.server/server-run.exp b/gdb/testsuite/gdb.server/server-run.exp index 72ba02c977c..e680ef50035 100644 --- a/gdb/testsuite/gdb.server/server-run.exp +++ b/gdb/testsuite/gdb.server/server-run.exp @@ -29,7 +29,15 @@ if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} { return -1 } -clean_restart $binfile +save_vars { GDBFLAGS } { + # If GDB and GDBserver are both running locally, set the sysroot to avoid + # reading files via the remote protocol. + if { ![is_remote host] && ![is_remote target] } { + set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\"" + } + + clean_restart $binfile +} # Make sure we're disconnected, in case we're testing with an # extended-remote board, therefore already connected. diff --git a/gdb/testsuite/gdb.server/solib-list.exp b/gdb/testsuite/gdb.server/solib-list.exp index c4934ed1416..3a8c739dd7b 100644 --- a/gdb/testsuite/gdb.server/solib-list.exp +++ b/gdb/testsuite/gdb.server/solib-list.exp @@ -42,7 +42,16 @@ set interp_system [section_get ${binfile} .interp] verbose -log "system interpreter is: $interp_system" foreach nonstop { 0 1 } { with_test_prefix "non-stop $nonstop" { - clean_restart + save_vars { GDBFLAGS } { + # If GDB and GDBserver are both running locally, set the sysroot to avoid + # reading files via the remote protocol. + if { ![is_remote host] && ![is_remote target] } { + set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\"" + } + + clean_restart + } + gdb_load_shlib ${binlibfile} set remote_binfile [gdb_remote_download target $binfile] diff --git a/gdb/testsuite/gdb.server/stop-reply-no-thread.exp b/gdb/testsuite/gdb.server/stop-reply-no-thread.exp index 5e93b4770aa..68bf42ac1a0 100644 --- a/gdb/testsuite/gdb.server/stop-reply-no-thread.exp +++ b/gdb/testsuite/gdb.server/stop-reply-no-thread.exp @@ -34,9 +34,17 @@ if { [build_executable "failed to prepare" $testfile $srcfile] == -1 } { # Run the tests with different features of GDBserver disabled. proc run_test { disable_feature target_nonstop } { - global binfile gdb_prompt decimal + global binfile gdb_prompt decimal GDBFLAGS - clean_restart ${binfile} + save_vars { GDBFLAGS } { + # If GDB and GDBserver are both running locally, set the sysroot to avoid + # reading files via the remote protocol. + if { ![is_remote host] && ![is_remote target] } { + set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\"" + } + + clean_restart ${binfile} + } # Make sure we're disconnected, in case we're testing with an # extended-remote board, therefore already connected. diff --git a/gdb/testsuite/gdb.server/sysroot.exp b/gdb/testsuite/gdb.server/sysroot.exp index 158b7c5d0b8..5aea60a526b 100644 --- a/gdb/testsuite/gdb.server/sysroot.exp +++ b/gdb/testsuite/gdb.server/sysroot.exp @@ -40,39 +40,45 @@ foreach_with_prefix sysroot { "local" "remote" } { if { $sysroot == "local" } { set sysroot_command "/" set reading_symbols "Reading symbols from $binfile..." + set timeout_factor 1 } else { set sysroot_command "target:" set reading_symbols "Reading $binfile from remote target..." + set timeout_factor 5 } - # Restart GDB. - clean_restart + # Reading debug info from the remote target can take a bit of time, so + # increase the timeout in that case. + with_timeout_factor $timeout_factor { + # Restart GDB. + clean_restart - # Make sure we're disconnected, in case we're testing with an - # extended-remote board, therefore already connected. - gdb_test "disconnect" ".*" + # Make sure we're disconnected, in case we're testing with an + # extended-remote board, therefore already connected. + gdb_test "disconnect" ".*" - # Start GDBserver. - set res [gdbserver_start "" $binfile] - set gdbserver_protocol [lindex $res 0] - set gdbserver_gdbport [lindex $res 1] + # Start GDBserver. + set res [gdbserver_start "" $binfile] + set gdbserver_protocol [lindex $res 0] + set gdbserver_gdbport [lindex $res 1] - # Set the sysroot. - gdb_test_no_output "set sysroot $sysroot_command" + # Set the sysroot. + gdb_test_no_output "set sysroot $sysroot_command" - # Connect to gdbserver, making sure GDB reads in the binary correctly. - set test "connect to remote and read binary" - if {[gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport $reading_symbols] == 0} { - pass $test - } else { - fail $test - } + # Connect to gdbserver, making sure GDB reads in the binary correctly. + set test "connect to remote and read binary" + if {[gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport $reading_symbols] == 0} { + pass $test + } else { + fail $test + } - gdb_breakpoint main - gdb_test "continue" "Breakpoint $decimal.* main.*" "continue to main" + gdb_breakpoint main + gdb_test "continue" "Breakpoint $decimal.* main.*" "continue to main" - # Test that we can stop inside a library. - gdb_breakpoint printf - gdb_test "continue" "Breakpoint $decimal.* (__)?printf .*" \ - "continue to printf" + # Test that we can stop inside a library. + gdb_breakpoint printf + gdb_test "continue" "Breakpoint $decimal.* (__)?printf .*" \ + "continue to printf" + } } diff --git a/gdb/testsuite/gdb.server/wrapper.exp b/gdb/testsuite/gdb.server/wrapper.exp index 695deea174d..27d37bac02e 100644 --- a/gdb/testsuite/gdb.server/wrapper.exp +++ b/gdb/testsuite/gdb.server/wrapper.exp @@ -31,8 +31,16 @@ if { [istarget *-*-mingw*] return -1 } -if { [prepare_for_testing "failed to prepare" $testfile $srcfile debug] } { - return -1 +save_vars { GDBFLAGS } { + # If GDB and GDBserver are both running locally, set the sysroot to avoid + # reading files via the remote protocol. + if { ![is_remote host] && ![is_remote target] } { + set GDBFLAGS "$GDBFLAGS -ex \"set sysroot\"" + } + + if { [prepare_for_testing "failed to prepare" $testfile $srcfile debug] } { + return -1 + } } # Make sure we're disconnected, in case we're testing with an -- 2.30.2