1# Copyright 2007-2020 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# This test verifies that setting breakpoint on line in template
17# function will fire in all instantiations of that template.
18
19if { [skip_stl_tests] } { continue }
20
21
22standard_testfile .cc
23
24if [get_compiler_info "c++"] {
25    return -1
26}
27
28if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
29    return -1
30}
31
32set bp_location [gdb_get_line_number "set breakpoint here"]
33
34# Set a breakpoint with multiple locations
35# and a condition.
36
37gdb_test "break $srcfile:$bp_location if i==1" \
38    "Breakpoint.*at.*: $srcfile:$bp_location. \\(2 locations\\).*" \
39    "initial condition: set breakpoint"
40
41gdb_run_cmd
42
43set test "initial condition: run to breakpoint"
44gdb_test_multiple "" $test {
45    -re "Breakpoint \[0-9\]+,.*foo<int> \\(i=1\\).*$gdb_prompt $" {
46	pass $test
47	break
48    }
49}
50
51gdb_test "continue" \
52    ".*Breakpoint.*foo<double> \\(i=1\\).*" \
53    "initial condition: run to breakpoint 2"
54
55# Set breakpoint with multiple locations.
56# Separately set the condition.
57
58delete_breakpoints
59gdb_test "kill" "" "kill" \
60         {Kill the program being debugged\? \(y or n\) } "y"
61
62gdb_test "break $srcfile:$bp_location" \
63    "Breakpoint.*at.*: $srcfile:$bp_location. \\(2 locations\\).*" \
64    "separate condition: set breakpoint"
65
66gdb_test_no_output {condition $bpnum i==1} \
67    "separate condition: set condition"
68
69gdb_run_cmd
70gdb_test "" "Breakpoint \[0-9\]+,.*foo<int> \\(i=1\\).*" "separate condition: run to breakpoint"
71
72gdb_test "continue" \
73    ".*Breakpoint.*foo<double> \\(i=1\\).*" \
74    "separate condition: run to breakpoint 2"
75
76# Try disabling a single location. We also test
77# that at least in simple cases, the enable/disable
78# state of locations surive "run".
79gdb_test_no_output {disable $bpnum.1} "disabling location: disable"
80
81gdb_run_cmd
82gdb_test "" "Breakpoint \[0-9\]+,.*foo<double> \\(i=1\\).*" "disabling location: run to breakpoint"
83
84# Try disabling entire breakpoint
85gdb_test_no_output {enable $bpnum.1} "disabling location: enable"
86
87
88gdb_test_no_output {disable $bpnum} "disable breakpoint: disable"
89
90gdb_run_cmd
91gdb_test "" "$inferior_exited_re normally.*" "disable breakpoint: run to breakpoint"
92
93# Make sure breakpoint can be set on a specific instantion.
94delete_breakpoints
95gdb_test "break 'void foo<int>(int)'" ".*" \
96    "instantiation: set breakpoint"
97
98
99gdb_run_cmd
100gdb_test "" "Breakpoint \[0-9\]+,.*foo<int> \\(i=0\\).*" "instantiation: run to breakpoint"
101
102gdb_test "continue" \
103    ".*Breakpoint.*foo<int> \\(i=1\\).*" \
104    "instantiation: run to breakpoint 2"
105
106
107# Make sure we can set a breakpoint on a source statement that spans
108# multiple lines.
109
110delete_breakpoints
111
112set bp_location [gdb_get_line_number "set multi-line breakpoint here"]
113
114if { ![runto_main] } {
115    fail "can't run to main for multi_line_foo tests."
116    return 0
117}
118
119gdb_test "break $srcfile:$bp_location" \
120    "Breakpoint.*at.*: $srcfile:$bp_location. \\(2 locations\\).*" \
121    "set multi_line_foo breakpoint"
122gdb_test "continue" \
123    ".*Breakpoint.*multi_line_foo<int> \\(i=0\\).*" \
124    "run to multi_line_foo breakpoint 2 <int>"
125gdb_test "continue" \
126    ".*Breakpoint.*multi_line_foo<double> \\(i=0\\).*" \
127    "run to multi_line_foo breakpoint 2 <double>"
128