1 # Copyright 2002-2004, 2007-2012 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 file was written by Michael Snyder (msnyder@redhat.com)
17 # This is a test for the gdb command "generate-core-file".
23 # Single-threaded test case
24 set testfile "gcore-thread"
25 set srcfile pthreads.c
26 set objfile ${objdir}/${subdir}/${testfile}.o
27 set binfile ${objdir}/${subdir}/${testfile}
28 set corefile ${objdir}/${subdir}/${testfile}.test
29 set core0file ${objdir}/${subdir}/${testfile}0.test
31 if [istarget "*-*-linux"] then {
32 set target_cflags "-D_MIT_POSIX_THREADS"
37 # Attempt to prevent -Wl,-z,relro which happens by default at least on
38 # Kubuntu-10.10. Due to PR corefiles/11804 will then GDB be unable to find
39 # libpthread, therefore libthread_db will not fail as expected
40 # on the test `zeroed-threads cannot be listed'.
42 set opts [list debug "incdir=${objdir}"]
43 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${objfile}" object $opts] != ""
44 || ([gdb_compile_pthreads "${objfile}" "${binfile}" executable [concat $opts {additional_flags=-Wl,-z,norelro}] ] != ""
45 && [gdb_compile_pthreads "${objfile}" "${binfile}" executable $opts] != "") } {
49 # Now we can proceed with the real testing.
51 # Start with a fresh gdb.
53 clean_restart ${testfile}
55 # regexp for "horizontal" text (i.e. doesn't include newline or
57 set horiz "\[^\n\r\]*"
64 gdb_test_multiple "help gcore" "help gcore" {
65 -re "Undefined command: .gcore.*$gdb_prompt $" {
66 # gcore command not supported -- nothing to test here.
67 unsupported "gdb does not support gcore on this target"
70 -re "Save a core file .*$gdb_prompt $" {
75 if { ! [ runto_main ] } then {
76 untested gcore-thread.exp
80 gdb_test_multiple "info threads" "threads are supported" {
81 -re ".* main .*$gdb_prompt $" {
82 # OK, threads are supported.
84 -re "${nl}$gdb_prompt $" {
85 unsupported "gdb does not support threads on this target"
90 # Make sure thread 1 is running
92 gdb_breakpoint "thread1"
93 gdb_test "continue" "Continuing.*Breakpoint.* thread1 .*" "thread 1 is running"
95 # Make sure thread 2 is running
97 gdb_breakpoint "thread2"
98 gdb_test "continue" "Continuing.*Breakpoint.* thread2 .*" "thread 2 is running"
100 set escapedfilename [string_to_regexp $corefile]
103 gdb_test_multiple "gcore $corefile" "save a corefile" \
105 -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
106 pass "save a corefile"
107 global core_supported
110 -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
111 unsupported "save a corefile"
115 if {!$core_supported} {
120 # Test the uninitialized thread list.
121 # Provide the case of glibc td_thr_get_info handling of:
122 # /* Special case for the main thread before initialization. */
124 foreach symbol {__stack_user stack_used} {
125 set test "clear ${symbol}.next"
126 gdb_test_multiple "p *(void **) &${symbol} = 0" $test {
127 -re " = \\(void \\*\\) 0x0\r\n$gdb_prompt $" {
130 -re "No symbol \"${symbol}\" in current context\\.\r\n$gdb_prompt $" {
132 # Do not do the verification.
138 if {"$core0file" != ""} {
139 gdb_test "gcore $core0file" "Saved corefile .*" "save a zeroed-threads corefile"
143 # Now restart gdb and load the corefile.
144 clean_restart ${testfile}
146 proc load_core { corefile } {
148 global libthread_db_seen
150 set libthread_db_seen 0
151 gdb_test_multiple "core $corefile" \
152 "re-load generated corefile" {
153 -re "\\\[Thread debugging using \[^ \r\n\]* enabled\\\]\r\n" {
154 set libthread_db_seen 1
157 -re " is not a core dump:.*\r\n$gdb_prompt $" {
158 fail "re-load generated corefile (bad file format)"
159 # No use proceeding from here.
162 -re ": No such file or directory.*\r\n$gdb_prompt $" {
163 fail "re-load generated corefile (file not found)"
164 # No use proceeding from here.
167 -re "Couldn't find .* registers in core file.*\r\n$gdb_prompt $" {
168 fail "re-load generated corefile (incomplete note section)"
170 -re "Core was generated by .*\r\n$gdb_prompt $" {
171 pass "re-load generated corefile"
177 if ![load_core $corefile] {
181 # FIXME: now what can we test about the thread state?
182 # We do not know for certain that there should be at least
183 # three threads, because who knows what kind of many-to-one
184 # mapping various OS's may do? Let's assume that there must
185 # be at least two threads:
187 gdb_test "info threads" ".*${nl} 2 ${horiz}${nl}\\* 1 .*" \
188 "corefile contains at least two threads"
190 # One thread in the corefile should be in the "thread2" function.
192 gdb_test "info threads" ".* thread2 .*" \
193 "a corefile thread is executing thread2"
195 # The thread2 thread should be marked as the current thread.
197 gdb_test "info threads" ".*${nl}\\* ${horiz} thread2 .*" \
198 "thread2 is current thread in corefile"
201 # Test the uninitialized thread list.
203 if {"$core0file" != "" && [load_core $core0file]} {
204 set test "zeroed-threads cannot be listed"
206 if {!$libthread_db_seen} {
207 verbose -log "No libthread_db loaded - -Wl,-z,relro compilation?"
210 gdb_test "info threads" "Cannot find new threads: .*" $test