old-cross-binutils/gdb/testsuite/gdb.linespec/cpexplicit.exp

113 lines
3.9 KiB
Text
Raw Normal View History

# Copyright 2012-2016 Free Software Foundation, Inc.
Explicit locations: add UI features for CLI This patch exposes explicit locations to the CLI user. This enables users to "explicitly" specify attributes of the breakpoint location to avoid any ambiguity that might otherwise exist with linespecs. The general syntax of explicit locations is: -source SOURCE_FILENAME -line {+-}LINE -function FUNCTION_NAME -label LABEL_NAME Option names may be abbreviated, e.g., "-s SOURCE_FILENAME -li 3" and users may use the completer with either options or values. gdb/ChangeLog: * completer.c: Include location.h. (enum match_type): New enum. (location_completer): Rename to ... (linespec_completer): ... this. (collect_explicit_location_matches, backup_text_ptr) (explicit_location_completer): New functions. (location_completer): "New" function; handle linespec and explicit location completions. (complete_line_internal): Remove all location completer-specific handling. * linespec.c (linespec_lexer_lex_keyword, is_ada_operator) (find_toplevel_char): Export. (linespec_parse_line_offset): Export. Issue error if STRING is not numerical. (gdb_get_linespec_parser_quote_characters): New function. * linespec.h (linespec_parse_line_offset): Declare. (get_gdb_linespec_parser_quote_characters): Declare. (is_ada_operator): Declare. (find_toplevel_char): Declare. (linespec_lexer_lex_keyword): Declare. * location.c (explicit_to_event_location): New function. (explicit_location_lex_one): New function. (string_to_explicit_location): New function. (string_to_event_location): Handle explicit locations. * location.h (explicit_to_event_location): Declare. (string_to_explicit_location): Declare. gdb/testsuite/ChangeLog: * gdb.linespec/3explicit.c: New file. * gdb.linespec/cpexplicit.cc: New file. * gdb.linespec/cpexplicit.exp: New file. * gdb.linespec/explicit.c: New file. * gdb.linespec/explicit.exp: New file. * gdb.linespec/explicit2.c: New file. * gdb.linespec/ls-errs.exp: Add explicit location tests. * lib/gdb.exp (capture_command_output): Regexp-escape `command' before using in the matching pattern. Clarify that `prefix' is a regular expression.
2015-08-12 00:09:36 +00:00
# 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 $testfile $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