1# Copyright 2007, 2008, 2009, 2010, 2011 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 once binary file has changed, GDB correctly handles
19# previously defined MI variables.
20#
21
22
23load_lib mi-support.exp
24set MIFLAGS "-i=mi"
25
26gdb_exit
27if [mi_gdb_start] {
28    continue
29}
30
31set testfile "var-cmd"
32set srcfile ${testfile}.c
33set binfile ${objdir}/${subdir}/mi-var-invalidate
34if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
35    untested mi-var-invalidate.exp
36    return -1
37}
38# Just change the output binary.
39set binfile_bis ${objdir}/${subdir}/mi-var-invalidate_bis
40if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile_bis}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
41    untested mi-var-invalidate.exp
42    return -1
43}
44
45set testfile2 "basics"
46set srcfile2 ${testfile2}.c
47set binfile2 ${objdir}/${subdir}/${testfile2}
48if  { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
49    untested mi-var-invalidate.exp
50    return -1
51}
52
53mi_delete_breakpoints
54mi_gdb_reinitialize_dir $srcdir/$subdir
55mi_gdb_load ${binfile}
56
57# Desc:  Create global variable.
58mi_create_varobj global_simple global_simple "create global variable"
59
60mi_runto do_locals_tests
61
62# Desc: create local variables
63mi_create_varobj linteger linteger "create local variable linteger"
64
65#
66# Reload the same binary.
67# Global variable should remain, local should be invalidated.
68#
69mi_delete_breakpoints
70mi_gdb_load ${binfile_bis}
71mi_runto main
72
73# Check local variable is "invalid".
74mi_gdb_test "-var-update linteger" \
75	"\\^done,changelist=\\\[\{name=\"linteger\",in_scope=\"invalid\",has_more=\"0\"\}\\\]" \
76	"linteger not anymore in scope due to binary changes"
77
78mi_gdb_test "-var-info-type linteger" \
79	"\\^done,type=\"\"" \
80	"no type for invalid variable linteger (1)"
81
82# Check global variable is still correct.
83mi_gdb_test "-var-update global_simple" \
84	"\\^done,changelist=\\\[\]" \
85	"global_simple still alive"
86
87mi_gdb_test "-var-info-type global_simple" \
88	"\\^done,type=\"simpleton\"" \
89	"type simpleton for valid variable global_simple"
90
91
92#
93# Load an other binary.
94# All variables must be invalidated.
95#
96mi_delete_breakpoints
97mi_gdb_load ${binfile2}
98# Check local variable are "invalid"
99mi_gdb_test "-var-update linteger" \
100	"\\^done,changelist=\\\[\{name=\"linteger\",in_scope=\"invalid\",has_more=\"0\"\}\\\]" \
101	"linteger not valid anymore due to binary changes"
102
103mi_gdb_test "-var-info-type linteger" \
104	"\\^done,type=\"\"" \
105	"no type for invalid variable linteger (2)"
106
107# Check global variable are still correct.
108mi_gdb_test "-var-update global_simple" \
109	"\\^done,changelist=\\\[\{name=\"global_simple\",in_scope=\"invalid\",has_more=\"0\"\}\\\]" \
110	"global_simple not anymore in scope due to binary changes"
111
112mi_gdb_test "-var-info-type global_simple" \
113	"\\^done,type=\"\"" \
114	"no type for invalid variable global_simple"
115
116mi_gdb_exit
117return 0
118