1 # Copyright 2007-2024 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Test essential Machine interface (MI) operations
18 # Verify that once binary file has changed, GDB correctly handles
19 # previously defined MI variables.
23 load_lib mi-support.exp
26 standard_testfile var-cmd.c
28 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
29 untested "failed to compile"
32 # Just change the output binary.
33 set binfile_bis [standard_output_file mi-var-invalidate_bis]
34 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile_bis}" executable {debug}] != "" } {
35 untested "failed to compile"
39 set testfile2 "basics"
40 set srcfile2 ${testfile2}.c
41 set binfile2 [standard_output_file ${testfile2}]
42 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
43 untested "failed to compile"
47 if {[mi_clean_restart $binfile]} {
51 # Desc: Create global variable.
52 mi_create_varobj global_simple global_simple "create global variable"
54 mi_runto do_locals_tests
56 # Desc: create local variables
57 mi_create_varobj linteger linteger "create local variable linteger"
59 # Desc: create floating variable
60 mi_create_floating_varobj float_simple array "create floating variable"
63 # Reload the same binary.
64 # Global variable should remain, local should be invalidated.
67 mi_gdb_load ${binfile_bis}
70 # Change format of floating variable immediately after reload reveals a
71 # bug where gdb still uses a free'd pointer.
72 mi_gdb_test "-var-set-format float_simple hexadecimal" \
73 "\\^done,format=\"hexadecimal\",value=\"\\\[3\\\]\"" \
74 "set format variable float_simple"
76 # Check local variable is "invalid".
77 mi_gdb_test "-var-update linteger" \
78 "\\^done,changelist=\\\[\{name=\"linteger\",in_scope=\"invalid\",has_more=\"0\"\}\\\]" \
79 "linteger not anymore in scope due to binary changes"
81 mi_gdb_test "-var-info-type linteger" \
83 "no type for invalid variable linteger (1)"
85 # Check global variable is still correct.
86 mi_gdb_test "-var-update global_simple" \
87 "\\^done,changelist=\\\[\]" \
88 "global_simple still alive"
90 mi_gdb_test "-var-info-type global_simple" \
91 "\\^done,type=\"simpleton\"" \
92 "type simpleton for valid variable global_simple"
96 # Load an other binary.
97 # All variables must be invalidated.
100 mi_gdb_load ${binfile2}
101 # Check local variable are "invalid"
102 mi_gdb_test "-var-update linteger" \
103 "\\^done,changelist=\\\[\{name=\"linteger\",in_scope=\"invalid\",has_more=\"0\"\}\\\]" \
104 "linteger not valid anymore due to binary changes"
106 mi_gdb_test "-var-info-type linteger" \
107 "\\^done,type=\"\"" \
108 "no type for invalid variable linteger (2)"
110 # Check global variable are still correct.
111 mi_gdb_test "-var-update global_simple" \
112 "\\^done,changelist=\\\[\{name=\"global_simple\",in_scope=\"invalid\",has_more=\"0\"\}\\\]" \
113 "global_simple not anymore in scope due to binary changes"
115 mi_gdb_test "-var-info-type global_simple" \
116 "\\^done,type=\"\"" \
117 "no type for invalid variable global_simple"