]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.mi/mi-dprintf.exp
daily update
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-dprintf.exp
CommitLineData
c5867ab6
HZ
1# Copyright (C) 2013 Free Software Foundation, Inc.
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
17load_lib mi-support.exp
18set MIFLAGS "-i=mi"
19
20gdb_exit
21if [mi_gdb_start] {
22 continue
23}
24
25standard_testfile
26
27if {[build_executable $testfile.exp $testfile $srcfile {debug}] == -1} {
28 untested "failed to compile $testfile"
29 return -1
30}
31
32mi_delete_breakpoints
33
34set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
35set dp_location1 [gdb_get_line_number "set dprintf 1 here"]
36
37mi_run_to_main
38
39mi_gdb_test "1-dprintf-insert" \
40 "1\\^error,msg=\"-dprintf-insert: Missing <location>\"" "mi insert without location"
41
42mi_gdb_test "2-dprintf-insert foo" \
43 "2\\^error,msg=\"-dprintf-insert: Missing <format>\"" "mi insert breakpoint without format string"
44
45mi_gdb_test "3-dprintf-insert 29" \
46 "3\\^error,msg=\"-dprintf-insert: Missing <format>\"" "mi insert second breakpoint without format string"
47
48mi_gdb_test "-break-insert main" ".*" "mi insert breakpoint main"
49mi_delete_breakpoints
50
51mi_gdb_test "4-dprintf-insert foo \"At foo entry\\n\"" \
52 "4\\^done,bkpt=\{number=\".*\",type=\"dprintf\".*func=\"foo\",file=\".*mi-dprintf.c\",fullname=\".*mi-dprintf.c\",line=\".*\".*" "mi insert dprintf foo"
53
54mi_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
58mi_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
62mi_gdb_test "-break-insert $bp_location1" ".*" "mi insert breakpoint bp_location1"
63
64proc mi_continue_dprintf {args} {
65 with_test_prefix $args {
66 global mi_gdb_prompt
67
68 mi_run_cmd
69 set msg "mi 1st dprintf"
70 gdb_expect {
44e97363 71 -re ".*At foo entry.*arg=1234, g=1234" {
c5867ab6
HZ
72 pass $msg
73 }
74 -re ".*$mi_gdb_prompt$" {
75 fail $msg
76 }
77 timeout {
78 fail $msg
79 }
80 }
81 mi_expect_stop ".*" ".*" ".*" ".*" ".*" "" "$msg stop"
82
83 set msg "mi 2nd dprintf"
84 mi_send_resuming_command "exec-continue" "$msg continue"
85 gdb_expect {
8f56dad4 86 -re ".*At foo entry.*arg=1235, g=2222" {
c5867ab6
HZ
87 pass $msg
88 }
89 -re ".*$mi_gdb_prompt$" {
90 fail $msg
91 }
92 timeout {
93 fail $msg
94 }
95 }
8f56dad4 96 mi_expect_stop ".*" ".*" ".*" ".*" ".*" "" "$msg 2nd stop"
c5867ab6
HZ
97 }
98}
99
100mi_continue_dprintf "gdb"
101
102# The "call" style depends on having I/O functions available, so test.
103
104if ![target_info exists gdb,noinferiorio] {
105
106 # Now switch styles and rerun; in the absence of redirection the
107 # output should be the same.
108
109 mi_gdb_test "set dprintf-style call" ".*" "mi set dprintf style to call"
110 mi_continue_dprintf "call"
111
112 mi_gdb_test "set dprintf-function fprintf" ".*" "mi set dprintf-channel stderr"
113 mi_gdb_test "set dprintf-channel stderr" ".*" "mi set dprintf channel"
114 mi_continue_dprintf "fprintf"
115}
116
117set target_can_dprintf 0
118set msg "set dprintf style to agent"
119send_gdb "set dprintf-style agent\n"
120gdb_expect {
121 -re "warning: Target cannot run dprintf commands, falling back to GDB printf.*$mi_gdb_prompt$" {
122 unsupported "$msg"
123 }
124 -re ".*done.*$mi_gdb_prompt$" {
125 set target_can_dprintf 1
126 pass "$msg"
127 }
128 -re ".*$mi_gdb_prompt$" {
129 fail "$msg"
130 }
131 timeout {
132 fail "$msg"
133 }
134}
135
136if $target_can_dprintf {
137 mi_run_cmd
138
8f56dad4 139 mi_expect_stop ".*" ".*" ".*" ".*" ".*" "" "mi expect stop"
c5867ab6 140
8f56dad4
JK
141 mi_send_resuming_command "exec-continue" "mi 1st dprintf continue, agent"
142 mi_expect_stop ".*" "foo" ".*" ".*" ".*" "" "mi 1st dprintf, agent"
c5867ab6 143
8f56dad4
JK
144 mi_send_resuming_command "exec-continue" "mi 2nd dprintf continue, agent"
145
146 # The =breakpoint-modified text is a part of the "-exec-continue" output.
147 set msg "mi info dprintf second time"
148 gdb_expect {
149 -re "=breakpoint-modified," {
150 pass $msg
151 }
152 -re ".*$mi_gdb_prompt$" {
153 fail "$msg"
154 }
155 timeout {
156 fail "$msg"
157 }
158 }
159
160 mi_expect_stop ".*" "foo" ".*" ".*" ".*" "" "mi 2nd dprintf, agent"
c5867ab6
HZ
161}
162
163mi_gdb_test "set dprintf-style foobar" ".*error.*" "mi set dprintf style to an unrecognized type"