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