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