mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-01-06 12:09:26 +08:00
6e22f11784
When building gdb using CFLAGS/CXXFLAGS+=-fsanitizer=address and LDFLAGS+=-lasan, and running test-case gdb.threads/attach-slow-waitpid.exp, we get: ... spawn gdb -nw -nx -data-directory data-directory^M ==16079==ASan runtime does not come first in initial library list; \ you should either link runtime to your application or manually preload \ it with LD_PRELOAD.^M ERROR: (eof) GDB never initialized. ERROR: : spawn id exp10 not open while executing "expect { -i exp10 -timeout 120 -re "Kill the program being debugged. .y or n. $" { send_gdb "y\n" answer verbose "\t\tKilling previous pro..." ("uplevel" body line 1) invoked from within "uplevel $body" NONE : spawn id exp10 not open WARNING: remote_expect statement without a default case ERROR: : spawn id exp10 not open while executing "expect { -i exp10 -timeout 120 -re "Reading symbols from.*LZMA support was disabled.*$gdb_prompt $" { verbose "\t\tLoaded $arg into $GDB; .gnu_..." ("uplevel" body line 1) invoked from within "uplevel $body" NONE : spawn id exp10 not open ERROR: Couldn't load attach-slow-waitpid into GDB (eof). ERROR: Couldn't send attach 16070 to GDB. UNRESOLVED: gdb.threads/attach-slow-waitpid.exp: attach to target ... Bail out at the first ERROR, such that we have instead: ... ERROR: (eof) GDB never initialized. UNTESTED: gdb.threads/attach-slow-waitpid.exp: \ Couldn't start GDB with preloaded lib ... Tested on x86_64-linux. gdb/testsuite/ChangeLog: 2020-07-20 Tom de Vries <tdevries@suse.de> * gdb.threads/attach-slow-waitpid.exp: Bail out if gdb_start fails.
106 lines
3.5 KiB
Plaintext
106 lines
3.5 KiB
Plaintext
# Copyright 2018-2020 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/>.
|
|
|
|
# This test script tries to expose a bug in some of the uses of
|
|
# waitpid in the Linux native support within GDB. The problem was
|
|
# spotted on systems which were heavily loaded when attaching to
|
|
# threaded test programs. What happened was that during the initial
|
|
# attach, the loop of waitpid calls that normally received the stop
|
|
# events from each of the threads in the inferior was not receiving a
|
|
# stop event for some threads (the kernel just hadn't sent the stop
|
|
# event yet).
|
|
#
|
|
# GDB would then trigger a call to stop_all_threads which would
|
|
# continue to wait for all of the outstanding threads to stop, when
|
|
# the outstanding stop events finally arrived GDB would then
|
|
# (incorrectly) discard the stop event, resume the thread, and
|
|
# continue to wait for the thread to stop.... which it now never
|
|
# would.
|
|
#
|
|
# In order to try and expose this issue reliably, this test preloads a
|
|
# library that intercepts waitpid calls. All waitpid calls targeting
|
|
# pid -1 with the WNOHANG flag are rate limited so that only 1 per
|
|
# second can complete. Additional calls are forced to return 0
|
|
# indicating no event waiting. This is enough to trigger the bug
|
|
# during the attach phase.
|
|
|
|
# This test only works on Linux
|
|
if { ![isnative] || [is_remote host] || [use_gdb_stub]
|
|
|| ![istarget *-linux*] } {
|
|
continue
|
|
}
|
|
|
|
standard_testfile
|
|
|
|
set libfile slow-waitpid
|
|
set libsrc "${srcdir}/${subdir}/${libfile}.c"
|
|
set libobj [standard_output_file ${libfile}.so]
|
|
|
|
with_test_prefix "compile preload library" {
|
|
# Compile the preload library. We only get away with this as we
|
|
# limit this test to running when ISNATIVE is true.
|
|
if { [gdb_compile_shlib_pthreads \
|
|
$libsrc $libobj {debug}] != "" } then {
|
|
return -1
|
|
}
|
|
}
|
|
|
|
with_test_prefix "compile test executable" {
|
|
# Compile the test program
|
|
if { [gdb_compile_pthreads \
|
|
"${srcdir}/${subdir}/${srcfile}" "${binfile}" \
|
|
executable {debug}] != "" } {
|
|
return -1
|
|
}
|
|
}
|
|
|
|
# Spawn GDB with LIB preloaded with LD_PRELOAD.
|
|
|
|
proc gdb_spawn_with_ld_preload {lib} {
|
|
global env
|
|
|
|
save_vars { env(LD_PRELOAD) } {
|
|
if { ![info exists env(LD_PRELOAD) ]
|
|
|| $env(LD_PRELOAD) == "" } {
|
|
set env(LD_PRELOAD) "$lib"
|
|
} else {
|
|
append env(LD_PRELOAD) ":$lib"
|
|
}
|
|
|
|
gdb_start
|
|
}
|
|
}
|
|
|
|
# Run test program in the background.
|
|
set test_spawn_id [spawn_wait_for_attach $binfile]
|
|
set testpid [spawn_id_get_pid $test_spawn_id]
|
|
|
|
# Start GDB with preload library in place.
|
|
if { [gdb_spawn_with_ld_preload $libobj] == -1 } {
|
|
# Make sure we get UNTESTED rather than UNRESOLVED.
|
|
set errcnt 0
|
|
untested "Couldn't start GDB with preloaded lib"
|
|
return -1
|
|
}
|
|
|
|
# Load binary, and attach to running program.
|
|
gdb_load ${binfile}
|
|
gdb_test "attach $testpid" "Attaching to program.*" "attach to target"
|
|
|
|
gdb_exit
|
|
|
|
# Kill of test program.
|
|
kill_wait_spawned_process $test_spawn_id
|