2022-01-01 18:56:03 +04:00
|
|
|
# Copyright 2017-2022 Free Software Foundation, Inc.
|
2018-06-08 18:06:46 +01:00
|
|
|
|
|
|
|
# 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 only works for native processes on GNU/Linux.
|
|
|
|
if {[target_info gdb_protocol] != "" || ![istarget *-linux*]} {
|
2022-05-13 13:23:57 -03:00
|
|
|
return
|
2018-06-08 18:06:46 +01:00
|
|
|
}
|
|
|
|
|
2019-05-17 15:35:08 +01:00
|
|
|
# Test relies on checking gdb debug output. Do not run if gdb debug is
|
|
|
|
# enabled as any debug will be redirected to the log.
|
|
|
|
if [gdb_debug_enabled] {
|
|
|
|
untested "debug is enabled"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2018-06-08 18:06:46 +01:00
|
|
|
standard_testfile
|
|
|
|
|
|
|
|
if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
|
|
|
|
executable debug] != "" } {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
[gdb/testsuite] Fix check-libthread-db.exp FAILs with glibc 2.33
When running test-case gdb.threads/check-libthread-db.exp on openSUSE
Tumbleweed with glibc 2.33, I get:
...
(gdb) maint check libthread-db^M
Running libthread_db integrity checks:^M
Got thread 0x7ffff7c79b80 => 9354 => 0x7ffff7c79b80; errno = 0 ... OK^M
libthread_db integrity checks passed.^M
(gdb) FAIL: gdb.threads/check-libthread-db.exp: user-initiated check: \
libpthread.so not initialized (pattern 2)
...
The test-case expects instead:
...
Got thread 0x0 => 9354 => 0x0 ... OK^M
...
which is what I get on openSUSE Leap 15.2 with glibc 2.26, and what is
described in the test-case like this:
...
# libthread_db should fake a single thread with th_unique == NULL.
...
Using a breakpoint on check_thread_db_callback we can compare the two
scenarios, and find that in the latter case we hit this code in glibc function
iterate_thread_list in nptl_db/td_ta_thr_iter.c:
...
if (next == 0 && fake_empty)
{
/* __pthread_initialize_minimal has not run. There is just the main
thread to return. We cannot rely on its thread register. They
sometimes contain garbage that would confuse us, left by the
kernel at exec. So if it looks like initialization is incomplete,
we only fake a special descriptor for the initial thread. */
td_thrhandle_t th = { ta, 0 };
return callback (&th, cbdata_p) != 0 ? TD_DBERR : TD_OK;
}
...
while in the former case we don't because this preceding statement doesn't
result in next == 0:
...
err = DB_GET_FIELD (next, ta, head, list_t, next, 0);
...
Note that the comment mentions __pthread_initialize_minimal, but in both cases
it has already run before we hit the callback, so it's possible the comment is
no longer accurate.
The change in behaviour bisect to glibc commit 1daccf403b "nptl: Move stack
list variables into _rtld_global", which moves the initialization of stack
list variables such as __stack_user to an earlier moment, which explains well
enough the observed difference.
Fix this by updating the regexp patterns to agree with what libthread-db is
telling us.
Tested on x86_64-linux, both with glibc 2.33 and 2.26.
gdb/testsuite/ChangeLog:
2021-07-07 Tom de Vries <tdevries@suse.de>
PR testsuite/27690
* gdb.threads/check-libthread-db.exp: Update patterns for glibc 2.33.
2021-07-13 15:56:49 +02:00
|
|
|
# Case 1: libthread_db fakes a single thread with th_unique == NULL.
|
|
|
|
set thread_re1 "0 => $decimal => 0"
|
|
|
|
# Case 2: libthread_db already initialized.
|
|
|
|
set thread_re2 "$hex => $decimal => ${hex}(; errno = 0)?"
|
|
|
|
# Match either of the two cases.
|
|
|
|
set initial_thread_re "($thread_re1|$thread_re2)"
|
|
|
|
|
2018-06-08 18:06:46 +01:00
|
|
|
with_test_prefix "user-initiated check" {
|
|
|
|
|
|
|
|
# User-initiated check with libthread_db not loaded.
|
|
|
|
clean_restart ${binfile}
|
|
|
|
|
|
|
|
gdb_test "maint show check-libthread-db" \
|
|
|
|
"Whether to check libthread_db at load time is off."
|
|
|
|
|
|
|
|
gdb_test_no_output "set stop-on-solib-events 1"
|
|
|
|
gdb_run_cmd
|
|
|
|
gdb_test "" \
|
|
|
|
".*Stopped due to shared library event.*no libraries added or removed.*"
|
|
|
|
|
|
|
|
gdb_test "maint check libthread-db" \
|
|
|
|
"No libthread_db loaded" \
|
|
|
|
"no libpthread.so loaded"
|
|
|
|
|
[gdb/testsuite] Fix check-libthread-db.exp FAILs with glibc 2.33
When running test-case gdb.threads/check-libthread-db.exp on openSUSE
Tumbleweed with glibc 2.33, I get:
...
(gdb) maint check libthread-db^M
Running libthread_db integrity checks:^M
Got thread 0x7ffff7c79b80 => 9354 => 0x7ffff7c79b80; errno = 0 ... OK^M
libthread_db integrity checks passed.^M
(gdb) FAIL: gdb.threads/check-libthread-db.exp: user-initiated check: \
libpthread.so not initialized (pattern 2)
...
The test-case expects instead:
...
Got thread 0x0 => 9354 => 0x0 ... OK^M
...
which is what I get on openSUSE Leap 15.2 with glibc 2.26, and what is
described in the test-case like this:
...
# libthread_db should fake a single thread with th_unique == NULL.
...
Using a breakpoint on check_thread_db_callback we can compare the two
scenarios, and find that in the latter case we hit this code in glibc function
iterate_thread_list in nptl_db/td_ta_thr_iter.c:
...
if (next == 0 && fake_empty)
{
/* __pthread_initialize_minimal has not run. There is just the main
thread to return. We cannot rely on its thread register. They
sometimes contain garbage that would confuse us, left by the
kernel at exec. So if it looks like initialization is incomplete,
we only fake a special descriptor for the initial thread. */
td_thrhandle_t th = { ta, 0 };
return callback (&th, cbdata_p) != 0 ? TD_DBERR : TD_OK;
}
...
while in the former case we don't because this preceding statement doesn't
result in next == 0:
...
err = DB_GET_FIELD (next, ta, head, list_t, next, 0);
...
Note that the comment mentions __pthread_initialize_minimal, but in both cases
it has already run before we hit the callback, so it's possible the comment is
no longer accurate.
The change in behaviour bisect to glibc commit 1daccf403b "nptl: Move stack
list variables into _rtld_global", which moves the initialization of stack
list variables such as __stack_user to an earlier moment, which explains well
enough the observed difference.
Fix this by updating the regexp patterns to agree with what libthread-db is
telling us.
Tested on x86_64-linux, both with glibc 2.33 and 2.26.
gdb/testsuite/ChangeLog:
2021-07-07 Tom de Vries <tdevries@suse.de>
PR testsuite/27690
* gdb.threads/check-libthread-db.exp: Update patterns for glibc 2.33.
2021-07-13 15:56:49 +02:00
|
|
|
# User-initiated check with NPTL possibly uninitialized.
|
2018-06-08 18:06:46 +01:00
|
|
|
gdb_test "continue" \
|
2021-10-07 18:00:08 +02:00
|
|
|
[multi_line \
|
|
|
|
"Stopped due to shared library event:" \
|
|
|
|
" Inferior loaded .*(libpthread|libc).*"]
|
2018-06-08 18:06:46 +01:00
|
|
|
|
|
|
|
gdb_test_sequence "maint check libthread-db" \
|
[gdb/testsuite] Fix check-libthread-db.exp FAILs with glibc 2.33
When running test-case gdb.threads/check-libthread-db.exp on openSUSE
Tumbleweed with glibc 2.33, I get:
...
(gdb) maint check libthread-db^M
Running libthread_db integrity checks:^M
Got thread 0x7ffff7c79b80 => 9354 => 0x7ffff7c79b80; errno = 0 ... OK^M
libthread_db integrity checks passed.^M
(gdb) FAIL: gdb.threads/check-libthread-db.exp: user-initiated check: \
libpthread.so not initialized (pattern 2)
...
The test-case expects instead:
...
Got thread 0x0 => 9354 => 0x0 ... OK^M
...
which is what I get on openSUSE Leap 15.2 with glibc 2.26, and what is
described in the test-case like this:
...
# libthread_db should fake a single thread with th_unique == NULL.
...
Using a breakpoint on check_thread_db_callback we can compare the two
scenarios, and find that in the latter case we hit this code in glibc function
iterate_thread_list in nptl_db/td_ta_thr_iter.c:
...
if (next == 0 && fake_empty)
{
/* __pthread_initialize_minimal has not run. There is just the main
thread to return. We cannot rely on its thread register. They
sometimes contain garbage that would confuse us, left by the
kernel at exec. So if it looks like initialization is incomplete,
we only fake a special descriptor for the initial thread. */
td_thrhandle_t th = { ta, 0 };
return callback (&th, cbdata_p) != 0 ? TD_DBERR : TD_OK;
}
...
while in the former case we don't because this preceding statement doesn't
result in next == 0:
...
err = DB_GET_FIELD (next, ta, head, list_t, next, 0);
...
Note that the comment mentions __pthread_initialize_minimal, but in both cases
it has already run before we hit the callback, so it's possible the comment is
no longer accurate.
The change in behaviour bisect to glibc commit 1daccf403b "nptl: Move stack
list variables into _rtld_global", which moves the initialization of stack
list variables such as __stack_user to an earlier moment, which explains well
enough the observed difference.
Fix this by updating the regexp patterns to agree with what libthread-db is
telling us.
Tested on x86_64-linux, both with glibc 2.33 and 2.26.
gdb/testsuite/ChangeLog:
2021-07-07 Tom de Vries <tdevries@suse.de>
PR testsuite/27690
* gdb.threads/check-libthread-db.exp: Update patterns for glibc 2.33.
2021-07-13 15:56:49 +02:00
|
|
|
"libpthread.so possibly not initialized" \
|
|
|
|
[list \
|
|
|
|
"\[\r\n\]+Running libthread_db integrity checks:" \
|
|
|
|
"\[\r\n\]+\[ \]+Got thread $initial_thread_re ... OK" \
|
|
|
|
"\[\r\n\]+libthread_db integrity checks passed."]
|
2018-06-08 18:06:46 +01:00
|
|
|
|
|
|
|
# User-initiated check with NPTL fully operational.
|
|
|
|
gdb_test_no_output "set stop-on-solib-events 0"
|
|
|
|
gdb_breakpoint break_here
|
|
|
|
gdb_continue_to_breakpoint break_here
|
|
|
|
|
|
|
|
gdb_test_sequence "maint check libthread-db" \
|
|
|
|
"libpthread.so fully initialized" {
|
|
|
|
"\[\r\n\]+Running libthread_db integrity checks:"
|
|
|
|
"\[\r\n\]+\[ \]+Got thread 0x\[1-9a-f\]\[0-9a-f\]+ => \[0-9\]+ => 0x\[1-9a-f\]\[0-9a-f\]+; errno = 23 ... OK"
|
|
|
|
"\[\r\n\]+\[ \]+Got thread 0x\[1-9a-f\]\[0-9a-f\]+ => \[0-9\]+ => 0x\[1-9a-f\]\[0-9a-f\]+; errno = 42 ... OK"
|
|
|
|
"\[\r\n\]+libthread_db integrity checks passed."
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
with_test_prefix "automated load-time check" {
|
|
|
|
|
[gdb/testsuite] Fix check-libthread-db.exp FAILs with glibc 2.33
When running test-case gdb.threads/check-libthread-db.exp on openSUSE
Tumbleweed with glibc 2.33, I get:
...
(gdb) maint check libthread-db^M
Running libthread_db integrity checks:^M
Got thread 0x7ffff7c79b80 => 9354 => 0x7ffff7c79b80; errno = 0 ... OK^M
libthread_db integrity checks passed.^M
(gdb) FAIL: gdb.threads/check-libthread-db.exp: user-initiated check: \
libpthread.so not initialized (pattern 2)
...
The test-case expects instead:
...
Got thread 0x0 => 9354 => 0x0 ... OK^M
...
which is what I get on openSUSE Leap 15.2 with glibc 2.26, and what is
described in the test-case like this:
...
# libthread_db should fake a single thread with th_unique == NULL.
...
Using a breakpoint on check_thread_db_callback we can compare the two
scenarios, and find that in the latter case we hit this code in glibc function
iterate_thread_list in nptl_db/td_ta_thr_iter.c:
...
if (next == 0 && fake_empty)
{
/* __pthread_initialize_minimal has not run. There is just the main
thread to return. We cannot rely on its thread register. They
sometimes contain garbage that would confuse us, left by the
kernel at exec. So if it looks like initialization is incomplete,
we only fake a special descriptor for the initial thread. */
td_thrhandle_t th = { ta, 0 };
return callback (&th, cbdata_p) != 0 ? TD_DBERR : TD_OK;
}
...
while in the former case we don't because this preceding statement doesn't
result in next == 0:
...
err = DB_GET_FIELD (next, ta, head, list_t, next, 0);
...
Note that the comment mentions __pthread_initialize_minimal, but in both cases
it has already run before we hit the callback, so it's possible the comment is
no longer accurate.
The change in behaviour bisect to glibc commit 1daccf403b "nptl: Move stack
list variables into _rtld_global", which moves the initialization of stack
list variables such as __stack_user to an earlier moment, which explains well
enough the observed difference.
Fix this by updating the regexp patterns to agree with what libthread-db is
telling us.
Tested on x86_64-linux, both with glibc 2.33 and 2.26.
gdb/testsuite/ChangeLog:
2021-07-07 Tom de Vries <tdevries@suse.de>
PR testsuite/27690
* gdb.threads/check-libthread-db.exp: Update patterns for glibc 2.33.
2021-07-13 15:56:49 +02:00
|
|
|
# Automated load-time check with NPTL possibly uninitialized.
|
|
|
|
with_test_prefix "libpthread.so possibly not initialized" {
|
2018-06-08 18:06:46 +01:00
|
|
|
clean_restart ${binfile}
|
|
|
|
|
|
|
|
gdb_test_no_output "maint set check-libthread-db 1"
|
|
|
|
gdb_test_no_output "set debug libthread-db 1"
|
|
|
|
gdb_breakpoint break_here
|
|
|
|
gdb_run_cmd
|
|
|
|
|
|
|
|
gdb_test_sequence "" \
|
[gdb/testsuite] Fix check-libthread-db.exp FAILs with glibc 2.33
When running test-case gdb.threads/check-libthread-db.exp on openSUSE
Tumbleweed with glibc 2.33, I get:
...
(gdb) maint check libthread-db^M
Running libthread_db integrity checks:^M
Got thread 0x7ffff7c79b80 => 9354 => 0x7ffff7c79b80; errno = 0 ... OK^M
libthread_db integrity checks passed.^M
(gdb) FAIL: gdb.threads/check-libthread-db.exp: user-initiated check: \
libpthread.so not initialized (pattern 2)
...
The test-case expects instead:
...
Got thread 0x0 => 9354 => 0x0 ... OK^M
...
which is what I get on openSUSE Leap 15.2 with glibc 2.26, and what is
described in the test-case like this:
...
# libthread_db should fake a single thread with th_unique == NULL.
...
Using a breakpoint on check_thread_db_callback we can compare the two
scenarios, and find that in the latter case we hit this code in glibc function
iterate_thread_list in nptl_db/td_ta_thr_iter.c:
...
if (next == 0 && fake_empty)
{
/* __pthread_initialize_minimal has not run. There is just the main
thread to return. We cannot rely on its thread register. They
sometimes contain garbage that would confuse us, left by the
kernel at exec. So if it looks like initialization is incomplete,
we only fake a special descriptor for the initial thread. */
td_thrhandle_t th = { ta, 0 };
return callback (&th, cbdata_p) != 0 ? TD_DBERR : TD_OK;
}
...
while in the former case we don't because this preceding statement doesn't
result in next == 0:
...
err = DB_GET_FIELD (next, ta, head, list_t, next, 0);
...
Note that the comment mentions __pthread_initialize_minimal, but in both cases
it has already run before we hit the callback, so it's possible the comment is
no longer accurate.
The change in behaviour bisect to glibc commit 1daccf403b "nptl: Move stack
list variables into _rtld_global", which moves the initialization of stack
list variables such as __stack_user to an earlier moment, which explains well
enough the observed difference.
Fix this by updating the regexp patterns to agree with what libthread-db is
telling us.
Tested on x86_64-linux, both with glibc 2.33 and 2.26.
gdb/testsuite/ChangeLog:
2021-07-07 Tom de Vries <tdevries@suse.de>
PR testsuite/27690
* gdb.threads/check-libthread-db.exp: Update patterns for glibc 2.33.
2021-07-13 15:56:49 +02:00
|
|
|
"check debug libthread-db output" \
|
|
|
|
[list \
|
|
|
|
"\[\r\n\]+Running libthread_db integrity checks:" \
|
|
|
|
"\[\r\n\]+\[ \]+Got thread $initial_thread_re ... OK" \
|
|
|
|
"\[\r\n\]+libthread_db integrity checks passed." \
|
|
|
|
"\[\r\n\]+\\\[Thread debugging using libthread_db enabled\\\]"]
|
2018-06-08 18:06:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Automated load-time check with NPTL fully operational.
|
|
|
|
with_test_prefix "libpthread.so fully initialized" {
|
|
|
|
clean_restart ${binfile}
|
|
|
|
|
|
|
|
gdb_test_no_output "maint set check-libthread-db 1"
|
|
|
|
gdb_test_no_output "set debug libthread-db 1"
|
|
|
|
|
|
|
|
set test_spawn_id [spawn_wait_for_attach $binfile]
|
|
|
|
set testpid [spawn_id_get_pid $test_spawn_id]
|
|
|
|
|
|
|
|
gdb_test_sequence "attach $testpid" \
|
|
|
|
"check debug libthread-db output" {
|
|
|
|
"\[\r\n\]+Running libthread_db integrity checks:"
|
|
|
|
"\[\r\n\]+\[ \]+Got thread 0x\[1-9a-f\]\[0-9a-f\]+ => \[0-9\]+ => 0x\[1-9a-f\]\[0-9a-f\]+ ... OK"
|
|
|
|
"\[\r\n\]+\[ \]+Got thread 0x\[1-9a-f\]\[0-9a-f\]+ => \[0-9\]+ => 0x\[1-9a-f\]\[0-9a-f\]+ ... OK"
|
|
|
|
"\[\r\n\]+libthread_db integrity checks passed."
|
|
|
|
"\[\r\n\]+[Thread debugging using libthread_db enabled]"
|
|
|
|
}
|
|
|
|
|
|
|
|
gdb_exit
|
|
|
|
kill_wait_spawned_process $test_spawn_id
|
|
|
|
}
|
|
|
|
}
|