1 # Copyright 2012-2018 Free Software Foundation, Inc.
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.
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.
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/>. */
16 if {[skip_shlib_tests]} {
20 set executable ctxobj-m
22 # The sources used to build two shared libraries (SO). We use the exact
23 # same sources to build both SOs, but differentiate them through the use
24 # of macros defined when calling the compiler.
26 # We need two source files per SO, because we need to test the situation
27 # where we are trying to print the value of a global variable defined
28 # in that SO while the variable's associated symtab has not been created
30 set libsrc [list "${srcdir}/${subdir}/ctxobj-v.c" \
31 "${srcdir}/${subdir}/ctxobj-f.c"]
33 set libobj1 [standard_output_file libctxobj1.so]
34 set libobj2 [standard_output_file libctxobj2.so]
36 set libobj1_opts { debug additional_flags=-fPIC
37 additional_flags=-DVERSION=104
38 additional_flags=-DGET_VERSION=get_version_1 }
39 set libobj2_opts { debug additional_flags=-fPIC
40 additional_flags=-DVERSION=203
41 additional_flags=-DGET_VERSION=get_version_2 }
43 if { [gdb_compile_shlib $libsrc $libobj1 $libobj1_opts ] != "" } {
46 if { [gdb_compile_shlib $libsrc $libobj2 $libobj2_opts ] != "" } {
49 if { [gdb_compile "${srcdir}/${subdir}/${executable}.c" \
50 [standard_output_file ${executable}] \
52 [list debug shlib=${libobj1} shlib=${libobj2}]]
57 clean_restart $executable
58 gdb_load_shlib $libobj1
59 gdb_load_shlib $libobj2
62 untested "could not run to main"
66 set bp_location [gdb_get_line_number "STOP" "ctxobj-f.c"]
67 gdb_test "break ctxobj-f.c:$bp_location" \
68 "Breakpoint \[0-9\]+ at 0x\[0-9a-fA-F\]+: .*" \
69 "break in get_version functions"
72 "Breakpoint $decimal, get_version_1 \\(\\).*" \
73 "continue to get_version_1"
75 # Try printing "this_version_num". There are two global variables
76 # with that name, and some systems such as GNU/Linux merge them
77 # into one single entity, while some other systems such as Windows
78 # keep them separate. In the first situation, we have to verify
79 # that GDB does not randomly select the wrong instance. And in
80 # the second case, we have to verify that GDB prints the value
81 # of the instance from the current debugging context (the shared
82 # library currently being debugged).
84 # We perform two tests: The first print test verifies that we are
85 # doing things right when the partial symtab hasn't been expanded.
86 # And the second print test will do the same, but after the partial
87 # symtab has been expanded.
89 # To avoid adding target-specific code in this testcase, the program
90 # sets a local variable named 'v' with the value of the global
91 # variable 'this_version_number'. This allows us to compare the value
92 # that GDB thinks 'this_version_num' has, against the actual value
93 # seen by the program itself.
95 gdb_test "print this_version_num == v" \
97 "print libctxobj1's this_version_num from partial symtab"
99 gdb_test "print this_version_num == v" \
101 "print libctxobj1's this_version_num from symtab"
103 # Do the same, but from get_version_2.
105 gdb_test "continue" \
106 "Breakpoint $decimal, get_version_2 \\(\\).*" \
107 "continue to get_version_2"
109 gdb_test "print this_version_num == v" \
111 "print libctxobj2's this_version_num from partial symtab"
113 gdb_test "print this_version_num == v" \
115 "print libctxobj2's this_version_num from symtab"