Explicit locations: add UI features for CLI
[external/binutils.git] / gdb / testsuite / gdb.linespec / cpexplicit.exp
1 # Copyright 2012-2015 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 if {[skip_cplus_tests]} {
19     unsupported "skipping C++ tests"
20     return
21 }
22
23 standard_testfile .cc
24 set exefile $testfile
25
26 if {[prepare_for_testing $testfile $exefile $srcfile \
27          {c++ debug nowarnings}]} {
28     return -1
29 }
30
31 # Wrap this whole test in a namespace to avoid contaminating other tests.
32 namespace eval $testfile {
33     # Test the given (explicit) LINESPEC which should cause gdb to break
34     # at LOCATION.
35     proc test_breakpoint {linespec location} {
36
37         # Delete all breakpoints, set a new breakpoint at LINESPEC,
38         # and attempt to run to it.
39         delete_breakpoints
40         gdb_breakpoint $linespec
41         gdb_continue_to_breakpoint $linespec $location
42     }
43
44     # Add the given LINESPEC to the array named in THEARRAY.  GDB is expected
45     # to stop at LOCATION.
46     proc add {thearray linespec location} {
47         upvar $thearray ar
48
49         lappend ar(linespecs) $linespec
50         lappend ar(locations) $location
51     }
52
53     # Some locations used in this test
54     variable lineno
55     variable location
56     set lineno(normal) [gdb_get_line_number "myfunction location" $srcfile]
57     set lineno(entry) [gdb_get_line_number "entry location" $srcfile]
58     set lineno(top) [gdb_get_line_number "top location" $srcfile]
59     set lineno(operator) [gdb_get_line_number "operator location" $srcfile]
60     foreach v [array names lineno] {
61         set location($v) ".*[string_to_regexp "$srcfile:$lineno($v)"].*"
62     }
63
64     # A list of explicit linespecs and the corresponding location
65     variable linespecs
66     set linespecs(linespecs) {}
67     set linespecs(location) {}
68
69     add linespecs "-source $srcfile -function myclass::myfunction" \
70         $location(normal)
71     add linespecs "-source $srcfile -function myclass::myfunction -label top" \
72         $location(top)
73
74     # This isn't implemented yet; -line is silently ignored.
75     add linespecs \
76         "-source $srcfile -function myclass::myfunction -label top -line 3" \
77         $location(top)
78     add linespecs "-source $srcfile -line $lineno(top)" $location(top)
79     add linespecs "-function myclass::myfunction" $location(normal)
80     add linespecs "-function myclass::myfunction -label top" $location(top)
81
82     # These are also not yet supported; -line is silently ignored.
83     add linespecs "-function myclass::myfunction -line 3" $location(normal)
84     add linespecs "-function myclass::myfunction -label top -line 3" \
85         $location(top)
86     add linespecs "-line 3" $location(normal)
87     add linespecs "-function myclass::operator," $location(operator)
88     add linespecs "-function 'myclass::operator,'" $location(operator)
89     add linespecs "-function \"myclass::operator,\"" $location(operator)
90
91     # Fire up gdb.
92     if {![runto_main]} {
93         namespace delete $testfile
94         return -1
95     }
96
97     # Test explicit linespecs, with and without conditions.
98     foreach linespec $linespecs(linespecs) loc_pattern $linespecs(locations) {
99         # Test the linespec
100         test_breakpoint $linespec $loc_pattern
101     }
102
103     # Special (orphaned) dprintf cases.
104     gdb_test "dprintf -function myclass::operator,,\"hello\"" \
105         "Dprintf .*$srcfile, line $lineno(operator)\\."
106     gdb_test "dprintf -function 'myclass::operator,',\"hello\"" \
107         "Dprintf .*$srcfile, line $lineno(operator)\\."
108     gdb_test "dprintf -function \"myclass::operator,\",\"hello\"" \
109         "Dprintf .*$srcfile, line $lineno(operator)\\."
110 }
111
112 namespace delete $testfile