]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright 2012-2024 Free Software Foundation, Inc. |
64ea88dc JB |
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 | ||
d6195dc9 | 16 | require allow_shlib_tests |
48b56b6a | 17 | |
1d58d6a2 PA |
18 | proc test {hidden dlopen version_id_main lang} { |
19 | global srcdir subdir | |
20 | ||
21 | set main "print-file-var-main" | |
22 | ||
23 | set suffix "-hidden$hidden-dlopen$dlopen-version_id_main$version_id_main" | |
24 | ||
25 | # Normally we place different builds (C/C++) of a test into | |
26 | # subdirectories within the test build directory, however, using | |
27 | # gdb_load_shlib doesn't work well with this approach, so instead | |
28 | # add a language specific suffix to the binary and library names. | |
29 | if { $lang == "c" } { | |
30 | set suffix "${suffix}_c" | |
31 | } else { | |
32 | set suffix "${suffix}_cpp" | |
33 | } | |
34 | ||
35 | set executable $main$suffix | |
36 | ||
37 | set lib1 "print-file-var-lib1" | |
38 | set lib2 "print-file-var-lib2" | |
39 | ||
40 | set libobj1 [standard_output_file ${lib1}$suffix.so] | |
41 | set libobj2 [standard_output_file ${lib2}$suffix.so] | |
42 | ||
2f413264 | 43 | set lib_opts { debug $lang } |
1d58d6a2 PA |
44 | lappend lib_opts "additional_flags=-DHIDDEN=$hidden" |
45 | ||
46 | if { [gdb_compile_shlib ${srcdir}/${subdir}/${lib1}.c \ | |
47 | ${libobj1} \ | |
48 | ${lib_opts} ] != "" } { | |
49 | return -1 | |
50 | } | |
51 | if { [gdb_compile_shlib ${srcdir}/${subdir}/${lib2}.c \ | |
52 | ${libobj2} \ | |
53 | ${lib_opts} ] != "" } { | |
54 | return -1 | |
55 | } | |
56 | ||
1c2bec19 GB |
57 | set main_opts [list debug $lang] |
58 | set link_opts [list debug shlib=${libobj1}] | |
1d58d6a2 | 59 | |
4b4f2a7d TV |
60 | set target_libobj2 [gdb_download_shlib $libobj2] |
61 | ||
1d58d6a2 | 62 | if {$dlopen} { |
4b4f2a7d | 63 | lappend main_opts "additional_flags=-DSHLIB_NAME=\"$target_libobj2\"" |
1c2bec19 | 64 | lappend link_opts "shlib_load" |
1d58d6a2 | 65 | } else { |
1c2bec19 | 66 | lappend link_opts "shlib=${libobj2}" |
1d58d6a2 PA |
67 | } |
68 | ||
69 | lappend main_opts "additional_flags=-DVERSION_ID_MAIN=$version_id_main" | |
70 | ||
1c2bec19 GB |
71 | if { [build_executable_from_specs ${main} \ |
72 | $executable \ | |
73 | $link_opts \ | |
74 | ${main}.c \ | |
1d58d6a2 | 75 | $main_opts] |
1c2bec19 | 76 | != 0 } { |
1d58d6a2 PA |
77 | return -1 |
78 | } | |
79 | ||
80 | clean_restart $executable | |
81 | gdb_load_shlib $libobj1 | |
4b4f2a7d | 82 | gdb_locate_shlib $libobj2 |
1d58d6a2 PA |
83 | |
84 | if ![runto_main] { | |
1d58d6a2 PA |
85 | return -1 |
86 | } | |
87 | ||
88 | # Try printing "this_version_num" qualified with the name of the file | |
89 | # where the variables are defined. There are three global variables | |
90 | # with that name, and some systems such as GNU/Linux merge them | |
91 | # into one single entity, while some other systems such as Windows | |
92 | # keep them separate. In the first situation, we have to verify | |
93 | # that GDB does not randomly select the wrong instance, even when | |
94 | # a specific filename is used to qualified the lookup. And in the | |
95 | # second case, we have to verify that GDB does select the instance | |
96 | # defined in the given filename. | |
97 | # | |
98 | # To avoid adding target-specific code in this testcase, the program | |
99 | # sets three local variables named 'vm', 'v1' and 'v2' with the value of | |
100 | # our global variables. This allows us to compare the value that | |
101 | # GDB returns for each query against the actual value seen by | |
102 | # the program itself. | |
103 | ||
104 | # Get past the initialization of the v* variables. | |
105 | ||
106 | set bp_location \ | |
107 | [gdb_get_line_number "STOP" "${main}.c"] | |
108 | gdb_test "break $main.c:$bp_location" \ | |
109 | "Breakpoint \[0-9\]+ at 0x\[0-9a-fA-F\]+: .*" \ | |
33bf4c5c | 110 | "breakpoint at STOP marker" |
1d58d6a2 PA |
111 | |
112 | gdb_test "continue" \ | |
113 | "Breakpoint \[0-9\]+, main \\(\\) at.*STOP.*" \ | |
114 | "continue to STOP marker" | |
115 | ||
116 | # Now check the value of this_version_id in all of | |
117 | # print-file-var-main.c, print-file-var-lib1.c and | |
118 | # print-file-var-lib2.c. | |
119 | ||
120 | # Compare the values of $sym1 and $sym2. | |
121 | proc compare {sym1 sym2} { | |
122 | with_test_prefix "sym1=$sym1,sym2=$sym2" { | |
123 | # Done this way instead of comparing the symbols with "print $sym1 | |
124 | # == sym2" in GDB directly so that the values of the symbols end | |
125 | # up visible in the logs, for debug purposes. | |
126 | set vsym1 [get_integer_valueof $sym1 -1] | |
127 | set vsym2 [get_integer_valueof $sym2 -1] | |
128 | gdb_assert {$vsym1 == $vsym2} "$sym1 == $sym2" | |
129 | } | |
130 | } | |
131 | ||
132 | if $version_id_main { | |
133 | compare "'print-file-var-main.c'::this_version_id" "vm" | |
134 | compare "this_version_id" "vm" | |
135 | } | |
136 | ||
137 | compare "'print-file-var-lib1.c'::this_version_id" "v1" | |
138 | compare "'print-file-var-lib2.c'::this_version_id" "v2" | |
64ea88dc | 139 | } |
64ea88dc | 140 | |
1d58d6a2 | 141 | # Only test C++ if we are able. Always use C. |
0b94d2b9 TT |
142 | set lang_list {c} |
143 | if {[allow_cplus_tests]} { | |
144 | lappend lang_list c++ | |
64ea88dc JB |
145 | } |
146 | ||
1d58d6a2 PA |
147 | foreach_with_prefix lang $lang_list { |
148 | foreach_with_prefix hidden {0 1} { | |
149 | foreach_with_prefix dlopen {0 1} { | |
150 | foreach_with_prefix version_id_main {0 1} { | |
151 | test $hidden $dlopen $version_id_main $lang | |
152 | } | |
153 | } | |
154 | } | |
155 | } |