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