]>
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 | ||
58789a91 PA |
75 | # Helper for mi_continue_dprintf. |
76 | ||
77 | proc mi_expect_dprintf {args where msg} { | |
78 | global mi_gdb_prompt | |
79 | global inferior_spawn_id gdb_spawn_id | |
80 | ||
81 | if { $args == "call" || $args == "fprintf" } { | |
82 | set foobarbazqux "\"foobarbazqux\"" | |
83 | set sid $inferior_spawn_id | |
84 | } else { | |
85 | set foobarbazqux "\\\\\"foobarbazqux\\\\\"" | |
86 | set sid $gdb_spawn_id | |
87 | } | |
c5867ab6 | 88 | |
58789a91 PA |
89 | # Don't expect the prompt here to avoid a race with mi_expect_stop |
90 | # in case $inferior_spawn_id != $gdb_spawn_id. Otherwise, in that | |
91 | # case, we could see the gdb prompt before the inferior output. | |
92 | gdb_expect { | |
93 | -i $sid | |
94 | -re ".*$foobarbazqux $where" { | |
95 | pass $msg | |
96 | } | |
97 | eof { | |
98 | fail "$msg (eof)" | |
fa876972 | 99 | } |
58789a91 PA |
100 | timeout { |
101 | fail "$msg (timeout)" | |
102 | } | |
103 | } | |
104 | mi_expect_stop ".*" ".*" ".*" ".*" ".*" "" "$msg stop" | |
105 | } | |
fa876972 | 106 | |
58789a91 PA |
107 | proc mi_continue_dprintf {args} { |
108 | with_test_prefix $args { | |
c5867ab6 | 109 | set msg "mi 1st dprintf" |
58789a91 PA |
110 | mi_run_cmd |
111 | mi_expect_dprintf $args "At foo entry.*arg=1234, g=1234" $msg | |
c5867ab6 HZ |
112 | |
113 | set msg "mi 2nd dprintf" | |
114 | mi_send_resuming_command "exec-continue" "$msg continue" | |
58789a91 | 115 | mi_expect_dprintf $args "At foo entry.*arg=1235, g=2222" $msg |
c5867ab6 HZ |
116 | } |
117 | } | |
118 | ||
119 | mi_continue_dprintf "gdb" | |
120 | ||
121 | # The "call" style depends on having I/O functions available, so test. | |
122 | ||
123 | if ![target_info exists gdb,noinferiorio] { | |
124 | ||
125 | # Now switch styles and rerun; in the absence of redirection the | |
126 | # output should be the same. | |
127 | ||
128 | mi_gdb_test "set dprintf-style call" ".*" "mi set dprintf style to call" | |
129 | mi_continue_dprintf "call" | |
130 | ||
131 | mi_gdb_test "set dprintf-function fprintf" ".*" "mi set dprintf-channel stderr" | |
132 | mi_gdb_test "set dprintf-channel stderr" ".*" "mi set dprintf channel" | |
133 | mi_continue_dprintf "fprintf" | |
134 | } | |
135 | ||
136 | set target_can_dprintf 0 | |
137 | set msg "set dprintf style to agent" | |
138 | send_gdb "set dprintf-style agent\n" | |
139 | gdb_expect { | |
140 | -re "warning: Target cannot run dprintf commands, falling back to GDB printf.*$mi_gdb_prompt$" { | |
141 | unsupported "$msg" | |
142 | } | |
143 | -re ".*done.*$mi_gdb_prompt$" { | |
144 | set target_can_dprintf 1 | |
145 | pass "$msg" | |
146 | } | |
147 | -re ".*$mi_gdb_prompt$" { | |
148 | fail "$msg" | |
149 | } | |
150 | timeout { | |
151 | fail "$msg" | |
152 | } | |
153 | } | |
154 | ||
155 | if $target_can_dprintf { | |
88bbeca9 HZ |
156 | if {[mi_run_cmd] < 0} { |
157 | # This likely means we failed to use target side commands in | |
158 | # combination with software breakpoints. IOW, the target | |
159 | # likely doesn't support target-side software breakpoints. | |
160 | set target_can_dprintf 0 | |
161 | unsupported "send dprintf to target" | |
162 | } | |
c5867ab6 | 163 | |
88bbeca9 HZ |
164 | if $target_can_dprintf { |
165 | mi_expect_stop ".*" ".*" ".*" ".*" ".*" "" "mi expect stop" | |
c5867ab6 | 166 | |
88bbeca9 HZ |
167 | mi_send_resuming_command "exec-continue" "mi 1st dprintf continue, agent" |
168 | mi_expect_stop ".*" "foo" ".*" ".*" ".*" "" "mi 1st dprintf, agent" | |
c5867ab6 | 169 | |
88bbeca9 | 170 | mi_send_resuming_command "exec-continue" "mi 2nd dprintf continue, agent" |
8f56dad4 | 171 | |
88bbeca9 HZ |
172 | # The =breakpoint-modified text is a part of the |
173 | # "-exec-continue" output. | |
174 | set msg "mi info dprintf second time" | |
175 | gdb_expect { | |
176 | -re "=breakpoint-modified," { | |
177 | pass $msg | |
178 | } | |
179 | -re ".*$mi_gdb_prompt$" { | |
180 | fail "$msg" | |
181 | } | |
182 | timeout { | |
183 | fail "$msg" | |
184 | } | |
8f56dad4 | 185 | } |
8f56dad4 | 186 | |
88bbeca9 HZ |
187 | mi_expect_stop ".*" "foo" ".*" ".*" ".*" "" "mi 2nd dprintf, agent" |
188 | } | |
c5867ab6 HZ |
189 | } |
190 | ||
191 | mi_gdb_test "set dprintf-style foobar" ".*error.*" "mi set dprintf style to an unrecognized type" |