Update years in copyright notice for the GDB files.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / dprintf.exp
CommitLineData
28e7fd62 1# Copyright (C) 2012-2013 Free Software Foundation, Inc.
e7e0cddf
SS
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16
17if { [prepare_for_testing dprintf.exp "dprintf" {} {debug}] } {
18 return -1
19}
20
21set srcfile dprintf.c
22
23set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
24set dp_location1 [gdb_get_line_number "set dprintf 1 here"]
25
01429c8e
JK
26if ![runto main] {
27 return -1
28}
e7e0cddf
SS
29
30gdb_test "dprintf" "Format string required"
31
32gdb_test "dprintf foo" "Format string required"
33
34gdb_test "dprintf 29" "Format string required"
35
36delete_breakpoints
37
38gdb_breakpoint "main"
39
40gdb_test "dprintf foo,\"At foo entry\\n\"" \
41 "Dprintf .*"
42
43gdb_test "dprintf $dp_location1,\"arg=%d, g=%d\\n\", arg, g" \
44 "Dprintf .*"
45
46gdb_test "break $bp_location1" \
47 "Breakpoint .*"
48
49gdb_run_cmd
50
51gdb_test "" "Breakpoint"
52
53gdb_test "continue" "At foo entry.*arg=1234, g=1234.*" "1st dprintf, gdb"
54
55gdb_test "continue" "At foo entry.*arg=1235, g=2222.*" "2nd dprintf, gdb"
56
57# The "call" style depends on having I/O functions available, so test.
58
59if ![target_info exists gdb,noinferiorio] {
60
61 # Now switch styles and rerun; in the absence of redirection the
62 # output should be the same.
63
64 gdb_test_no_output "set dprintf-style call" "Set dprintf style to call"
65
66 gdb_run_cmd
67
68 gdb_test "" "Breakpoint"
69
70 gdb_test "continue" "At foo entry.*arg=1234, g=1234.*" "1st dprintf, call"
71
72 gdb_test "continue" "At foo entry.*arg=1235, g=2222.*" "2nd dprintf, call"
73
74 gdb_test_no_output "set dprintf-function fprintf" "Set dprintf function"
75 gdb_test_no_output "set dprintf-channel stderr" "Set dprintf channel"
76
77 gdb_run_cmd
78
79 gdb_test "" "Breakpoint"
80
81 gdb_test "continue" "At foo entry.*arg=1234, g=1234.*" \
82 "1st dprintf, fprintf"
83
84 gdb_test "continue" "At foo entry.*arg=1235, g=2222.*" \
85 "2nd dprintf, fprintf"
86}
87
d3ce09f5
SS
88set target_can_dprintf 1
89set msg "Set dprintf style to agent"
90gdb_test_multiple "set dprintf-style agent" $msg {
f9cf0f4a 91 -re "warning: Target cannot run dprintf commands.*\r\n$gdb_prompt $" {
d3ce09f5
SS
92 set target_can_dprintf 0
93 pass "$msg - cannot do"
94 }
95 -re ".*$gdb_prompt $" {
96 pass "$msg - can do"
97 }
98}
99
100if $target_can_dprintf {
101
102 gdb_run_cmd
103
104 gdb_test "" "Breakpoint"
105
106 gdb_test "continue" "Breakpoint \[0-9\]+, foo .*" "1st dprintf, agent"
107
108 gdb_test "continue" "Breakpoint \[0-9\]+, foo .*" "2nd dprintf, agent"
109
110}
111
e7e0cddf
SS
112gdb_test "set dprintf-style foobar" "Undefined item: \"foobar\"." \
113 "Set dprintf style to an unrecognized type"
114
This page took 0.101446 seconds and 4 git commands to generate.