1 # Copyright 2012-2024 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Tests for explicit linespecs
18 require allow_cplus_tests
23 if {[prepare_for_testing "failed to prepare" $exefile $srcfile \
24 {c++ debug nowarnings}]} {
28 # Wrap this whole test in a namespace to avoid contaminating other tests.
29 namespace eval $testfile {
30 # Test the given (explicit) LINESPEC which should cause gdb to break
32 proc test_breakpoint {linespec location} {
34 # Delete all breakpoints, set a new breakpoint at LINESPEC,
35 # and attempt to run to it.
37 gdb_breakpoint $linespec
38 gdb_continue_to_breakpoint $linespec $location
41 # Add the given LINESPEC to the array named in THEARRAY. GDB is expected
42 # to stop at LOCATION.
43 proc add {thearray linespec location} {
46 lappend ar(linespecs) $linespec
47 lappend ar(locations) $location
50 # Some locations used in this test
53 set lineno(normal) [gdb_get_line_number "myfunction location" $srcfile]
54 set lineno(entry) [gdb_get_line_number "entry location" $srcfile]
55 set lineno(top) [gdb_get_line_number "top location" $srcfile]
56 set lineno(operator) [gdb_get_line_number "operator location" $srcfile]
57 foreach v [array names lineno] {
58 set location($v) ".*[string_to_regexp "$srcfile:$lineno($v)"].*"
61 # A list of explicit linespecs and the corresponding location
63 set linespecs(linespecs) {}
64 set linespecs(location) {}
66 add linespecs "-source $srcfile -function myclass::myfunction" \
68 add linespecs "-source $srcfile -function myclass::myfunction -label top" \
71 # This isn't implemented yet; -line is silently ignored.
73 "-source $srcfile -function myclass::myfunction -label top -line 3" \
75 add linespecs "-source $srcfile -line $lineno(top)" $location(top)
76 add linespecs "-function myclass::myfunction" $location(normal)
77 add linespecs "-function myclass::myfunction -label top" $location(top)
79 # These are also not yet supported; -line is silently ignored.
80 add linespecs "-function myclass::myfunction -line 3" $location(normal)
81 add linespecs "-function myclass::myfunction -label top -line 3" \
83 add linespecs "-line 3" $location(normal)
84 add linespecs "-function myclass::operator," $location(operator)
85 add linespecs "-function 'myclass::operator,'" $location(operator)
86 add linespecs "-function \"myclass::operator,\"" $location(operator)
90 namespace delete $testfile
94 # Test explicit linespecs, with and without conditions.
95 foreach linespec $linespecs(linespecs) loc_pattern $linespecs(locations) {
97 test_breakpoint $linespec $loc_pattern
100 # Special (orphaned) dprintf cases.
101 gdb_test "dprintf -function myclass::operator,,\"hello\"" \
102 "Dprintf .*$srcfile, line $lineno(operator)\\."
103 gdb_test "dprintf -function 'myclass::operator,',\"hello\"" \
104 "Dprintf .*$srcfile, line $lineno(operator)\\."
105 gdb_test "dprintf -function \"myclass::operator,\",\"hello\"" \
106 "Dprintf .*$srcfile, line $lineno(operator)\\."
109 namespace delete $testfile