1 # Copyright 2002-2024 Free Software Foundation, Inc. 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 5 # the Free Software Foundation; either version 3 of the License, or 6 # (at your option) any later version. 7 # 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. 12 # 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/>. 15 16 # This file was written by Michael Snyder (msnyder (at) redhat.com) 17 # This is a test for the gdb command "generate-core-file". 18 19 # Single-threaded test case 20 standard_testfile pthreads.c 21 set objfile $binfile.o 22 set corefile $binfile.test 23 set core0file ${binfile}0.test 24 25 if {[istarget "*-*-linux"]} { 26 set target_cflags "-D_MIT_POSIX_THREADS" 27 } else { 28 set target_cflags "" 29 } 30 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 36 set opts [list debug] 37 if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${objfile}" object $opts] != "" 38 || ([gdb_compile_pthreads "${objfile}" "${binfile}" executable [concat $opts {ldflags=-Wl,-z,norelro}] ] != "" 39 && [gdb_compile_pthreads "${objfile}" "${binfile}" executable $opts] != "") } { 40 return -1 41 } 42 43 # Now we can proceed with the real testing. 44 45 # Start with a fresh gdb. 46 47 clean_restart ${testfile} 48 49 # regexp for "horizontal" text (i.e. doesn't include newline or 50 # carriage return) 51 set horiz "\[^\n\r\]*" 52 53 # regexp for newline 54 set nl "\r\n" 55 56 set timeout 30 57 58 if {![runto_main]} { 59 return -1 60 } 61 62 gdb_test_multiple "info threads" "threads are supported" { 63 -re ".* main .*$gdb_prompt $" { 64 # OK, threads are supported. 65 } 66 -re "${nl}$gdb_prompt $" { 67 unsupported "gdb does not support threads on this target" 68 return -1 69 } 70 } 71 72 # Make sure thread 1 is running 73 delete_breakpoints 74 gdb_breakpoint "thread1" 75 gdb_test "continue" "Continuing.*Breakpoint.* thread1 .*" "thread 1 is running" 76 77 # Make sure thread 2 is running 78 delete_breakpoints 79 gdb_breakpoint "thread2" 80 gdb_test "continue" "Continuing.*Breakpoint.* thread2 .*" "thread 2 is running" 81 82 # Drop corefile 83 set core_supported [gdb_gcore_cmd "$corefile" "save a corefile"] 84 85 if {!$core_supported} { 86 return -1 87 } 88 89 90 # Test the uninitialized thread list. 91 # Provide the case of glibc td_thr_get_info handling of: 92 # /* Special case for the main thread before initialization. */ 93 94 foreach symbol {__stack_user stack_used} { 95 set test "clear ${symbol}.next" 96 gdb_test_multiple "p *(void **) &${symbol} = 0" $test { 97 -re " = \\(void \\*\\) 0x0\r\n$gdb_prompt $" { 98 pass $test 99 } 100 -re "No symbol \"${symbol}\" in current context\\.\r\n$gdb_prompt $" { 101 xfail $test 102 # Do not do the verification. 103 set core0file "" 104 } 105 } 106 } 107 108 if {"$core0file" != ""} { 109 gdb_gcore_cmd $core0file "save a zeroed-threads corefile" 110 } 111 112 113 # Now restart gdb and load the corefile. 114 clean_restart ${testfile} 115 116 proc load_core { filename } { 117 global horiz nl 118 119 set core_loaded [gdb_core_cmd $filename "re-load generated corefile"] 120 if { $core_loaded == -1 } { 121 # No use proceeding from here. 122 return 123 } 124 125 # FIXME: now what can we test about the thread state? 126 # We do not know for certain that there should be at least 127 # three threads, because who knows what kind of many-to-one 128 # mapping various OS's may do? Let's assume that there must 129 # be at least two threads: 130 131 gdb_test "info threads" "\\* 1 ${horiz}${nl} 2 ${horiz}.*" \ 132 "corefile contains at least two threads" 133 134 # One thread in the corefile should be in the "thread2" function. 135 136 gdb_test "info threads" ".* thread2 .*" \ 137 "a corefile thread is executing thread2" 138 139 # The thread2 thread should be marked as the current thread. 140 141 gdb_test "info threads" "\\* ${horiz} thread2 .*" \ 142 "thread2 is current thread in corefile" 143 } 144 145 foreach name { corefile core0file } { 146 set filename [subst $$name] 147 if { $filename == "" } { 148 continue 149 } 150 with_test_prefix $name { 151 load_core $filename 152 } 153 } 154