1# Copyright 2003, 2004 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 2 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, write to the Free Software 15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 17# This file was written by Elena Zannoni (ezannoni@cygnus.com) 18 19if $tracelevel then { 20 strace $tracelevel 21} 22 23 24# are we on a target board? If so, don't run these tests. 25# note: this is necessary because we cannot use runto_main (which would 26# work for remote targets too) because of the different prompt we get 27# when using annotation level 2. 28# 29if [is_remote target] then { 30 return 0 31} 32 33 34# 35# test running programs 36# 37set prms_id 0 38set bug_id 0 39 40set testfile "annota3" 41set srcfile ${testfile}.c 42set binfile ${objdir}/${subdir}/${testfile} 43 44if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-w}] != "" } { 45 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." 46} 47 48 49gdb_exit 50gdb_start 51gdb_reinitialize_dir $srcdir/$subdir 52gdb_load ${binfile} 53 54if [target_info exists gdb_stub] { 55 gdb_step_for_stub; 56} 57 58# 59# the line at which break main will put the breakpoint 60# 61set main_line 32 62 63# The commands we test here produce many lines of output; disable "press 64# <return> to continue" prompts. 65send_gdb "set height 0\n" 66gdb_expect -re "$gdb_prompt $" 67 68# 69# break at main 70# 71gdb_test "break main" \ 72 "Breakpoint.*at.* file .*$srcfile, line.*" \ 73 "breakpoint main" 74 75 76# NOTE: this prompt is OK only when the annotation level is > 1 77 78# NOTE: When this prompt is in use the gdb_test procedure cannot be 79# used because it assumes that the last char after the gdb_prompt is a 80# white space. This is not true with this annotated prompt. So we must 81# use send_gdb and gdb_expect or gdb_expect_list. 82 83set old_gdb_prompt $gdb_prompt 84set gdb_prompt "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n" 85 86 87 88# 89# set the annotation level to 3 90# 91# of course, this will test: 92# annotate-pre-prompt 93# annotate-prompt 94# annotate-post-prompt (in the next block) 95# 96send_gdb "set annotate 3\n" 97gdb_expect_list "annotation set at level 3" "\r\n$gdb_prompt$" { 98 "set annotate 3" 99} 100 101 102# 103# info break: 104# 105send_gdb "info break\n" 106gdb_expect_list "breakpoint info" "$gdb_prompt$" { 107 "\r\n\032\032post-prompt\r\n" 108 "Num Type Disp Enb Address +What\r\n" 109 "1 breakpoint keep y 0x\[0-9a-zA-Z\]+ +in main at .*annota3.c:32\r\n" 110} 111 112 113# 114# run to a break point will test: 115# 116#exp_internal 1 117send_gdb "run\n" 118gdb_expect_list "run until main breakpoint" "$gdb_prompt$" { 119 "\r\n\032\032post-prompt\r\n" 120 "Starting program: .*annota3 \r\n" 121 "\(\r\n\032\032\(frames-invalid|breakpoints-invalid\)\r\n\)+" 122 "\r\n\032\032starting\r\n" 123 "\(\r\n\032\032\(frames-invalid|breakpoints-invalid\)\r\n\)+" 124 "\r\n\032\032breakpoint 1\r\n" 125 "\r\n" 126 "Breakpoint 1, main \\(\\) at .*annota3.c:32\r\n" 127 "\r\n\032\032source.*annota3.c:32:.*:beg:0x\[0-9a-z\]+\r\n" 128 "\r\n\032\032stopped\r\n" 129} 130#exp_internal 0 131#exit 0 132 133# 134# Let's do a next, to get to a point where the array is initialized 135# We don't care about the annotated output for this operation, it is the same as 136# the one produced by run above 137# 138send_gdb "next\n" 139gdb_expect_list "go after array init line" "$gdb_prompt$" { 140 "\r\n\032\032post-prompt\r\n" 141 "\r\n\032\032starting\r\n" 142 "\(\r\n\032\032frames-invalid\r\n\)+" 143 "\r\n\032\032source .*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n" 144 "\r\n\032\032stopped\r\n" 145} 146 147 148# 149# printing the array: 150# 151send_gdb "print my_array\n" 152gdb_expect_list "print array" "$gdb_prompt$" { 153 "\r\n\032\032post-prompt\r\n" 154 ".*= .1, 2, 3.\r\n" 155} 156 157 158# 159# this should generate an error message, so to test: 160# annotate-error-begin 161# FIXME: annotate-error not tested 162# 163 164#exp_internal 1 165send_gdb "print non_existent_value\n" 166gdb_expect_list "print non_existent_value" "$gdb_prompt$" { 167 "\r\n\032\032post-prompt\r\n" 168 "\r\n\032\032error-begin\r\n" 169 "No symbol \"non_existent_value\" in current context.\r\n" 170 "\r\n\032\032error\r\n" 171} 172 173 174# 175# break at signal handler 176# 177send_gdb "break handle_USR1\n" 178gdb_expect_list "breakpoint handle_USR1" "$gdb_prompt$" { 179 "\r\n\032\032post-prompt\r\n" 180 "\r\n\032\032breakpoints-invalid\r\n" 181 "Breakpoint.*at 0x\[0-9a-z\]+: file.*annota3.c, line.*\r\n" 182} 183 184# 185# break at printf. When we are stopped at printf, we can test 186# 187send_gdb "break printf\n" 188gdb_expect_list "breakpoint printf" "$gdb_prompt$" { 189 "\r\n\032\032post-prompt\r\n" 190 "\r\n\032\032breakpoints-invalid\r\n" 191 "Breakpoint.*at 0x\[0-9a-z\]+.*" 192} 193 194# 195# get to printf 196# 197send_gdb "continue\n" 198gdb_expect_list "continue to printf" "$gdb_prompt$" { 199 "\r\n\032\032post-prompt\r\n" 200 "Continuing.\r\n" 201 "\r\n\032\032starting\r\n" 202 "\r\n\032\032frames-invalid\r\n" 203 "\r\n\032\032breakpoint 3\r\n" 204 "\r\n" 205 "Breakpoint 3, \[^\r\n\]*\r\n" 206 "\r\n\032\032stopped\r\n" 207} 208 209send_gdb "backtrace\n" 210gdb_expect_list "backtrace from shlibrary" "$gdb_prompt$" { 211 "\r\n\032\032post-prompt\r\n" 212 "#0 .* printf \[^\r\n\]*\r\n" 213 "#1 .* main \[^\r\n\]*\r\n" 214} 215 216 217# 218# test printing a frame with some arguments: 219# 220 221if [target_info exists gdb,nosignals] { 222 unsupported "send SIGUSR1" 223 unsupported "backtrace @ signal handler" 224} else { 225 send_gdb "signal SIGUSR1\n" 226 gdb_expect_list "send SIGUSR1" "$gdb_prompt$" { 227 "\r\n\032\032post-prompt\r\n" 228 "Continuing with signal SIGUSR1.\r\n" 229 "\r\n\032\032starting\r\n" 230 "\r\n\032\032frames-invalid\r\n" 231 "\r\n\032\032breakpoint 2\r\n" 232 "Breakpoint 2, handle_USR1 \\(sig=\[0-9\]+\\) at .*annota3.c:\[0-9\]+\r\n" 233 "\r\n\032\032source .*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n" 234 "\r\n\032\032stopped\r\n" 235 } 236 237 # 238 # test: 239 # 240 verbose "match_max local is: [match_max]" 241 verbose "match_max default is: [match_max -d]" 242 # This is necessary because a 2000 buffer is not enought to get everything 243 # up to the prompt ad the test gets a timeout. 244 match_max 3000 245 verbose "match_max now is: [match_max]" 246 send_gdb "backtrace\n" 247 gdb_expect_list "backtrace @ signal handler" "$gdb_prompt$" { 248 "#0 +handle_USR1 \[^\r\n\]+\r\n" 249 "#1 +.signal handler called.\r\n" 250 "#2 .* printf \[^\r\n\]+\r\n" 251 "#3 .* main \[^\r\n\]+\r\n" 252 } 253} 254 255# 256# delete all the breakpoints 257# 258send_gdb "delete 1\n" 259gdb_expect_list "delete bp 1" "$gdb_prompt$" { 260 "\r\n\032\032post-prompt\r\n" 261} 262 263send_gdb "delete 2\n" 264gdb_expect_list "delete bp 2" "$gdb_prompt$" { 265 "\r\n\032\032post-prompt\r\n" 266} 267 268send_gdb "delete 3\n" 269gdb_expect_list "delete bp 3" "$gdb_prompt$" { 270 "\r\n\032\032post-prompt\r\n" 271} 272 273# 274# break at main, after value is initialized. This is in preparation 275# to test the annotate output for the display command. 276# 277send_gdb "break main\n" 278gdb_expect_list "break at 28" "$gdb_prompt$" { 279 "\r\n\032\032post-prompt\r\n" 280 "\r\n\032\032breakpoints-invalid\r\n" 281 "Breakpoint 4 at 0x\[0-9a-z\]+: file .*annota3.c, line 32.\r\n" 282} 283 284# 285# display the value 286# 287send_gdb "display value\n" 288gdb_expect_list "set up display" "$gdb_prompt$" { 289 "\r\n\032\032post-prompt\r\n" 290 "1: value = 7\r\n" 291} 292 293 294# should ask query. Test annotate-query. 295# we don't care about anything else here, only the query. 296 297send_gdb "run\n" 298gdb_expect { 299 -re "pre-query.*already.*\\(y or n\\).*query\r\n" { 300 send_gdb "y\n" 301 gdb_expect { 302 -re ".*post-query.*$gdb_prompt$" \ 303 { pass "re-run" } 304 -re ".*$gdb_prompt$" { fail "re-run" } 305 timeout { fail "re-run (timeout)" } 306 } 307 } 308 -re ".*$gdb_prompt$" { fail "re-run" } 309 timeout { fail "re-run (timeout)" } 310} 311 312# 313# Test that breakpoints-invalid is issued once and only once for 314# breakpoint ignore count changes, after annotation stopped. 315# 316send_gdb "break 46\n" 317gdb_expect_list "break at 46" "$gdb_prompt$" { 318 "\r\n\032\032post-prompt\r\n" 319 "\r\n\032\032breakpoints-invalid\r\n" 320 "Breakpoint 5 at 0x\[0-9a-z\]+: file .*annota3.c, line 46.\r\n" 321} 322 323send_gdb "ignore 5 4\n" 324gdb_expect_list "ignore 5 4" "$gdb_prompt$" { 325 "\r\n\032\032post-prompt\r\n" 326 "Will ignore next 4 crossings of breakpoint 5" 327 "\r\n\032\032breakpoints-invalid\r\n" 328 "\r\n" 329} 330 331send_gdb "continue\n" 332gdb_expect_list "annotate ignore count change" "$gdb_prompt$" { 333 "\r\n\032\032post-prompt\r\n" 334 "\(\r\n\032\032frames-invalid\r\n\)+" 335 "\r\n\032\032breakpoint 5\r\n" 336 "Breakpoint 5, main \\(\\) at .*annota3.c:46\r\n" 337 "\r\n\032\032source .*annota3.c:46:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n" 338 "1: value = 11\r\n" 339 "\r\n\032\032stopped\r\n" 340 "\r\n\032\032breakpoints-invalid\r\n" 341} 342 343# check that ignore command is working, or the above can provide 344# misleading assurance ... 345 346send_gdb "next\n" 347gdb_expect_list "next to exit loop" "$gdb_prompt$" { 348 "\r\n\032\032post-prompt\r\n" 349 "\r\n\032\032starting\r\n" 350 "\(\r\n\032\032frames-invalid\r\n\)+" 351 "\r\n\032\032source.*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n" 352 "1: value = 12\r\n" 353 "\r\n\032\032stopped\r\n" 354} 355 356send_gdb "next\n" 357gdb_expect_list "breakpoint ignore count" "$gdb_prompt$" { 358 "\r\n\032\032post-prompt\r\n" 359 "\r\n\032\032starting\r\n" 360 "\(\r\n\032\032frames-invalid\r\n\)+" 361 "\r\n\032\032source.*annota3.c:49:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n" 362 "1: value = 12\r\n" 363 "\r\n\032\032stopped\r\n" 364} 365 366# 367# Send a signal that is not handled 368# 369# SIGTRAP signals are dropped before they get to the inferior process 370# on hpux11. In theory, this behaivor can be controlled by setting 371# TTEO_NORM_SIGTRAP in the inferior, but doing so did not cause 372# the signal to be properly delivered. 373# 374# It has been verified that other signals will be delivered. However, 375# rather than twiddle the test, I choose to leave it as-is as it 376# exposes an interesting failure on hpux11. 377 378if [target_info exists gdb,nosignals] { 379 unsupported "signal sent" 380} else { 381 setup_xfail hppa*-*-hpux11* 382 send_gdb "signal SIGTRAP\n" 383 gdb_expect_list "signal sent" "$gdb_prompt$" { 384 "\r\n\032\032post-prompt\r\n" 385 "Continuing with signal SIGTRAP.\r\n" 386 "\r\n\032\032starting\r\n" 387 "\r\n\032\032frames-invalid\r\n" 388 "\r\n\032\032frames-invalid\r\n" 389 "\r\n\032\032signalled\r\n" 390 "\r\nProgram terminated with signal SIGTRAP, Trace.breakpoint trap.\r\n" 391 "The program no longer exists.\r\n" 392 "\r\n\032\032stopped\r\n" 393 } 394} 395 396 397# Check for production of a core file and remove it! 398 399set exec_output [remote_exec build "ls core"] 400 401set test "cleanup core file" 402if [ regexp "core not found" $exec_output] { 403 pass "$test (not dumped)" 404} else { 405 if [ regexp "No such file or directory" $exec_output] { 406 pass "$test (not dumped)" 407 } else { 408 remote_exec build "rm -f core" 409 pass "$test (removed)" 410 } 411} 412 413# restore the original prompt for the rest of the testsuite 414 415set gdb_prompt $old_gdb_prompt 416