]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.threads/gcore-thread.exp
Update years in copyright notice for the GDB files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / gcore-thread.exp
CommitLineData
8acc9f48 1# Copyright 2002-2013 Free Software Foundation, Inc.
a911c360
MS
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
a911c360 6# (at your option) any later version.
e22f8b7c 7#
a911c360
MS
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.
e22f8b7c 12#
a911c360 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
a911c360 15
a911c360
MS
16# This file was written by Michael Snyder (msnyder@redhat.com)
17# This is a test for the gdb command "generate-core-file".
18
a911c360 19# Single-threaded test case
0efbbabc
TT
20standard_testfile pthreads.c
21set objfile $binfile.o
22set corefile $binfile.test
23set core0file ${binfile}0.test
a911c360 24
a911c360
MS
25if [istarget "*-*-linux"] then {
26 set target_cflags "-D_MIT_POSIX_THREADS"
27} else {
28 set target_cflags ""
29}
b5ab8ff3 30
774094b8
JK
31# Attempt to prevent -Wl,-z,relro which happens by default at least on
32# Kubuntu-10.10. Due to PR corefiles/11804 will then GDB be unable to find
33# libpthread, therefore libthread_db will not fail as expected
34# on the test `zeroed-threads cannot be listed'.
35
0efbbabc 36set opts [list debug]
774094b8
JK
37if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${objfile}" object $opts] != ""
38 || ([gdb_compile_pthreads "${objfile}" "${binfile}" executable [concat $opts {additional_flags=-Wl,-z,norelro}] ] != ""
39 && [gdb_compile_pthreads "${objfile}" "${binfile}" executable $opts] != "") } {
a911c360
MS
40 return -1
41}
42
43# Now we can proceed with the real testing.
44
45# Start with a fresh gdb.
46
4fe85f5c 47clean_restart ${testfile}
a911c360
MS
48
49# regexp for "horizontal" text (i.e. doesn't include newline or
50# carriage return)
51set horiz "\[^\n\r\]*"
52
53# regexp for newline
54set nl "\[\r\n\]+"
55
56set timeout 30
57
9db70545 58gdb_test_multiple "help gcore" "help gcore" {
a911c360
MS
59 -re "Undefined command: .gcore.*$gdb_prompt $" {
60 # gcore command not supported -- nothing to test here.
61 unsupported "gdb does not support gcore on this target"
62 return -1;
63 }
64 -re "Save a core file .*$gdb_prompt $" {
65 pass "help gcore"
66 }
a911c360
MS
67}
68
3ad13771 69if { ! [ runto_main ] } then {
b60f0898
JB
70 untested gcore-thread.exp
71 return -1
a911c360
MS
72}
73
9db70545 74gdb_test_multiple "info threads" "threads are supported" {
a911c360
MS
75 -re ".* main .*$gdb_prompt $" {
76 # OK, threads are supported.
77 }
78 -re "${nl}$gdb_prompt $" {
79 unsupported "gdb does not support threads on this target"
80 return -1;
81 }
82}
83
84# Make sure thread 1 is running
85delete_breakpoints
86gdb_breakpoint "thread1"
87gdb_test "continue" "Continuing.*Breakpoint.* thread1 .*" "thread 1 is running"
88
89# Make sure thread 2 is running
90delete_breakpoints
91gdb_breakpoint "thread2"
92gdb_test "continue" "Continuing.*Breakpoint.* thread2 .*" "thread 2 is running"
93
94# Drop corefile
2d338fa9 95set core_supported [gdb_gcore_cmd "$corefile" "save a corefile"]
7d605576 96
7d605576
DJ
97if {!$core_supported} {
98 return -1
99}
a911c360 100
4fe85f5c 101
254f582e
JK
102# Test the uninitialized thread list.
103# Provide the case of glibc td_thr_get_info handling of:
104# /* Special case for the main thread before initialization. */
105
106foreach symbol {__stack_user stack_used} {
107 set test "clear ${symbol}.next"
108 gdb_test_multiple "p *(void **) &${symbol} = 0" $test {
109 -re " = \\(void \\*\\) 0x0\r\n$gdb_prompt $" {
110 pass $test
111 }
112 -re "No symbol \"${symbol}\" in current context\\.\r\n$gdb_prompt $" {
113 xfail $test
114 # Do not do the verification.
115 set core0file ""
116 }
117 }
118}
119
120if {"$core0file" != ""} {
121 gdb_test "gcore $core0file" "Saved corefile .*" "save a zeroed-threads corefile"
122}
123
124
a911c360 125# Now restart gdb and load the corefile.
4fe85f5c
JK
126clean_restart ${testfile}
127
128proc load_core { corefile } {
129 global gdb_prompt
774094b8 130 global libthread_db_seen
4fe85f5c
JK
131
132 gdb_test_multiple "core $corefile" \
133 "re-load generated corefile" {
774094b8 134 -re "\\\[Thread debugging using \[^ \r\n\]* enabled\\\]\r\n" {
774094b8
JK
135 exp_continue
136 }
4fe85f5c
JK
137 -re " is not a core dump:.*\r\n$gdb_prompt $" {
138 fail "re-load generated corefile (bad file format)"
139 # No use proceeding from here.
140 return 0;
141 }
142 -re ": No such file or directory.*\r\n$gdb_prompt $" {
143 fail "re-load generated corefile (file not found)"
144 # No use proceeding from here.
145 return 0;
146 }
147 -re "Couldn't find .* registers in core file.*\r\n$gdb_prompt $" {
148 fail "re-load generated corefile (incomplete note section)"
149 }
150 -re "Core was generated by .*\r\n$gdb_prompt $" {
151 pass "re-load generated corefile"
152 }
9db70545 153 }
4fe85f5c
JK
154 return 1
155}
156
fcb44371
JK
157foreach name { corefile core0file } { with_test_prefix $name {
158 if ![load_core [subst $$name]] {
159 continue
160 }
a911c360 161
fcb44371
JK
162 # FIXME: now what can we test about the thread state?
163 # We do not know for certain that there should be at least
164 # three threads, because who knows what kind of many-to-one
165 # mapping various OS's may do? Let's assume that there must
166 # be at least two threads:
a911c360 167
fcb44371
JK
168 gdb_test "info threads" ".*${nl} 2 ${horiz}${nl}\\* 1 .*" \
169 "corefile contains at least two threads"
254f582e 170
fcb44371 171 # One thread in the corefile should be in the "thread2" function.
254f582e 172
fcb44371
JK
173 gdb_test "info threads" ".* thread2 .*" \
174 "a corefile thread is executing thread2"
254f582e 175
fcb44371 176 # The thread2 thread should be marked as the current thread.
254f582e 177
fcb44371
JK
178 gdb_test "info threads" ".*${nl}\\* ${horiz} thread2 .*" \
179 "thread2 is current thread in corefile"
180}}