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