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