| OLD | NEW |
| 1 # Copyright 2002-2004, 2007-2012 Free Software Foundation, Inc. | 1 # Copyright 2002-2004, 2007-2012 Free Software Foundation, Inc. |
| 2 | 2 |
| 3 # This program is free software; you can redistribute it and/or modify | 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 | 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 | 5 # the Free Software Foundation; either version 3 of the License, or |
| 6 # (at your option) any later version. | 6 # (at your option) any later version. |
| 7 # | 7 # |
| 8 # This program is distributed in the hope that it will be useful, | 8 # This program is distributed in the hope that it will be useful, |
| 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 # GNU General Public License for more details. | 11 # GNU General Public License for more details. |
| 12 # | 12 # |
| 13 # You should have received a copy of the GNU General Public License | 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/>. | 14 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | 15 |
| 16 # This file was written by Michael Snyder (msnyder@redhat.com) | 16 # This file was written by Michael Snyder (msnyder@redhat.com) |
| 17 # This is a test for the gdb command "generate-core-file". | 17 # This is a test for the gdb command "generate-core-file". |
| 18 | 18 |
| 19 if $tracelevel then { | |
| 20 strace $tracelevel | |
| 21 } | |
| 22 | |
| 23 # Single-threaded test case | 19 # Single-threaded test case |
| 24 set testfile "gcore-thread" | 20 standard_testfile pthreads.c |
| 25 set srcfile pthreads.c | 21 set objfile $binfile.o |
| 26 set objfile ${objdir}/${subdir}/${testfile}.o | 22 set corefile $binfile.test |
| 27 set binfile ${objdir}/${subdir}/${testfile} | 23 set core0file ${binfile}0.test |
| 28 set corefile ${objdir}/${subdir}/${testfile}.test | |
| 29 set core0file ${objdir}/${subdir}/${testfile}0.test | |
| 30 | 24 |
| 31 if [istarget "*-*-linux"] then { | 25 if [istarget "*-*-linux"] then { |
| 32 set target_cflags "-D_MIT_POSIX_THREADS" | 26 set target_cflags "-D_MIT_POSIX_THREADS" |
| 33 } else { | 27 } else { |
| 34 set target_cflags "" | 28 set target_cflags "" |
| 35 } | 29 } |
| 36 | 30 |
| 37 # Attempt to prevent -Wl,-z,relro which happens by default at least on | 31 # 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 | 32 # 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 | 33 # libpthread, therefore libthread_db will not fail as expected |
| 40 # on the test `zeroed-threads cannot be listed'. | 34 # on the test `zeroed-threads cannot be listed'. |
| 41 | 35 |
| 42 set opts [list debug "incdir=${objdir}"] | 36 set opts [list debug] |
| 43 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${objfile}" object $
opts] != "" | 37 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${objfile}" object $
opts] != "" |
| 44 || ([gdb_compile_pthreads "${objfile}" "${binfile}" executable [concat $opts
{additional_flags=-Wl,-z,norelro}] ] != "" | 38 || ([gdb_compile_pthreads "${objfile}" "${binfile}" executable [concat $opts
{additional_flags=-Wl,-z,norelro}] ] != "" |
| 45 && [gdb_compile_pthreads "${objfile}" "${binfile}" executable $opts] !=
"") } { | 39 && [gdb_compile_pthreads "${objfile}" "${binfile}" executable $opts] !=
"") } { |
| 46 return -1 | 40 return -1 |
| 47 } | 41 } |
| 48 | 42 |
| 49 # Now we can proceed with the real testing. | 43 # Now we can proceed with the real testing. |
| 50 | 44 |
| 51 # Start with a fresh gdb. | 45 # Start with a fresh gdb. |
| 52 | 46 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 } | 134 } |
| 141 | 135 |
| 142 | 136 |
| 143 # Now restart gdb and load the corefile. | 137 # Now restart gdb and load the corefile. |
| 144 clean_restart ${testfile} | 138 clean_restart ${testfile} |
| 145 | 139 |
| 146 proc load_core { corefile } { | 140 proc load_core { corefile } { |
| 147 global gdb_prompt | 141 global gdb_prompt |
| 148 global libthread_db_seen | 142 global libthread_db_seen |
| 149 | 143 |
| 150 set libthread_db_seen 0 | |
| 151 gdb_test_multiple "core $corefile" \ | 144 gdb_test_multiple "core $corefile" \ |
| 152 "re-load generated corefile" { | 145 "re-load generated corefile" { |
| 153 -re "\\\[Thread debugging using \[^ \r\n\]* enabled\\\]\r\n" { | 146 -re "\\\[Thread debugging using \[^ \r\n\]* enabled\\\]\r\n" { |
| 154 set libthread_db_seen 1 | |
| 155 exp_continue | 147 exp_continue |
| 156 } | 148 } |
| 157 -re " is not a core dump:.*\r\n$gdb_prompt $" { | 149 -re " is not a core dump:.*\r\n$gdb_prompt $" { |
| 158 fail "re-load generated corefile (bad file format)" | 150 fail "re-load generated corefile (bad file format)" |
| 159 # No use proceeding from here. | 151 # No use proceeding from here. |
| 160 return 0; | 152 return 0; |
| 161 } | 153 } |
| 162 -re ": No such file or directory.*\r\n$gdb_prompt $" { | 154 -re ": No such file or directory.*\r\n$gdb_prompt $" { |
| 163 fail "re-load generated corefile (file not found)" | 155 fail "re-load generated corefile (file not found)" |
| 164 # No use proceeding from here. | 156 # No use proceeding from here. |
| 165 return 0; | 157 return 0; |
| 166 } | 158 } |
| 167 -re "Couldn't find .* registers in core file.*\r\n$gdb_prompt $" { | 159 -re "Couldn't find .* registers in core file.*\r\n$gdb_prompt $" { |
| 168 fail "re-load generated corefile (incomplete note section)" | 160 fail "re-load generated corefile (incomplete note section)" |
| 169 } | 161 } |
| 170 -re "Core was generated by .*\r\n$gdb_prompt $" { | 162 -re "Core was generated by .*\r\n$gdb_prompt $" { |
| 171 pass "re-load generated corefile" | 163 pass "re-load generated corefile" |
| 172 } | 164 } |
| 173 } | 165 } |
| 174 return 1 | 166 return 1 |
| 175 } | 167 } |
| 176 | 168 |
| 177 if ![load_core $corefile] { | 169 foreach name { corefile core0file } { with_test_prefix $name { |
| 178 return | 170 if ![load_core [subst $$name]] { |
| 179 } | 171 » continue |
| 172 } |
| 180 | 173 |
| 181 # FIXME: now what can we test about the thread state? | 174 # FIXME: now what can we test about the thread state? |
| 182 # We do not know for certain that there should be at least | 175 # We do not know for certain that there should be at least |
| 183 # three threads, because who knows what kind of many-to-one | 176 # three threads, because who knows what kind of many-to-one |
| 184 # mapping various OS's may do? Let's assume that there must | 177 # mapping various OS's may do? Let's assume that there must |
| 185 # be at least two threads: | 178 # be at least two threads: |
| 186 | 179 |
| 187 gdb_test "info threads" ".*${nl} 2 ${horiz}${nl}\\* 1 .*" \ | 180 gdb_test "info threads" ".*${nl} 2 ${horiz}${nl}\\* 1 .*" \ |
| 188 » "corefile contains at least two threads" | 181 » "corefile contains at least two threads" |
| 189 | 182 |
| 190 # One thread in the corefile should be in the "thread2" function. | 183 # One thread in the corefile should be in the "thread2" function. |
| 191 | 184 |
| 192 gdb_test "info threads" ".* thread2 .*" \ | 185 gdb_test "info threads" ".* thread2 .*" \ |
| 193 » "a corefile thread is executing thread2" | 186 » "a corefile thread is executing thread2" |
| 194 | 187 |
| 195 # The thread2 thread should be marked as the current thread. | 188 # The thread2 thread should be marked as the current thread. |
| 196 | 189 |
| 197 gdb_test "info threads" ".*${nl}\\* ${horiz} thread2 .*" \ | 190 gdb_test "info threads" ".*${nl}\\* ${horiz} thread2 .*" \ |
| 198 » "thread2 is current thread in corefile" | 191 » "thread2 is current thread in corefile" |
| 199 | 192 }} |
| 200 | |
| 201 # Test the uninitialized thread list. | |
| 202 | |
| 203 if {"$core0file" != "" && [load_core $core0file]} { | |
| 204 set test "zeroed-threads cannot be listed" | |
| 205 | |
| 206 if {!$libthread_db_seen} { | |
| 207 » verbose -log "No libthread_db loaded - -Wl,-z,relro compilation?" | |
| 208 » xfail $test | |
| 209 } else { | |
| 210 » gdb_test "info threads" "Cannot find new threads: .*" $test | |
| 211 } | |
| 212 } | |
| OLD | NEW |