Home | History | Annotate | Line # | Download | only in gdb.python
py-mi.exp revision 1.7
      1 # Copyright (C) 2008-2017 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 is part of the GDB testsuite.  It tests Python-based
     17 # pretty-printing for MI.
     18 
     19 load_lib mi-support.exp
     20 set MIFLAGS "-i=mi2"
     21 
     22 gdb_exit
     23 if [mi_gdb_start] {
     24     continue
     25 }
     26 
     27 standard_testfile py-prettyprint.c
     28 set pyfile py-prettyprint.py
     29 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DMI}] != "" } {
     30     untested "failed to compile"
     31     return -1
     32 }
     33 
     34 mi_delete_breakpoints
     35 mi_gdb_reinitialize_dir $srcdir/$subdir
     36 mi_gdb_load ${binfile}
     37 
     38 if {[lsearch -exact [mi_get_features] python] < 0} {
     39     unsupported "python support is disabled"
     40     return -1
     41 }
     42 
     43 mi_runto main
     44 
     45 set remote_python_file [gdb_remote_download host ${srcdir}/${subdir}/${pyfile}]
     46 
     47 mi_gdb_test "source ${remote_python_file}" "load python file"
     48 
     49 mi_continue_to_line [gdb_get_line_number {MI breakpoint here} ${srcfile}] \
     50   "step to breakpoint"
     51 
     52 mi_create_floating_varobj container c \
     53   "create container varobj, no pretty-printing"
     54 
     55 mi_list_varobj_children container {
     56   { container.name name 1 string }
     57   { container.len len 0 int }
     58   { container.elements elements 1 "int ." }
     59 } "examine container children=0, no pretty-printing"
     60 
     61 mi_delete_varobj container "delete varobj"
     62 
     63 mi_create_floating_varobj nscont nstype \
     64   "create nscont varobj, no pretty-printing"
     65 
     66 mi_list_varobj_children nscont {
     67   { nscont.len len 0 int }
     68   { nscont.elements elements 1 "int ." }
     69 } "examine nscont children=0, no pretty-printing"
     70 
     71 mi_delete_varobj nscont "delete varobj"
     72 
     73 mi_gdb_test "-enable-pretty-printing" ""
     74 
     75 mi_create_varobj_checked string string_1 \
     76     "struct string_repr" \
     77     "create string_1 varobj"
     78 
     79 mi_create_varobj_checked lstring estring \
     80     "struct lazystring" \
     81     "create estring varobj"
     82 
     83 mi_gdb_test "-data-evaluate-expression \"string_1 = string_2\"" ".*" \
     84     "assign string_1 from string_2"
     85 
     86 mi_gdb_test "-var-update string" \
     87     "\\^done,changelist=\\\[{name=\"string\",in_scope=\"true\",type_changed=\"false\",dynamic=\"1\",has_more=\"0\"}\\\]" \
     88     "update string varobj after assignment"
     89 
     90 # The "elements" field of "c" is still empty, so the attribute
     91 # "has_more" is expected to be zero.
     92 mi_create_dynamic_varobj container c 0 \
     93   "create container varobj"
     94 
     95 mi_list_varobj_children container {
     96 } "examine container children=0"
     97 
     98 mi_next "next over update 1"
     99 
    100 mi_varobj_update_dynamic container "varobj update 1" {
    101     type_changed false new_num_children 1 dynamic 1 has_more 0
    102 } {
    103 } {
    104     { name {container.\[0\]} exp {\[0\]} numchild 0 type int thread-id 1 }
    105 }
    106 
    107 mi_next "next over update 2"
    108 
    109 mi_varobj_update_dynamic container "varobj update 2" {
    110     type_changed false new_num_children 2 dynamic 1 has_more 0
    111 } {
    112 } {
    113     { name {container.\[1\]} exp {\[1\]} numchild 0 type int thread-id 1 }
    114 }
    115 
    116 mi_gdb_test "-var-set-visualizer container None" \
    117   "\\^done" \
    118   "clear visualizer"
    119 
    120 mi_gdb_test "-var-update container" \
    121   "\\^done,changelist=\\\[\\\]" \
    122   "varobj update after clearing"
    123 
    124 mi_gdb_test "-var-set-visualizer container gdb.default_visualizer" \
    125   "\\^done" \
    126   "choose default visualizer"
    127 
    128 mi_varobj_update_dynamic container "varobj update after choosing default" {
    129     type_changed false new_num_children 2 dynamic 1 has_more 0
    130 } {
    131 } {
    132     { name {container.\[0\]} exp {\[0\]} numchild 0 type int thread-id 1 }
    133     { name {container.\[1\]} exp {\[1\]} numchild 0 type int thread-id 1 }
    134 }
    135 
    136 mi_gdb_test "-var-set-visualizer container ContainerPrinter" \
    137   "\\^done" \
    138   "choose visualizer using expression"
    139 
    140 mi_varobj_update_dynamic container \
    141   "varobj update after choosing via expression" {
    142       type_changed false new_num_children 2 dynamic 1 has_more 0
    143   } {
    144   } {
    145       { name {container.\[0\]} exp {\[0\]} numchild 0 type int thread-id 1 }
    146       { name {container.\[1\]} exp {\[1\]} numchild 0 type int thread-id 1 }
    147   }
    148 
    149 mi_list_varobj_children_range container 1 2 2 {
    150     { {container.\[1\]} {\[1\]} 0 int }
    151 } "list varobj children after selecting child range"
    152 
    153 mi_list_varobj_children_range container -1 -1 2 {
    154     { {container.\[0\]} {\[0\]} 0 int }
    155     { {container.\[1\]} {\[1\]} 0 int }
    156 } "list varobj children after resetting child range"
    157 
    158 mi_next "next over update 3"
    159 
    160 mi_gdb_test "-var-set-update-range container 0 1" \
    161   "\\^done" \
    162   "set update range"
    163 
    164 # This should truncate the list.
    165 mi_list_varobj_children container {
    166     { {container.\[0\]} {\[0\]} 0 int }
    167 } "list children after setting update range"
    168 
    169 # This should return just the items in [1,2).
    170 mi_list_varobj_children_range container 1 2 2 {
    171     { {container.\[1\]} {\[1\]} 0 int }
    172 } "list selected children after setting range"
    173 
    174 # This should not be affected by the previous list-children request.
    175 mi_list_varobj_children container {
    176     { {container.\[0\]} {\[0\]} 0 int }
    177 } "list children after listing selected range"
    178 
    179 mi_next "next over update 4"
    180 
    181 # This should only show the first child, because the update range has
    182 # been set.
    183 mi_varobj_update_dynamic container \
    184   "update after next with restricted range" {
    185       type_changed false new_num_children 1 dynamic 1 has_more 1
    186   } {
    187       { name {container.\[0\]} in_scope true type_changed false has_more 0 }
    188   } {
    189   }
    190 
    191 mi_gdb_test "-var-set-update-range container 3 4" \
    192   "\\^done" \
    193   "set update range with non-zero start"
    194 
    195 # Elements were updated but should not be reported.
    196 mi_varobj_update_dynamic container \
    197   "update varobj with change outside selected range" {
    198       type_changed false new_num_children 3 dynamic 1 has_more 0
    199   } {
    200   } {
    201   }
    202 
    203 mi_next "next over update 5"
    204 
    205 # Regression test: examine an object that has no children, then update
    206 # it to ensure that we don't print the children.
    207 mi_create_dynamic_varobj container2 c2 0 \
    208   "create second container varobj"
    209 
    210 mi_gdb_test "-var-update container2" \
    211   "\\^done,changelist=.." \
    212   "update varobj, no children requested"
    213 
    214 mi_next "next over update 6"
    215 
    216 # Now container2 has an element -- and an update should mention that
    217 # it has_more.  But, because we did not request children, we still
    218 # should not actually see them.
    219 mi_varobj_update_dynamic container2 \
    220     "update varobj 2, no children requested" {
    221 	type_changed false dynamic 1 has_more 1
    222     } {} {}
    223 
    224 mi_continue_to_line \
    225     [gdb_get_line_number {MI outer breakpoint here} ${srcfile}] \
    226     "step to outer breakpoint"
    227 
    228 mi_create_dynamic_varobj outer outer 1 \
    229   "create outer varobj"
    230 
    231 mi_list_varobj_children outer {
    232   { outer.s s 2 "struct substruct" }
    233   { outer.x x 0 "int" }
    234 } "list children of outer"
    235 
    236 mi_list_varobj_children outer.s {
    237   { outer.s.a a 0 int }
    238   { outer.s.b b 0 int }
    239 } "list children of outer.s"
    240 
    241 mi_next "next over outer update"
    242 
    243 mi_gdb_test "-var-update outer" \
    244   ".done,changelist=.{name=\"outer.s.a\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"}." \
    245   "update after updating element of outer"
    246 
    247 mi_continue_to_line \
    248     [gdb_get_line_number {Another MI breakpoint} ${srcfile}] \
    249     "step to second breakpoint"
    250 
    251 mi_varobj_update_with_type_change container int 0 "update after type change"
    252 
    253 
    254 mi_continue_to_line \
    255     [gdb_get_line_number {break to inspect struct and union} ${srcfile}] \
    256     "step to outer breakpoint"
    257 
    258 mi_create_dynamic_varobj nscont nstype 1 \
    259   "create nstype varobj"
    260 
    261 mi_list_varobj_children nscont {
    262     { {nscont.\[0\]} {\[0\]} 0 int }
    263     { {nscont.\[1\]} {\[1\]} 0 int }
    264 } "list children after setting update range"
    265 
    266 mi_gdb_test "-var-set-visualizer nscont None" \
    267   "\\^done" \
    268   "clear visualizer"
    269 
    270 mi_gdb_test "-var-update nscont" \
    271   "\\^done,changelist=\\\[\\\]" \
    272   "varobj update after clearing"
    273 
    274 mi_gdb_test "-var-set-visualizer nscont gdb.default_visualizer" \
    275   "\\^done" \
    276   "choose default visualizer"
    277 
    278 mi_gdb_test "python exception_flag = True" ""
    279 
    280 mi_create_dynamic_varobj nstype2 nstype2 1 \
    281   "create nstype2 varobj"
    282 
    283 mi_list_varobj_children nstype2 {
    284     { {nstype2.<error at 0>} {<error at 0>} 6 {char \[6\]} }
    285 } "list children after setting exception flag"
    286 
    287 mi_create_varobj me me \
    288   "create me varobj"
    289 
    290 mi_gdb_test "-var-evaluate-expression me" \
    291 	"\\^done,value=\"<error reading variable: Cannot access memory.>.*\"" \
    292 	"evaluate me varobj"
    293 
    294 # Regression test for python/14836.
    295 mi_create_dynamic_varobj children_as_list children_as_list 1 \
    296     "printer whose children are returned as a list"
    297 
    298 # Regression test for bug 14741.
    299 mi_continue_to_line \
    300     [gdb_get_line_number {breakpoint bug 14741} ${srcfile}] \
    301     "step to breakpoint for bug 14741"
    302 
    303 mi_create_dynamic_varobj c c 1 \
    304   "create varobj for c"
    305 
    306 mi_gdb_test "-var-set-visualizer c ArrayPrinter" \
    307   "\\^done" \
    308   "choose array visualizer for c"
    309 
    310 mi_list_varobj_children c {
    311     { {c.\[0\]} {\[0\]} 0 int }
    312 } "list children of c"
    313 
    314 mi_next "next over change of array element"
    315 
    316 mi_gdb_test "-var-update c" \
    317     "\\^done,changelist=\\\[{name=\"c.\\\[0\\\]\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"}\\\]" \
    318     "update varobj after element change"
    319 
    320 # C++ MI tests
    321 gdb_exit
    322 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}-cxx" \
    323 	   executable {debug c++ additional_flags=-DMI}] != "" } {
    324     untested "failed to compile in C++ mode"
    325     return -1
    326 }
    327 
    328 if [mi_gdb_start] {
    329     continue
    330 }
    331 mi_delete_breakpoints
    332 mi_gdb_reinitialize_dir $srcdir/$subdir
    333 mi_gdb_load ${binfile}-cxx
    334 
    335 if {[lsearch -exact [mi_get_features] python] < 0} {
    336     unsupported "python support is disabled"
    337     return -1
    338 }
    339 
    340 mi_runto main
    341 mi_continue_to_line \
    342     [gdb_get_line_number {break to inspect struct and union} ${srcfile}] \
    343     "step to breakpoint"
    344 
    345 # Test python/12531.  Install visualizer on a cplus_fake_child.
    346 mi_create_varobj fake fake \
    347   "create fake varobj"
    348 
    349 mi_list_varobj_children fake {
    350     { fake.private private 1 }
    351 } "list children of fake"
    352 
    353 mi_list_varobj_children fake.private {
    354     { fake.private.sname sname 0 int }
    355 } "list children fake.private"
    356 
    357 mi_gdb_test "-var-set-visualizer fake.private gdb.default_visualizer" \
    358     "\\^done" "Install visualizer on a cplus_fake_child"
    359