Home | History | Annotate | Line # | Download | only in gdb.base
annota3.exp revision 1.1.1.7
      1 # Copyright 2003-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 # This file was written by Elena Zannoni (ezannoni (at) 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 #
     22 if ![target_can_use_run_cmd] {
     23     return 0
     24 }
     25 
     26 
     27 #
     28 # test running programs
     29 #
     30 
     31 standard_testfile .c
     32 
     33 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
     34     untested "failed to compile"
     35     return -1
     36 }
     37 
     38 
     39 clean_restart ${binfile}
     40 
     41 # The commands we test here produce many lines of output; disable "press
     42 # <return> to continue" prompts.
     43 gdb_test_no_output "set height 0"
     44 
     45 #
     46 # break in main
     47 #
     48 
     49 set main_line [gdb_get_line_number "break main"]
     50 
     51 gdb_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 
     63 set old_gdb_prompt $gdb_prompt
     64 set 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 #
     76 send_gdb "set annotate 3\n"
     77 gdb_expect_list "annotation set at level 3" "\r\n$gdb_prompt$" {
     78     "set annotate 3"
     79 }
     80 
     81 #
     82 # if construct:
     83 #
     84 gdb_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 
     90 gdb_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 #
     99 send_gdb "info break\n"
    100 gdb_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
    110 send_gdb "run\n"
    111 gdb_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 #
    131 send_gdb "next\n"
    132 gdb_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 #
    143 send_gdb "print my_array\n"
    144 gdb_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
    157 send_gdb "print non_existent_value\n"
    158 gdb_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 #
    169 send_gdb "break handle_USR1\n"
    170 gdb_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 #
    178 send_gdb "break printf\n"
    179 gdb_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 #
    187 send_gdb "continue\n"
    188 gdb_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 
    198 send_gdb "backtrace\n"
    199 gdb_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 
    210 if [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 #
    243 send_gdb "delete 1\n"
    244 gdb_expect_list "delete bp 1" "$gdb_prompt$" {
    245     "\r\n\032\032post-prompt\r\n"
    246 }
    247 
    248 send_gdb "delete 2\n"
    249 gdb_expect_list "delete bp 2" "$gdb_prompt$" {
    250     "\r\n\032\032post-prompt\r\n"
    251 }
    252 
    253 send_gdb "delete 3\n"
    254 gdb_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 #
    262 send_gdb "break ${srcfile}:${main_line}\n"
    263 gdb_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 #
    270 send_gdb "display value\n"
    271 gdb_expect_list "set up display" "$gdb_prompt$" {
    272     "\r\n\032\032post-prompt\r\n"
    273     "1: value = 7\r\n"
    274 }
    275 
    276 # Get the core into the output directory.
    277 if {![is_remote host]} {
    278     gdb_test -prompt "$gdb_prompt$" \
    279 	"set cwd [file dirname $binfile]" "" \
    280 	"set inferior cwd to test directory"
    281 }
    282 
    283 # should ask query. Test annotate-query.
    284 # we don't care about anything else here, only the query.
    285 
    286 send_gdb "run\n"
    287 gdb_expect {
    288   -re "pre-query.*already.*\\(y or n\\).*query\r\n" {
    289          send_gdb "y\n"
    290          gdb_expect {
    291 	     -re ".*post-query.*$gdb_prompt$" \
    292 		     { pass "re-run" }
    293 	     -re ".*$gdb_prompt$"  { fail "re-run" }
    294 	     timeout { fail "re-run (timeout)" }
    295 	 }
    296      }
    297   -re ".*$gdb_prompt$"  { fail "re-run" }
    298   timeout { fail "re-run (timeout)" }
    299 }
    300 
    301 #
    302 # Test that breakpoints-invalid is issued once and only once for
    303 # breakpoint ignore count changes, after annotation stopped.
    304 # NOTE: breakpoints-invalid annotations have been removed from
    305 # level 3 but keep these tests for continuity and comparison
    306 # with annota1.exp.
    307 
    308 set value_inc_line [gdb_get_line_number "increment value"]
    309 
    310 send_gdb "break $value_inc_line\n"
    311 gdb_expect_list  "break at value++" "$gdb_prompt$" [concat {
    312     "\r\n\032\032post-prompt\r\n" } [list \
    313     "Breakpoint 5 at 0x\[0-9a-z\]+: file .*annota3.c, line $value_inc_line.\r\n"]]
    314 
    315 send_gdb "ignore 5 4\n"
    316 gdb_expect_list "ignore 5 4" "$gdb_prompt$" {
    317     "\r\n\032\032post-prompt\r\n"
    318     "Will ignore next 4 crossings of breakpoint 5"
    319     "\r\n"
    320 }
    321 
    322 send_gdb "continue\n"
    323 gdb_expect_list "annotate ignore count change" "$gdb_prompt$" [concat {
    324     "\r\n\032\032post-prompt\r\n"
    325     "\r\n\032\032breakpoint 5\r\n"
    326     "\r\n"
    327     "Breakpoint 5, "
    328     "\r\n\032\032frame-begin 0 0x\[0-9a-z\]+\r\n" } [list \
    329     "main \\(\\) at .*annota3.c:$value_inc_line\r\n"] [list \
    330     "\r\n\032\032source .*annota3.c:$value_inc_line:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"] {
    331     "1: value = 11\r\n"
    332     "\r\n\032\032stopped\r\n"
    333 }]
    334 
    335 # check that ignore command is working, or the above can provide
    336 # misleading assurance ...
    337 
    338 send_gdb "next\n"
    339 gdb_expect_list "next to exit loop" "$gdb_prompt$"  {
    340     "\r\n\032\032post-prompt\r\n"
    341     "\r\n\032\032starting\r\n"
    342     "\r\n\032\032source.*annota3.c:\[0-9\]+:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"
    343     "1: value = 12\r\n"
    344     "\r\n\032\032stopped\r\n"
    345 }
    346 
    347 set after_loop_line [gdb_get_line_number "after loop"]
    348 
    349 send_gdb "next\n"
    350 gdb_expect_list "breakpoint ignore count" "$gdb_prompt$" [concat {
    351     "\r\n\032\032post-prompt\r\n"
    352     "\r\n\032\032starting\r\n" } [list \
    353     "\r\n\032\032source.*annota3.c:$after_loop_line:\[0-9\]+:beg:0x\[0-9a-z\]+\r\n"] {
    354     "1: value = 12\r\n"
    355     "\r\n\032\032stopped\r\n"
    356 }]
    357 
    358 # Get the inferior's PID for later.
    359 
    360 set test "get inferior pid"
    361 set pid -1
    362 gdb_test_multiple "info inferior 1" "$test" {
    363     -re "process (\[0-9\]*).*$gdb_prompt$" {
    364 	set pid $expect_out(1,string)
    365 	pass "$test"
    366     }
    367 }
    368 
    369 # Send a signal that is not handled
    370 
    371 if [target_info exists gdb,nosignals] {
    372     unsupported "signal sent"
    373 } else {
    374     send_gdb "signal SIGTRAP\n"
    375     gdb_expect_list "signal sent" "$gdb_prompt$" {
    376 	"\r\n\032\032post-prompt\r\n"
    377 	"Continuing with signal SIGTRAP.\r\n"
    378 	"\r\n\032\032starting\r\n"
    379 	"\r\n\032\032signalled\r\n"
    380 	"\r\nProgram terminated with signal SIGTRAP, Trace.breakpoint trap.\r\n"
    381 	"The program no longer exists.\r\n"
    382 	"\r\n\032\032stopped\r\n"
    383     }
    384 }
    385 
    386 
    387 # Check for production of a core file and remove it!
    388 remove_core $pid
    389 
    390 # restore the original prompt for the rest of the testsuite
    391 
    392 set gdb_prompt $old_gdb_prompt
    393