Revert accidental push of "Inline breakpoints" commit
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.opt / inline-break.exp
1 # Copyright 2012-2018 Free Software Foundation, Inc.
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 # Note that the testcase gdb.dwarf2/dw2-inline-break.exp largely
17 # mirrors this testcase, and should be updated if this testcase is
18 # changed.
19
20 standard_testfile
21
22 if { [prepare_for_testing "failed to prepare" $testfile $srcfile \
23 {debug additional_flags=-Winline}] } {
24 return -1
25 }
26
27 # Return a string that may be used to match the output of "info break NUM".
28 #
29 # Optional arguments:
30 #
31 # source - the name of the source file
32 # func - the name of the function
33 # disp - the event disposition
34 # enabled - enable state
35 # locs - number of locations
36 # line - source line number (ignored without -source)
37
38 proc break_info_1 {num args} {
39 global decimal
40
41 # Column delimiter
42 set c {[\t ]+}
43
44 # Row delimiter
45 set end {[\r\n \t]+}
46
47 # Table header
48 set header "[join [list Num Type Disp Enb Address What] ${c}]"
49
50 # Get/configure any optional parameters.
51 parse_args [list {source ""} {func ".*"} {disp "keep"} \
52 {enabled "y"} {locs 1} [list line $decimal] \
53 {type "breakpoint"}]
54
55 if {$source != ""} {
56 set source "$source:$line"
57 }
58
59 # Result starts with the standard header.
60 set result "$header${end}"
61
62 # Set up for multi-location breakpoint marker.
63 if {$locs == 1} {
64 set multi ".*"
65 } else {
66 set multi "<MULTIPLE>${end}"
67 }
68 append result "[join [list $num $type $disp $enabled $multi] $c]"
69
70 # Add location info.
71 for {set i 1} {$i <= $locs} {incr i} {
72 if {$locs > 1} {
73 append result "[join [list $num.$i $enabled] $c].*"
74 }
75
76 # Add function/source file info.
77 append result "in $func at .*$source${end}"
78 }
79
80 return $result
81 }
82
83 #
84 # func1 is a static inlined function that is called once.
85 # The result should be a single-location breakpoint.
86 #
87 gdb_test "break func1" \
88 "Breakpoint.*at.* file .*$srcfile, line.*"
89
90 #
91 # func2 is a non-static inlined function that is called once.
92 # The result should be a breakpoint with two locations: the
93 # out-of-line function and the single inlined instance.
94 #
95 gdb_test "break func2" \
96 "Breakpoint.*at.*func2.*\\(2 locations\\)"
97
98 #
99 # func3b is a static inlined function that is called once from
100 # within another static inlined function. The result should be
101 # a single-location breakpoint.
102 #
103 gdb_test "break func3b" \
104 "Breakpoint.*at.* file .*$srcfile, line.*"
105
106 #
107 # func4b is a static inlined function that is called once from
108 # within a non-static inlined function. The result should be
109 # a breakpoint with two locations: the inlined instance within
110 # the inlined call to func4a in main, and the inlined instance
111 # within the out-of-line func4a.
112 #
113 gdb_test "break func4b" \
114 "Breakpoint.*at.*func4b.*\\(2 locations\\)"
115
116 #
117 # func5b is a non-static inlined function that is called once
118 # from within a static inlined function. The result should be a
119 # breakpoint with two locations: the out-of-line function and the
120 # inlined instance within the inlined call to func5a in main.
121 #
122 gdb_test "break func5b" \
123 "Breakpoint.*at.*func5b.*\\(2 locations\\)"
124 #
125 # func6b is a non-static inlined function that is called once from
126 # within another non-static inlined function. The result should be
127 # a breakpoint with three locations: the out-of-line function, the
128 # inlined instance within the out-of-line func6a, and the inlined
129 # instance within the inlined call to func6a in main,
130 #
131 gdb_test "break func6b" \
132 "Breakpoint.*at.*func6b.*\\(3 locations\\)"
133
134 #
135 # func7b is a static inlined function that is called twice: once from
136 # func7a, and once from main. The result should be a breakpoint with
137 # two locations: the inlined instance within the inlined instance of
138 # func7a, and the inlined instance within main.
139 #
140 gdb_test "break func7b" \
141 "Breakpoint.*at.*func7b.*\\(2 locations\\)"
142
143 #
144 # func8b is a non-static inlined function that is called twice: once
145 # func8a, and once from main. The result should be a breakpoint with
146 # three locations: the out-of-line function, the inlined instance
147 # within the inlined instance of func7a, and the inlined instance
148 # within main.
149 #
150 gdb_test "break func8b" \
151 "Breakpoint.*at.*func8b.*\\(3 locations\\)"
152
153 #
154 # func1 is a static inlined function. The result should be that no
155 # symbol is found to print.
156 #
157 gdb_test "print func1" \
158 "No symbol \"func1\" in current context."
159
160 #
161 # func2 is a non-static inlined function. The result should be that
162 # one symbol is found to print, and that the printed symbol is called
163 # "func2". Note that this does not cover the failure case that two
164 # symbols were found, but that gdb chose the out-of-line copy to
165 # print, but if this was failing the "print func1" test would likely
166 # fail instead.
167 #
168 gdb_test "print func2" \
169 "\\\$.* = {int \\(int\\)} .* <func2>"
170
171 # Test that "info break" reports the location of the breakpoints "inside"
172 # the inlined functions
173
174 set results(1) [break_info_1 1 -source $srcfile -func "func1"]
175 set results(2) [break_info_1 2 -locs 2 -source $srcfile -func "func2"]
176 set results(3) [break_info_1 3 -source $srcfile -func "func3b"]
177 set results(4) [break_info_1 4 -locs 2 -source $srcfile -func "func4b"]
178 set results(5) [break_info_1 5 -locs 2 -source $srcfile -func "func5b"]
179 set results(6) [break_info_1 6 -locs 3 -source $srcfile -func "func6b"]
180 set results(7) [break_info_1 7 -locs 2 -source $srcfile -func "func7b"]
181 set results(8) [break_info_1 8 -locs 3 -source $srcfile -func "func8b"]
182
183 for {set i 1} {$i <= [array size results]} {incr i} {
184 send_log "Expecting: $results($i)\n"
185 gdb_test "info break $i" $results($i)
186 }
187
188 # Test "permanent" and "temporary" breakpoints.
189 foreach_with_prefix cmd [list "break" "tbreak"] {
190
191 # Start with a clean state.
192 delete_breakpoints
193 if {![runto main]} {
194 untested "could not run to main"
195 return -1
196 }
197
198 # Assemble flags to pass to gdb_breakpoint. Lame but this is just
199 # a test suite!
200 set break_flags "message"
201 if {[string match $cmd "tbreak"]} {
202 lappend break_flags "temporary"
203 }
204
205 # Insert breakpoints for all inline_func? and not_inline_func? and check
206 # that we actually stop where we think we should.
207 for {set i 1} {$i < 4} {incr i} {
208 foreach inline {"not_inline" "inline"} {
209 eval gdb_breakpoint "${inline}_func$i" $break_flags
210 }
211 }
212
213 set ws {[\r\n\t ]+}
214 set backtrace [list "(in|at)? main"]
215 for {set i 3} {$i > 0} {incr i -1} {
216
217 foreach inline {"not_inline" "inline"} {
218
219 # Check that we stop at the correct location and print out
220 # the (possibly) inlined frames.
221 set num [gdb_get_line_number "/* ${inline}_func$i */"]
222 set pattern ".*$srcfile:$num${ws}.*$num${ws}int y = $decimal;"
223 append pattern "${ws}/\\\* ${inline}_func$i \\\*/"
224 send_log "Expecting $pattern\n"
225 gdb_continue_to_breakpoint "${inline}_func$i" $pattern
226
227 # Also check for the correct backtrace.
228 set backtrace [linsert $backtrace 0 "(in|at)?${ws}${inline}_func$i"]
229 gdb_test_sequence "bt" "bt stopped in ${inline}_func$i" $backtrace
230 }
231 }
232 }
233
234 unset -nocomplain results
This page took 0.036308 seconds and 4 git commands to generate.