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