]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.threads/tls-sepdebug.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / tls-sepdebug.exp
CommitLineData
1d506c26 1# Copyright 2006-2024 Free Software Foundation, Inc.
3ec033fa
KB
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 test creates a shared library and a main program which uses
17# that library, extracts the debug info of the library to a separate
18# file, and then tests that a symbol from the shared library is
19# accessible using both absolute and relative settings of
20# LD_LIBRARY_PATH.
21
22# This test needs to change the environment in which the test program
23# is run, specifically the setting of LD_LIBRARY_PATH. GDB can adjust
24# this setting for both native and extended-remote targets, but not
25# for targets to which GDB connects after the program has already
26# started. Therefore, this test won't work for targets which use
27# "target remote".
28require !use_gdb_stub
29require {have_compile_flag -std=c11}
30
31set testfile tls-sepdebug
32set srcmainfile ${testfile}-main.c
33set srcsharedfile ${testfile}-shared.c
34
35set binmainfile [standard_output_file ${testfile}-main]
36set binsharedbase ${testfile}-shared.so
37set binsharedfile [standard_output_file ${binsharedbase}]
38
39# Build the shared library, but use explicit -soname; otherwise the
40# full path to the library would get encoded into ${binmainfile}
41# making LD_LIBRARY_PATH tests useless.
42#
43# The compile flag -std=c11 is required because the test case uses
44# 'thread_local' to indicate thread local storage. This is available
45# as a macro starting in C11 and became a C-language keyword in C23.
46if { [gdb_compile_shlib \
47 "${srcdir}/${subdir}/${srcsharedfile}" "${binsharedfile}" \
48 [list debug \
49 ldflags=-Wl,-soname=${binsharedbase} \
50 additional_flags=-std=c11]] \
51 != "" } {
52 untested "Couldn't compile test library"
53 return -1
54}
55
56# Strip debug information from $binsharedfile, placing it in
57# ${binsharedfile}.debug. Also add a .gnu_debuglink in the former,
58# pointing to the latter.
59gdb_gnu_strip_debug ${binsharedfile}
60
61# Build main program, but do not use `shlib=' since that would
62# automatically add -rpath for gcc.
63if { [gdb_compile_pthreads \
64 "${srcdir}/${subdir}/${srcmainfile} ${binsharedfile}" \
65 "${binmainfile}" executable [list debug additional_flags=-std=c11]] \
66 != "" } {
67 untested "Couldn't compile test program"
68 return -1
69}
70
71set absdir [file dirname [standard_output_file ${binsharedbase}]]
72
73foreach ld_library_path [list $absdir [relative_filename [pwd] $absdir]] \
74 name { absolute relative } {
75 with_test_prefix $name {
76
77 # Restart, but defer loading until after setting LD_LIBRARY_PATH.
78 clean_restart
79
80 gdb_test_no_output "set env LD_LIBRARY_PATH=$ld_library_path" \
81 "set env LD_LIBRARY_PATH"
82
83 gdb_load ${binmainfile}
84
85 if ![runto_main] {
86 return
87 }
88
89 # Print a thread local variable from the shared library to be certain
90 # that its symbols were loaded from the separate debuginfo file.
91 gdb_test "print var" \
92 "\\\$1 = 42" \
93 "print TLS variable from a shared library with separate debug info file"
94 }
95}