Commit | Line | Data |
---|---|---|
ecd75fc8 | 1 | # Copyright (C) 2012-2014 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 | ||
16 | ||
17 | if { [prepare_for_testing dprintf.exp "dprintf" {} {debug}] } { | |
18 | return -1 | |
19 | } | |
20 | ||
21 | set srcfile dprintf.c | |
22 | ||
23 | set bp_location1 [gdb_get_line_number "set breakpoint 1 here"] | |
24 | set dp_location1 [gdb_get_line_number "set dprintf 1 here"] | |
25 | ||
01429c8e JK |
26 | if ![runto main] { |
27 | return -1 | |
28 | } | |
e7e0cddf SS |
29 | |
30 | gdb_test "dprintf" "Format string required" | |
31 | ||
32 | gdb_test "dprintf foo" "Format string required" | |
33 | ||
34 | gdb_test "dprintf 29" "Format string required" | |
35 | ||
36 | delete_breakpoints | |
37 | ||
38 | gdb_breakpoint "main" | |
39 | ||
40 | gdb_test "dprintf foo,\"At foo entry\\n\"" \ | |
41 | "Dprintf .*" | |
42 | ||
a11cfd87 HZ |
43 | gdb_test "ignore \$bpnum 1" ".*Will ignore next crossing of breakpoint.*" |
44 | ||
e7e0cddf SS |
45 | gdb_test "dprintf $dp_location1,\"arg=%d, g=%d\\n\", arg, g" \ |
46 | "Dprintf .*" | |
47 | ||
5bf480a5 | 48 | gdb_test_sequence "info breakpoints" "dprintf info 1" { |
04164e8e | 49 | "\[\r\n\]Num Type Disp Enb Address +What" |
5bf480a5 YQ |
50 | "\[\r\n\]2 breakpoint" |
51 | "\[\r\n\]3 dprintf" | |
52 | "\[\r\n\] printf \"At foo entry\\\\n\"" | |
5bf480a5 YQ |
53 | "\[\r\n\]4 dprintf" |
54 | "\[\r\n\] printf \"arg=%d, g=%d\\\\n\", arg, g" | |
5bf480a5 YQ |
55 | } |
56 | ||
e7e0cddf SS |
57 | gdb_test "break $bp_location1" \ |
58 | "Breakpoint .*" | |
59 | ||
60 | gdb_run_cmd | |
61 | ||
62 | gdb_test "" "Breakpoint" | |
63 | ||
a11cfd87 | 64 | gdb_test "continue" "arg=1234, g=1234.*" "1st dprintf, gdb" |
e7e0cddf SS |
65 | |
66 | gdb_test "continue" "At foo entry.*arg=1235, g=2222.*" "2nd dprintf, gdb" | |
67 | ||
68 | # The "call" style depends on having I/O functions available, so test. | |
69 | ||
70 | if ![target_info exists gdb,noinferiorio] { | |
71 | ||
72 | # Now switch styles and rerun; in the absence of redirection the | |
73 | # output should be the same. | |
74 | ||
75 | gdb_test_no_output "set dprintf-style call" "Set dprintf style to call" | |
76 | ||
77 | gdb_run_cmd | |
78 | ||
79 | gdb_test "" "Breakpoint" | |
80 | ||
81 | gdb_test "continue" "At foo entry.*arg=1234, g=1234.*" "1st dprintf, call" | |
82 | ||
83 | gdb_test "continue" "At foo entry.*arg=1235, g=2222.*" "2nd dprintf, call" | |
84 | ||
85 | gdb_test_no_output "set dprintf-function fprintf" "Set dprintf function" | |
86 | gdb_test_no_output "set dprintf-channel stderr" "Set dprintf channel" | |
87 | ||
88 | gdb_run_cmd | |
89 | ||
90 | gdb_test "" "Breakpoint" | |
91 | ||
92 | gdb_test "continue" "At foo entry.*arg=1234, g=1234.*" \ | |
93 | "1st dprintf, fprintf" | |
94 | ||
95 | gdb_test "continue" "At foo entry.*arg=1235, g=2222.*" \ | |
96 | "2nd dprintf, fprintf" | |
97 | } | |
98 | ||
88bbeca9 HZ |
99 | # Now test the "agent" style. |
100 | ||
d3ce09f5 | 101 | set target_can_dprintf 1 |
88bbeca9 | 102 | set msg "set dprintf style to agent" |
d3ce09f5 | 103 | gdb_test_multiple "set dprintf-style agent" $msg { |
f9cf0f4a | 104 | -re "warning: Target cannot run dprintf commands.*\r\n$gdb_prompt $" { |
88bbeca9 HZ |
105 | |
106 | # The target reports that it doesn't support target side | |
107 | # commands at all. | |
d3ce09f5 | 108 | set target_can_dprintf 0 |
88bbeca9 | 109 | unsupported "$msg" |
d3ce09f5 SS |
110 | } |
111 | -re ".*$gdb_prompt $" { | |
88bbeca9 | 112 | pass "$msg" |
d3ce09f5 SS |
113 | } |
114 | } | |
115 | ||
116 | if $target_can_dprintf { | |
d3ce09f5 SS |
117 | gdb_run_cmd |
118 | ||
119 | gdb_test "" "Breakpoint" | |
120 | ||
88bbeca9 HZ |
121 | # Even if the the target reports that it does support target side |
122 | # commands, we can only tell that it supports them in combination | |
123 | # with a particular breakpoint type (Z0, Z1, etc.) when we try to | |
124 | # insert the breakpoint. When "set breakpoint always-inserted is | |
125 | # off", that'll be on next continue. | |
126 | set msg "1st dprintf, agent" | |
127 | gdb_test_multiple "continue" $msg { | |
128 | -re "Warning:.*Target doesn't support breakpoints that have target side commands.*\r\n$gdb_prompt $" { | |
129 | set target_can_dprintf 0 | |
130 | unsupported "$msg" | |
131 | } | |
132 | -re "Breakpoint \[0-9\]+, foo .*$gdb_prompt $" { | |
133 | pass "$msg" | |
134 | } | |
135 | } | |
d3ce09f5 | 136 | |
88bbeca9 HZ |
137 | if $target_can_dprintf { |
138 | gdb_test "continue" "Breakpoint \[0-9\]+, foo .*" "2nd dprintf, agent" | |
139 | ||
140 | gdb_test_sequence "info breakpoints" "dprintf info 2" { | |
141 | "\[\r\n\]Num Type Disp Enb Address +What" | |
142 | "\[\r\n\]2 breakpoint" | |
143 | "\[\r\n\]\tbreakpoint already hit 2 times" | |
144 | "\[\r\n\]3 dprintf" | |
145 | "\[\r\n\]\tbreakpoint already hit 2 times" | |
146 | "\[\r\n\] agent-printf \"At foo entry\\\\n\"" | |
147 | "\[\r\n\]4 dprintf" | |
148 | "\[\r\n\]\tbreakpoint already hit 2 times" | |
149 | "\[\r\n\] agent-printf \"arg=%d, g=%d\\\\n\", arg, g" | |
150 | } | |
5bf480a5 | 151 | } |
d3ce09f5 SS |
152 | } |
153 | ||
e7e0cddf SS |
154 | gdb_test "set dprintf-style foobar" "Undefined item: \"foobar\"." \ |
155 | "Set dprintf style to an unrecognized type" |