summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.linespec/cpexplicit.exp
blob: 4f8c41b015b2ccd0ca34bf53ee13710c870e08e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Copyright 2012-2021 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Tests for explicit linespecs

if {[skip_cplus_tests]} {
    unsupported "skipping C++ tests"
    return
}

standard_testfile .cc
set exefile $testfile

if {[prepare_for_testing "failed to prepare" $exefile $srcfile \
	 {c++ debug nowarnings}]} {
    return -1
}

# Wrap this whole test in a namespace to avoid contaminating other tests.
namespace eval $testfile {
    # Test the given (explicit) LINESPEC which should cause gdb to break
    # at LOCATION.
    proc test_breakpoint {linespec location} {

	# Delete all breakpoints, set a new breakpoint at LINESPEC,
	# and attempt to run to it.
	delete_breakpoints
	gdb_breakpoint $linespec
	gdb_continue_to_breakpoint $linespec $location
    }

    # Add the given LINESPEC to the array named in THEARRAY.  GDB is expected
    # to stop at LOCATION.
    proc add {thearray linespec location} {
	upvar $thearray ar

	lappend ar(linespecs) $linespec
	lappend ar(locations) $location
    }

    # Some locations used in this test
    variable lineno
    variable location
    set lineno(normal) [gdb_get_line_number "myfunction location" $srcfile]
    set lineno(entry) [gdb_get_line_number "entry location" $srcfile]
    set lineno(top) [gdb_get_line_number "top location" $srcfile]
    set lineno(operator) [gdb_get_line_number "operator location" $srcfile]
    foreach v [array names lineno] {
	set location($v) ".*[string_to_regexp "$srcfile:$lineno($v)"].*"
    }

    # A list of explicit linespecs and the corresponding location
    variable linespecs
    set linespecs(linespecs) {}
    set linespecs(location) {}

    add linespecs "-source $srcfile -function myclass::myfunction" \
	$location(normal)
    add linespecs "-source $srcfile -function myclass::myfunction -label top" \
	$location(top)

    # This isn't implemented yet; -line is silently ignored.
    add linespecs \
	"-source $srcfile -function myclass::myfunction -label top -line 3" \
	$location(top)
    add linespecs "-source $srcfile -line $lineno(top)" $location(top)
    add linespecs "-function myclass::myfunction" $location(normal)
    add linespecs "-function myclass::myfunction -label top" $location(top)

    # These are also not yet supported; -line is silently ignored.
    add linespecs "-function myclass::myfunction -line 3" $location(normal)
    add linespecs "-function myclass::myfunction -label top -line 3" \
	$location(top)
    add linespecs "-line 3" $location(normal)
    add linespecs "-function myclass::operator," $location(operator)
    add linespecs "-function 'myclass::operator,'" $location(operator)
    add linespecs "-function \"myclass::operator,\"" $location(operator)

    # Fire up gdb.
    if {![runto_main]} {
	namespace delete $testfile
	return -1
    }

    # Test explicit linespecs, with and without conditions.
    foreach linespec $linespecs(linespecs) loc_pattern $linespecs(locations) {
	# Test the linespec
	test_breakpoint $linespec $loc_pattern
    }

    # Special (orphaned) dprintf cases.
    gdb_test "dprintf -function myclass::operator,,\"hello\"" \
	"Dprintf .*$srcfile, line $lineno(operator)\\."
    gdb_test "dprintf -function 'myclass::operator,',\"hello\"" \
	"Dprintf .*$srcfile, line $lineno(operator)\\."
    gdb_test "dprintf -function \"myclass::operator,\",\"hello\"" \
	"Dprintf .*$srcfile, line $lineno(operator)\\."
}

namespace delete $testfile