192906Smarkm# Copyright 2012-2020 Free Software Foundation, Inc. 292906Smarkm 322347Spst# This program is free software; you can redistribute it and/or modify 422347Spst# it under the terms of the GNU General Public License as published by 522347Spst# the Free Software Foundation; either version 3 of the License, or 622347Spst# (at your option) any later version. 722347Spst# 822347Spst# This program is distributed in the hope that it will be useful, 922347Spst# but WITHOUT ANY WARRANTY; without even the implied warranty of 1022347Spst# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1122347Spst# GNU General Public License for more details. 1222347Spst# 1322347Spst# You should have received a copy of the GNU General Public License 1422347Spst# along with this program. If not, see <http://www.gnu.org/licenses/>. 1522347Spst 1622347Spst# Note that the testcase gdb.dwarf2/dw2-inline-break.exp largely 1722347Spst# mirrors this testcase, and should be updated if this testcase is 1822347Spst# changed. 1922347Spst 2022347Spststandard_testfile 2122347Spst 2222347Spstif { [prepare_for_testing "failed to prepare" $testfile $srcfile \ 2322347Spst {debug additional_flags=-Winline}] } { 2422347Spst return -1 2522347Spst} 2622347Spst 2722347Spst# Return a string that may be used to match the output of "info break NUM". 2822347Spst# 2992906Smarkm# Optional arguments: 3092906Smarkm# 3192906Smarkm# source - the name of the source file 3229964Sache# func - the name of the function 3329964Sache# disp - the event disposition 3429964Sache# enabled - enable state 3592906Smarkm# locs - number of locations 3692906Smarkm# line - source line number (ignored without -source) 3792906Smarkm 3892906Smarkmproc break_info_1 {num args} { 3992906Smarkm global decimal 4092906Smarkm 4192906Smarkm # Column delimiter 4292906Smarkm set c {[\t ]+} 4392906Smarkm 4492906Smarkm # Row delimiter 4592906Smarkm set end {[\r\n \t]+} 4692906Smarkm 4792906Smarkm # Table header 4892906Smarkm set header "[join [list Num Type Disp Enb Address What] ${c}]" 4992906Smarkm 5092906Smarkm # Get/configure any optional parameters. 5192906Smarkm parse_args [list {source ""} {func ".*"} {disp "keep"} \ 5292906Smarkm {enabled "y"} {locs 1} [list line $decimal] \ 5392906Smarkm {type "breakpoint"}] 5492906Smarkm 5592906Smarkm if {$source != ""} { 5692906Smarkm set source "$source:$line" 5792906Smarkm } 5892906Smarkm 5992906Smarkm # Result starts with the standard header. 6092906Smarkm set result "$header${end}" 6192906Smarkm 6292906Smarkm # Set up for multi-location breakpoint marker. 6392906Smarkm if {$locs == 1} { 6492906Smarkm set multi ".*" 6592906Smarkm } else { 6692906Smarkm set multi "<MULTIPLE>${end}" 6792906Smarkm } 6892906Smarkm append result "[join [list $num $type $disp $enabled $multi] $c]" 6992906Smarkm 7092906Smarkm # Add location info. 7192906Smarkm for {set i 1} {$i <= $locs} {incr i} { 7292906Smarkm if {$locs > 1} { 7392906Smarkm append result "[join [list $num.$i $enabled] $c].*" 7492906Smarkm } 7592906Smarkm 7692906Smarkm # Add function/source file info. 7792906Smarkm append result "in $func at .*$source${end}" 7892906Smarkm } 7992906Smarkm 8092906Smarkm return $result 8192906Smarkm} 8292906Smarkm 8392906Smarkm# 8492906Smarkm# func1 is a static inlined function that is called once. 8592906Smarkm# The result should be a single-location breakpoint. 8692906Smarkm# 8792906Smarkmgdb_test "break func1" \ 8892906Smarkm "Breakpoint.*at.* file .*$srcfile, line.*" 8992906Smarkm 9092906Smarkm# 9192906Smarkm# func2 is a non-static inlined function that is called once. 9292906Smarkm# The result should be a breakpoint with two locations: the 9392906Smarkm# out-of-line function and the single inlined instance. 9492906Smarkm# 9592906Smarkmgdb_test "break func2" \ 9692906Smarkm "Breakpoint.*at.*func2.*\\(2 locations\\)" 9792906Smarkm 9892906Smarkm# 9992906Smarkm# func3b is a static inlined function that is called once from 10092906Smarkm# within another static inlined function. The result should be 10192906Smarkm# a single-location breakpoint. 10292906Smarkm# 10392906Smarkmgdb_test "break func3b" \ 10492906Smarkm "Breakpoint.*at.* file .*$srcfile, line.*" 10592906Smarkm 10692906Smarkm# 10792906Smarkm# func4b is a static inlined function that is called once from 10892906Smarkm# within a non-static inlined function. The result should be 10992906Smarkm# a breakpoint with two locations: the inlined instance within 11092906Smarkm# the inlined call to func4a in main, and the inlined instance 11192906Smarkm# within the out-of-line func4a. 11292906Smarkm# 11392906Smarkmgdb_test "break func4b" \ 11492906Smarkm "Breakpoint.*at.*func4b.*\\(2 locations\\)" 11592906Smarkm 11692906Smarkm# 11792906Smarkm# func5b is a non-static inlined function that is called once 11892906Smarkm# from within a static inlined function. The result should be a 11992906Smarkm# breakpoint with two locations: the out-of-line function and the 12092906Smarkm# inlined instance within the inlined call to func5a in main. 12192906Smarkm# 12292906Smarkmgdb_test "break func5b" \ 12392906Smarkm "Breakpoint.*at.*func5b.*\\(2 locations\\)" 12492906Smarkm# 12522347Spst# func6b is a non-static inlined function that is called once from 12622347Spst# within another non-static inlined function. The result should be 12722347Spst# a breakpoint with three locations: the out-of-line function, the 12822347Spst# inlined instance within the out-of-line func6a, and the inlined 12922347Spst# instance within the inlined call to func6a in main, 13022347Spst# 13122347Spstgdb_test "break func6b" \ 13222347Spst "Breakpoint.*at.*func6b.*\\(3 locations\\)" 13329964Sache 13422347Spst# 13522347Spst# func7b is a static inlined function that is called twice: once from 13622347Spst# func7a, and once from main. The result should be a breakpoint with 13722347Spst# two locations: the inlined instance within the inlined instance of 13822347Spst# func7a, and the inlined instance within main. 13922347Spst# 14022347Spstgdb_test "break func7b" \ 14122347Spst "Breakpoint.*at.*func7b.*\\(2 locations\\)" 14222347Spst 14322347Spst# 14422347Spst# func8b is a non-static inlined function that is called twice: once 14522347Spst# func8a, and once from main. The result should be a breakpoint with 14622347Spst# three locations: the out-of-line function, the inlined instance 14729964Sache# within the inlined instance of func7a, and the inlined instance 14822347Spst# within main. 14922347Spst# 15022347Spstgdb_test "break func8b" \ 15122347Spst "Breakpoint.*at.*func8b.*\\(3 locations\\)" 15222347Spst 15322347Spst# 15422347Spst# func1 is a static inlined function. The result should be that no 15522347Spst# symbol is found to print. 15622347Spst# 15722347Spstgdb_test "print func1" \ 15822347Spst "No symbol \"func1\" in current context." 15922347Spst 16022347Spst# 16122347Spst# func2 is a non-static inlined function. The result should be that 16222347Spst# one symbol is found to print, and that the printed symbol is called 16322347Spst# "func2". Note that this does not cover the failure case that two 16422347Spst# symbols were found, but that gdb chose the out-of-line copy to 16522347Spst# print, but if this was failing the "print func1" test would likely 16622347Spst# fail instead. 16722347Spst# 16829964Sachegdb_test "print func2" \ 16992906Smarkm "\\\$.* = {int \\(int\\)} .* <func2>" 17022347Spst 17122347Spst# Test that "info break" reports the location of the breakpoints "inside" 17222347Spst# the inlined functions 17322347Spst 17422347Spstset results(1) [break_info_1 1 -source $srcfile -func "func1"] 17522347Spstset results(2) [break_info_1 2 -locs 2 -source $srcfile -func "func2"] 17622347Spstset results(3) [break_info_1 3 -source $srcfile -func "func3b"] 17722347Spstset results(4) [break_info_1 4 -locs 2 -source $srcfile -func "func4b"] 17822347Spstset results(5) [break_info_1 5 -locs 2 -source $srcfile -func "func5b"] 179set results(6) [break_info_1 6 -locs 3 -source $srcfile -func "func6b"] 180set results(7) [break_info_1 7 -locs 2 -source $srcfile -func "func7b"] 181set results(8) [break_info_1 8 -locs 3 -source $srcfile -func "func8b"] 182 183for {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. 189foreach_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# func_extern_caller calls func_inline_caller which calls 235# func_inline_callee. The latter two are both inline functions. Test 236# that setting a breakpoint on each of the functions reports a stop at 237# that function. This exercises the inline frame skipping logic. If 238# we set a breakpoint at function A, we want to present the stop at A, 239# even if A's entry code is an inlined call to another inline function 240# B. 241 242foreach_with_prefix func { 243 "func_extern_caller" 244 "func_inline_caller" 245 "func_inline_callee" 246} { 247 clean_restart $binfile 248 249 if {![runto main]} { 250 untested "could not run to main" 251 continue 252 } 253 254 gdb_breakpoint $func 255 gdb_test "continue" "Breakpoint .* $func .*at .*$srcfile.*" \ 256 "breakpoint hit presents stop at breakpointed function" 257} 258 259# Test setting a breakpoint in an inline function by line number and 260# by address, and that GDB presents the stop there. 261 262set line [gdb_get_line_number "break here"] 263 264with_test_prefix "line number" { 265 clean_restart $binfile 266 267 if {![runto main]} { 268 untested "could not run to main" 269 continue 270 } 271 272 # Set the breakpoint by line number, and check that GDB reports 273 # the breakpoint location being the inline function. 274 gdb_test "break $srcfile:$line" ".*Breakpoint .* at .*: file .*$srcfile, line $line." 275 276 gdb_test "info break \$bpnum" "in func1 at .*$srcfile:$line" 277 278 gdb_test "continue" "Breakpoint .*, func1 \\(x=1\\) at .*$srcfile:$line.*break here.*" \ 279 "breakpoint hit presents stop at inlined function" 280 281 # Save the PC for the following by-address test. 282 set address [get_hexadecimal_valueof "\$pc" "0"] 283} 284 285# Test setting a breakpoint in an inline function by address, and that 286# GDB presents the stop there. 287 288with_test_prefix "address" { 289 290 clean_restart $binfile 291 292 if {![runto main]} { 293 untested "could not run to main" 294 continue 295 } 296 297 # Set the breakpoint by address, and check that GDB reports the 298 # breakpoint location being the inline function. 299 gdb_test "break *$address" ".*Breakpoint .* at $address: file .*$srcfile, line $line." 300 301 gdb_test "info break \$bpnum" "in func1 at .*$srcfile:$line" 302 303 gdb_test "continue" "Breakpoint .*, func1 \\(x=1\\) at .*$srcfile:$line.*break here.*" \ 304 "breakpoint hit presents stop at inlined function" 305} 306 307with_test_prefix "check alignment" { 308 309 clean_restart $binfile 310 311 if {![runto main]} { 312 untested "could not run to main" 313 continue 314 } 315 316 gdb_test "break func4b" \ 317 "Breakpoint.*at.*func4b.*\\(2 locations\\)" 318 319 set expected_line_length -1 320 gdb_test_multiple "info break \$bpnum" "xxxx" { 321 -re "Num Type Disp Enb Address What\r\n" { 322 exp_continue 323 } 324 -re "($decimal \[^\r\n\]+)<MULTIPLE>\[^\r\n\]+\r\n" { 325 if {$expected_line_length != -1} { 326 fail "multiple header lines seen" 327 } 328 set expected_line_length [string length $expect_out(1,string)] 329 exp_continue 330 } 331 -re "($decimal\.($decimal) \[^\r\n\]+)$hex\[^\r\n\]+\r\n" { 332 set len [string length $expect_out(1,string)] 333 set loc $expect_out(2,string) 334 gdb_assert {$len == $expected_line_length} \ 335 "check alignment of location line $loc" 336 exp_continue 337 } 338 -re "$gdb_prompt $" { 339 } 340 } 341} 342 343unset -nocomplain results 344