[gdbsupport] Handle EINTR in event-pipe.cc
[binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-frame-regs.exp
blob0374ec06731a813e2feb789388f20a53f248dbb0
1 # Copyright 2018-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 -var-update will provide the correct values for floating
19 # and fixed varobjs that represent the pc register.
22 load_lib mi-support.exp
23 set MIFLAGS "-i=mi"
25 standard_testfile basics.c
27 if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
28 executable {debug}] != "" } then {
29 untested "failed to compile"
30 return -1
33 # Return the address of the specified breakpoint.
35 proc breakpoint_address {bpnum} {
36 global hex
37 global expect_out
38 global mi_gdb_prompt
40 send_gdb "info breakpoint $bpnum\n"
41 gdb_expect {
42 -re ".*($hex).*$mi_gdb_prompt$" {
43 return $expect_out(1,string)
45 -re ".*$mi_gdb_prompt$" {
46 unresolved "get address of breakpoint $bpnum"
47 return ""
49 timeout {
50 unresolved "get address of breakpoint $bpnum (timeout)"
51 return ""
56 # Test that a floating varobj representing $pc will provide the
57 # correct value via -var-update as the program stops at
58 # breakpoints in different functions.
60 proc_with_prefix do_floating_varobj_test {} {
61 global srcfile binfile
62 global hex
63 global expect_out
65 if {[mi_clean_restart $binfile]} {
66 fail "couldn't start gdb"
67 return
70 mi_runto_main
72 # Create a floating varobj for $pc.
73 mi_gdb_test "-var-create --thread 1 --frame 0 - @ \$pc" \
74 "\\^done,.*value=\"$hex.*" \
75 "create varobj for pc in frame 0"
77 set nframes 4
78 for {set i 1} {$i < $nframes} {incr i} {
80 # Run to a breakpoint in each callee function in succession.
81 # Note that we can't use mi_runto because we need the
82 # breakpoint to be persistent, so we can use its address.
83 set bpnum [expr $i + 1]
84 mi_create_breakpoint \
85 "basics.c:callee$i" \
86 "insert breakpoint at basics.c:callee$i" \
87 -number $bpnum -func callee$i -file ".*basics.c"
89 mi_execute_to "exec-continue" "breakpoint-hit" \
90 "callee$i" ".*" ".*${srcfile}" ".*" \
91 { "" "disp=\"keep\"" } "breakpoint hit in callee$i"
93 # Get the value of $pc from the floating varobj.
94 mi_gdb_test "-var-update 1 var1" \
95 "\\^done,.*value=\"($hex) .*" \
96 "-var-update for frame $i"
97 set pcval $expect_out(3,string)
99 # Get the address of the current breakpoint.
100 set bpaddr [breakpoint_address $bpnum]
101 if {$bpaddr == ""} { return }
103 # Check that the addresses are the same.
104 gdb_assert [expr $bpaddr == $pcval] "\$pc equals address of breakpoint in callee$i"
108 # Test that fixed varobjs representing $pc in different stack frames
109 # will provide the correct value via -var-update after the program
110 # counter changes (without substantially changing the stack).
112 proc_with_prefix do_fixed_varobj_test {} {
113 global srcfile binfile
114 global hex
116 if {[mi_clean_restart $binfile] != 0} {
117 fail "couldn't start gdb"
118 return
121 mi_runto_main
123 # Run to the function 'callee3' so we have several frames.
124 mi_create_breakpoint "basics.c:callee3" \
125 "insert breakpoint at basics.c:callee3" \
126 -number 2 -func callee3 -file ".*basics.c"
128 mi_execute_to "exec-continue" "breakpoint-hit" \
129 "callee3" ".*" ".*${srcfile}" ".*" \
130 { "" "disp=\"keep\"" } "breakpoint hit in callee3"
132 # At the breakpoint in callee3 there are 4 frames.
134 # Create some varobj based on $pc in all frames. When we single
135 # step we expect the varobj for frame 0 to change, while the
136 # varobj for all other frames should be unchanged.
138 # Track in FIRST_UNCHANGING_VARNUM the number of the first varobj
139 # that is not in frame 0, varobj with a lower number we expect to
140 # change, while this and later varobj should not change.
142 # Track the number of the next varobj to be created in VARNUM.
143 set first_unchanging_varnum 0
144 set varnum 1
146 for {set i 0} {$i < 4} {incr i} {
148 if {$i == 1} { set first_unchanging_varnum $varnum }
150 mi_gdb_test "-var-create --thread 1 --frame $i - \* \$pc" \
151 "\\^done,.*value=\"$hex.*" \
152 "create varobj for \$pc in frame $i"
153 incr varnum
155 mi_gdb_test "-var-create --thread 1 --frame $i - \* \"global_zero + \$pc\"" \
156 "\\^done,.*value=\"$hex.*" \
157 "create varobj for 'global_zero + \$pc' in frame $i"
158 incr varnum
161 # Step one instruction to change the program counter.
162 mi_execute_to "exec-next-instruction" "end-stepping-range" \
163 "callee3" ".*" ".*${srcfile}" ".*" "" \
164 "next instruction in callee3"
166 # Check that -var-update reports that the values are changed for
167 # varobj in frame 0.
168 for {set i 1} {$i < $first_unchanging_varnum} {incr i} {
169 mi_gdb_test "-var-update 1 var$i" \
170 "\\^done,(changelist=\\\[\{name=\"var$i\"\[^\\\]\]+\\\])" \
171 "varobj var$i has changed"
174 # Check that -var-update reports that the values are unchanged for
175 # varobj in frames other than 0.
176 for {set i $first_unchanging_varnum} {$i < $varnum} {incr i} {
177 mi_gdb_test "-var-update 1 var$i" \
178 "\\^done,(changelist=\\\[\\\])" \
179 "varobj var$i has not changed"
183 do_fixed_varobj_test
184 do_floating_varobj_test