]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/nodebug.exp
Stop assuming no-debug-info functions return 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
156 gdb_test "p dataglobal" "= 3"
157 gdb_test "whatis dataglobal" \
158 "<(data variable|variable), no debug info>|int"
159 gdb_test "ptype dataglobal" "<(data variable|variable), no debug info>|int"
160
161 # The only symbol xcoff puts out for statics is for the TOC entry.
162 # Possible, but hairy, for gdb to deal. Right now it doesn't, it
163 # doesn't know the variables exist at all.
164 setup_xfail "rs6000*-*-aix*"
165 setup_xfail "powerpc*-*-aix*"
166
167 gdb_test "p datalocal" "= 4"
168
169 setup_xfail "rs6000*-*-aix*"
170 setup_xfail "powerpc*-*-aix*"
171
172 gdb_test "whatis datalocal" "<(data variable|variable), no debug info>"
173
174 setup_xfail "rs6000*-*-aix*"
175 setup_xfail "powerpc*-*-aix*"
176
177 gdb_test "ptype datalocal" "<(data variable|variable), no debug info>"
178 gdb_test "p bssglobal" "= 0"
179 gdb_test "whatis bssglobal" "<(data variable|variable), no debug info>|int"
180 gdb_test "ptype bssglobal" "<(data variable|variable), no debug info>|int"
181
182 setup_xfail "rs6000*-*-aix*"
183 setup_xfail "powerpc*-*-aix*"
184
185 gdb_test "p bsslocal" "= 0"
186
187 setup_xfail "rs6000*-*-aix*"
188 setup_xfail "powerpc*-*-aix*"
189
190 gdb_test "whatis bsslocal" "<(data variable|variable), no debug info>"
191
192 setup_xfail "rs6000*-*-aix*"
193 setup_xfail "powerpc*-*-aix*"
194
195 gdb_test "ptype bsslocal" "<(data variable|variable), no debug info>"
196
197 gdb_test "backtrace 10" "#0.*inner.*#1.*middle.*#2.*top.*#3.*main.*" \
198 "backtrace from inner in nodebug.exp"
199 # Or if that doesn't work, at least hope for the external symbols
200 # Commented out because if we aren't going to xfail the above test
201 # ever, why bother with a weaker test?
202 #gdb_test "backtrace 10" "#0.*inner.*#1.*#2.*top.*#3.*main.*" \
203 # "backtrace from inner in nodebug.exp for externals"
204
205 # This test is not as obscure as it might look. `p getenv ("TERM")'
206 # is a real-world example, at least on many systems.
207
208 gdb_test {p/c array_index("abcdef",2)} \
209 "'array_index' has unknown return type; cast the call to its declared return type"
210 gdb_test {ptype array_index("abcdef",2)} \
211 "function has unknown return type; cast the call to its declared return type"
212 gdb_test {whatis array_index("abcdef",2)} \
213 "function has unknown return type; cast the call to its declared return type"
214
215 if [target_info exists gdb,cannot_call_functions] {
216 unsupported "p/c (int) array_index(\"abcdef\",2)"
217 } else {
218 # We need to up this because this can be really slow on some boards.
219 # (malloc() is called as part of the test).
220 set prev_timeout $timeout
221 set timeout 60
222 gdb_test {p/c (int) array_index("abcdef",2)} " = 99 'c'"
223 set timeout $prev_timeout
224 }
225
226 test_call_promotion
227
228 # Now, try that we can give names of file-local symbols which happen
229 # to be unique, and have it still work
230 if [runto middle] then {
231 gdb_test "backtrace 10" "#0.*middle.*#1.*top.*#2.*main.*" \
232 "backtrace from middle in nodebug.exp"
233 }
234 }