1 # Copyright 2002, 2003, 2004, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # This file was written by Michael Snyder (msnyder@redhat.com)
18 # This is a test for the gdb command "generate-core-file".
24 # Single-threaded test case
25 set testfile "gcore-thread"
26 set srcfile pthreads.c
27 set objfile ${objdir}/${subdir}/${testfile}.o
28 set binfile ${objdir}/${subdir}/${testfile}
29 set corefile ${objdir}/${subdir}/${testfile}.test
30 set core0file ${objdir}/${subdir}/${testfile}0.test
32 if [istarget "*-*-linux"] then {
33 set target_cflags "-D_MIT_POSIX_THREADS"
38 # Attempt to prevent -Wl,-z,relro which happens by default at least on
39 # Kubuntu-10.10. Due to PR corefiles/11804 will then GDB be unable to find
40 # libpthread, therefore libthread_db will not fail as expected
41 # on the test `zeroed-threads cannot be listed'.
43 set opts [list debug "incdir=${objdir}"]
44 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${objfile}" object $opts] != ""
45 || ([gdb_compile_pthreads "${objfile}" "${binfile}" executable [concat $opts {additional_flags=-Wl,-z,norelro}] ] != ""
46 && [gdb_compile_pthreads "${objfile}" "${binfile}" executable $opts] != "") } {
50 # Now we can proceed with the real testing.
52 # Start with a fresh gdb.
54 clean_restart ${testfile}
56 # regexp for "horizontal" text (i.e. doesn't include newline or
58 set horiz "\[^\n\r\]*"
65 gdb_test_multiple "help gcore" "help gcore" {
66 -re "Undefined command: .gcore.*$gdb_prompt $" {
67 # gcore command not supported -- nothing to test here.
68 unsupported "gdb does not support gcore on this target"
71 -re "Save a core file .*$gdb_prompt $" {
76 if { ! [ runto_main ] } then {
77 untested gcore-thread.exp
81 gdb_test_multiple "info threads" "threads are supported" {
82 -re ".* main .*$gdb_prompt $" {
83 # OK, threads are supported.
85 -re "${nl}$gdb_prompt $" {
86 unsupported "gdb does not support threads on this target"
91 # Make sure thread 1 is running
93 gdb_breakpoint "thread1"
94 gdb_test "continue" "Continuing.*Breakpoint.* thread1 .*" "thread 1 is running"
96 # Make sure thread 2 is running
98 gdb_breakpoint "thread2"
99 gdb_test "continue" "Continuing.*Breakpoint.* thread2 .*" "thread 2 is running"
101 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"
112 global core_supported
117 global core_supported
118 if {!$core_supported} {
123 # Test the uninitialized thread list.
124 # Provide the case of glibc td_thr_get_info handling of:
125 # /* Special case for the main thread before initialization. */
127 foreach symbol {__stack_user stack_used} {
128 set test "clear ${symbol}.next"
129 gdb_test_multiple "p *(void **) &${symbol} = 0" $test {
130 -re " = \\(void \\*\\) 0x0\r\n$gdb_prompt $" {
133 -re "No symbol \"${symbol}\" in current context\\.\r\n$gdb_prompt $" {
135 # Do not do the verification.
141 if {"$core0file" != ""} {
142 gdb_test "gcore $core0file" "Saved corefile .*" "save a zeroed-threads corefile"
146 # Now restart gdb and load the corefile.
147 clean_restart ${testfile}
149 proc load_core { corefile } {
151 global libthread_db_seen
153 set libthread_db_seen 0
154 gdb_test_multiple "core $corefile" \
155 "re-load generated corefile" {
156 -re "\\\[Thread debugging using \[^ \r\n\]* enabled\\\]\r\n" {
157 set libthread_db_seen 1
160 -re " is not a core dump:.*\r\n$gdb_prompt $" {
161 fail "re-load generated corefile (bad file format)"
162 # No use proceeding from here.
165 -re ": No such file or directory.*\r\n$gdb_prompt $" {
166 fail "re-load generated corefile (file not found)"
167 # No use proceeding from here.
170 -re "Couldn't find .* registers in core file.*\r\n$gdb_prompt $" {
171 fail "re-load generated corefile (incomplete note section)"
173 -re "Core was generated by .*\r\n$gdb_prompt $" {
174 pass "re-load generated corefile"
180 if ![load_core $corefile] {
184 # FIXME: now what can we test about the thread state?
185 # We do not know for certain that there should be at least
186 # three threads, because who knows what kind of many-to-one
187 # mapping various OS's may do? Let's assume that there must
188 # be at least two threads:
190 gdb_test "info threads" ".*${nl} 2 ${horiz}${nl}\\* 1 .*" \
191 "corefile contains at least two threads"
193 # One thread in the corefile should be in the "thread2" function.
195 gdb_test "info threads" ".* thread2 .*" \
196 "a corefile thread is executing thread2"
198 # The thread2 thread should be marked as the current thread.
200 gdb_test "info threads" ".*${nl}\\* ${horiz} thread2 .*" \
201 "thread2 is current thread in corefile"
204 # Test the uninitialized thread list.
206 if {"$core0file" != "" && [load_core $core0file]} {
207 set test "zeroed-threads cannot be listed"
209 if {!$libthread_db_seen} {
210 verbose -log "No libthread_db loaded - -Wl,-z,relro compilation?"
213 gdb_test "info threads" "Cannot find new threads: .*" $test