]> 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-2024 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] != ""} {
18 return
19 }
20 require {istarget *-linux*}
21
22 # Test relies on checking gdb debug output. Do not run if gdb debug is
23 # enabled as any debug will be redirected to the log.
24 require !gdb_debug_enabled
25
26 standard_testfile
27
28 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
29 executable debug] != "" } {
30 return -1
31 }
32
33 # Case 1: libthread_db fakes a single thread with th_unique == NULL.
34 set thread_re1 "0 => $decimal => 0"
35 # Case 2: libthread_db already initialized.
36 set thread_re2 "$hex => $decimal => ${hex}(; errno = 0)?"
37 # Match either of the two cases.
38 set initial_thread_re "($thread_re1|$thread_re2)"
39
40 with_test_prefix "user-initiated check" {
41
42 # User-initiated check with libthread_db not loaded.
43 clean_restart ${binfile}
44
45 gdb_test "maint show check-libthread-db" \
46 "Whether to check libthread_db at load time is off."
47
48 gdb_test_no_output "set stop-on-solib-events 1"
49 gdb_run_cmd
50 gdb_test "" \
51 ".*Stopped due to shared library event.*no libraries added or removed.*"
52
53 gdb_test "maint check libthread-db" \
54 "No libthread_db loaded" \
55 "no libpthread.so loaded"
56
57 # User-initiated check with NPTL possibly uninitialized.
58 gdb_test "continue" \
59 [multi_line \
60 "Stopped due to shared library event:" \
61 " Inferior loaded .*(libpthread|libc).*"]
62
63 gdb_test_sequence "maint check libthread-db" \
64 "libpthread.so possibly not initialized" \
65 [list \
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."]
69
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
74
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."
81 }
82 }
83
84 with_test_prefix "automated load-time check" {
85
86 # Automated load-time check with NPTL possibly uninitialized.
87 with_test_prefix "libpthread.so possibly not initialized" {
88 clean_restart ${binfile}
89
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
93 gdb_run_cmd
94
95 gdb_test_sequence "" \
96 "check debug libthread-db output" \
97 [list \
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\\\]"]
102 }
103
104 # Automated load-time check with NPTL fully operational.
105 with_test_prefix "libpthread.so fully initialized" {
106 clean_restart ${binfile}
107
108 gdb_test_no_output "maint set check-libthread-db 1"
109 gdb_test_no_output "set debug libthread-db 1"
110
111 set test_spawn_id [spawn_wait_for_attach $binfile]
112 set testpid [spawn_id_get_pid $test_spawn_id]
113
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]"
121 }
122
123 gdb_exit
124 kill_wait_spawned_process $test_spawn_id
125 }
126 }