]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.threads/check-libthread-db.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / check-libthread-db.exp
1 # Copyright 2017-2023 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
15
16 # This test only works for native processes on GNU/Linux.
17 if {[target_info gdb_protocol] != "" || ![istarget *-linux*]} {
18 return
19 }
20
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"
25 return 0
26 }
27
28 standard_testfile
29
30 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
31 executable debug] != "" } {
32 return -1
33 }
34
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)"
41
42 with_test_prefix "user-initiated check" {
43
44 # User-initiated check with libthread_db not loaded.
45 clean_restart ${binfile}
46
47 gdb_test "maint show check-libthread-db" \
48 "Whether to check libthread_db at load time is off."
49
50 gdb_test_no_output "set stop-on-solib-events 1"
51 gdb_run_cmd
52 gdb_test "" \
53 ".*Stopped due to shared library event.*no libraries added or removed.*"
54
55 gdb_test "maint check libthread-db" \
56 "No libthread_db loaded" \
57 "no libpthread.so loaded"
58
59 # User-initiated check with NPTL possibly uninitialized.
60 gdb_test "continue" \
61 [multi_line \
62 "Stopped due to shared library event:" \
63 " Inferior loaded .*(libpthread|libc).*"]
64
65 gdb_test_sequence "maint check libthread-db" \
66 "libpthread.so possibly not initialized" \
67 [list \
68 "\[\r\n\]+Running libthread_db integrity checks:" \
69 "\[\r\n\]+\[ \]+Got thread $initial_thread_re ... OK" \
70 "\[\r\n\]+libthread_db integrity checks passed."]
71
72 # User-initiated check with NPTL fully operational.
73 gdb_test_no_output "set stop-on-solib-events 0"
74 gdb_breakpoint break_here
75 gdb_continue_to_breakpoint break_here
76
77 gdb_test_sequence "maint check libthread-db" \
78 "libpthread.so fully initialized" {
79 "\[\r\n\]+Running libthread_db integrity checks:"
80 "\[\r\n\]+\[ \]+Got thread 0x\[1-9a-f\]\[0-9a-f\]+ => \[0-9\]+ => 0x\[1-9a-f\]\[0-9a-f\]+; errno = 23 ... OK"
81 "\[\r\n\]+\[ \]+Got thread 0x\[1-9a-f\]\[0-9a-f\]+ => \[0-9\]+ => 0x\[1-9a-f\]\[0-9a-f\]+; errno = 42 ... OK"
82 "\[\r\n\]+libthread_db integrity checks passed."
83 }
84 }
85
86 with_test_prefix "automated load-time check" {
87
88 # Automated load-time check with NPTL possibly uninitialized.
89 with_test_prefix "libpthread.so possibly not initialized" {
90 clean_restart ${binfile}
91
92 gdb_test_no_output "maint set check-libthread-db 1"
93 gdb_test_no_output "set debug libthread-db 1"
94 gdb_breakpoint break_here
95 gdb_run_cmd
96
97 gdb_test_sequence "" \
98 "check debug libthread-db output" \
99 [list \
100 "\[\r\n\]+Running libthread_db integrity checks:" \
101 "\[\r\n\]+\[ \]+Got thread $initial_thread_re ... OK" \
102 "\[\r\n\]+libthread_db integrity checks passed." \
103 "\[\r\n\]+\\\[Thread debugging using libthread_db enabled\\\]"]
104 }
105
106 # Automated load-time check with NPTL fully operational.
107 with_test_prefix "libpthread.so fully initialized" {
108 clean_restart ${binfile}
109
110 gdb_test_no_output "maint set check-libthread-db 1"
111 gdb_test_no_output "set debug libthread-db 1"
112
113 set test_spawn_id [spawn_wait_for_attach $binfile]
114 set testpid [spawn_id_get_pid $test_spawn_id]
115
116 gdb_test_sequence "attach $testpid" \
117 "check debug libthread-db output" {
118 "\[\r\n\]+Running libthread_db integrity checks:"
119 "\[\r\n\]+\[ \]+Got thread 0x\[1-9a-f\]\[0-9a-f\]+ => \[0-9\]+ => 0x\[1-9a-f\]\[0-9a-f\]+ ... OK"
120 "\[\r\n\]+\[ \]+Got thread 0x\[1-9a-f\]\[0-9a-f\]+ => \[0-9\]+ => 0x\[1-9a-f\]\[0-9a-f\]+ ... OK"
121 "\[\r\n\]+libthread_db integrity checks passed."
122 "\[\r\n\]+[Thread debugging using libthread_db enabled]"
123 }
124
125 gdb_exit
126 kill_wait_spawned_process $test_spawn_id
127 }
128 }