1# Copyright 1997, 1998, 1999, 2001, 2003, 2004 2# Free Software Foundation, Inc. 3 4# This program is free software; you can redistribute it and/or modify 5# it under the terms of the GNU General Public License as published by 6# the Free Software Foundation; either version 2 of the License, or 7# (at your option) any later version. 8# 9# This program is distributed in the hope that it will be useful, 10# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12# GNU General Public License for more details. 13# 14# You should have received a copy of the GNU General Public License 15# along with this program; if not, write to the Free Software 16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 18# Please email any bugs, comments, and/or additions to this file to: 19# bug-gdb@prep.ai.mit.edu 20 21# Test that GDB properly ignores invalid stabs. 22# Also test that GDB can debug a .o file, and that it doesn't mind 23# a file that's more minimal than what a compiler normally puts out. 24if $tracelevel then { 25 strace $tracelevel 26} 27 28# If the test directory was not created by configure then skip 29# this test. 30if ![file isdirectory ${objdir}/${subdir}] then { 31 return 0 32} 33 34set prms_id 0 35set bug_id 0 36 37set testfile weird 38set srcfile ${objdir}/${subdir}/weird.s 39set binfile ${objdir}/${subdir}/weirdx.o 40 41if { [ get_compiler_info "$binfile" ] } { 42 return -1 43} 44 45if { $hp_cc_compiler || $hp_aCC_compiler } { 46 # The native hp-ux assembler does not support stabs at all. 47 # If the compiler is native hp-ux, of course the assembler is too. 48 # But if someone builds gcc with the native assembler (not recommended) 49 # rather than the gnu assembler, then this logic will not suppress it. 50 # -- chastain 2004-01-07 51 unsupported "stabs with hp-ux assembler" 52 continue 53} 54 55proc do_tests {} { 56 global binfile 57 global gdb_prompt 58 59 # Mips/alpha targets that use gcc with mips-tfile put out the stabs 60 # assembler directives embedded in comments. If the assembler 61 # file is then processed with native cc, all stabs directives 62 # will be lost. 63 # Skip the rest of the stabs tests for this case. 64 send_gdb "ptype inttype\n" 65 gdb_expect { 66 -re "^ptype inttype\r*\ntype = inttype.*$gdb_prompt $" { 67 pass "stabs found" 68 } 69 -re ".*$gdb_prompt $" { 70 setup_xfail "mips-*-*" 71 setup_xfail "alpha-*-*" 72 fail "stabs not found" 73 return 74 } 75 default { fail "checking for stabs" } 76 } 77 78 print_weird_var var0 79 print_weird_var var1 80 print_weird_var var2 81 print_weird_var var3 82 83 print_weird_var attr32 84 print_weird_var attr33 85 print_weird_var attr35 86 print_weird_var attr36 87 print_weird_var attr37 88 print_weird_var attr38 89 print_weird_var attr39 90 print_weird_var attr41 91 print_weird_var attr42 92 print_weird_var attr43 93 print_weird_var attr44 94 print_weird_var attr46 95 print_weird_var attr47 96 print_weird_var attr58 97 print_weird_var attr59 98 print_weird_var attr60 99 print_weird_var attr61 100 print_weird_var attr62 101 print_weird_var attr63 102 print_weird_var attr64 103 print_weird_var attr65 104 print_weird_var attr66 105 print_weird_var attr67 106 print_weird_var attr68 107 print_weird_var attr69 108 print_weird_var attr70 109 print_weird_var attr71 110 print_weird_var attr72 111 print_weird_var attr73 112 print_weird_var attr74 113 print_weird_var attr75 114 print_weird_var attr76 115 print_weird_var attr77 116 print_weird_var attr78 117 print_weird_var attr79 118 print_weird_var attr80 119 print_weird_var attr81 120 print_weird_var attr82 121 print_weird_var attr83 122 print_weird_var attr84 123 print_weird_var attr85 124 print_weird_var attr86 125 print_weird_var attr87 126 print_weird_var attr88 127 print_weird_var attr89 128 print_weird_var attr90 129 print_weird_var attr91 130 print_weird_var attr92 131 print_weird_var attr93 132 print_weird_var attr94 133 print_weird_var attr95 134 print_weird_var attr96 135 print_weird_var attr97 136 print_weird_var attr98 137 print_weird_var attr99 138 print_weird_var attr100 139 print_weird_var attr101 140 print_weird_var attr102 141 print_weird_var attr103 142 print_weird_var attr104 143 print_weird_var attr105 144 print_weird_var attr106 145 print_weird_var attr107 146 print_weird_var attr108 147 print_weird_var attr109 148 print_weird_var attr110 149 print_weird_var attr111 150 print_weird_var attr112 151 print_weird_var attr113 152 print_weird_var attr114 153 print_weird_var attr115 154 print_weird_var attr116 155 print_weird_var attr117 156 print_weird_var attr118 157 print_weird_var attr119 158 print_weird_var attr120 159 print_weird_var attr121 160 print_weird_var attr122 161 print_weird_var attr123 162 print_weird_var attr124 163 print_weird_var attr125 164 print_weird_var attr126 165 166 gdb_test "p const69" " = 69" "'e' constant on non-enum type" 167 gdb_test "whatis const69" "type = (unsigned int|inttype)" "whatis const69" 168 169 gdb_test "p sizeof (const70)" " = 2" "'e' constant with embedded type" 170 171 gdb_test "p bad_neg0" " = \{field0 = 42, field2 =.*field3 = 45\}" "p bad_neg0" 172 173 gdb_test "ptype inttype" "type = (unsigned int|inttype)" "ptype on inttype" 174 gdb_test "p sizeof (float72type)" " = 9" "unrecognized floating point type" 175 176 # This big number needs to be kept as one piece 177 gdb_test "p/x int256var" " = 0x0*2a0000002b0000002c0000002d0000002d0000002c0000002b0000002a" "print very big integer" 178 179 gdb_test "whatis consth" "type = inttype" "whatis consth" 180 gdb_test "whatis consth2" "type = inttype" "whatis consth2" 181 182 # GDB does not yet understand S constants 183 setup_xfail "*-*-*" 184 gdb_test "p/x bad_neg0const" " = \{field0 = 0x11222211, field2 =.*\ 185field3 = 0x77888877\}" "print struct constant" 186 187 gdb_test "ptype bad_type0" "type = .*" "print bad_type0" 188 gdb_test "ptype bad_type1" "type = .*" "print bad_type1" 189 190 # GDB does not yet support arrays indexed by anything at all unusual 191 setup_xfail "*-*-*" 192 gdb_test "p array0" " = \\{42, 43, 44, 45, 46, 47\\}" "array0 with strange index" 193 setup_xfail "*-*-*" 194 gdb_test "p array1" " = \\{42, 43, 44\\}" "array1 with strange index" 195 196 # GDB does not yet support this feature 197 gdb_test "whatis one_var" "type = inttype_one" \ 198 "whatis one_var (known failure in gdb 4.10)" 199 # But do make sure that it prints as something reasonable 200 gdb_test "whatis one_var" "type = inttype(|_one)" \ 201 "whatis one_var test 2" 202 203 gdb_test "whatis two_var" "type = inttype_two" \ 204 "whatis two_var (known failure in gdb 4.10)" 205 # But do make sure that it prints as something reasonable 206 gdb_test "whatis two_var" "type = inttype(|_two)" \ 207 "whatis two_var test 2" 208 209 setup_xfail "*-*-*" 210 gdb_test "whatis pointer_to_int_var" "type = int \[*\]" 211 setup_xfail "*-*-*" 212 gdb_test "whatis intp_var" "type = intp" 213 214 gdb_test "p common0var0" "= 42" 215 # GDB seems to only understand common blocks local to a function. 216 # These variables never get relocated to be relative to the common 217 # block. 218 # I'm not sure whether it is valid to have a common block which 219 # is not local to a function. 220 setup_xfail "*-*-*" 221 gdb_test "p common0var1" "= 24" 222 setup_xfail "*-*-*" 223 gdb_test "p common0var2" "= 22" 224} 225 226proc print_weird_var { var } { 227 global gdb_prompt 228 229 # Make sure that the variable gets printed out correctly, without 230 # any sort of warning message. 231 send_gdb "print $var\n" 232 gdb_expect { 233 -re "^print $var\r*\n.\[0-9\]* = 42.*$gdb_prompt $" { 234 pass "variable $var printed properly" 235 } 236 -re ".*$gdb_prompt $" { 237 fail "variable $var printed properly" 238 } 239 timeout { fail "variable $var printed properly (timeout)" } 240 eof { fail "variable $var printed properly (eof)" } 241 } 242 243 # Make sure that the stabs did get loaded in a sensible way. 244 # If somehow the stabs got skipped, then the above test can 245 # pass because GDB assumes int for variables without a stab. 246 247 # This doesn't work because 32=45 doesn't preserve the name in 248 # gdb (as of 14 Sep 93 anyway). 249 #gdb_test "whatis $var" "type = (unsigned int|inttype)" 250 251 # But the size should be right. 252 gdb_test "print sizeof ($var)" "= 4" 253} 254 255 256# Don't use gdb_load; it doesn't bitch if the loading produced some 257# error messages during symbol reading. 258 259global target_os 260set sedscript ${srcdir}/${subdir}/aout.sed 261switch -glob ${target_triplet} { 262 "hppa*-*-*" { 263 set sedscript ${srcdir}/${subdir}/hppa.sed 264 } 265 "mips-*-ecoff" { 266 set sedscript ${srcdir}/${subdir}/ecoff.sed 267 } 268 "powerpc-*-aix*" { 269 set sedscript ${srcdir}/${subdir}/xcoff.sed 270 } 271 "rs6000-*-aix*" { 272 set sedscript ${srcdir}/${subdir}/xcoff.sed 273 } 274 "*-*-aout" { 275 set sedscript ${srcdir}/${subdir}/aout.sed 276 } 277 "*-*-xcoff" { 278 set sedscript ${srcdir}/${subdir}/xcoff.sed 279 } 280 "alpha-*-*" { 281 set sedscript ${srcdir}/${subdir}/ecoff.sed 282 } 283} 284 285# Hope this is a Unix box. 286set exec_output [remote_exec build "sed" "-f ${sedscript}" "${srcdir}/${subdir}/weird.def" "${srcfile}"] 287if { [lindex $exec_output 0] != 0 } { 288 perror "Couldn't make test case. $exec_output" 289 return -1 290} 291 292if { [gdb_compile "${srcfile}" "${binfile}" object ""] != "" } { 293 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." 294} 295 296remote_file build delete ${srcfile} 297 298# Start with a fresh gdb 299gdb_exit 300gdb_start 301gdb_reinitialize_dir $srcdir/$subdir 302 303set binfile [remote_download host ${binfile} object.o] 304send_gdb "file $binfile\n" 305# If $binfile is very long, a \r (but not a \n) will echo in the 306# middle of the echo of the command. So to match the echo, we 307# would like to match anything not containing \n 308# (we would prefer to be sure not to match any warning message). 309# But \[^\n\]* doesn't seem to work, so instead use the heuristic 310# that a filename won't contain a space and a warning message will. 311# But spaces following by backspaces aren't really spaces. 312gdb_expect 60 { 313 -re "^file (\[^ \]| +\008)*\r*\n" { 314 exp_continue 315 } 316 -re "A program is being debugged already. Kill it\\? \\(y or n\\)" { 317 send_gdb "y\n" 318 exp_continue 319 } 320 -re "^Reading symbols from .*$binfile\\.\\.\\.done\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)\r\n$gdb_prompt $" { 321 pass "weirdx.o read without error" 322 } 323 -re ".*$gdb_prompt $" { 324 fail "Errors reading weirdx.o" 325 } 326 timeout { 327 perror "couldn't load $binfile into $GDB (timed out)." 328 return -1 329 } 330 eof { fail "(eof) cannot read weirdx.o" } 331} 332 333do_tests 334 335remote_file host delete ${binfile} 336 337return 0 338