]>
Commit | Line | Data |
---|---|---|
1 | # Copyright 2012-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 | require allow_shlib_tests | |
17 | ||
18 | set executable ctxobj-m | |
19 | ||
20 | # The sources used to build two shared libraries (SO). We use the exact | |
21 | # same sources to build both SOs, but differentiate them through the use | |
22 | # of macros defined when calling the compiler. | |
23 | # | |
24 | # We need two source files per SO, because we need to test the situation | |
25 | # where we are trying to print the value of a global variable defined | |
26 | # in that SO while the variable's associated symtab has not been created | |
27 | # yet. | |
28 | set libsrc [list "${srcdir}/${subdir}/ctxobj-v.c" \ | |
29 | "${srcdir}/${subdir}/ctxobj-f.c"] | |
30 | ||
31 | set libobj1 [standard_output_file libctxobj1.so] | |
32 | set libobj2 [standard_output_file libctxobj2.so] | |
33 | ||
34 | set libobj1_opts { debug | |
35 | additional_flags=-DVERSION=104 | |
36 | additional_flags=-DGET_VERSION=get_version_1 } | |
37 | set libobj2_opts { debug | |
38 | additional_flags=-DVERSION=203 | |
39 | additional_flags=-DGET_VERSION=get_version_2 } | |
40 | ||
41 | if { [gdb_compile_shlib $libsrc $libobj1 $libobj1_opts ] != "" } { | |
42 | return -1 | |
43 | } | |
44 | if { [gdb_compile_shlib $libsrc $libobj2 $libobj2_opts ] != "" } { | |
45 | return -1 | |
46 | } | |
47 | if { [gdb_compile "${srcdir}/${subdir}/${executable}.c" \ | |
48 | [standard_output_file ${executable}] \ | |
49 | executable \ | |
50 | [list debug shlib=${libobj1} shlib=${libobj2}]] | |
51 | != ""} { | |
52 | return -1 | |
53 | } | |
54 | ||
55 | clean_restart $executable | |
56 | gdb_load_shlib $libobj1 | |
57 | gdb_load_shlib $libobj2 | |
58 | ||
59 | if ![runto_main] { | |
60 | return -1 | |
61 | } | |
62 | ||
63 | set bp_location [gdb_get_line_number "STOP" "ctxobj-f.c"] | |
64 | gdb_test "break ctxobj-f.c:$bp_location" \ | |
65 | "Breakpoint \[0-9\]+ at 0x\[0-9a-fA-F\]+: .*" \ | |
66 | "break in get_version functions" | |
67 | ||
68 | global expect_out | |
69 | set test "continue to get_version_1" | |
70 | gdb_test_multiple "continue" $test { | |
71 | -re "Breakpoint ($bkptno_num_re), get_version_1 \\(\\).*\r\n.*$gdb_prompt $" { | |
72 | set bpno $expect_out(1,string) | |
73 | pass $test | |
74 | } | |
75 | } | |
76 | # Verify $_hit_bpnum.$_hit_locno convenience variables are set to the hit bpno. | |
77 | gdb_test "printf \"%d.%d\\n\", \$_hit_bpnum, \$_hit_locno" "$bpno" \ | |
78 | "$test \$_hit_bpnum.\$_hit_locno is $bpno" | |
79 | ||
80 | # Try printing "this_version_num". There are two global variables | |
81 | # with that name, and some systems such as GNU/Linux merge them | |
82 | # into one single entity, while some other systems such as Windows | |
83 | # keep them separate. In the first situation, we have to verify | |
84 | # that GDB does not randomly select the wrong instance. And in | |
85 | # the second case, we have to verify that GDB prints the value | |
86 | # of the instance from the current debugging context (the shared | |
87 | # library currently being debugged). | |
88 | # | |
89 | # We perform two tests: The first print test verifies that we are | |
90 | # doing things right when the partial symtab hasn't been expanded. | |
91 | # And the second print test will do the same, but after the partial | |
92 | # symtab has been expanded. | |
93 | # | |
94 | # To avoid adding target-specific code in this testcase, the program | |
95 | # sets a local variable named 'v' with the value of the global | |
96 | # variable 'this_version_number'. This allows us to compare the value | |
97 | # that GDB thinks 'this_version_num' has, against the actual value | |
98 | # seen by the program itself. | |
99 | ||
100 | gdb_test "print this_version_num == v" \ | |
101 | " = 1" \ | |
102 | "print libctxobj1's this_version_num from partial symtab" | |
103 | ||
104 | gdb_test "print this_version_num == v" \ | |
105 | " = 1" \ | |
106 | "print libctxobj1's this_version_num from symtab" | |
107 | ||
108 | # Do the same, but from get_version_2. | |
109 | set test "continue to get_version_2" | |
110 | gdb_test_multiple "continue" $test { | |
111 | -re "Breakpoint ($bkptno_num_re), get_version_2 \\(\\).*\r\n.*$gdb_prompt $" { | |
112 | set bpno $expect_out(1,string) | |
113 | pass $test | |
114 | } | |
115 | } | |
116 | # Verify the $_hit_bpnum.$_hit_locno convenience variables are set to the hit bpno. | |
117 | gdb_test "printf \"%d.%d\\n\", \$_hit_bpnum, \$_hit_locno" "$bpno" \ | |
118 | "$test \$_hit_bpnum.\$_hit_locno is $bpno" | |
119 | ||
120 | gdb_test "print this_version_num == v" \ | |
121 | " = 1" \ | |
122 | "print libctxobj2's this_version_num from partial symtab" | |
123 | ||
124 | gdb_test "print this_version_num == v" \ | |
125 | " = 1" \ | |
126 | "print libctxobj2's this_version_num from symtab" |