1# Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2# 2010, 2011 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 3 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, see <http://www.gnu.org/licenses/>. 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# 37 38set testfile "annota1" 39set srcfile ${testfile}.c 40set binfile ${objdir}/${subdir}/${testfile} 41 42if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } { 43 untested annota1.exp 44 return -1 45} 46 47 48gdb_exit 49gdb_start 50gdb_reinitialize_dir $srcdir/$subdir 51gdb_load ${binfile} 52 53if [target_info exists gdb_stub] { 54 gdb_step_for_stub; 55} 56 57# 58# the line at which break main will put the breakpoint 59# 60set main_line 32 61 62# The commands we test here produce many lines of output; disable "press 63# <return> to continue" prompts. 64gdb_test_no_output "set height 0" 65 66# 67# break at main 68# 69gdb_test "break main" \ 70 "Breakpoint.*at.* file .*$srcfile, line.*" \ 71 "breakpoint main" 72 73 74# 75# NOTE: this prompt is OK only when the annotation level is > 1 76# NOTE: When this prompt is in use the gdb_test procedure cannot be used because 77# it assumes that the last char after the gdb_prompt is a white space. This is not 78# true with this annotated prompt. So we must use send_gdb and gdb_expect. 79# 80 81set old_gdb_prompt $gdb_prompt 82set gdb_prompt "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n" 83 84# 85# Escape all the characters in the path that need it. For instance 86# the directory name could contain '+'. 87# 88set escapedsrcfile [string_to_regexp ${srcdir}/${subdir}/${srcfile}] 89 90 91# 92# set the annotation level to 2 93# 94# of course, this will test: 95# annotate-pre-prompt 96# annotate-prompt 97# annotate-post-prompt (in the next block) 98# 99send_gdb "set annotate 2\n" 100gdb_expect { 101 -re "set annotate 2\r\n$gdb_prompt$" { pass "annotation set at level 2" } 102 -re ".*$gdb_prompt$" { fail "annotation set at level 2" } 103 timeout { fail "annotation set at level 2 (timeout)" } 104 } 105 106 107# 108# info break will test: 109# annotate-breakpoints-headers 110# annotate-field 111# annotate-breakpoints-table 112# annotate-record 113# annotate-breakpoints-table-end 114# 115gdb_test_multiple "info break" "breakpoint info" { 116 -re "\r\n\032\032post-prompt\r\n\r\n\032\032breakpoints-headers\r\n\r\n\032\032field 0\r\nNum \r\n\032\032field 1\r\nType \r\n\032\032field 2\r\nDisp \r\n\032\032field 3\r\nEnb \r\n\032\032field 4\r\nAddress +\r\n\032\032field 5\r\nWhat\r\n\r\n\032\032breakpoints-table\r\n\r\n\032\032record\r\n\r\n\032\032field 0\r\n1 \r\n\032\032field 1\r\nbreakpoint \r\n\032\032field 2\r\nkeep \r\n\032\032field 3\r\ny \r\n\032\032field 4\r\n$hex +\r\n\032\032field 5\r\nin main at ${escapedsrcfile}:$main_line\r\n\r\n\032\032breakpoints-table-end\r\n$gdb_prompt$" { 117 pass "breakpoint info" 118 } 119 -re "\r\n\032\032post-prompt\r\n\r\n\032\032breakpoints-headers\r\n\r\n\032\032field 0\r\nNum \r\n\032\032field 1\r\nType \r\n\032\032field 2\r\nDisp \r\n\032\032field 3\r\nEnb \r\n\032\032field 4\r\nAddress +\r\n\032\032field 5\r\nWhat\r\n\r\n\032\032breakpoints-table\r\n\r\n\032\032record\r\n\r\n\032\032field 0\r\n1 \r\n\032\032field 1\r\nbreakpoint \r\n\032\032field 2\r\nkeep \r\n\032\032field 3\r\ny \r\n\032\032field 4\r\n$hex +\r\n\032\032field 5\r\nin main at .*${srcfile}:$main_line\r\n\r\n\032\032breakpoints-table-end\r\n$gdb_prompt$" { 120 setup_xfail "*-*-*" 1270 121 fail "breakpoint info" 122 } 123} 124 125 126# 127# run to a break point will test: 128# annotate-frames-invalid 129# annotate-breakpoints-invalid (a.k.a. breakpoints-changed) 130# annotate-starting 131# annotate-breakpoint 132# annotate-frame-begin 133# annotate-frame-function-name 134# annotate-frame-args 135# annotate-frame-source-begin 136# annotate-frame-source-file 137# annotate-frame-source-file-end 138# annotate-frame-source-line 139# annotate-frame-source-end 140# annotate-source 141# annotate-frame-end 142# annotate-stopped 143# 144#exp_internal 1 145set binexp [string_to_regexp $binfile] 146gdb_test_multiple "run" "run until main breakpoint" { 147 -re "\r\n\032\032post-prompt\r\nStarting program: $binexp \(\(\r\n\r\n\032\032frames-invalid\)|\(\r\n\r\n\032\032breakpoints-invalid\)\)+\r\n\r\n\032\032starting\(\(\r\n\r\n\032\032frames-invalid\)|\(\r\n\r\n\032\032breakpoints-invalid\)\)*\r\n\r\n\032\032breakpoint 1\r\n\r\nBreakpoint 1, \r\n\032\032frame-begin 0 $hex\r\n\r\n\032\032frame-function-name\r\nmain\r\n\032\032frame-args\r\n \\(\\)\r\n\032\032frame-source-begin\r\n at \r\n\032\032frame-source-file\r\n.*annota1.c\r\n\032\032frame-source-file-end\r\n:\r\n\032\032frame-source-line\r\n$main_line\r\n\032\032frame-source-end\r\n\r\n\r\n\032\032source.*$srcfile:$main_line:.*:beg:$hex\r\n\r\n\032\032frame-end\r\n\r\n\032\032stopped.*$gdb_prompt$" { 148 pass "run until main breakpoint" 149 } 150} 151#exp_internal 0 152#exit 0 153 154# 155# Let's do a next, to get to a point where the array is initialized 156# We don't care about the annotated output for this operation, it is the same as 157# the one produced by run above 158# 159gdb_test_multiple "next" "go after array init line" { 160 -re "source .*annota1.c.*$gdb_prompt$" { 161 pass "go after array init line" 162 } 163} 164 165 166# 167# printing the array will test: 168# annotate-value-history-begin 169# annotate-value-history-value 170# annotate-array-section-begin 171# annotate-elt 172# FIXME: annotate-elt-rep and annotate-elt-rep-end not tested 173# annotate-array-section-end 174# annotate-value-history-end 175# FIXME: annotate-value-begin and annotate-value-end not tested (the gdb output 176# command would cause them to be used) 177# 178gdb_test_multiple "print my_array" "print array" { 179 -re "\r\n\032\032post-prompt\r\n\r\n\032\032value-history-begin 1 -\r\n.*= \r\n\032\032value-history-value\r\n.\r\n\032\032array-section-begin 0 -\r\n1\r\n\032\032elt\r\n, 2\r\n\032\032elt\r\n, 3\r\n\032\032elt\r\n\r\n\032\032array-section-end\r\n.\r\n\r\n\032\032value-history-end\r\n$gdb_prompt$" { 180 pass "print array" 181 } 182} 183 184 185# 186# this should generate an error message, so to test: 187# annotate-error-begin 188# FIXME: annotate-error not tested 189# 190 191#exp_internal 1 192gdb_test_multiple "print non_existent_value" "print non_existent_value" { 193 -re "\r\n\032\032post-prompt\r\n\r\n\032\032error-begin\r\nNo symbol \"non_existent_value\" in current context.\r\n\r\n\032\032error\r\n$gdb_prompt$" { 194 pass "print non_existent_value" 195 } 196} 197 198 199# 200# break at signal handler. So that, once we are in the sig handler, if we do a bt 201# we can test annotate-signal-handler-caller 202# 203gdb_test_multiple "break handle_USR1" "break handle_USR1" { 204 -re "\r\n\032\032post-prompt\r\n\r\n\032\032breakpoints-invalid\r\nBreakpoint.*at $hex: file.*$srcfile, line.*\r\n$gdb_prompt$" { 205 pass "break handle_USR1" 206 } 207} 208 209# 210# break at printf. When we are stopped at printf, we can test 211# 212gdb_test_multiple "break printf" "break printf" { 213 -re "\r\n\032\032post-prompt\r\n\r\n\032\032breakpoints-invalid\r\nBreakpoint.*at $hex.*$gdb_prompt$" { 214 pass "break printf" 215 } 216 -re "\r\n\032\032post-prompt\r\nwarning: Breakpoint address adjusted from $hex to $hex.\r\n\r\n\032\032breakpoints-invalid\r\nBreakpoint.*at $hex.*$gdb_prompt$" { 217 pass "break printf" 218 } 219} 220 221# 222# get to printf 223# 224set pat_begin "\r\n\032\032post-prompt\r\nContinuing.\r\n\r\n\032\032starting\(\r\n\r\n\032\032frames-invalid\)+\r\n" 225set pat_adjust "warning: Breakpoint 3 address previously adjusted from $hex to $hex.\r\n" 226set pat_end "\r\n\032\032breakpoint 3\r\n\r\nBreakpoint 3, \r\n\032\032frame-begin 0 $hex\r\n\r\n(\032\032frame-address\r\n$hex\r\n\032\032frame-address-end\r\n in \r\n)*.*\032\032frame-function-name\r\n.*printf(@.*)?\r\n\032\032frame-args\r\n.*\032\032frame-end\r\n\r\n\032\032stopped\r\n$gdb_prompt$" 227 228gdb_test_multiple "continue" "continue to printf" { 229 -re "${pat_begin}($pat_adjust)?$pat_end" { 230 pass "continue to printf" 231 } 232 -re ".*$gdb_prompt$" { fail "continue to printf" } 233} 234 235# 236# test: 237# annotate-frame-where 238# annotate-frame-address 239# annotate-frame-address-end 240# 241set pat_begin "\r\n\032\032post-prompt\r\n\r\n\032\032frame-begin 0 $hex\r\n.0 \r\n(\032\032frame-address\r\n$hex\r\n\032\032frame-address-end\r\n in \r\n)*\032\032frame-function-name\r\n.*printf(@.*)?\r\n\032\032frame-args\r\n \\(.*frame-end\r\n\r\n\032\032frame-begin 1 $hex\r\n.1 \r\n\032\032frame-address\r\n$hex\r\n\032\032frame-address-end\r\n in \r\n\032\032frame-function-name\r\nmain\r\n\032\032frame-args\r\n \\(\\)\r\n\032\032frame-source-begin\r\n at \r\n\032\032frame-source-file\r\n" 242 243set pat_end "\r\n\032\032frame-source-file-end\r\n:\r\n\032\032frame-source-line\r\n.*\r\n\032\032frame-source-end\r\n\r\n\r\n\032\032frame-end\r\n(\r\n\032\032frame-begin .*\r\n\r\n\032\032frame-end\r\n)*$gdb_prompt$" 244 245gdb_test_multiple "backtrace" "backtrace from shlibrary" { 246 -re "$pat_begin$escapedsrcfile$pat_end" { 247 pass "backtrace from shlibrary" 248 } 249 -re "$pat_begin.*$srcfile$pat_end" { 250 setup_xfail "*-*-*" 1270 251 fail "backtrace from shlibrary" 252 } 253} 254 255 256# 257# test printing a frame with some arguments: 258# annotate-arg-begin 259# annotate-arg-name-end 260# annotate-arg-value 261# annotate-arg-end 262# 263 264if [target_info exists gdb,nosignals] { 265 unsupported "send SIGUSR1" 266 unsupported "backtrace @ signal handler" 267} else { 268 gdb_test_multiple "signal SIGUSR1" "send SIGUSR1" { 269 -re "\r\n\032\032post-prompt\r\nContinuing with signal SIGUSR1.\r\n\r\n\032\032starting\(\r\n\r\n\032\032frames-invalid\)+\r\n\r\n\032\032breakpoint 2\r\n\r\nBreakpoint 2, \r\n\032\032frame-begin 0 $hex\r\n\r\n\032\032frame-function-name\r\nhandle_USR1\r\n\032\032frame-args\r\n \\(\r\n\032\032arg-begin\r\nsig\r\n\032\032arg-name-end\r\n=\r\n\032\032arg-value -\r\n$decimal\r\n\032\032arg-end\r\n\\)\r\n\032\032frame-source-begin\r\n at \r\n\032\032frame-source-file\r\n${escapedsrcfile}\r\n\032\032frame-source-file-end\r\n:\r\n\032\032frame-source-line\r\n.*\r\n\032\032frame-source-end\r\n\r\n\r\n\032\032source.*annota1.c:.*:.*:beg:$hex\r\n\r\n\032\032frame-end\r\n\r\n\032\032stopped\r\n$gdb_prompt$" { 270 pass "send SIGUSR1" 271 } 272 -re "\r\n\032\032post-prompt\r\nContinuing with signal SIGUSR1.\r\n\r\n\032\032starting\(\r\n\r\n\032\032frames-invalid\)+\r\n\r\n\032\032breakpoint 2\r\n\r\nBreakpoint 2, \r\n\032\032frame-begin 0 $hex\r\n\r\n\032\032frame-function-name\r\nhandle_USR1\r\n\032\032frame-args\r\n \\(\r\n\032\032arg-begin\r\nsig\r\n\032\032arg-name-end\r\n=\r\n\032\032arg-value -\r\n$decimal\r\n\032\032arg-end\r\n\\)\r\n\032\032frame-source-begin\r\n at \r\n\032\032frame-source-file\r\n.*${srcfile}\r\n\032\032frame-source-file-end\r\n:\r\n\032\032frame-source-line\r\n.*\r\n\032\032frame-source-end\r\n\r\n\r\n\032\032source.*annota1.c:.*:.*:beg:$hex\r\n\r\n\032\032frame-end\r\n\r\n\032\032stopped\r\n$gdb_prompt$" { 273 setup_xfail "*-*-*" 1270 274 fail "send SIGUSR1" 275 } 276 } 277 278 # 279 # test: 280 # annotate-signal-handler-caller 281 # 282 gdb_test_multiple "backtrace" "backtrace @ signal handler" { 283 -re "frame-begin 0 $hex\r\n#0.*frame-end.*frame-begin 1 $hex\r\n#1.*(\032\032signal-handler-caller\r\n.signal handler called.\r\n\r\n)+\032\032frame-end\r\n\r\n\032\032frame-begin 2 $hex\r\n#2.*(frame-begin 3 $hex\r\n#3.*)*frame-end.*$gdb_prompt$" { 284 pass "backtrace @ signal handler" 285 } 286 } 287} 288 289# 290# delete all the breakpoints 291# 292gdb_test_multiple "delete 1" "delete bp 1" { 293 -re "\r\n\032\032post-prompt\r\n$gdb_prompt$" { 294 pass "delete bp 1" 295 } 296} 297 298gdb_test_multiple "delete 2" "delete bp 2" { 299 -re "\r\n\032\032post-prompt\r\n$gdb_prompt$" { 300 pass "delete bp 2" 301 } 302} 303 304gdb_test_multiple "delete 3" "delete bp 3" { 305 -re "\r\n\032\032post-prompt\r\n$gdb_prompt$" { 306 pass "delete bp 3" 307 } 308} 309 310# 311# break at main, after value is initialized. This is in preparation 312# to test the annotate output for the display command. 313# 314gdb_test_multiple "break main" "break at 28" { 315 -re "post-prompt.*\032\032breakpoints-invalid.*Breakpoint 4 at $hex: file ${escapedsrcfile}, line $main_line.*$gdb_prompt$" { 316 pass "break at 28" 317 } 318 -re "post-prompt.*\032\032breakpoints-invalid.*Breakpoint 4 at $hex: file .*${srcfile}, line $main_line.*$gdb_prompt$" { 319 setup_xfail "*-*-*" 1270 320 fail "break at 28" 321 } 322} 323 324# 325# display the value; test: 326# annotate-display-begin 327# annotate-display-number-end 328# annotate-display-format 329# annotate-display-expression 330# annotate-display-expression-end 331# annotate-display-end 332# FIXME: annotate-display-value not tested 333# 334gdb_test_multiple "display value" "set up display" { 335 -re "post-prompt\r\n\r\n\032\032display-begin\r\n1\r\n\032\032display-number-end\r\n: \r\n\032\032display-format\r\n\r\n\032\032display-expression\r\nvalue\r\n\032\032display-expression-end\r\n = \r\n\032\032display-expression\r\n7\r\n\r\n\032\032display-end\r\n$gdb_prompt$" { 336 pass "set up display" 337 } 338} 339 340 341# should ask query. Test annotate-query. 342# we don't care about anything else here, only the query. 343 344send_gdb "run\n" 345gdb_expect { 346 -re "pre-query.*already.*\\(y or n\\).*query\r\n" { 347 send_gdb "y\n" 348 gdb_expect { 349 -re ".*post-query.*$gdb_prompt$" \ 350 { pass "re-run" } 351 -re ".*$gdb_prompt$" { fail "re-run" } 352 timeout { fail "re-run (timeout)" } 353 } 354 } 355 -re ".*$gdb_prompt$" { fail "re-run" } 356 timeout { fail "re-run (timeout)" } 357} 358 359# 360# Test that breakpoints-invalid is issued once and only once for 361# breakpoint ignore count changes, after annotation stopped. 362# 363gdb_test_multiple "break 46" "break at 46" { 364 -re "Breakpoint 5 at $hex: file .*$srcfile, line 46.*$gdb_prompt$" { 365 pass "break at 46" 366 } 367} 368 369gdb_test_multiple "ignore 5 4" "ignore 5 4" { 370 -re "Will ignore next 4 crossings of breakpoint 5.*$gdb_prompt$" { 371 pass "ignore 5 4" 372 } 373} 374 375gdb_test_multiple "continue" "annotate ignore count change" { 376 -re ".*$srcfile:46:.*\032\032stopped\r\n\r\n\032\032breakpoints-invalid\r\n$gdb_prompt$" { 377 pass "annotate ignore count change" 378 } 379} 380 381# check that ignore command is working, or the above can provide 382# misleading assurance ... 383 384gdb_test_multiple "next" "next to exit loop" { 385 -re "source .*annota1.c.*$gdb_prompt$" { 386 } 387} 388 389gdb_test_multiple "next" "breakpoint ignore count" { 390 -re ".*$srcfile:49:.*$gdb_prompt$" { 391 pass "breakpoint ignore count" 392 } 393} 394 395# 396# Send a signal that is not handled; test: 397# annotate-signalled 398# annotate-signal-name 399# annotate-signal-name-end 400# annotate-signal-string 401# annotate-signal-string-end 402# FIXME: annotate-signal not tested (requires that the inferior be 403# stopped by a "random" signal) 404# 405# SIGTRAP signals are dropped before they get to the inferior process 406# on hpux11. In theory, this behaivor can be controlled by setting 407# TTEO_NORM_SIGTRAP in the inferior, but doing so did not cause 408# the signal to be properly delivered. 409# 410# It has been verified that other signals will be delivered. However, 411# rather than twiddle the test, I choose to leave it as-is as it 412# exposes an interesting failure on hpux11. 413 414if [target_info exists gdb,nosignals] { 415 unsupported "signal sent" 416} else { 417 setup_xfail hppa*-*-hpux11* 418 gdb_test_multiple "signal SIGTRAP" "signal sent" { 419 -re ".*\032\032post-prompt\r\nContinuing with signal SIGTRAP.\r\n\r\n\032\032starting\(\r\n\r\n\032\032frames-invalid\)+\r\n\r\n\032\032signalled\r\n\r\nProgram terminated with signal \r\n\032\032signal-name\r\nSIGTRAP\r\n\032\032signal-name-end\r\n, \r\n\032\032signal-string\r\nTrace.breakpoint trap\r\n\032\032signal-string-end\r\n.\r\nThe program no longer exists.\r\n\r\n\032\032stopped\r\n$gdb_prompt$" { 420 pass "signal sent" 421 } 422 } 423} 424 425 426# Check for production of a core file and remove it! 427 428set exec_output [remote_exec build "ls core"] 429 430set test "cleanup core file" 431if [ regexp "core not found" $exec_output] { 432 pass "$test (not dumped)" 433} else { 434 if [ regexp "No such file or directory" $exec_output] { 435 pass "$test (not dumped)" 436 } else { 437 remote_exec build "rm -f core" 438 pass "$test (removed)" 439 } 440} 441 442proc thread_test {} { 443 global objdir subdir srcdir testfile 444 global gdb_prompt old_gdb_prompt 445 set srcfile watch_thread_num.c 446 set binfile ${objdir}/${subdir}/${testfile}-watch_thread_num 447 set gdb_prompt $old_gdb_prompt 448 449 if { ![get_compiler_info ${binfile}] && [gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] == "" } { 450 451 gdb_exit 452 gdb_start 453 gdb_reinitialize_dir $srcdir/$subdir 454 gdb_load ${binfile} 455 if { ![runto main] } then { 456 fail "run to main" 457 return 458 } 459 460 set gdb_prompt \ 461 "\r\n\032\032pre-prompt\r\n$gdb_prompt \r\n\032\032prompt\r\n" 462 463 gdb_test_multiple "set annotate 2" "" { 464 -re "set annotate 2\r\n$gdb_prompt$" { 465 } 466 } 467 468 gdb_test_multiple "next 2" "new thread" { 469 -re ".*\032\032new-thread" { 470 pass "new thread" 471 } 472 } 473 } 474} 475 476proc thread_switch {} { 477 gdb_test_multiple "thread 1" "thread switch" { 478 -re ".*\032\032thread-changed" { 479 pass "thread switch" 480 } 481 } 482} 483 484thread_test 485thread_switch 486 487# restore the original prompt for the rest of the testsuite 488 489set gdb_prompt $old_gdb_prompt 490