1 # Copyright
(C
) 2012-2023 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
/>.
20 lappend_include_file flags $srcdir
/lib
/unbuffer_output.c
22 if { [prepare_for_testing
"failed to prepare" $testfile $srcfile $flags] } {
26 set bp_location1
[gdb_get_line_number
"set breakpoint 1 here"]
27 set dp_location1
[gdb_get_line_number
"set dprintf 1 here"]
33 gdb_test
"dprintf" "Format string required"
35 gdb_test
"dprintf foo" "Format string required"
37 gdb_test
"dprintf 29" "Format string required"
43 gdb_test
"dprintf foo,\"At foo entry\\n\"" \
46 gdb_test
"ignore \$bpnum 1" ".*Will ignore next crossing of breakpoint.*"
48 gdb_test
"dprintf $dp_location1,\"arg=%d, g=%d\\n\", arg, g" \
51 gdb_test_sequence
"info breakpoints" "dprintf info 1" {
52 "\[\r\n\]Num Type Disp Enb Address +What"
53 "\[\r\n\]2 breakpoint"
55 "\[\r\n\] printf \"At foo entry\\\\n\""
57 "\[\r\n\] printf \"arg=%d, g=%d\\\\n\", arg, g"
60 gdb_test
"break $bp_location1" \
65 gdb_test
"" "Breakpoint"
67 gdb_test
"continue" "arg=1234, g=1234.*" "1st dprintf, gdb"
69 gdb_test
"continue" "At foo entry.*arg=1235, g=2222.*" "2nd dprintf, gdb"
71 # Restart GDB and
set set up
for testing.
75 global bp_location1 dp_location1
77 clean_restart $binfile
83 gdb_test
"dprintf foo,\"At foo entry\\n\"" \
86 gdb_test
"dprintf $dp_location1,\"arg=%d, g=%d\\n\", arg, g" \
89 gdb_test
"break $bp_location1" "Breakpoint .*"
92 # Test continuing across a dprintf. PATTERN matches the output
93 # generated by the dprintf. MSG is used as test message.
95 proc test_dprintf
{pattern msg
} {
96 gdb_test_stdio
"continue" $pattern "" "$msg"
99 # Test the
"call" style.
105 # Now
switch styles and rerun
; in the absence of redirection the
106 # output should be the same.
108 with_test_prefix
"printf" {
111 gdb_test_no_output
"set dprintf-style call" "set dprintf style to call"
113 test_dprintf
"At foo entry.*arg=1234, g=1234\r\n" "1st dprintf"
115 test_dprintf
"At foo entry.*arg=1235, g=2222\r\n" "2nd dprintf"
118 gdb_test_multiple
"print stderr" "stderr symbol check" {
119 -re
"\\'stderr\\' has unknown type.*" {
120 untested
"No information available for stderr, exiting early"
128 with_test_prefix
"fprintf" {
131 gdb_test_no_output
"set dprintf-function fprintf" "set dprintf function"
132 gdb_test_no_output
"set dprintf-channel stderr" "set dprintf channel"
134 gdb_test_no_output
"set dprintf-style call" "set dprintf style to call"
136 test_dprintf
"At foo entry.*arg=1234, g=1234\r\n" "1st dprintf"
138 test_dprintf
"At foo entry.*arg=1235, g=2222\r\n" "2nd dprintf"
142 # The
"call" style depends on having I/O functions available.
144 if ![target_info
exists gdb
,noinferiorio
] {
145 with_test_prefix
"call" {
150 # Test the
"agent" style.
158 set target_can_dprintf
1
159 set msg
"set dprintf style to agent"
160 gdb_test_multiple
"set dprintf-style agent" $msg {
161 -re
"warning: Target cannot run dprintf commands.*\r\n$gdb_prompt $" {
163 # The target reports that it doesn
't support target side
165 set target_can_dprintf 0
168 -re ".*$gdb_prompt $" {
173 if !$target_can_dprintf {
177 # Even if the target reports that it does support target side
178 # commands, we can only tell that it supports them in combination
179 # with a particular breakpoint type (Z0, Z1, etc.) when we try to
180 # insert the breakpoint. When "set breakpoint always-inserted is
181 # off", that'll be
on next
continue.
182 set msg
"1st dprintf"
183 gdb_test_multiple
"continue" $msg {
184 -re
"Warning:.*Target doesn't support breakpoints that have target side commands.*\r\n$gdb_prompt $" {
185 set target_can_dprintf
0
188 -re
"Breakpoint \[0-9\]+, foo .*$gdb_prompt $" {
193 if $target_can_dprintf
{
194 gdb_test
"continue" "Breakpoint \[0-9\]+, foo .*" "2nd dprintf"
196 gdb_test_sequence
"info breakpoints" "dprintf info" {
197 "\[\r\n\]Num Type Disp Enb Address +What"
198 "\[\r\n\]1 breakpoint"
199 "\[\r\n\]\tbreakpoint already hit 1 time"
201 "\[\r\n\] agent-printf \"At foo entry\\\\n\""
203 "\[\r\n\] agent-printf \"arg=%d, g=%d\\\\n\", arg, g"
204 "\[\r\n\]4 breakpoint"
205 "\[\r\n\]\tbreakpoint already hit 2 times"
210 with_test_prefix
"agent" {
214 gdb_test
"set dprintf-style foobar" "Undefined item: \"foobar\"." \
215 "Set dprintf style to an unrecognized type"
217 # Test that force
-disabling the BreakpointCommands RSP feature works
218 # as expected. dprintf relies
on support
for target
-side breakpoint
219 # commands
--- use it as proxy.
220 if [gdb_is_target_remote
] {
222 "set remote breakpoint-commands-packet off" \
223 "Support for the 'BreakpointCommands' packet on the current remote target is set to \"off\"."
225 gdb_test
"set dprintf-style agent" \
226 "warning: Target cannot run dprintf commands.*" \
227 "set dprintf-style agent, with feature disabled"