Commit | Line | Data |
---|---|---|
88b9d363 | 1 | # Copyright 2018-2022 Free Software Foundation, Inc. |
ae451627 AB |
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 -var-update will provide the correct values for floating | |
19 | # and fixed varobjs that represent the pc register. | |
20 | # | |
21 | ||
22 | load_lib mi-support.exp | |
23 | set MIFLAGS "-i=mi" | |
24 | ||
25 | standard_testfile basics.c | |
26 | ||
27 | if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \ | |
28 | executable {debug}] != "" } then { | |
29 | untested mi-frame-regs.exp | |
30 | return -1 | |
31 | } | |
32 | ||
33 | # Return the address of the specified breakpoint. | |
34 | ||
35 | proc breakpoint_address {bpnum} { | |
36 | global hex | |
37 | global expect_out | |
38 | global mi_gdb_prompt | |
39 | ||
40 | send_gdb "info breakpoint $bpnum\n" | |
41 | gdb_expect { | |
42 | -re ".*($hex).*$mi_gdb_prompt$" { | |
43 | return $expect_out(1,string) | |
44 | } | |
45 | -re ".*$mi_gdb_prompt$" { | |
46 | unresolved "get address of breakpoint $bpnum" | |
47 | return "" | |
48 | } | |
49 | timeout { | |
50 | unresolved "get address of breakpoint $bpnum (timeout)" | |
51 | return "" | |
52 | } | |
53 | } | |
54 | } | |
55 | ||
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. | |
59 | ||
60 | proc_with_prefix do_floating_varobj_test {} { | |
b75d55d4 | 61 | global srcfile binfile |
ae451627 AB |
62 | global hex |
63 | global expect_out | |
64 | ||
b75d55d4 | 65 | if {[mi_clean_restart $binfile]} { |
ae451627 AB |
66 | fail "couldn't start gdb" |
67 | return | |
68 | } | |
69 | ||
b75d55d4 | 70 | mi_runto_main |
ae451627 AB |
71 | |
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" | |
76 | ||
77 | set nframes 4 | |
78 | for {set i 1} {$i < $nframes} {incr i} { | |
79 | ||
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" | |
88 | ||
89 | mi_execute_to "exec-continue" "breakpoint-hit" \ | |
90 | "callee$i" ".*" ".*${srcfile}" ".*" \ | |
91 | { "" "disp=\"keep\"" } "breakpoint hit in callee$i" | |
92 | ||
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) | |
98 | ||
99 | # Get the address of the current breakpoint. | |
100 | set bpaddr [breakpoint_address $bpnum] | |
101 | if {$bpaddr == ""} then { return } | |
102 | ||
103 | # Check that the addresses are the same. | |
104 | gdb_assert [expr $bpaddr == $pcval] "\$pc equals address of breakpoint in callee$i" | |
105 | } | |
106 | } | |
107 | ||
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). | |
111 | ||
112 | proc_with_prefix do_fixed_varobj_test {} { | |
b75d55d4 | 113 | global srcfile binfile |
ae451627 AB |
114 | global hex |
115 | ||
b75d55d4 | 116 | if {[mi_clean_restart $binfile] != 0} { |
ae451627 AB |
117 | fail "couldn't start gdb" |
118 | return | |
119 | } | |
120 | ||
b75d55d4 | 121 | mi_runto_main |
ae451627 AB |
122 | |
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" | |
127 | ||
128 | mi_execute_to "exec-continue" "breakpoint-hit" \ | |
129 | "callee3" ".*" ".*${srcfile}" ".*" \ | |
130 | { "" "disp=\"keep\"" } "breakpoint hit in callee3" | |
131 | ||
132 | # At the breakpoint in callee3 there are 4 frames. | |
133 | # | |
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. | |
137 | # | |
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. | |
141 | # | |
142 | # Track the number of the next varobj to be created in VARNUM. | |
143 | set first_unchanging_varnum 0 | |
144 | set varnum 1 | |
145 | ||
146 | for {set i 0} {$i < 4} {incr i} { | |
147 | ||
148 | if { $i == 1 } then { set first_unchanging_varnum $varnum } | |
149 | ||
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 | |
154 | ||
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 | |
159 | } | |
160 | ||
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" | |
165 | ||
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" | |
172 | } | |
173 | ||
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" | |
180 | } | |
181 | } | |
182 | ||
183 | do_fixed_varobj_test | |
184 | do_floating_varobj_test |