]>
Commit | Line | Data |
---|---|---|
32d0add0 | 1 | # Copyright (C) 2013-2015 Free Software Foundation, Inc. |
c5867ab6 HZ |
2 | # Contributed by Hui Zhu <hui@codesourcery.com> |
3 | ||
4 | # This program is free software; you can redistribute it and/or modify | |
5 | # it under the terms of the GNU General Public License as published by | |
6 | # the Free Software Foundation; either version 3 of the License, or | |
7 | # (at your option) any later version. | |
8 | # | |
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. | |
13 | # | |
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | ||
17 | load_lib mi-support.exp | |
18 | set MIFLAGS "-i=mi" | |
19 | ||
20 | gdb_exit | |
21 | if [mi_gdb_start] { | |
22 | continue | |
23 | } | |
24 | ||
25 | standard_testfile | |
26 | ||
27 | if {[build_executable $testfile.exp $testfile $srcfile {debug}] == -1} { | |
28 | untested "failed to compile $testfile" | |
29 | return -1 | |
30 | } | |
31 | ||
32 | mi_delete_breakpoints | |
33 | ||
34 | set bp_location1 [gdb_get_line_number "set breakpoint 1 here"] | |
35 | set dp_location1 [gdb_get_line_number "set dprintf 1 here"] | |
36 | ||
37 | mi_run_to_main | |
38 | ||
4b48d439 KS |
39 | set i 0 |
40 | mi_gdb_test "[incr i]-dprintf-insert" \ | |
41 | "$i\\^error,msg=\"-dprintf-insert: Missing <location>\"" "mi insert without location" | |
c5867ab6 | 42 | |
4b48d439 KS |
43 | mi_gdb_test "[incr i]-dprintf-insert foo" \ |
44 | "$i\\^error,msg=\"-dprintf-insert: Missing <format>\"" "mi insert breakpoint without format string" | |
c5867ab6 | 45 | |
4b48d439 KS |
46 | mi_gdb_test "[incr i]-dprintf-insert 29" \ |
47 | "$i\\^error,msg=\"-dprintf-insert: Missing <format>\"" "mi insert second breakpoint without format string" | |
c5867ab6 HZ |
48 | |
49 | mi_gdb_test "-break-insert main" ".*" "mi insert breakpoint main" | |
50 | mi_delete_breakpoints | |
51 | ||
4b48d439 KS |
52 | set bps [mi_make_breakpoint -type dprintf -func foo -file ".*mi-dprintf.c" \ |
53 | -fullname ".*mi-dprintf.c"] | |
54 | mi_gdb_test "[incr i]-dprintf-insert foo \"\\\"foobarbazqux\\\" At foo entry\\n\"" \ | |
55 | "$i\\^done,$bps" "mi insert dprintf foo" | |
56 | ||
57 | set bps [mi_make_breakpoint -type dprintf -func foo \ | |
58 | -file ".*mi-dprintf.c" -fullname ".*mi-dprintf.c" \ | |
59 | -line $dp_location1] | |
60 | mi_gdb_test "[incr i]-dprintf-insert $dp_location1 \"arg=%d, g=%d\\n\" arg g" \ | |
61 | "$i\\^done,$bps" "mi insert dprintf dp_location1" | |
62 | ||
63 | set bps {} | |
64 | lappend bps [mi_make_breakpoint -number 3 -type dprintf -func foo \ | |
65 | -file ".*mi-dprintf.c" -fullname ".*mi-dprintf.c"] | |
66 | lappend bps [mi_make_breakpoint -type dprintf -func foo \ | |
67 | -file ".*mi-dprintf.c" -fullname ".*mi-dprintf.c" \ | |
68 | -line $dp_location1] | |
69 | mi_gdb_test "[incr i]-break-info" \ | |
70 | "$i\\^done,[mi_make_breakpoint_table $bps]" \ | |
c5867ab6 HZ |
71 | "mi info dprintf" |
72 | ||
73 | mi_gdb_test "-break-insert $bp_location1" ".*" "mi insert breakpoint bp_location1" | |
74 | ||
75 | proc mi_continue_dprintf {args} { | |
76 | with_test_prefix $args { | |
77 | global mi_gdb_prompt | |
78 | ||
fa876972 HZ |
79 | if { $args == "call" || $args == "fprintf" } { |
80 | set foobarbazqux "\"foobarbazqux\"" | |
81 | } else { | |
82 | set foobarbazqux "\\\\\"foobarbazqux\\\\\"" | |
83 | } | |
84 | ||
c5867ab6 HZ |
85 | mi_run_cmd |
86 | set msg "mi 1st dprintf" | |
87 | gdb_expect { | |
fa876972 | 88 | -re ".*$foobarbazqux At foo entry.*arg=1234, g=1234" { |
c5867ab6 HZ |
89 | pass $msg |
90 | } | |
91 | -re ".*$mi_gdb_prompt$" { | |
92 | fail $msg | |
93 | } | |
94 | timeout { | |
95 | fail $msg | |
96 | } | |
97 | } | |
98 | mi_expect_stop ".*" ".*" ".*" ".*" ".*" "" "$msg stop" | |
99 | ||
100 | set msg "mi 2nd dprintf" | |
101 | mi_send_resuming_command "exec-continue" "$msg continue" | |
102 | gdb_expect { | |
fa876972 | 103 | -re ".*$foobarbazqux At foo entry.*arg=1235, g=2222" { |
c5867ab6 HZ |
104 | pass $msg |
105 | } | |
106 | -re ".*$mi_gdb_prompt$" { | |
107 | fail $msg | |
108 | } | |
109 | timeout { | |
110 | fail $msg | |
111 | } | |
112 | } | |
8f56dad4 | 113 | mi_expect_stop ".*" ".*" ".*" ".*" ".*" "" "$msg 2nd stop" |
c5867ab6 HZ |
114 | } |
115 | } | |
116 | ||
117 | mi_continue_dprintf "gdb" | |
118 | ||
119 | # The "call" style depends on having I/O functions available, so test. | |
120 | ||
121 | if ![target_info exists gdb,noinferiorio] { | |
122 | ||
123 | # Now switch styles and rerun; in the absence of redirection the | |
124 | # output should be the same. | |
125 | ||
126 | mi_gdb_test "set dprintf-style call" ".*" "mi set dprintf style to call" | |
127 | mi_continue_dprintf "call" | |
128 | ||
129 | mi_gdb_test "set dprintf-function fprintf" ".*" "mi set dprintf-channel stderr" | |
130 | mi_gdb_test "set dprintf-channel stderr" ".*" "mi set dprintf channel" | |
131 | mi_continue_dprintf "fprintf" | |
132 | } | |
133 | ||
134 | set target_can_dprintf 0 | |
135 | set msg "set dprintf style to agent" | |
136 | send_gdb "set dprintf-style agent\n" | |
137 | gdb_expect { | |
138 | -re "warning: Target cannot run dprintf commands, falling back to GDB printf.*$mi_gdb_prompt$" { | |
139 | unsupported "$msg" | |
140 | } | |
141 | -re ".*done.*$mi_gdb_prompt$" { | |
142 | set target_can_dprintf 1 | |
143 | pass "$msg" | |
144 | } | |
145 | -re ".*$mi_gdb_prompt$" { | |
146 | fail "$msg" | |
147 | } | |
148 | timeout { | |
149 | fail "$msg" | |
150 | } | |
151 | } | |
152 | ||
153 | if $target_can_dprintf { | |
88bbeca9 HZ |
154 | if {[mi_run_cmd] < 0} { |
155 | # This likely means we failed to use target side commands in | |
156 | # combination with software breakpoints. IOW, the target | |
157 | # likely doesn't support target-side software breakpoints. | |
158 | set target_can_dprintf 0 | |
159 | unsupported "send dprintf to target" | |
160 | } | |
c5867ab6 | 161 | |
88bbeca9 HZ |
162 | if $target_can_dprintf { |
163 | mi_expect_stop ".*" ".*" ".*" ".*" ".*" "" "mi expect stop" | |
c5867ab6 | 164 | |
88bbeca9 HZ |
165 | mi_send_resuming_command "exec-continue" "mi 1st dprintf continue, agent" |
166 | mi_expect_stop ".*" "foo" ".*" ".*" ".*" "" "mi 1st dprintf, agent" | |
c5867ab6 | 167 | |
88bbeca9 | 168 | mi_send_resuming_command "exec-continue" "mi 2nd dprintf continue, agent" |
8f56dad4 | 169 | |
88bbeca9 HZ |
170 | # The =breakpoint-modified text is a part of the |
171 | # "-exec-continue" output. | |
172 | set msg "mi info dprintf second time" | |
173 | gdb_expect { | |
174 | -re "=breakpoint-modified," { | |
175 | pass $msg | |
176 | } | |
177 | -re ".*$mi_gdb_prompt$" { | |
178 | fail "$msg" | |
179 | } | |
180 | timeout { | |
181 | fail "$msg" | |
182 | } | |
8f56dad4 | 183 | } |
8f56dad4 | 184 | |
88bbeca9 HZ |
185 | mi_expect_stop ".*" "foo" ".*" ".*" ".*" "" "mi 2nd dprintf, agent" |
186 | } | |
c5867ab6 HZ |
187 | } |
188 | ||
189 | mi_gdb_test "set dprintf-style foobar" ".*error.*" "mi set dprintf style to an unrecognized type" |