1 # Copyright 2017-2022 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # This test only works for native processes on GNU/Linux.
17 if {[target_info gdb_protocol] != "" || ![istarget *-linux*]} {
21 # Test relies on checking gdb debug output. Do not run if gdb debug is
22 # enabled as any debug will be redirected to the log.
23 if [gdb_debug_enabled] {
24 untested "debug is enabled"
30 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
31 executable debug] != "" } {
35 # Case 1: libthread_db fakes a single thread with th_unique == NULL.
36 set thread_re1 "0 => $decimal => 0"
37 # Case 2: libthread_db already initialized.
38 set thread_re2 "$hex => $decimal => ${hex}(; errno = 0)?"
39 # Match either of the two cases.
40 set initial_thread_re "($thread_re1|$thread_re2)"
42 with_test_prefix "user-initiated check" {
44 # User-initiated check with libthread_db not loaded.
45 clean_restart ${binfile}
47 gdb_test "maint show check-libthread-db" \
48 "Whether to check libthread_db at load time is off."
50 gdb_test_no_output "set stop-on-solib-events 1"
53 ".*Stopped due to shared library event.*no libraries added or removed.*"
55 gdb_test "maint check libthread-db" \
56 "No libthread_db loaded" \
57 "no libpthread.so loaded"
59 # User-initiated check with NPTL possibly uninitialized.
61 ".*Stopped due to shared library event.*Inferior loaded .*libpthread.*"
63 gdb_test_sequence "maint check libthread-db" \
64 "libpthread.so possibly not initialized" \
66 "\[\r\n\]+Running libthread_db integrity checks:" \
67 "\[\r\n\]+\[ \]+Got thread $initial_thread_re ... OK" \
68 "\[\r\n\]+libthread_db integrity checks passed."]
70 # User-initiated check with NPTL fully operational.
71 gdb_test_no_output "set stop-on-solib-events 0"
72 gdb_breakpoint break_here
73 gdb_continue_to_breakpoint break_here
75 gdb_test_sequence "maint check libthread-db" \
76 "libpthread.so fully initialized" {
77 "\[\r\n\]+Running libthread_db integrity checks:"
78 "\[\r\n\]+\[ \]+Got thread 0x\[1-9a-f\]\[0-9a-f\]+ => \[0-9\]+ => 0x\[1-9a-f\]\[0-9a-f\]+; errno = 23 ... OK"
79 "\[\r\n\]+\[ \]+Got thread 0x\[1-9a-f\]\[0-9a-f\]+ => \[0-9\]+ => 0x\[1-9a-f\]\[0-9a-f\]+; errno = 42 ... OK"
80 "\[\r\n\]+libthread_db integrity checks passed."
84 with_test_prefix "automated load-time check" {
86 # Automated load-time check with NPTL possibly uninitialized.
87 with_test_prefix "libpthread.so possibly not initialized" {
88 clean_restart ${binfile}
90 gdb_test_no_output "maint set check-libthread-db 1"
91 gdb_test_no_output "set debug libthread-db 1"
92 gdb_breakpoint break_here
95 gdb_test_sequence "" \
96 "check debug libthread-db output" \
98 "\[\r\n\]+Running libthread_db integrity checks:" \
99 "\[\r\n\]+\[ \]+Got thread $initial_thread_re ... OK" \
100 "\[\r\n\]+libthread_db integrity checks passed." \
101 "\[\r\n\]+\\\[Thread debugging using libthread_db enabled\\\]"]
104 # Automated load-time check with NPTL fully operational.
105 with_test_prefix "libpthread.so fully initialized" {
106 clean_restart ${binfile}
108 gdb_test_no_output "maint set check-libthread-db 1"
109 gdb_test_no_output "set debug libthread-db 1"
111 set test_spawn_id [spawn_wait_for_attach $binfile]
112 set testpid [spawn_id_get_pid $test_spawn_id]
114 gdb_test_sequence "attach $testpid" \
115 "check debug libthread-db output" {
116 "\[\r\n\]+Running libthread_db integrity checks:"
117 "\[\r\n\]+\[ \]+Got thread 0x\[1-9a-f\]\[0-9a-f\]+ => \[0-9\]+ => 0x\[1-9a-f\]\[0-9a-f\]+ ... OK"
118 "\[\r\n\]+\[ \]+Got thread 0x\[1-9a-f\]\[0-9a-f\]+ => \[0-9\]+ => 0x\[1-9a-f\]\[0-9a-f\]+ ... OK"
119 "\[\r\n\]+libthread_db integrity checks passed."
120 "\[\r\n\]+[Thread debugging using libthread_db enabled]"
124 kill_wait_spawned_process $test_spawn_id