1 # Copyright 2017-2020 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 with_test_prefix "user-initiated check" {
37 # User-initiated check with libthread_db not loaded.
38 clean_restart ${binfile}
40 gdb_test "maint show check-libthread-db" \
41 "Whether to check libthread_db at load time is off."
43 gdb_test_no_output "set stop-on-solib-events 1"
46 ".*Stopped due to shared library event.*no libraries added or removed.*"
48 gdb_test "maint check libthread-db" \
49 "No libthread_db loaded" \
50 "no libpthread.so loaded"
53 # User-initiated check with NPTL uninitialized.
54 # libthread_db should fake a single thread with th_unique == NULL.
56 ".*Stopped due to shared library event.*Inferior loaded .*libpthread.*"
58 gdb_test_sequence "maint check libthread-db" \
59 "libpthread.so not initialized" {
60 "\[\r\n\]+Running libthread_db integrity checks:"
61 "\[\r\n\]+\[ \]+Got thread 0x0 => \[0-9\]+ => 0x0 ... OK"
62 "\[\r\n\]+libthread_db integrity checks passed."
65 # User-initiated check with NPTL fully operational.
66 gdb_test_no_output "set stop-on-solib-events 0"
67 gdb_breakpoint break_here
68 gdb_continue_to_breakpoint break_here
70 gdb_test_sequence "maint check libthread-db" \
71 "libpthread.so fully initialized" {
72 "\[\r\n\]+Running libthread_db integrity checks:"
73 "\[\r\n\]+\[ \]+Got thread 0x\[1-9a-f\]\[0-9a-f\]+ => \[0-9\]+ => 0x\[1-9a-f\]\[0-9a-f\]+; errno = 23 ... OK"
74 "\[\r\n\]+\[ \]+Got thread 0x\[1-9a-f\]\[0-9a-f\]+ => \[0-9\]+ => 0x\[1-9a-f\]\[0-9a-f\]+; errno = 42 ... OK"
75 "\[\r\n\]+libthread_db integrity checks passed."
79 with_test_prefix "automated load-time check" {
81 # Automated load-time check with NPTL uninitialized.
82 with_test_prefix "libpthread.so not initialized" {
83 clean_restart ${binfile}
85 gdb_test_no_output "maint set check-libthread-db 1"
86 gdb_test_no_output "set debug libthread-db 1"
87 gdb_breakpoint break_here
90 gdb_test_sequence "" \
91 "check debug libthread-db output" {
92 "\[\r\n\]+Running libthread_db integrity checks:"
93 "\[\r\n\]+\[ \]+Got thread 0x0 => \[0-9\]+ => 0x0 ... OK"
94 "\[\r\n\]+libthread_db integrity checks passed."
95 "\[\r\n\]+[Thread debugging using libthread_db enabled]"
99 # Automated load-time check with NPTL fully operational.
100 with_test_prefix "libpthread.so fully initialized" {
101 clean_restart ${binfile}
103 gdb_test_no_output "maint set check-libthread-db 1"
104 gdb_test_no_output "set debug libthread-db 1"
106 set test_spawn_id [spawn_wait_for_attach $binfile]
107 set testpid [spawn_id_get_pid $test_spawn_id]
109 gdb_test_sequence "attach $testpid" \
110 "check debug libthread-db output" {
111 "\[\r\n\]+Running libthread_db integrity checks:"
112 "\[\r\n\]+\[ \]+Got thread 0x\[1-9a-f\]\[0-9a-f\]+ => \[0-9\]+ => 0x\[1-9a-f\]\[0-9a-f\]+ ... OK"
113 "\[\r\n\]+\[ \]+Got thread 0x\[1-9a-f\]\[0-9a-f\]+ => \[0-9\]+ => 0x\[1-9a-f\]\[0-9a-f\]+ ... OK"
114 "\[\r\n\]+libthread_db integrity checks passed."
115 "\[\r\n\]+[Thread debugging using libthread_db enabled]"
119 kill_wait_spawned_process $test_spawn_id