xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.base/display.exp (revision dd3ee07da436799d8de85f3055253118b76bf345)
1#   Copyright 1997-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# display.exp   Test display commands
17#               Also do some printing stuff for coverage's sake.
18#
19standard_testfile
20
21if {[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.
28set oldtimeout $timeout
29set timeout [expr "$timeout + 60"]
30verbose "Timeout is now $timeout seconds" 2
31
32# use this to debug:
33#log_user 1
34
35# Some coverage stuff
36#
37if !$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#
54if ![runto_main] then {
55    fail "could not run to main - other tests will fail."
56    continue
57}
58
59# Disable hardware watchpoints if necessary.
60if [target_info exists gdb,no_hardware_watchpoints] {
61    gdb_test_no_output "set can-use-hw-watchpoints 0" ""
62}
63
64set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
65gdb_test "break $bp_location1" ".*Breakpoint 2.*"           "break  do_loops"
66gdb_test "cont"     ".*Breakpoint 2, do_loops.*" "get to do_loops"
67
68# Create stopping points.
69#
70gdb_test "watch sum"    ".*\[Ww\]atchpoint 3: sum.*" "set watch"
71set bp_location2 [gdb_get_line_number "set breakpoint 2 here"]
72gdb_test "break $bp_location2"     ".*Breakpoint 4.*" "break loop end"
73
74# Create displays for those points
75#
76gdb_test "info disp" ".*There are no auto-display expressions now..*" "inf disp"
77gdb_test "disp i" ".*1: i = 0.*" "display i"
78gdb_test "disp/x j" ".*2: /x j = 0x0.*" "display j"
79gdb_test "disp/i &k" ".*3: x/i &k(\r\n|  )   $hex:.*" "display &k"
80gdb_test "disp/f f" ".*4: /f f = 3.1415*" "display/f f"
81gdb_test "disp/s &sum" ".*5: x/s &sum  $hex.*sum.:.*" "display/s &sum"
82
83# Hit the displays
84#
85gdb_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
94gdb_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
103gdb_test "enab  disp 6" ".*No display number 6..*" "catch err"
104gdb_test_no_output "disab disp 1" "disab disp 1"
105gdb_test_no_output "disab disp 2" "disab disp 2"
106gdb_test_no_output "enab disp 1"  "re-enab"
107gdb_test_no_output "enab disp 1"  "re-enab of enab"
108gdb_test_no_output "undisp 5"     "undisp"
109gdb_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			 ] "info disp"
116
117gdb_test "cont" [multi_line \
118		     ".*\[Ww\]atch.*" \
119		     ".*i = 0" \
120		     ".*5.1415" \
121		    ] "next hit"
122
123gdb_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.
133set can_read_0 [is_address_zero_readable]
134
135if { !$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
149gdb_test "disab 3" ".*.*" "disab 3"
150gdb_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".
158gdb_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
168gdb_test "step"      ".*do_vars.*.*i = 9.*"
169set bp_location3 [gdb_get_line_number "set breakpoint 3 here"]
170gdb_test "tbreak $bp_location3" ".*breakpoint 5 a.*" "tbreak in do_vars"
171gdb_test "cont"      ".*do_vars.*$bp_location3.*$bp_location3.*"
172
173# Beat on printf a bit
174#
175gdb_test "printf" ".*Argument required.*"
176gdb_test "printf %d" ".*Bad format string, missing.*"
177gdb_test "printf \"%d" ".*Bad format string, non-terminated.*"
178gdb_test "printf \"%d%d\",i" ".*Wrong number of arguments.*"
179gdb_test "printf \"\\\\!\\a\\f\\r\\t\\v\\b\\n\"" ".*!.*"
180gdb_test_no_output "printf \"\"" "re-set term"
181gdb_test "printf \"\\w\"" ".*Unrecognized escape character.*"
182gdb_test "printf \"%d\" j" ".*Invalid argument syntax.*"
183gdb_test "printf \"%p\\n\", 0" "\\(nil\\)"
184gdb_test "printf \"%p\\n\", 1" "0x1"
185
186# play with "print", too
187#
188gdb_test "print/k j" ".*Undefined output format.*"
189gdb_test "print/d j" " = 0\[\\r\\n\]+"   "debug test output 1"
190gdb_test "print/r j" " = 0\[\\r\\n\]+"   "debug test output 1a"
191gdb_test "print/x j" " = 0x0\[\\r\\n\]+" "debug test output 2"
192gdb_test "print/r j" " = 0x0\[\\r\\n\]+" "debug test output 2a"
193gdb_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
196gdb_test_no_output "x/0 j"
197
198gdb_test "print/0 j" ".*Item count other than 1 is meaningless.*" "print/0 j"
199gdb_test "print/s sum" " = 1000" "ignored s"
200gdb_test "print/i sum" ".*Format letter.*is meaningless.*.*" "no i"
201gdb_test "print/a &sum" ".*= $hex.*<sum>.*"
202# If the constant below is larger than the length of main, then
203# this test will (incorrectly) fail.  So use a small number.
204gdb_test "print/a main+4" ".*= $hex.*<.*>.*"
205gdb_test "print/a \$pc" ".*= $hex.*<do_vars+.*>.*"
206gdb_test "print/a &&j" ".*A .* error in expression.*"
207
208# Done!
209#
210gdb_exit
211
212# Restore the preserved old timeout value.
213set timeout $oldtimeout
214verbose "Timeout is now $timeout seconds" 2
215
216return 0
217