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