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".
19 # Single-threaded test case
20 set testfile "gcore-thread"
21 set srcfile pthreads.c
22 set objfile ${objdir}/${subdir}/${testfile}.o
23 set binfile ${objdir}/${subdir}/${testfile}
24 set corefile ${objdir}/${subdir}/${testfile}.test
25 set core0file ${objdir}/${subdir}/${testfile}0.test
27 if [istarget "*-*-linux"] then {
28 set target_cflags "-D_MIT_POSIX_THREADS"
33 # Attempt to prevent -Wl,-z,relro which happens by default at least on
34 # Kubuntu-10.10. Due to PR corefiles/11804 will then GDB be unable to find
35 # libpthread, therefore libthread_db will not fail as expected
36 # on the test `zeroed-threads cannot be listed'.
38 set opts [list debug "incdir=${objdir}"]
39 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${objfile}" object $opts] != ""
40 || ([gdb_compile_pthreads "${objfile}" "${binfile}" executable [concat $opts {additional_flags=-Wl,-z,norelro}] ] != ""
41 && [gdb_compile_pthreads "${objfile}" "${binfile}" executable $opts] != "") } {
45 # Now we can proceed with the real testing.
47 # Start with a fresh gdb.
49 clean_restart ${testfile}
51 # regexp for "horizontal" text (i.e. doesn't include newline or
53 set horiz "\[^\n\r\]*"
60 gdb_test_multiple "help gcore" "help gcore" {
61 -re "Undefined command: .gcore.*$gdb_prompt $" {
62 # gcore command not supported -- nothing to test here.
63 unsupported "gdb does not support gcore on this target"
66 -re "Save a core file .*$gdb_prompt $" {
71 if { ! [ runto_main ] } then {
72 untested gcore-thread.exp
76 gdb_test_multiple "info threads" "threads are supported" {
77 -re ".* main .*$gdb_prompt $" {
78 # OK, threads are supported.
80 -re "${nl}$gdb_prompt $" {
81 unsupported "gdb does not support threads on this target"
86 # Make sure thread 1 is running
88 gdb_breakpoint "thread1"
89 gdb_test "continue" "Continuing.*Breakpoint.* thread1 .*" "thread 1 is running"
91 # Make sure thread 2 is running
93 gdb_breakpoint "thread2"
94 gdb_test "continue" "Continuing.*Breakpoint.* thread2 .*" "thread 2 is running"
96 set escapedfilename [string_to_regexp $corefile]
99 gdb_test_multiple "gcore $corefile" "save a corefile" \
101 -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
102 pass "save a corefile"
103 global core_supported
106 -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
107 unsupported "save a corefile"
111 if {!$core_supported} {
116 # Test the uninitialized thread list.
117 # Provide the case of glibc td_thr_get_info handling of:
118 # /* Special case for the main thread before initialization. */
120 foreach symbol {__stack_user stack_used} {
121 set test "clear ${symbol}.next"
122 gdb_test_multiple "p *(void **) &${symbol} = 0" $test {
123 -re " = \\(void \\*\\) 0x0\r\n$gdb_prompt $" {
126 -re "No symbol \"${symbol}\" in current context\\.\r\n$gdb_prompt $" {
128 # Do not do the verification.
134 if {"$core0file" != ""} {
135 gdb_test "gcore $core0file" "Saved corefile .*" "save a zeroed-threads corefile"
139 # Now restart gdb and load the corefile.
140 clean_restart ${testfile}
142 proc load_core { corefile } {
144 global libthread_db_seen
146 set libthread_db_seen 0
147 gdb_test_multiple "core $corefile" \
148 "re-load generated corefile" {
149 -re "\\\[Thread debugging using \[^ \r\n\]* enabled\\\]\r\n" {
150 set libthread_db_seen 1
153 -re " is not a core dump:.*\r\n$gdb_prompt $" {
154 fail "re-load generated corefile (bad file format)"
155 # No use proceeding from here.
158 -re ": No such file or directory.*\r\n$gdb_prompt $" {
159 fail "re-load generated corefile (file not found)"
160 # No use proceeding from here.
163 -re "Couldn't find .* registers in core file.*\r\n$gdb_prompt $" {
164 fail "re-load generated corefile (incomplete note section)"
166 -re "Core was generated by .*\r\n$gdb_prompt $" {
167 pass "re-load generated corefile"
173 if ![load_core $corefile] {
177 # FIXME: now what can we test about the thread state?
178 # We do not know for certain that there should be at least
179 # three threads, because who knows what kind of many-to-one
180 # mapping various OS's may do? Let's assume that there must
181 # be at least two threads:
183 gdb_test "info threads" ".*${nl} 2 ${horiz}${nl}\\* 1 .*" \
184 "corefile contains at least two threads"
186 # One thread in the corefile should be in the "thread2" function.
188 gdb_test "info threads" ".* thread2 .*" \
189 "a corefile thread is executing thread2"
191 # The thread2 thread should be marked as the current thread.
193 gdb_test "info threads" ".*${nl}\\* ${horiz} thread2 .*" \
194 "thread2 is current thread in corefile"
197 # Test the uninitialized thread list.
199 if {"$core0file" != "" && [load_core $core0file]} {
200 set test "zeroed-threads cannot be listed"
202 if {!$libthread_db_seen} {
203 verbose -log "No libthread_db loaded - -Wl,-z,relro compilation?"
206 gdb_test "info threads" "Cannot find new threads: .*" $test