Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / check-libthread-db.exp
1 # Copyright 2017-2022 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 continue
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 ".*Stopped due to shared library event.*Inferior loaded .*libpthread.*"
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 }
This page took 0.035589 seconds and 4 git commands to generate.