]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.linespec/cpexplicit.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.linespec / cpexplicit.exp
1 # Copyright 2012-2024 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 # Tests for explicit linespecs
17
18 require allow_cplus_tests
19
20 standard_testfile .cc
21 set exefile $testfile
22
23 if {[prepare_for_testing "failed to prepare" $exefile $srcfile \
24 {c++ debug nowarnings}]} {
25 return -1
26 }
27
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
31 # at LOCATION.
32 proc test_breakpoint {linespec location} {
33
34 # Delete all breakpoints, set a new breakpoint at LINESPEC,
35 # and attempt to run to it.
36 delete_breakpoints
37 gdb_breakpoint $linespec
38 gdb_continue_to_breakpoint $linespec $location
39 }
40
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} {
44 upvar $thearray ar
45
46 lappend ar(linespecs) $linespec
47 lappend ar(locations) $location
48 }
49
50 # Some locations used in this test
51 variable lineno
52 variable location
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)"].*"
59 }
60
61 # A list of explicit linespecs and the corresponding location
62 variable linespecs
63 set linespecs(linespecs) {}
64 set linespecs(location) {}
65
66 add linespecs "-source $srcfile -function myclass::myfunction" \
67 $location(normal)
68 add linespecs "-source $srcfile -function myclass::myfunction -label top" \
69 $location(top)
70
71 # This isn't implemented yet; -line is silently ignored.
72 add linespecs \
73 "-source $srcfile -function myclass::myfunction -label top -line 3" \
74 $location(top)
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)
78
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" \
82 $location(top)
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)
87
88 # Fire up gdb.
89 if {![runto_main]} {
90 namespace delete $testfile
91 return -1
92 }
93
94 # Test explicit linespecs, with and without conditions.
95 foreach linespec $linespecs(linespecs) loc_pattern $linespecs(locations) {
96 # Test the linespec
97 test_breakpoint $linespec $loc_pattern
98 }
99
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)\\."
107 }
108
109 namespace delete $testfile