# tls.exp -- Expect script to test thread-local storage
-# Copyright (C) 1992, 2003 Free Software Foundation, Inc.
+# Copyright (C) 1992-2013 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
+# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+# along with this program. If not, see <http://www.gnu.org/licenses/>. */
-# Please email any bugs, comments, and/or additions to this file to:
-# bug-gdb@prep.ai.mit.edu
-
-set testfile tls
-set srcfile ${testfile}.c
-set binfile ${objdir}/${subdir}/${testfile}
+standard_testfile tls.c tls2.c
if [istarget "*-*-linux"] then {
set target_cflags "-D_MIT_POSIX_THREADS"
set target_cflags ""
}
-if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug "incdir=${objdir}"]] != "" } {
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile} ${srcdir}/${subdir}/${srcfile2}" "${binfile}" executable [list c++ debug]] != "" } {
return -1
}
"= $expected_value" \
"${number} thread local storage"
- gdb_test "p another_thread_local" \
+ gdb_test "p K::another_thread_local" \
"= $me_variable" \
"${number} another thread local storage"
".*a_thread_local.*a thread-local variable at offset.*" \
"${number} info address a_thread_local"
- gdb_test "info address another_thread_local" \
+ gdb_test "info address K::another_thread_local" \
".*another_thread_local.*a thread-local variable at offset.*" \
"${number} info address another_thread_local"
}
}
}
-gdb_exit
-gdb_start
-gdb_reinitialize_dir $srcdir/$subdir
-
-gdb_load ${binfile}
+clean_restart ${binfile}
if ![runto_main] then {
fail "Can't run to main"
return 0
unsupported "continue to first thread: system does not support TLS"
return -1
}
- -re ".*Program exited normally.*$gdb_prompt $" {
+ -re ".*$inferior_exited_re normally.*$gdb_prompt $" {
fail "continue to first thread: program runaway"
}
-re ".*Pass 0 done.*Pass 1 done.*$gdb_prompt $" {
set no_of_threads 0
send_gdb "info thread\n"
gdb_expect {
- -re "^info thread\[ \t\r\n\]+(\[0-9\]+) Thread.*$gdb_prompt $" {
+ -re "^info thread\[ \t\r\n\]+ *Id .*Frame\[ \t\r\n\]+(\[0-9\]+) *Thread.*$gdb_prompt $" {
set no_of_threads $expect_out(1,string)
pass "get number of threads"
}
incr thrs_in_spin
select_thread $i
set level $spin_threads_level($i)
- gdb_test "up $level" ".*spin.*sem_wait.*" "thread $i up"
+ # We expect to be in sem_wait, but if the thread has not yet
+ # been scheduled, we might be in sem_post still. We could be at
+ # any intermediate point in spin, too, but that is much less
+ # likely.
+ gdb_test "up $level" ".*spin.*sem_(wait|post).*" "thread $i up"
check_thread_local $i
}
}
send_gdb "info thread\n"
gdb_expect {
- -re ".* 1 Thread.*2 Thread.*$gdb_prompt $" {
+ -re ".* 1 *Thread.*2 *Thread.*$gdb_prompt $" {
fail "Too many threads left at end"
}
- -re ".*\\\* 1 Thread.*main.*$gdb_prompt $" {
+ -re ".*\\\* 1 *Thread.*main.*$gdb_prompt $" {
pass "Expect only base thread at end"
}
-re ".*No stack.*$gdb_prompt $" {
gdb_test "info address a_global" \
".*a_global.*static storage at address.*" "info address a_global"
-setup_kfail "gdb/1294" "*-*-*"
-gdb_test "info address me" ".*me.*is a variable at offset.*" "info address me"
+gdb_test "info address me" ".*me.*is a (complex DWARF expression:|variable).*" \
+ "info address me"
+
+
+# Test LOC_UNRESOLVED references resolving for `extern' TLS variables.
+
+gdb_test "p a_thread_local" " = \[0-9\]+"
+# Here it could crash with: Cannot access memory at address 0x0
+gdb_test "p file2_thread_local" " = \[0-9\]+"
+# Depending on the current lookup scope we get LOC_UNRESOLVED or LOC_COMPUTED
+# both printing:
+# Symbol "file2_thread_local" is a thread-local variable at offset 8 in the thread-local storage for `.../gdb.threads/tls'.
+gdb_test "info address file2_thread_local" "Symbol \"file2_thread_local\" is a thread-local variable.*"
+# Here it could also crash with: Cannot access memory at address 0x0
+gdb_test "p a_thread_local" " = \[0-9\]+" "p a_thread_local second time"
+gdb_test "info address a_thread_local" "Symbol \"a_thread_local\" is a thread-local variable.*"
# Done!
#