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