1# Copyright 1999-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# Test essential Machine interface (MI) operations 17# 18# Verify that, using the MI, we can create, update, delete variables. 19# 20 21 22load_lib mi-support.exp 23set MIFLAGS "-i=mi" 24 25gdb_exit 26if [mi_gdb_start] { 27 return 28} 29 30standard_testfile var-cmd.c 31 32if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { 33 untested "failed to compile" 34 return -1 35} 36 37mi_delete_breakpoints 38mi_gdb_reinitialize_dir $srcdir/$subdir 39mi_gdb_load ${binfile} 40 41mi_runto do_block_tests 42 43# step to "cb = 12;" 44mi_step_to "do_block_tests" "" "var-cmd.c" \ 45 [gdb_get_line_number "cb = 12;"] \ 46 "step at do_block_test 0" 47 48# Test: c_variable-3.2 49# Desc: create cb and foo 50mi_create_varobj "cb" "cb" "create local variable cb" 51 52mi_gdb_test "-var-create foo * foo" \ 53 "\\^error,msg=\"-var-create: unable to create variable object\"" \ 54 "try to create local variable foo" 55 56# step to "foo = 123;" 57mi_step_to "do_block_tests" "" "var-cmd.c" \ 58 [gdb_get_line_number "foo = 123;"] \ 59 "step at do_block_test 1" 60 61 62# Be paranoid and assume 3.2 created foo 63mi_gdb_test "-var-delete foo" \ 64 "\\^error,msg=\"Variable object not found\"" \ 65 "delete var foo 1" 66 67 68# Test: c_variable-3.3 69# Desc: create foo 70mi_create_varobj "foo" "foo" "create local variable foo" 71 72# step to "foo2 = 123;" 73mi_step_to "do_block_tests" "" "var-cmd.c" \ 74 [gdb_get_line_number "foo2 = 123;"] \ 75 "step at do_block_test 2" 76 77# Test: c_variable-3.4 78# Desc: check foo, cb changed 79mi_gdb_test "-var-update *" \ 80 "\\^done,changelist=\\\[\{name=\"foo\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\},\{name=\"cb\",in_scope=\"true\",type_changed=\"false\",has_more=\"0\"\}\\\]" \ 81 "update all vars: cb foo changed" 82 83# step to "foo = 321;" 84mi_step_to "do_block_tests" "" "var-cmd.c" \ 85 [gdb_get_line_number "foo = 321;"] \ 86 "step at do_block_test 3" 87 88# Test: c_variable-3.5 89# Desc: create inner block foo 90mi_create_varobj "inner_foo" "foo" "create local variable inner_foo" 91 92# step to "foo2 = 0;" 93mi_step_to "do_block_tests" "" "var-cmd.c" \ 94 [gdb_get_line_number "foo2 = 0;"] \ 95 "step at do_block_test 4" 96 97# Test: c_variable-3.6 98# Desc: create foo2 99mi_create_varobj "foo2" "foo2" "create local variable foo2" 100 101# Test: c_variable-3.7 102# Desc: check that outer foo in scope and inner foo out of scope 103# Note: also a known gdb problem 104setup_xfail *-*-* 105mi_gdb_test "-var-update inner_foo" \ 106 "\\^done,changelist=\{FIXME\}" \ 107 "update inner_foo: should be out of scope: KNOWN PROBLEM" 108clear_xfail *-*-* 109 110setup_xfail *-*-* 111mi_gdb_test "-var-evaluate-expression inner_foo" \ 112 "\\^done,value=\{FIXME\}" \ 113 "evaluate inner_foo: should be out of scope: KNOWN PROBLEM" 114clear_xfail *-*-* 115 116mi_gdb_test "-var-update foo" \ 117 "\\^done,changelist=\\\[\\\]" \ 118 "update foo: did not change" 119 120mi_gdb_test "-var-delete inner_foo" \ 121 "\\^done,ndeleted=\"1\"" \ 122 "delete var inner_foo" 123 124# step to "foo = 0;" 125mi_step_to "do_block_tests" "" "var-cmd.c" \ 126 [gdb_get_line_number "foo = 0;"] \ 127 "step at do_block_test 5" 128 129# Test: c_variable-3.8 130# Desc: check that foo2 out of scope (known gdb problem) 131setup_xfail *-*-* 132mi_gdb_test "-var-update foo2" \ 133 "\\^done,changelist=\{FIXME\}" \ 134 "update foo2: should be out of scope: KNOWN PROBLEM" 135clear_xfail *-*-* 136 137# step to "cb = 21;" 138mi_step_to "do_block_tests" "" "var-cmd.c" \ 139 [gdb_get_line_number "cb = 21;"] \ 140 "step at do_block_test 6" 141 142# Test: c_variable-3.9 143# Desc: check that only cb is in scope (known gdb problem) 144setup_xfail *-*-* 145mi_gdb_test "-var-update foo2" \ 146 "\\^done,changelist=\\\[FIXME\\\]" \ 147 "update foo2 should be out of scope: KNOWN PROBLEM" 148clear_xfail *-*-* 149setup_xfail *-*-* 150mi_gdb_test "-var-update foo" \ 151 "\\^done,changelist=\{FIXME\}" \ 152 "update foo should be out of scope: KNOWN PROBLEM" 153clear_xfail *-*-* 154mi_gdb_test "-var-update cb" \ 155 "\\^done,changelist=\\\[\\\]" \ 156 "update cb" 157 158# Test: c_variable-3.10 159# Desc: names of editable variables 160#gdbtk_test c_variable-3.10 {names of editable variables} { 161# editable_variables 162#} {{foo cb foo2} {}} 163 164# Done with block tests 165mi_gdb_test "-var-delete foo" \ 166 "\\^done,ndeleted=\"1\"" \ 167 "delete var foo 2" 168 169mi_gdb_test "-var-delete foo2" \ 170 "\\^done,ndeleted=\"1\"" \ 171 "delete var foo2" 172 173mi_gdb_test "-var-delete cb" \ 174 "\\^done,ndeleted=\"1\"" \ 175 "delete var cb" 176 177mi_gdb_exit 178return 0 179