]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright (C) 2013-2024 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 | ||
c5867ab6 HZ |
20 | standard_testfile |
21 | ||
d1de9f5c TV |
22 | set flags {} |
23 | lappend flags debug | |
24 | lappend_include_file flags $srcdir/lib/unbuffer_output.c | |
25 | ||
26 | if {[build_executable $testfile.exp $testfile $srcfile $flags] == -1} { | |
84c93cd5 | 27 | untested "failed to compile" |
c5867ab6 HZ |
28 | return -1 |
29 | } | |
30 | ||
c5867ab6 HZ |
31 | set bp_location1 [gdb_get_line_number "set breakpoint 1 here"] |
32 | set dp_location1 [gdb_get_line_number "set dprintf 1 here"] | |
33 | ||
b75d55d4 PA |
34 | mi_clean_restart $binfile |
35 | mi_runto_main | |
c5867ab6 | 36 | |
4b48d439 KS |
37 | set i 0 |
38 | mi_gdb_test "[incr i]-dprintf-insert" \ | |
39 | "$i\\^error,msg=\"-dprintf-insert: Missing <location>\"" "mi insert without location" | |
c5867ab6 | 40 | |
4b48d439 KS |
41 | mi_gdb_test "[incr i]-dprintf-insert foo" \ |
42 | "$i\\^error,msg=\"-dprintf-insert: Missing <format>\"" "mi insert breakpoint without format string" | |
c5867ab6 | 43 | |
4b48d439 KS |
44 | mi_gdb_test "[incr i]-dprintf-insert 29" \ |
45 | "$i\\^error,msg=\"-dprintf-insert: Missing <format>\"" "mi insert second breakpoint without format string" | |
c5867ab6 HZ |
46 | |
47 | mi_gdb_test "-break-insert main" ".*" "mi insert breakpoint main" | |
eb8c4e2e KS |
48 | |
49 | mi_gdb_test "-dprintf-insert --function main \"hello\"" \ | |
50 | "\\^done,bkpt={.*}" "explicit dprintf at main" | |
51 | ||
52 | mi_gdb_test "-dprintf-insert --source $srcfile --line $dp_location1 \"hello\"" \ | |
53 | "\\^done,bkpt={.*}" "explicit breakpoint at $srcfile:$dp_location1" | |
54 | ||
55 | mi_gdb_test "-dprintf-insert --source $srcfile \"hello\"" \ | |
56 | "\\^error,msg=\"-dprintf-insert: --source option requires --function, --label, or --line\"" "invalid explicit dprintf" | |
57 | ||
c5867ab6 HZ |
58 | mi_delete_breakpoints |
59 | ||
4b48d439 KS |
60 | set bps [mi_make_breakpoint -type dprintf -func foo -file ".*mi-dprintf.c" \ |
61 | -fullname ".*mi-dprintf.c"] | |
62 | mi_gdb_test "[incr i]-dprintf-insert foo \"\\\"foobarbazqux\\\" At foo entry\\n\"" \ | |
63 | "$i\\^done,$bps" "mi insert dprintf foo" | |
64 | ||
65 | set bps [mi_make_breakpoint -type dprintf -func foo \ | |
66 | -file ".*mi-dprintf.c" -fullname ".*mi-dprintf.c" \ | |
67 | -line $dp_location1] | |
68 | mi_gdb_test "[incr i]-dprintf-insert $dp_location1 \"arg=%d, g=%d\\n\" arg g" \ | |
69 | "$i\\^done,$bps" "mi insert dprintf dp_location1" | |
70 | ||
71 | set bps {} | |
eb8c4e2e | 72 | lappend bps [mi_make_breakpoint -type dprintf -func foo \ |
4b48d439 KS |
73 | -file ".*mi-dprintf.c" -fullname ".*mi-dprintf.c"] |
74 | lappend bps [mi_make_breakpoint -type dprintf -func foo \ | |
75 | -file ".*mi-dprintf.c" -fullname ".*mi-dprintf.c" \ | |
76 | -line $dp_location1] | |
77 | mi_gdb_test "[incr i]-break-info" \ | |
78 | "$i\\^done,[mi_make_breakpoint_table $bps]" \ | |
c5867ab6 HZ |
79 | "mi info dprintf" |
80 | ||
81 | mi_gdb_test "-break-insert $bp_location1" ".*" "mi insert breakpoint bp_location1" | |
82 | ||
58789a91 PA |
83 | # Helper for mi_continue_dprintf. |
84 | ||
85 | proc mi_expect_dprintf {args where msg} { | |
86 | global mi_gdb_prompt | |
87 | global inferior_spawn_id gdb_spawn_id | |
88 | ||
89 | if { $args == "call" || $args == "fprintf" } { | |
90 | set foobarbazqux "\"foobarbazqux\"" | |
91 | set sid $inferior_spawn_id | |
92 | } else { | |
93 | set foobarbazqux "\\\\\"foobarbazqux\\\\\"" | |
94 | set sid $gdb_spawn_id | |
95 | } | |
c5867ab6 | 96 | |
58789a91 PA |
97 | # Don't expect the prompt here to avoid a race with mi_expect_stop |
98 | # in case $inferior_spawn_id != $gdb_spawn_id. Otherwise, in that | |
99 | # case, we could see the gdb prompt before the inferior output. | |
100 | gdb_expect { | |
101 | -i $sid | |
102 | -re ".*$foobarbazqux $where" { | |
103 | pass $msg | |
104 | } | |
105 | eof { | |
106 | fail "$msg (eof)" | |
fa876972 | 107 | } |
58789a91 PA |
108 | timeout { |
109 | fail "$msg (timeout)" | |
110 | } | |
111 | } | |
112 | mi_expect_stop ".*" ".*" ".*" ".*" ".*" "" "$msg stop" | |
113 | } | |
fa876972 | 114 | |
58789a91 PA |
115 | proc mi_continue_dprintf {args} { |
116 | with_test_prefix $args { | |
c5867ab6 | 117 | set msg "mi 1st dprintf" |
58789a91 PA |
118 | mi_run_cmd |
119 | mi_expect_dprintf $args "At foo entry.*arg=1234, g=1234" $msg | |
c5867ab6 HZ |
120 | |
121 | set msg "mi 2nd dprintf" | |
122 | mi_send_resuming_command "exec-continue" "$msg continue" | |
58789a91 | 123 | mi_expect_dprintf $args "At foo entry.*arg=1235, g=2222" $msg |
c5867ab6 HZ |
124 | } |
125 | } | |
126 | ||
127 | mi_continue_dprintf "gdb" | |
128 | ||
129 | # The "call" style depends on having I/O functions available, so test. | |
f8bf778c | 130 | set has_stderr_symbol [mi_gdb_is_stderr_available] |
c5867ab6 HZ |
131 | |
132 | if ![target_info exists gdb,noinferiorio] { | |
133 | ||
134 | # Now switch styles and rerun; in the absence of redirection the | |
135 | # output should be the same. | |
136 | ||
137 | mi_gdb_test "set dprintf-style call" ".*" "mi set dprintf style to call" | |
138 | mi_continue_dprintf "call" | |
139 | ||
f8bf778c GL |
140 | # Some compilers don't add information about stderr, |
141 | # so skip these tests if needed. | |
142 | if {$::has_stderr_symbol} { | |
143 | mi_gdb_test "set dprintf-function fprintf" ".*" "mi set dprintf function" | |
144 | mi_gdb_test "set dprintf-channel stderr" ".*" "mi set dprintf channel" | |
145 | mi_continue_dprintf "fprintf" | |
146 | } | |
c5867ab6 HZ |
147 | } |
148 | ||
149 | set target_can_dprintf 0 | |
150 | set msg "set dprintf style to agent" | |
151 | send_gdb "set dprintf-style agent\n" | |
152 | gdb_expect { | |
153 | -re "warning: Target cannot run dprintf commands, falling back to GDB printf.*$mi_gdb_prompt$" { | |
154 | unsupported "$msg" | |
155 | } | |
156 | -re ".*done.*$mi_gdb_prompt$" { | |
157 | set target_can_dprintf 1 | |
158 | pass "$msg" | |
159 | } | |
160 | -re ".*$mi_gdb_prompt$" { | |
161 | fail "$msg" | |
162 | } | |
163 | timeout { | |
164 | fail "$msg" | |
165 | } | |
166 | } | |
167 | ||
168 | if $target_can_dprintf { | |
88bbeca9 HZ |
169 | if {[mi_run_cmd] < 0} { |
170 | # This likely means we failed to use target side commands in | |
171 | # combination with software breakpoints. IOW, the target | |
172 | # likely doesn't support target-side software breakpoints. | |
173 | set target_can_dprintf 0 | |
174 | unsupported "send dprintf to target" | |
175 | } | |
c5867ab6 | 176 | |
88bbeca9 HZ |
177 | if $target_can_dprintf { |
178 | mi_expect_stop ".*" ".*" ".*" ".*" ".*" "" "mi expect stop" | |
c5867ab6 | 179 | |
88bbeca9 HZ |
180 | mi_send_resuming_command "exec-continue" "mi 1st dprintf continue, agent" |
181 | mi_expect_stop ".*" "foo" ".*" ".*" ".*" "" "mi 1st dprintf, agent" | |
c5867ab6 | 182 | |
88bbeca9 | 183 | mi_send_resuming_command "exec-continue" "mi 2nd dprintf continue, agent" |
8f56dad4 | 184 | |
88bbeca9 HZ |
185 | # The =breakpoint-modified text is a part of the |
186 | # "-exec-continue" output. | |
187 | set msg "mi info dprintf second time" | |
188 | gdb_expect { | |
189 | -re "=breakpoint-modified," { | |
190 | pass $msg | |
191 | } | |
192 | -re ".*$mi_gdb_prompt$" { | |
193 | fail "$msg" | |
194 | } | |
195 | timeout { | |
196 | fail "$msg" | |
197 | } | |
8f56dad4 | 198 | } |
8f56dad4 | 199 | |
88bbeca9 HZ |
200 | mi_expect_stop ".*" "foo" ".*" ".*" ".*" "" "mi 2nd dprintf, agent" |
201 | } | |
c5867ab6 HZ |
202 | } |
203 | ||
204 | mi_gdb_test "set dprintf-style foobar" ".*error.*" "mi set dprintf style to an unrecognized type" |