1# Copyright 2007-2019 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 31standard_testfile var-cmd.c 32 33if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { 34 untested "failed to compile" 35 return -1 36} 37# Just change the output binary. 38set binfile_bis [standard_output_file mi-var-invalidate_bis] 39if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile_bis}" executable {debug}] != "" } { 40 untested "failed to compile" 41 return -1 42} 43 44set testfile2 "basics" 45set srcfile2 ${testfile2}.c 46set binfile2 [standard_output_file ${testfile2}] 47if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } { 48 untested "failed to compile" 49 return -1 50} 51 52mi_delete_breakpoints 53mi_gdb_reinitialize_dir $srcdir/$subdir 54mi_gdb_load ${binfile} 55 56# Desc: Create global variable. 57mi_create_varobj global_simple global_simple "create global variable" 58 59mi_runto do_locals_tests 60 61# Desc: create local variables 62mi_create_varobj linteger linteger "create local variable linteger" 63 64# Desc: create floating variable 65mi_create_floating_varobj float_simple array "create floating variable" 66 67# 68# Reload the same binary. 69# Global variable should remain, local should be invalidated. 70# 71mi_delete_breakpoints 72mi_gdb_load ${binfile_bis} 73mi_runto main 74 75# Change format of floating variable immediately after reload reveals a 76# bug where gdb still uses a free'd pointer. 77mi_gdb_test "-var-set-format float_simple hexadecimal" \ 78 "\\^done,format=\"hexadecimal\",value=\"\\\[-1\\\]\"" \ 79 "set format variable float_simple" 80 81# Check local variable is "invalid". 82mi_gdb_test "-var-update linteger" \ 83 "\\^done,changelist=\\\[\{name=\"linteger\",in_scope=\"invalid\",has_more=\"0\"\}\\\]" \ 84 "linteger not anymore in scope due to binary changes" 85 86mi_gdb_test "-var-info-type linteger" \ 87 "\\^done,type=\"\"" \ 88 "no type for invalid variable linteger (1)" 89 90# Check global variable is still correct. 91mi_gdb_test "-var-update global_simple" \ 92 "\\^done,changelist=\\\[\]" \ 93 "global_simple still alive" 94 95mi_gdb_test "-var-info-type global_simple" \ 96 "\\^done,type=\"simpleton\"" \ 97 "type simpleton for valid variable global_simple" 98 99 100# 101# Load an other binary. 102# All variables must be invalidated. 103# 104mi_delete_breakpoints 105mi_gdb_load ${binfile2} 106# Check local variable are "invalid" 107mi_gdb_test "-var-update linteger" \ 108 "\\^done,changelist=\\\[\{name=\"linteger\",in_scope=\"invalid\",has_more=\"0\"\}\\\]" \ 109 "linteger not valid anymore due to binary changes" 110 111mi_gdb_test "-var-info-type linteger" \ 112 "\\^done,type=\"\"" \ 113 "no type for invalid variable linteger (2)" 114 115# Check global variable are still correct. 116mi_gdb_test "-var-update global_simple" \ 117 "\\^done,changelist=\\\[\{name=\"global_simple\",in_scope=\"invalid\",has_more=\"0\"\}\\\]" \ 118 "global_simple not anymore in scope due to binary changes" 119 120mi_gdb_test "-var-info-type global_simple" \ 121 "\\^done,type=\"\"" \ 122 "no type for invalid variable global_simple" 123 124mi_gdb_exit 125return 0 126