]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright (C) 2012-2024 Free Software Foundation, Inc. |
e7e0cddf SS |
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 | ||
8396d2cd | 16 | standard_testfile |
e7e0cddf | 17 | |
d1de9f5c TV |
18 | set flags {} |
19 | lappend flags debug | |
20 | lappend_include_file flags $srcdir/lib/unbuffer_output.c | |
21 | ||
22 | if { [prepare_for_testing "failed to prepare" $testfile $srcfile $flags] } { | |
e7e0cddf SS |
23 | return -1 |
24 | } | |
25 | ||
e7e0cddf SS |
26 | set bp_location1 [gdb_get_line_number "set breakpoint 1 here"] |
27 | set dp_location1 [gdb_get_line_number "set dprintf 1 here"] | |
28 | ||
50441f0f | 29 | if ![runto_main] { |
01429c8e JK |
30 | return -1 |
31 | } | |
e7e0cddf SS |
32 | |
33 | gdb_test "dprintf" "Format string required" | |
34 | ||
35 | gdb_test "dprintf foo" "Format string required" | |
36 | ||
37 | gdb_test "dprintf 29" "Format string required" | |
38 | ||
39 | delete_breakpoints | |
40 | ||
41 | gdb_breakpoint "main" | |
42 | ||
43 | gdb_test "dprintf foo,\"At foo entry\\n\"" \ | |
44 | "Dprintf .*" | |
45 | ||
a11cfd87 HZ |
46 | gdb_test "ignore \$bpnum 1" ".*Will ignore next crossing of breakpoint.*" |
47 | ||
e7e0cddf SS |
48 | gdb_test "dprintf $dp_location1,\"arg=%d, g=%d\\n\", arg, g" \ |
49 | "Dprintf .*" | |
50 | ||
5bf480a5 | 51 | gdb_test_sequence "info breakpoints" "dprintf info 1" { |
04164e8e | 52 | "\[\r\n\]Num Type Disp Enb Address +What" |
5bf480a5 YQ |
53 | "\[\r\n\]2 breakpoint" |
54 | "\[\r\n\]3 dprintf" | |
55 | "\[\r\n\] printf \"At foo entry\\\\n\"" | |
5bf480a5 YQ |
56 | "\[\r\n\]4 dprintf" |
57 | "\[\r\n\] printf \"arg=%d, g=%d\\\\n\", arg, g" | |
5bf480a5 YQ |
58 | } |
59 | ||
e7e0cddf SS |
60 | gdb_test "break $bp_location1" \ |
61 | "Breakpoint .*" | |
62 | ||
63 | gdb_run_cmd | |
64 | ||
65 | gdb_test "" "Breakpoint" | |
66 | ||
a11cfd87 | 67 | gdb_test "continue" "arg=1234, g=1234.*" "1st dprintf, gdb" |
e7e0cddf SS |
68 | |
69 | gdb_test "continue" "At foo entry.*arg=1235, g=2222.*" "2nd dprintf, gdb" | |
70 | ||
8396d2cd | 71 | # Restart GDB and set set up for testing. |
e7e0cddf | 72 | |
8396d2cd PA |
73 | proc restart {} { |
74 | global binfile | |
75 | global bp_location1 dp_location1 | |
e7e0cddf | 76 | |
8396d2cd | 77 | clean_restart $binfile |
e7e0cddf | 78 | |
50441f0f | 79 | if ![runto_main] { |
8396d2cd PA |
80 | return -1 |
81 | } | |
e7e0cddf | 82 | |
8396d2cd PA |
83 | gdb_test "dprintf foo,\"At foo entry\\n\"" \ |
84 | "Dprintf .*" | |
e7e0cddf | 85 | |
8396d2cd PA |
86 | gdb_test "dprintf $dp_location1,\"arg=%d, g=%d\\n\", arg, g" \ |
87 | "Dprintf .*" | |
e7e0cddf | 88 | |
8396d2cd PA |
89 | gdb_test "break $bp_location1" "Breakpoint .*" |
90 | } | |
e7e0cddf | 91 | |
8396d2cd PA |
92 | # Test continuing across a dprintf. PATTERN matches the output |
93 | # generated by the dprintf. MSG is used as test message. | |
e7e0cddf | 94 | |
8396d2cd PA |
95 | proc test_dprintf {pattern msg} { |
96 | gdb_test_stdio "continue" $pattern "" "$msg" | |
97 | } | |
e7e0cddf | 98 | |
8396d2cd | 99 | # Test the "call" style. |
e7e0cddf | 100 | |
8396d2cd PA |
101 | proc test_call {} { |
102 | global binfile | |
103 | global bp_location1 | |
e7e0cddf | 104 | |
8396d2cd PA |
105 | # Now switch styles and rerun; in the absence of redirection the |
106 | # output should be the same. | |
e7e0cddf | 107 | |
8396d2cd PA |
108 | with_test_prefix "printf" { |
109 | restart | |
e7e0cddf | 110 | |
8396d2cd | 111 | gdb_test_no_output "set dprintf-style call" "set dprintf style to call" |
88bbeca9 | 112 | |
8396d2cd | 113 | test_dprintf "At foo entry.*arg=1234, g=1234\r\n" "1st dprintf" |
88bbeca9 | 114 | |
8396d2cd | 115 | test_dprintf "At foo entry.*arg=1235, g=2222\r\n" "2nd dprintf" |
d3ce09f5 | 116 | } |
8396d2cd | 117 | |
3f5bbc3e BL |
118 | gdb_test_multiple "print stderr" "stderr symbol check" { |
119 | -re "\\'stderr\\' has unknown type.*" { | |
120 | untested "No information available for stderr, exiting early" | |
121 | return | |
122 | } | |
123 | -re "\\\$1.*" { | |
124 | pass $gdb_test_name | |
125 | } | |
126 | } | |
127 | ||
8396d2cd PA |
128 | with_test_prefix "fprintf" { |
129 | restart | |
130 | ||
131 | gdb_test_no_output "set dprintf-function fprintf" "set dprintf function" | |
132 | gdb_test_no_output "set dprintf-channel stderr" "set dprintf channel" | |
133 | ||
134 | gdb_test_no_output "set dprintf-style call" "set dprintf style to call" | |
135 | ||
136 | test_dprintf "At foo entry.*arg=1234, g=1234\r\n" "1st dprintf" | |
137 | ||
138 | test_dprintf "At foo entry.*arg=1235, g=2222\r\n" "2nd dprintf" | |
139 | } | |
140 | } | |
141 | ||
142 | # The "call" style depends on having I/O functions available. | |
143 | ||
144 | if ![target_info exists gdb,noinferiorio] { | |
145 | with_test_prefix "call" { | |
146 | test_call | |
d3ce09f5 SS |
147 | } |
148 | } | |
149 | ||
8396d2cd | 150 | # Test the "agent" style. |
d3ce09f5 | 151 | |
8396d2cd PA |
152 | proc test_agent {} { |
153 | global binfile | |
154 | global gdb_prompt | |
155 | ||
156 | restart | |
157 | ||
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 $" { | |
162 | ||
163 | # The target reports that it doesn't support target side | |
164 | # commands at all. | |
165 | set target_can_dprintf 0 | |
166 | unsupported "$msg" | |
167 | } | |
168 | -re ".*$gdb_prompt $" { | |
169 | pass "$msg" | |
170 | } | |
171 | } | |
172 | ||
173 | if !$target_can_dprintf { | |
174 | return | |
175 | } | |
d3ce09f5 | 176 | |
09f2921c | 177 | # Even if the target reports that it does support target side |
88bbeca9 HZ |
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. | |
8396d2cd | 182 | set msg "1st dprintf" |
88bbeca9 HZ |
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 | |
186 | unsupported "$msg" | |
187 | } | |
188 | -re "Breakpoint \[0-9\]+, foo .*$gdb_prompt $" { | |
189 | pass "$msg" | |
190 | } | |
191 | } | |
d3ce09f5 | 192 | |
88bbeca9 | 193 | if $target_can_dprintf { |
8396d2cd | 194 | gdb_test "continue" "Breakpoint \[0-9\]+, foo .*" "2nd dprintf" |
88bbeca9 | 195 | |
8396d2cd | 196 | gdb_test_sequence "info breakpoints" "dprintf info" { |
88bbeca9 | 197 | "\[\r\n\]Num Type Disp Enb Address +What" |
8396d2cd PA |
198 | "\[\r\n\]1 breakpoint" |
199 | "\[\r\n\]\tbreakpoint already hit 1 time" | |
200 | "\[\r\n\]2 dprintf" | |
88bbeca9 | 201 | "\[\r\n\] agent-printf \"At foo entry\\\\n\"" |
8396d2cd | 202 | "\[\r\n\]3 dprintf" |
88bbeca9 | 203 | "\[\r\n\] agent-printf \"arg=%d, g=%d\\\\n\", arg, g" |
8396d2cd PA |
204 | "\[\r\n\]4 breakpoint" |
205 | "\[\r\n\]\tbreakpoint already hit 2 times" | |
88bbeca9 | 206 | } |
5bf480a5 | 207 | } |
d3ce09f5 SS |
208 | } |
209 | ||
8396d2cd PA |
210 | with_test_prefix "agent" { |
211 | test_agent | |
212 | } | |
213 | ||
e7e0cddf SS |
214 | gdb_test "set dprintf-style foobar" "Undefined item: \"foobar\"." \ |
215 | "Set dprintf style to an unrecognized type" | |
4082afcc PA |
216 | |
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] { | |
ff52c073 CS |
221 | gdb_test \ |
222 | "set remote breakpoint-commands-packet off" \ | |
223 | "Support for the 'BreakpointCommands' packet on the current remote target is set to \"off\"." | |
224 | ||
4082afcc PA |
225 | gdb_test "set dprintf-style agent" \ |
226 | "warning: Target cannot run dprintf commands.*" \ | |
227 | "set dprintf-style agent, with feature disabled" | |
228 | } |