]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/nodebug.exp
Stop assuming no-debug-info variables have type int
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / nodebug.exp
1 # Copyright 1997-2017 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 # Test that things still (sort of) work when compiled without -g.
17
18
19 standard_testfile .c
20
21 if [get_compiler_info] {
22 return -1
23 }
24
25 if [test_compiler_info "xlc-*"] {
26 # By default, IBM'x xlc compiler doesn't add static variables into the symtab.
27 # Use "-qstatsym" to do so.
28 set exec_opts additional_flags=-qstatsym
29 } else {
30 set exec_opts ""
31 }
32
33 if { [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != "" } {
34 untested "failed to compile"
35 return -1
36 }
37
38 # Start with a fresh gdb.
39
40 clean_restart $binfile
41
42 # Test calling no-debug functions involving argument types that may
43 # require coercion/promotion, both prototyped and unprototyped, both
44 # return-type-cast style, and function-pointer-cast styles.
45 proc test_call_promotion {} {
46 if [target_info exists gdb,cannot_call_functions] {
47 return
48 }
49
50 # Call prototyped function with float parameters via both
51 # return-type cast and function-pointer cast. This checks that
52 # GDB doesn't do float->double coercion.
53 gdb_test "p (float) multf(2.0f, 3.0f)" " = 6"
54 gdb_test "p ((float (*) (float, float)) multf)(2, 3)" " = 6"
55 gdb_test "p ((float (*) (float, float)) multf)(2.0f, 3.0f)" " = 6"
56
57 # Call unprototyped function with float parameters via
58 # function-pointer cast, only. return-type cast assumes
59 # protototyped. Check that GDB does float->double coercion.
60 gdb_test "p ((float (*) ()) multf_noproto)(2.0f, 3.0f)" " = 6"
61 gdb_test "p ((float (*) ()) multf_noproto)(2.0, 3.0)" " = 6"
62
63 # Same, but for double.
64 gdb_test "p (double) mult (2.0, 3.0)" " = 6"
65 gdb_test "p ((double (*) (double, double)) mult)(2.0f, 3.0f)" " = 6"
66 gdb_test "p ((double (*) (double, double)) mult)(2, 3)" " = 6"
67 gdb_test "p ((double (*) ()) mult_noproto)(2.0f, 3.0f)" " = 6"
68 gdb_test "p ((double (*) ()) mult_noproto)(2.0, 3.0)" " = 6"
69
70 # Check that GDB promotes char->int correctly.
71 gdb_test "p /d (uint8) add8((uint8) 2, (uint8) 3)" " = 5"
72 gdb_test "p /d ((uint8 (*) (uint8, uint8)) add8)((uint8) 2, (uint8) 3)" " = 5"
73 gdb_test "p /d ((uint8 (*) ()) add8_noproto)((uint8) 2, (uint8) 3)" " = 5"
74 }
75
76 if [runto inner] then {
77
78 # Expect to find global/local symbols in each of text/data/bss.
79
80 # The exact format for some of this output is not necessarily
81 # ideal, particularly interpreting "p top" requires a fair bit of
82 # savvy about gdb's workings and the meaning of the "{}"
83 # construct. So the details maybe could be tweaked. But the
84 # basic purpose should be maintained, which is (a) users should be
85 # able to interact with these variables with some care (they have
86 # to know how to interpret them according to their real type,
87 # since gdb doesn't know the type), but (b) users should be able
88 # to detect that gdb does not know the type, rather than just
89 # being told they are ints or functions returning int like old
90 # versions of gdb used to do.
91
92 # On alpha (and other ecoff systems) the native compilers put
93 # out debugging info for non-aggregate return values of functions
94 # even without -g, which should be accepted.
95
96 with_test_prefix "func" {
97 # Most languages default to printing like C.
98 set c_print_re " = \\{<text variable, no debug info>\\} $hex <top>"
99 set c_whatis_re " = <text variable, no debug info>"
100 set c_ptype_re "= <unknown return type> \\(\\)"
101
102 set cxx_ptype_re "= <unknown return type> \\(void\\)"
103
104 set ada_ptype_re " = function return <unknown return type>"
105
106 set m2_print_re " = \\{PROCEDURE <text variable, no debug info> \\(\\) : <unknown return type>\\} $hex <top>"
107 set m2_whatis_re "PROCEDURE <text variable, no debug info> \\(\\) : <unknown return type>"
108 set m2_ptype_re $m2_whatis_re
109
110 # Rust can't access minsyms?
111 set rust_nosym "No symbol 'top' in current context"
112
113 set pascal_ptype_re "type = procedure : <unknown return type>"
114
115 #LANG #PRINT #WHATIS #PTYPE
116 foreach lang_line {
117 {"ada" $c_print_re $c_whatis_re $ada_ptype_re}
118 {"asm" $c_print_re $c_whatis_re $c_ptype_re}
119 {"c" $c_print_re $c_whatis_re $c_ptype_re}
120 {"c++" $c_print_re $c_whatis_re $cxx_ptype_re}
121 {"d" $c_print_re $c_whatis_re $c_ptype_re}
122 {"fortran" $c_print_re $c_whatis_re $c_ptype_re}
123 {"go" $c_print_re $c_whatis_re $c_ptype_re}
124 {"minimal" $c_print_re $c_whatis_re $c_ptype_re}
125 {"modula-2" $m2_print_re $m2_whatis_re $m2_ptype_re}
126 {"objective-c" $c_print_re $c_whatis_re $c_ptype_re}
127 {"opencl" $c_print_re $c_whatis_re $c_ptype_re}
128 {"pascal" $c_print_re $c_whatis_re $pascal_ptype_re}
129 {"rust" $rust_nosym $rust_nosym $rust_nosym}
130 } {
131 set lang [lindex $lang_line 0]
132 set print_re [lindex $lang_line 1]
133 set whatis_re [lindex $lang_line 2]
134 set ptype_re [lindex $lang_line 3]
135
136 set print_re [subst "$print_re"]
137 set whatis_re [subst "$whatis_re"]
138 set ptype_re [subst "$ptype_re"]
139
140 with_test_prefix "$lang" {
141 gdb_test_no_output "set language $lang"
142 gdb_test "p top" $print_re
143 gdb_test "whatis top" $whatis_re
144 gdb_test "ptype top" $ptype_re
145 }
146 }
147 }
148
149 gdb_test_no_output "set language auto"
150
151 # We can't rely on uintXX_t being available/known to GDB because
152 # we may or may not have debug info for those (depending on
153 # whether we have debug info for the C runtime, for example).
154 gdb_test_no_output "macro define uint8 unsigned char"
155 gdb_test_no_output "macro define uint32 unsigned int"
156 gdb_test_no_output "macro define uint64 unsigned long long"
157
158 set data_var_type "<data variable, no debug info>"
159 set unk_type_re "has unknown type.*to its declared type"
160 set ptr_math_re "Cannot perform pointer math on incomplete type \"$data_var_type\", try casting to a known type, or void \\*\\."
161 set not_mem_re "Attempt to take address of value not located in memory\\."
162
163 set dataglobal_unk_re "dataglobal.*$unk_type_re"
164
165 #exp #fmt #print #ptype/whatis
166 foreach line {
167 {"dataglobal" "" $dataglobal_unk_re " = $data_var_type"}
168 {"(int) dataglobal" "" "= 3" " = int"}
169 {"sizeof(dataglobal)" "" $dataglobal_unk_re $dataglobal_unk_re}
170 {"sizeof(dataglobal + 1)" "" $dataglobal_unk_re $dataglobal_unk_re}
171 {"sizeof((int) dataglobal)" "" " = $decimal" " = int"}
172 {"dataglobal + 1" "" $dataglobal_unk_re $dataglobal_unk_re}
173 {"&dataglobal" "" "\\($data_var_type \\*\\) $hex <dataglobal>" " = $data_var_type \\*"}
174 {"&dataglobal + 1" "" $ptr_math_re $ptr_math_re}
175 {"(int *) &dataglobal + 1" "" " = \\(int \\*\\) $hex <datalocal>" "int \\*"}
176 {"&(int) dataglobal + 1" "" $not_mem_re $not_mem_re}
177 {"&dataglobal, &dataglobal" "" "\\($data_var_type \\*\\) $hex <dataglobal>" " = $data_var_type \\*"}
178 {"*dataglobal" "" $dataglobal_unk_re $dataglobal_unk_re}
179
180 {"dataglobal8" "/x" $dataglobal_unk_re " = $data_var_type"}
181 {"(uint8) dataglobal8" "/x" " = 0xff" "unsigned char"}
182
183 {"dataglobal32_1" "/x" $dataglobal_unk_re " = $data_var_type"}
184 {"(uint32) dataglobal32_1" "/x" " = 0x7fffffff" "unsigned int"}
185 {"dataglobal32_2" "/x" $dataglobal_unk_re " = $data_var_type"}
186 {"(uint32) dataglobal32_2" "/x" " = 0xff" "unsigned int"}
187
188 {"dataglobal64_1" "/x" $dataglobal_unk_re " = $data_var_type"}
189 {"(uint64) dataglobal64_1" "/x" " = 0x7fffffffffffffff" "unsigned long long"}
190 {"dataglobal64_2" "/x" $dataglobal_unk_re " = $data_var_type"}
191 {"(uint64) dataglobal64_2" "/x" " = 0xff" "unsigned long long"}
192 } {
193 set exp [lindex $line 0]
194 # Expand variables.
195 set fmt [subst -nobackslashes [lindex $line 1]]
196 set print [subst -nobackslashes [lindex $line 2]]
197 set whatis [subst -nobackslashes [lindex $line 3]]
198 if {$fmt == ""} {
199 gdb_test "p $exp" $print
200 } else {
201 gdb_test "p $fmt $exp" $print
202 }
203 gdb_test "whatis $exp" $whatis
204 gdb_test "ptype $exp" $whatis
205 }
206
207 # The only symbol xcoff puts out for statics is for the TOC entry.
208 # Possible, but hairy, for gdb to deal. Right now it doesn't, it
209 # doesn't know the variables exist at all.
210 setup_xfail "rs6000*-*-aix*"
211 setup_xfail "powerpc*-*-aix*"
212
213 gdb_test "p datalocal" "datalocal.*$unk_type_re"
214 gdb_test "p (int) datalocal" "= 4"
215
216 setup_xfail "rs6000*-*-aix*"
217 setup_xfail "powerpc*-*-aix*"
218
219 gdb_test "whatis datalocal" "datalocal.*$data_var_type"
220
221 setup_xfail "rs6000*-*-aix*"
222 setup_xfail "powerpc*-*-aix*"
223
224 gdb_test "ptype datalocal" "datalocal.*$data_var_type"
225
226 gdb_test "p bssglobal" "bssglobal.*$unk_type_re"
227 gdb_test "p (int) bssglobal" "= 0"
228 gdb_test "whatis bssglobal" $data_var_type
229 gdb_test "ptype bssglobal" $data_var_type
230
231 setup_xfail "rs6000*-*-aix*"
232 setup_xfail "powerpc*-*-aix*"
233
234 gdb_test "p bsslocal" "bsslocal.*$unk_type_re"
235 gdb_test "p (int) bsslocal" "= 0"
236
237 setup_xfail "rs6000*-*-aix*"
238 setup_xfail "powerpc*-*-aix*"
239
240 gdb_test "whatis bsslocal" $data_var_type
241
242 setup_xfail "rs6000*-*-aix*"
243 setup_xfail "powerpc*-*-aix*"
244
245 gdb_test "ptype bsslocal" $data_var_type
246
247 gdb_test "backtrace 10" "#0.*inner.*#1.*middle.*#2.*top.*#3.*main.*" \
248 "backtrace from inner in nodebug.exp"
249 # Or if that doesn't work, at least hope for the external symbols
250 # Commented out because if we aren't going to xfail the above test
251 # ever, why bother with a weaker test?
252 #gdb_test "backtrace 10" "#0.*inner.*#1.*#2.*top.*#3.*main.*" \
253 # "backtrace from inner in nodebug.exp for externals"
254
255 # This test is not as obscure as it might look. `p getenv ("TERM")'
256 # is a real-world example, at least on many systems.
257 foreach cmd {"p/c" "ptype" "whatis"} {
258 gdb_test "$cmd array_index(\"abcdef\",2)" \
259 "'array_index' has unknown return type; cast the call to its declared return type"
260 }
261 if [target_info exists gdb,cannot_call_functions] {
262 unsupported "p/c (int) array_index(\"abcdef\",2)"
263 } else {
264 # We need to up this because this can be really slow on some boards.
265 # (malloc() is called as part of the test).
266 set prev_timeout $timeout
267 set timeout 60
268 gdb_test {p/c (int) array_index("abcdef",2)} " = 99 'c'"
269 set timeout $prev_timeout
270 }
271
272 test_call_promotion
273
274 # Now, try that we can give names of file-local symbols which happen
275 # to be unique, and have it still work
276 if [runto middle] then {
277 gdb_test "backtrace 10" "#0.*middle.*#1.*top.*#2.*main.*" \
278 "backtrace from middle in nodebug.exp"
279 }
280 }