dac036fb2fe677b7f376ee20ea51a53666ae6ceb
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / display.exp
1 # Copyright 1997-2021 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 # display.exp Test display commands
17 # Also do some printing stuff for coverage's sake.
18 #
19 standard_testfile
20
21 if {[prepare_for_testing "failed to prepare" $testfile $srcfile \
22 {debug nowarnings}]} {
23 return -1
24 }
25
26 # Preserve the old timeout, and set a new one that should be
27 # sufficient to avoid timing out during this test.
28 set oldtimeout $timeout
29 set timeout [expr "$timeout + 60"]
30 verbose "Timeout is now $timeout seconds" 2
31
32 # use this to debug:
33 #log_user 1
34
35 # Some coverage stuff
36 #
37 if !$use_gdb_stub {
38 gdb_test "kill" ".*The program is not being run.*"
39 gdb_test "detach" ".*"
40 gdb_test "run" ".*"
41
42 gdb_load ${binfile}
43 gdb_test "kill" ".*" "kill again"
44 gdb_test "detach" ".*" "detach again"
45
46 gdb_exit
47 gdb_start
48 gdb_reinitialize_dir $srcdir/$subdir
49 gdb_load ${binfile}
50 }
51
52 # Ok, on to real life
53 #
54 if ![runto_main] then {
55 fail "could not run to main - other tests will fail."
56 continue
57 }
58
59 # Disable hardware watchpoints if necessary.
60 if [target_info exists gdb,no_hardware_watchpoints] {
61 gdb_test_no_output "set can-use-hw-watchpoints 0" ""
62 }
63
64 set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
65 gdb_test "break $bp_location1" ".*Breakpoint 2.*" "break do_loops"
66 gdb_test "cont" ".*Breakpoint 2, do_loops.*" "get to do_loops"
67
68 # Create stopping points.
69 #
70 gdb_test "watch sum" ".*\[Ww\]atchpoint 3: sum.*" "set watch"
71 set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
72 gdb_test "break $bp_location2" ".*Breakpoint 4.*" "break loop end"
73
74 # Create displays for those points
75 #
76 gdb_test "info disp" ".*There are no auto-display expressions now..*" "inf disp"
77 gdb_test "disp i" ".*1: i = 0.*" "display i"
78 gdb_test "disp/x j" ".*2: /x j = 0x0.*" "display j"
79 gdb_test "disp/i &k" ".*3: x/i &k(\r\n| ) $hex:.*" "display &k"
80 gdb_test "disp/f f" ".*4: /f f = 3.1415*" "display/f f"
81 gdb_test "disp/s &sum" ".*5: x/s &sum $hex.*sum.:.*" "display/s &sum"
82
83 # Hit the displays
84 #
85 gdb_test "cont" [multi_line \
86 ".*\[Ww\]atchpoint 3: sum.*" \
87 "\[1-9\]*: i = 0.*" \
88 "\[1-9\]*: /x j = 0x0" \
89 "\[1-9\]*: x/i &k.*" \
90 "\[1-9\]*: /f f = 3.1415" \
91 "\[1-9\]*: x/s &sum.*" \
92 ] "first disp"
93
94 gdb_test "cont" [multi_line \
95 ".*\[Ww\]atchpoint 3: sum.*" \
96 "\[1-9\]*: i = 0.*" \
97 "\[1-9\]*: /x j = 0x0.*" \
98 "\[1-9\]*: x/i &k.*" \
99 "\[1-9\]*: /f f = 4.1415" \
100 "\[1-9\]*: x/s &sum.*" \
101 ] "second disp"
102
103 gdb_test "enab disp 6" ".*No display number 6..*" "catch err"
104 gdb_test_no_output "disab disp 1" "disab disp 1"
105 gdb_test_no_output "disab disp 2" "disab disp 2"
106 gdb_test_no_output "enab disp 1" "re-enab"
107 gdb_test_no_output "enab disp 1" "re-enab of enab"
108 gdb_test_no_output "undisp 5" "undisp"
109 gdb_test "info disp" [multi_line \
110 "Auto-display expressions now in effect.*" \
111 ".*y i" \
112 ".*n /x j" \
113 ".*y /1bi &k" \
114 ".*y /f f" \
115 ]
116
117 gdb_test "cont" [multi_line \
118 ".*\[Ww\]atch.*" \
119 ".*i = 0" \
120 ".*5.1415" \
121 ] "next hit"
122
123 gdb_test "undisp" \
124 "" \
125 "undisp all" \
126 ".*Delete all auto-display expressions.*y or n. $" \
127 "y"
128
129
130 # Test displaying a variable that is temporarily at a bad address.
131 # But if we can examine what's at memory address 0, then we'll also be
132 # able to display it without error. Don't run the test in that case.
133 set can_read_0 [is_address_zero_readable]
134
135 if { !$can_read_0 } {
136 gdb_test "disp *p_i" ".*: \\*p_i = 0"
137 gdb_test "p p_i = 0x0" " = \\(int \\*\\) 0x0"
138 gdb_test "display" ".*: \\*p_i = <error: .*>" "display bad address"
139 gdb_test "p p_i = &i" " = \\(int \\*\\) $hex"
140 gdb_test "display" ".*: \\*p_i = 0" "display good address"
141
142 gdb_test "undisp" \
143 "" \
144 "undisp all again" \
145 ".*Delete all auto-display expressions.*y or n. $" \
146 "y"
147 }
148
149 gdb_test "disab 3" ".*.*"
150 gdb_test "cont" ".*Breakpoint 4.*" "watch off"
151
152 # Now the printf tests
153 #
154 # The "finish" command may leave us mid-line in the caller on some
155 # targets, including but not limited to the m68k, i386 & PA. So we
156 # have to arrange to step until we hit the line with the call to
157 # "do_vars".
158 gdb_test_multiple "finish" "finish" {
159 -re ".*do_loops\\(\\);.*$gdb_prompt $" {
160 send_gdb "step\n"
161 exp_continue
162 }
163 -re ".*do_vars.*$gdb_prompt $" {
164 pass "finish"
165 }
166 }
167
168 gdb_test "step" ".*do_vars.*.*i = 9.*"
169 set bp_location3 [gdb_get_line_number "set breakpoint 3 here"]
170 gdb_test "tbreak $bp_location3" ".*breakpoint 5 a.*" "tbreak in do_vars"
171 gdb_test "cont" ".*do_vars.*$bp_location3.*$bp_location3.*"
172
173 # Beat on printf a bit
174 #
175 gdb_test "printf" ".*Argument required.*"
176 gdb_test "printf %d" ".*Bad format string, missing.*"
177 gdb_test "printf \"%d" ".*Bad format string, non-terminated.*"
178 gdb_test "printf \"%d%d\",i" ".*Wrong number of arguments.*"
179 gdb_test "printf \"\\\\!\\a\\f\\r\\t\\v\\b\\n\"" ".*!.*"
180 gdb_test_no_output "printf \"\"" "re-set term"
181 gdb_test "printf \"\\w\"" ".*Unrecognized escape character.*"
182 gdb_test "printf \"%d\" j" ".*Invalid argument syntax.*"
183 gdb_test "printf \"%p\\n\", 0" "\\(nil\\)"
184 gdb_test "printf \"%p\\n\", 1" "0x1"
185
186 # play with "print", too
187 #
188 gdb_test "print/k j" ".*Undefined output format.*"
189 gdb_test "print/d j" " = 0\[\\r\\n\]+" "debug test output 1"
190 gdb_test "print/r j" " = 0\[\\r\\n\]+" "debug test output 1a"
191 gdb_test "print/x j" " = 0x0\[\\r\\n\]+" "debug test output 2"
192 gdb_test "print/r j" " = 0x0\[\\r\\n\]+" "debug test output 2a"
193 gdb_test "print j" " = 0\[\\r\\n\]+" "debug test output 3"
194
195 # x/0 j doesn't produce any output and terminates PA64 process when testing
196 gdb_test_no_output "x/0 j"
197
198 # For when the test is built in C++ mode.
199 gdb_test_no_output "set print asm-demangle on"
200
201 gdb_test "print/0 j" ".*Item count other than 1 is meaningless.*"
202 gdb_test "print/s sum" " = 1000" "ignored s"
203 gdb_test "print/i sum" ".*Format letter.*is meaningless.*.*" "no i"
204 gdb_test "print/a &sum" ".*= $hex.*<sum>.*"
205 # If the constant below is larger than the length of main, then
206 # this test will (incorrectly) fail. So use a small number.
207 gdb_test "print/a main+4" ".*= $hex.*<.*>.*"
208 gdb_test "print/a \$pc" ".*= $hex.*<do_vars+.*>.*"
209 gdb_test "print/a &&j" ".*A .* error in expression.*"
210
211 # Done!
212 #
213 gdb_exit
214
215 # Restore the preserved old timeout value.
216 set timeout $oldtimeout
217 verbose "Timeout is now $timeout seconds" 2
218
219 return 0
This page took 0.036564 seconds and 3 git commands to generate.