Commit | Line | Data |
---|---|---|
ecd75fc8 | 1 | # Copyright (C) 2013-2014 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 | ||
39 | mi_gdb_test "1-dprintf-insert" \ | |
40 | "1\\^error,msg=\"-dprintf-insert: Missing <location>\"" "mi insert without location" | |
41 | ||
42 | mi_gdb_test "2-dprintf-insert foo" \ | |
43 | "2\\^error,msg=\"-dprintf-insert: Missing <format>\"" "mi insert breakpoint without format string" | |
44 | ||
45 | mi_gdb_test "3-dprintf-insert 29" \ | |
46 | "3\\^error,msg=\"-dprintf-insert: Missing <format>\"" "mi insert second breakpoint without format string" | |
47 | ||
48 | mi_gdb_test "-break-insert main" ".*" "mi insert breakpoint main" | |
49 | mi_delete_breakpoints | |
50 | ||
fa876972 | 51 | mi_gdb_test "4-dprintf-insert foo \"\\\"foobarbazqux\\\" At foo entry\\n\"" \ |
c5867ab6 HZ |
52 | "4\\^done,bkpt=\{number=\".*\",type=\"dprintf\".*func=\"foo\",file=\".*mi-dprintf.c\",fullname=\".*mi-dprintf.c\",line=\".*\".*" "mi insert dprintf foo" |
53 | ||
54 | mi_gdb_test "5-dprintf-insert $dp_location1 \"arg=%d, g=%d\\n\" arg g" \ | |
55 | "5\\^done,bkpt=\{number=\".*\",type=\"dprintf\".*func=\"foo\",file=\".*mi-dprintf.c\",fullname=\".*mi-dprintf.c\",line=\"$dp_location1\".*" \ | |
56 | "mi insert dprintf dp_location1" | |
57 | ||
58 | mi_gdb_test "6-break-info" \ | |
59 | "6\\^done,BreakpointTable=\{nr_rows=\".\",nr_cols=\".\",hdr=\\\[\{width=\".*\",alignment=\".*\",col_name=\"number\",colhdr=\"Num\"\},\{width=\".*\",alignment=\".*\",col_name=\"type\",colhdr=\"Type\"\},\{width=\".*\",alignment=\".*\",col_name=\"disp\",colhdr=\"Disp\"\},\{width=\".*\",alignment=\".*\",col_name=\"enabled\",colhdr=\"Enb\"\},\{width=\".*\",alignment=\".*\",col_name=\"addr\",colhdr=\"Address\"\},\{width=\".*\",alignment=\".*\",col_name=\"what\",colhdr=\"What\"\}\\\],body=\\\[bkpt=\{number=\"3\",type=\"dprintf\".*func=\"foo\",file=\".*mi-dprintf.c\",fullname=\".*mi-dprintf.c\",line=\".*\".*,bkpt=\{number=\".*\",type=\"dprintf\".*func=\"foo\",file=\".*mi-dprintf.c\",fullname=\".*mi-dprintf.c\",line=\"$dp_location1\".*" \ | |
60 | "mi info dprintf" | |
61 | ||
62 | mi_gdb_test "-break-insert $bp_location1" ".*" "mi insert breakpoint bp_location1" | |
63 | ||
64 | proc mi_continue_dprintf {args} { | |
65 | with_test_prefix $args { | |
66 | global mi_gdb_prompt | |
67 | ||
fa876972 HZ |
68 | if { $args == "call" || $args == "fprintf" } { |
69 | set foobarbazqux "\"foobarbazqux\"" | |
70 | } else { | |
71 | set foobarbazqux "\\\\\"foobarbazqux\\\\\"" | |
72 | } | |
73 | ||
c5867ab6 HZ |
74 | mi_run_cmd |
75 | set msg "mi 1st dprintf" | |
76 | gdb_expect { | |
fa876972 | 77 | -re ".*$foobarbazqux At foo entry.*arg=1234, g=1234" { |
c5867ab6 HZ |
78 | pass $msg |
79 | } | |
80 | -re ".*$mi_gdb_prompt$" { | |
81 | fail $msg | |
82 | } | |
83 | timeout { | |
84 | fail $msg | |
85 | } | |
86 | } | |
87 | mi_expect_stop ".*" ".*" ".*" ".*" ".*" "" "$msg stop" | |
88 | ||
89 | set msg "mi 2nd dprintf" | |
90 | mi_send_resuming_command "exec-continue" "$msg continue" | |
91 | gdb_expect { | |
fa876972 | 92 | -re ".*$foobarbazqux At foo entry.*arg=1235, g=2222" { |
c5867ab6 HZ |
93 | pass $msg |
94 | } | |
95 | -re ".*$mi_gdb_prompt$" { | |
96 | fail $msg | |
97 | } | |
98 | timeout { | |
99 | fail $msg | |
100 | } | |
101 | } | |
8f56dad4 | 102 | mi_expect_stop ".*" ".*" ".*" ".*" ".*" "" "$msg 2nd stop" |
c5867ab6 HZ |
103 | } |
104 | } | |
105 | ||
106 | mi_continue_dprintf "gdb" | |
107 | ||
108 | # The "call" style depends on having I/O functions available, so test. | |
109 | ||
110 | if ![target_info exists gdb,noinferiorio] { | |
111 | ||
112 | # Now switch styles and rerun; in the absence of redirection the | |
113 | # output should be the same. | |
114 | ||
115 | mi_gdb_test "set dprintf-style call" ".*" "mi set dprintf style to call" | |
116 | mi_continue_dprintf "call" | |
117 | ||
118 | mi_gdb_test "set dprintf-function fprintf" ".*" "mi set dprintf-channel stderr" | |
119 | mi_gdb_test "set dprintf-channel stderr" ".*" "mi set dprintf channel" | |
120 | mi_continue_dprintf "fprintf" | |
121 | } | |
122 | ||
123 | set target_can_dprintf 0 | |
124 | set msg "set dprintf style to agent" | |
125 | send_gdb "set dprintf-style agent\n" | |
126 | gdb_expect { | |
127 | -re "warning: Target cannot run dprintf commands, falling back to GDB printf.*$mi_gdb_prompt$" { | |
128 | unsupported "$msg" | |
129 | } | |
130 | -re ".*done.*$mi_gdb_prompt$" { | |
131 | set target_can_dprintf 1 | |
132 | pass "$msg" | |
133 | } | |
134 | -re ".*$mi_gdb_prompt$" { | |
135 | fail "$msg" | |
136 | } | |
137 | timeout { | |
138 | fail "$msg" | |
139 | } | |
140 | } | |
141 | ||
142 | if $target_can_dprintf { | |
88bbeca9 HZ |
143 | if {[mi_run_cmd] < 0} { |
144 | # This likely means we failed to use target side commands in | |
145 | # combination with software breakpoints. IOW, the target | |
146 | # likely doesn't support target-side software breakpoints. | |
147 | set target_can_dprintf 0 | |
148 | unsupported "send dprintf to target" | |
149 | } | |
c5867ab6 | 150 | |
88bbeca9 HZ |
151 | if $target_can_dprintf { |
152 | mi_expect_stop ".*" ".*" ".*" ".*" ".*" "" "mi expect stop" | |
c5867ab6 | 153 | |
88bbeca9 HZ |
154 | mi_send_resuming_command "exec-continue" "mi 1st dprintf continue, agent" |
155 | mi_expect_stop ".*" "foo" ".*" ".*" ".*" "" "mi 1st dprintf, agent" | |
c5867ab6 | 156 | |
88bbeca9 | 157 | mi_send_resuming_command "exec-continue" "mi 2nd dprintf continue, agent" |
8f56dad4 | 158 | |
88bbeca9 HZ |
159 | # The =breakpoint-modified text is a part of the |
160 | # "-exec-continue" output. | |
161 | set msg "mi info dprintf second time" | |
162 | gdb_expect { | |
163 | -re "=breakpoint-modified," { | |
164 | pass $msg | |
165 | } | |
166 | -re ".*$mi_gdb_prompt$" { | |
167 | fail "$msg" | |
168 | } | |
169 | timeout { | |
170 | fail "$msg" | |
171 | } | |
8f56dad4 | 172 | } |
8f56dad4 | 173 | |
88bbeca9 HZ |
174 | mi_expect_stop ".*" "foo" ".*" ".*" ".*" "" "mi 2nd dprintf, agent" |
175 | } | |
c5867ab6 HZ |
176 | } |
177 | ||
178 | mi_gdb_test "set dprintf-style foobar" ".*error.*" "mi set dprintf style to an unrecognized type" |