forked from Imagelibrary/binutils-gdb
This patch teaches GDB about setting breakpoints in all scopes
(namespaces and classes) by default.
Here's a contrived example:
(gdb) b func<tab>
(anonymous namespace)::A::function() Bn::(anonymous namespace)::B::function() function(int, int)
(anonymous namespace)::B::function() Bn::(anonymous namespace)::function() gdb::(anonymous namespace)::A::function()
(anonymous namespace)::B::function() const Bn::(anonymous namespace)::function(int, int) gdb::(anonymous namespace)::function()
(anonymous namespace)::function() Bn::B::func() gdb::(anonymous namespace)::function(int, int)
(anonymous namespace)::function(int, int) Bn::B::function() gdb::A::func()
A::func() Bn::func() gdb::A::function()
A::function() Bn::function() gdb::func()
B::func() Bn::function(int, int) gdb::function()
B::function() Bn::function(long) gdb::function(int, int)
B::function() const func() gdb::function(long)
B::function_const() const function()
(gdb) b function
Breakpoint 1 at 0x4005ce: function. (26 locations)
(gdb) b B::function<tab>
(anonymous namespace)::B::function() B::function() const Bn::B::function()
(anonymous namespace)::B::function() const B::function_const() const
B::function() Bn::(anonymous namespace)::B::function()
(gdb) b B::function
Breakpoint 1 at 0x40072c: B::function. (6 locations)
To get back the original behavior of interpreting the function name as
a fully-qualified name, you can use the new "-qualified" (or "-q")
option/flag (added by this commit). For example:
(gdb) b B::function
(anonymous namespace)::B::function() B::function() const Bn::B::function()
(anonymous namespace)::B::function() const B::function_const() const
B::function() Bn::(anonymous namespace)::B::function()
vs:
(gdb) b -qualified B::function
B::function() B::function() const B::function_const() const
I've chosen "-qualified" / "-q" because "-f" (for "full" or
"fully-qualified") is already taken for "-function".
Note: the "-qualified" option works with both linespecs and explicit
locations. I.e., these are equivalent:
(gdb) b -q func
(gdb) b -q -f func
and so are these:
(gdb) b -q filename.cc:func
(gdb) b -q -s filename.cc -f func
(gdb) b -s filename.cc -q -f func
(gdb) b -s filename.cc -f func -q
To better understand why I consider wild matching the better default,
consider what happens when we get to the point when _all_ of GDB is
wrapped under "namespace gdb {}". I have a patch series that does
that, and when I started debugging that GDB, I immediately became
frustrated. You'd have to write "b gdb::internal_error", "b
gdb::foo", "b gdb::bar", etc. etc., which gets annoying pretty
quickly. OTOH, consider how this makes it very easy to set
breakpoints in classes wrapped in anonymous namespaces. You just
don't think of them, GDB finds the symbols for you automatically.
(At the Cauldron a couple months ago, several people told me that they
run into a similar issue when debugging other C++ projects. One
example was when debugging LLVM, which puts all its code under the
"llvm" namespace.)
Implementation-wise, what the patch does is:
- makes C++ symbol name hashing only consider the last component of
a symbol name. (so that we can look up symbol names by
last-component name only).
- adds a C++ symbol name matcher for symbol_name_match_type::WILD,
which ignores missing leading specifiers / components.
- adjusts a few preexisting testsuite tests to use "-qualified" when
they mean it.
- adds new testsuite tests.
- adds unit tests.
Grows the gdb.linespec/ tests like this:
-# of expected passes 7823
+# of expected passes 8977
gdb/ChangeLog:
2017-11-29 Pedro Alves <palves@redhat.com>
* NEWS: Mention that breakpoints on C++ functions are now set on
on all namespaces/classes by default, and mention "break
-qualified".
* ax-gdb.c (agent_command_1): Adjust to pass a
symbol_name_match_type to new_linespec_location.
* breakpoint.c (parse_breakpoint_sals): Adjust to
get_linespec_location's return type change.
(strace_marker_create_sals_from_location): Adjust to pass a
symbol_name_match_type to new_linespec_location.
(strace_marker_decode_location): Adjust to get_linespec_location's
return type change.
(strace_command): Adjust to pass a symbol_name_match_type to
new_linespec_location.
(LOCATION_HELP_STRING): Add paragraph about wildmatching, and
mention "-qualified".
* c-lang.c (cplus_language_defn): Install cp_search_name_hash.
* completer.c (explicit_location_match_type::MATCH_QUALIFIED): New
enumerator.
(complete_address_and_linespec_locations): New parameter
'match_type'. Pass it down.
(explicit_options): Add "-qualified".
(collect_explicit_location_matches): Pass the requested match type
to the linespec completers. Handle MATCH_QUALIFIED.
(location_completer): Handle "-qualified" combined with linespecs.
* cp-support.c (cp_search_name_hash): New.
(cp_symbol_name_matches_1): Implement wild matching for C++.
(cp_fq_symbol_name_matches): Reimplement.
(cp_get_symbol_name_matcher): Return different matchers depending
on the lookup name's match type.
(selftests::test_cp_symbol_name_matches): Add wild matching tests.
* cp-support.h (cp_search_name_hash): New declaration.
* dwarf2read.c
(selftests::dw2_expand_symtabs_matching::test_symbols): Add
symbols.
(test_dw2_expand_symtabs_matching_symbol): Add wild matching
tests.
* guile/scm-breakpoint.c (gdbscm_register_breakpoint_x): Adjust to
pass a symbol_name_match_type to new_linespec_location.
* linespec.c (linespec_parse_basic): Lookup function symbols using
the parser's symbol name match type.
(convert_explicit_location_to_linespec): New
symbol_name_match_type parameter. Pass it down to
find_linespec_symbols.
(convert_explicit_location_to_sals): Pass the location's name
match type to convert_explicit_location_to_linespec.
(parse_linespec): New match_type parameter. Save it in the
parser.
(linespec_parser_new): Default to symbol_name_match_type::WILD.
(linespec_complete_function): New symbol_name_match_type
parameter. Use it.
(complete_linespec_component): Pass down the parser's recorded
name match type.
(linespec_complete_label): New symbol_name_match_type parameter.
Use it.
(linespec_complete): New symbol_name_match_type parameter. Save
it in the parser and pass it down. Adjust to
get_linespec_location's prototype change.
(find_function_symbols, find_linespec_symbols): New
symbol_name_match_type parameter. Pass it down instead of
assuming symbol_name_match_type::WILD.
* linespec.h (linespec_complete, linespec_complete_function)
(linespec_complete_label): New symbol_name_match_type parameter.
* location.c (event_location::linespec_location): Now a struct
linespec_location.
(EL_LINESPEC): Adjust.
(initialize_explicit_location): Default to
symbol_name_match_type::WILD.
(new_linespec_location): New symbol_name_match_type parameter.
Record it in the location.
(get_linespec_location): Now returns a struct linespec_location.
(new_explicit_location): Also copy func_name_match_type.
(explicit_to_string_internal)
(string_to_explicit_location): Handle "-qualified".
(copy_event_location): Adjust to LINESPEC_LOCATION type change.
Copy symbol_name_match_type fields.
(event_location_deleter::operator()): Adjust to LINESPEC_LOCATION
type change.
(event_location_to_string): Adjust to LINESPEC_LOCATION type
change. Handle "-qualfied".
(string_to_explicit_location): Handle "-qualified".
(string_to_event_location_basic): New symbol_name_match_type
parameter. Pass it down.
(string_to_event_location): Handle "-qualified".
* location.h (struct linespec_location): New.
(explicit_location::func_name_match_type): New field.
(new_linespec_location): Now returns a const linespec_location *.
(string_to_event_location_basic): New symbol_name_match_type
parameter.
(explicit_completion_info::saw_explicit_location_option): New
field.
* mi/mi-cmd-break.c (mi_cmd_break_insert_1): Adjust to pass a
symbol_name_match_type to new_linespec_location.
* python/py-breakpoint.c (bppy_init): Likewise.
* python/python.c (gdbpy_decode_line): Likewise.
gdb/testsuite/ChangeLog:
2017-11-29 Pedro Alves <palves@redhat.com>
* gdb.base/langs.exp: Use -qualified.
* gdb.cp/meth-typedefs.exp: Use -qualified, and add tests without
it.
* gdb.cp/namespace.exp: Use -qualified.
* gdb.linespec/cpcompletion.exp (overload-2, fqn, fqn-2)
(overload-3, template-overload, template-ret-type, const-overload)
(const-overload-quoted, anon-ns, ambiguous-prefix): New
procedures.
(test_driver): Call them.
* gdb.cp/save-bp-qualified.cc: New.
* gdb.cp/save-bp-qualified.exp: New.
* gdb.linespec/explicit.exp: Test -qualified.
* lib/completion-support.exp (completion::explicit_opts_list): Add
"-qualified".
* lib/gdb.exp (gdb_breakpoint): Handle "qualified".
gdb/doc/ChangeLog:
2017-11-29 Pedro Alves <palves@redhat.com>
* gdb.texinfo (Linespec Locations): Document how "function" is
interpreted in C++ and Ada. Document "-qualified".
(Explicit Locations): Document how "-function" is interpreted in
C++ and Ada. Document "-qualified".
620 lines
18 KiB
Plaintext
620 lines
18 KiB
Plaintext
# Copyright 2012-2017 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 locations
|
|
|
|
load_lib completion-support.exp
|
|
|
|
standard_testfile explicit.c explicit2.c 3explicit.c
|
|
set exefile $testfile
|
|
|
|
if {[prepare_for_testing "failed to prepare" $exefile \
|
|
[list $srcfile $srcfile2 $srcfile3] {debug nowarnings}]} {
|
|
return -1
|
|
}
|
|
|
|
# Wrap the entire 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} {
|
|
|
|
set testname "set breakpoint at \"$linespec\""
|
|
# Delete all breakpoints, set a new breakpoint at LINESPEC,
|
|
# and attempt to run to it.
|
|
delete_breakpoints
|
|
if {[gdb_breakpoint $linespec]} {
|
|
pass $testname
|
|
send_log "\nexpecting locpattern \"$location\"\n"
|
|
gdb_continue_to_breakpoint $linespec $location
|
|
} else {
|
|
fail $testname
|
|
}
|
|
}
|
|
|
|
# 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
|
|
}
|
|
|
|
# A list of all explicit linespec arguments.
|
|
variable all_arguments
|
|
set all_arguments {"source" "function" "label" "line"}
|
|
|
|
# Some locations used in this test
|
|
variable lineno
|
|
variable location
|
|
set lineno(normal) [gdb_get_line_number "myfunction location" $srcfile]
|
|
set lineno(top) [gdb_get_line_number "top location" $srcfile]
|
|
foreach v [array names lineno] {
|
|
set location($v) ".*[string_to_regexp "$srcfile:$lineno($v)"].*"
|
|
}
|
|
|
|
# A list of explicit locations and the corresponding location.
|
|
variable linespecs
|
|
set linespecs(linespecs) {}
|
|
set linespecs(location) {}
|
|
|
|
add linespecs "-source $srcfile -function myfunction" $location(normal)
|
|
add linespecs "-source $srcfile -function myfunction -label top" \
|
|
$location(top)
|
|
|
|
# This isn't implemented yet; -line is silently ignored.
|
|
add linespecs "-source $srcfile -function myfunction -label top -line 3" \
|
|
$location(top)
|
|
add linespecs "-source $srcfile -line $lineno(top)" $location(top)
|
|
add linespecs "-function myfunction" $location(normal)
|
|
add linespecs "-function myfunction -label top" $location(top)
|
|
|
|
# These are also not yet supported; -line is silently ignored.
|
|
add linespecs "-function myfunction -line 3" $location(normal)
|
|
add linespecs "-function myfunction -label top -line 3" $location(top)
|
|
add linespecs "-line 3" $location(normal)
|
|
|
|
# Fire up gdb.
|
|
if {![runto_main]} {
|
|
return -1
|
|
}
|
|
|
|
# Turn off queries
|
|
gdb_test_no_output "set confirm off"
|
|
|
|
# Simple error tests (many more are tested in ls-err.exp)
|
|
foreach arg $all_arguments {
|
|
# Test missing argument
|
|
gdb_test "break -$arg" \
|
|
[string_to_regexp "missing argument for \"-$arg\""]
|
|
|
|
# Test abbreviations
|
|
set short [string range $arg 0 3]
|
|
gdb_test "break -$short" \
|
|
[string_to_regexp "missing argument for \"-$short\""]
|
|
}
|
|
|
|
# Test invalid arguments
|
|
foreach arg {"-foo" "-foo bar" "-function myfunction -foo" \
|
|
"-function -myfunction -foo bar"} {
|
|
gdb_test "break $arg" \
|
|
[string_to_regexp "invalid explicit location argument, \"-foo\""]
|
|
}
|
|
|
|
# Test explicit locations, with and without conditions.
|
|
# For these tests, it is easiest to turn of pending breakpoint.
|
|
gdb_test_no_output "set breakpoint pending off" \
|
|
"turn off pending breakpoints"
|
|
|
|
foreach linespec $linespecs(linespecs) loc_pattern $linespecs(locations) {
|
|
|
|
# Test the linespec
|
|
test_breakpoint $linespec $loc_pattern
|
|
|
|
# Test with a valid condition
|
|
delete_breakpoints
|
|
set tst "set breakpoint at \"$linespec\" with valid condition"
|
|
if {[gdb_breakpoint "$linespec if arg == 0"]} {
|
|
pass $tst
|
|
|
|
gdb_test "info break" ".*stop only if arg == 0.*" \
|
|
"info break of conditional breakpoint at \"$linespec\""
|
|
} else {
|
|
fail $tst
|
|
}
|
|
|
|
# Test with invalid condition
|
|
gdb_test "break $linespec if foofoofoo == 1" \
|
|
".*No symbol \"foofoofoo\" in current context.*" \
|
|
"set breakpoint at \"$linespec\" with invalid condition"
|
|
|
|
# Test with thread
|
|
delete_breakpoints
|
|
gdb_test "break $linespec thread 123" "Unknown thread 123."
|
|
}
|
|
|
|
# Tests below are about tab-completion, which doesn't work if readline
|
|
# library isn't used. Check it first.
|
|
if { [readline_is_used] } {
|
|
|
|
# Test the explicit location completer
|
|
foreach abbrev {"fun" "so" "lab" "li"} full {"function" "source" "label" "line"} {
|
|
set tst "complete 'break -$abbrev'"
|
|
send_gdb "break -${abbrev}\t"
|
|
gdb_test_multiple "" $tst {
|
|
-re "break -$full " {
|
|
send_gdb "\n"
|
|
gdb_test_multiple "" $tst {
|
|
-re "missing argument for \"-$full\".*$gdb_prompt " {
|
|
pass $tst
|
|
}
|
|
}
|
|
}
|
|
}
|
|
set tst "complete -$full with no value"
|
|
send_gdb "break -$full \t"
|
|
gdb_test_multiple "" $tst {
|
|
-re ".*break -$full " {
|
|
send_gdb "\n"
|
|
gdb_test_multiple "" $tst {
|
|
-re ".*Source filename requires function, label, or line offset\..*$gdb_prompt " {
|
|
if {[string equal $full "source"]} {
|
|
pass $tst
|
|
} else {
|
|
fail $tst
|
|
}
|
|
}
|
|
-re "missing argument for \"-$full\".*$gdb_prompt " {
|
|
pass $tst
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
set tst "complete unique function name"
|
|
send_gdb "break -function my_unique_func\t"
|
|
gdb_test_multiple "" $tst {
|
|
-re "break -function my_unique_function_name" {
|
|
send_gdb "\n"
|
|
gdb_test "" ".*Breakpoint \[0-9\]+.*" $tst
|
|
gdb_test_no_output "delete \$bpnum" "delete $tst breakpoint"
|
|
}
|
|
}
|
|
|
|
set tst "complete non-unique function name"
|
|
send_gdb "break -function myfunc\t"
|
|
gdb_test_multiple "" $tst {
|
|
-re "break -function myfunc\\\x07tion" {
|
|
send_gdb "\t\t"
|
|
gdb_test_multiple "" $tst {
|
|
-re "\\\x07\r\nmyfunction\[ \t\]+myfunction2\[ \t\]+myfunction3\[ \t\]+myfunction4\[ \t\]+\r\n$gdb_prompt " {
|
|
gdb_test "2" ".*Breakpoint \[0-9\]+.*" $tst
|
|
gdb_test_no_output "delete \$bpnum" "delete $tst breakpoint"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
set tst "complete non-existant function name"
|
|
send_gdb "break -function foo\t"
|
|
gdb_test_multiple "" $tst {
|
|
-re "break -function foo\\\x07" {
|
|
send_gdb "\t\t"
|
|
gdb_test_multiple "" $tst {
|
|
-re "\\\x07\\\x07" {
|
|
send_gdb "\n"
|
|
gdb_test "" {Function "foo" not defined.} $tst
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
with_test_prefix "complete unique file name" {
|
|
foreach qc $completion::maybe_quoted_list {
|
|
set cmd "break -source ${qc}3explicit.c${qc}"
|
|
test_gdb_complete_unique \
|
|
"break -source ${qc}3ex" \
|
|
$cmd
|
|
gdb_test $cmd \
|
|
{Source filename requires function, label, or line offset.}
|
|
}
|
|
}
|
|
|
|
set tst "complete non-unique file name"
|
|
send_gdb "break -source exp\t"
|
|
gdb_test_multiple "" $tst {
|
|
-re "break -source exp\\\x07licit" {
|
|
send_gdb "\t\t"
|
|
gdb_test_multiple "" $tst {
|
|
-re "\\\x07\r\nexplicit.c\[ \t\]+explicit2.c\[ \t\]+\r\n$gdb_prompt" {
|
|
send_gdb "\n"
|
|
gdb_test "" \
|
|
{Source filename requires function, label, or line offset.} \
|
|
$tst
|
|
}
|
|
}
|
|
}
|
|
|
|
-re "break -source exp\\\x07l" {
|
|
# This pattern may occur when glibc debuginfo is installed.
|
|
send_gdb "\t\t"
|
|
gdb_test_multiple "" $tst {
|
|
-re "\\\x07\r\nexplicit.c\[ \t\]+explicit2.c\[ \t\]+expl.*\r\n$gdb_prompt" {
|
|
send_gdb "\n"
|
|
gdb_test "" \
|
|
{Source filename requires function, label, or line offset.} \
|
|
$tst
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
set tst "complete non-existant file name"
|
|
send_gdb "break -source foo\t"
|
|
gdb_test_multiple "" $tst {
|
|
-re "break -source foo" {
|
|
send_gdb "\t\t"
|
|
gdb_test_multiple "" $tst {
|
|
-re "\\\x07\\\x07" {
|
|
send_gdb "\n"
|
|
gdb_test "" \
|
|
{Source filename requires function, label, or line offset.} \
|
|
$tst
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
set tst "complete filename and unique function name"
|
|
send_gdb "break -source explicit.c -function ma\t"
|
|
gdb_test_multiple "" $tst {
|
|
-re "break -source explicit.c -function main " {
|
|
send_gdb "\n"
|
|
gdb_test "" ".*Breakpoint .*" $tst
|
|
gdb_test_no_output "delete \$bpnum" "delete $tst breakpoint"
|
|
}
|
|
}
|
|
|
|
set tst "complete filename and non-unique function name"
|
|
send_gdb "break -so 3explicit.c -func myfunc\t"
|
|
gdb_test_multiple "" $tst {
|
|
-re "break -so 3explicit.c -func myfunc\\\x07tion" {
|
|
send_gdb "\t\t"
|
|
gdb_test_multiple "" $tst {
|
|
-re "\\\x07\r\nmyfunction3\[ \t\]+myfunction4\[ \t\]+\r\n$gdb_prompt " {
|
|
gdb_test "3" ".*Breakpoint \[0-9\]+.*" $tst
|
|
gdb_test_no_output "delete \$bpnum" "delete $tst breakpoint"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
set tst "complete filename and non-existant function name"
|
|
send_gdb "break -sou 3explicit.c -fun foo\t"
|
|
gdb_test_multiple "" $tst {
|
|
-re "break -sou 3explicit.c -fun foo\\\x07" {
|
|
send_gdb "\t\t"
|
|
gdb_test_multiple "" $tst {
|
|
-re "\\\x07\\\x07" {
|
|
send_gdb "\n"
|
|
gdb_test "" \
|
|
{Function "foo" not defined in "3explicit.c".} $tst
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
set tst "complete filename and function reversed"
|
|
send_gdb "break -func myfunction4 -source 3ex\t"
|
|
gdb_test_multiple "" $tst {
|
|
-re "break -func myfunction4 -source 3explicit.c " {
|
|
send_gdb "\n"
|
|
gdb_test "" "Breakpoint \[0-9\]+.*" $tst
|
|
gdb_test_no_output "delete \$bpnum" "delete $tst breakpoint"
|
|
}
|
|
}
|
|
|
|
with_test_prefix "complete unique label name" {
|
|
foreach qc $completion::maybe_quoted_list {
|
|
test_gdb_complete_unique \
|
|
"break -function myfunction -label ${qc}to" \
|
|
"break -function myfunction -label ${qc}top${qc}"
|
|
}
|
|
}
|
|
|
|
with_test_prefix "complete unique label name with source file" {
|
|
test_gdb_complete_unique \
|
|
"break -source explicit.c -function myfunction -label to" \
|
|
"break -source explicit.c -function myfunction -label top"
|
|
}
|
|
|
|
with_test_prefix "complete unique label name reversed" {
|
|
test_gdb_complete_multiple "b -label top -function " "myfunction" "" {
|
|
"myfunction"
|
|
"myfunction2"
|
|
"myfunction3"
|
|
"myfunction4"
|
|
}
|
|
}
|
|
|
|
with_test_prefix "complete non-unique label name" {
|
|
test_gdb_complete_multiple "b -function myfunction -label " "" "" {
|
|
"done"
|
|
"top"
|
|
}
|
|
}
|
|
|
|
# The program is stopped at myfunction, so gdb is able to
|
|
# infer the label's function.
|
|
with_test_prefix "complete label name with no function" {
|
|
test_gdb_complete_unique \
|
|
"break -label to" \
|
|
"break -label top"
|
|
check_bp_locations_match_list \
|
|
"break -label top" {
|
|
"-function myfunction -label top"
|
|
}
|
|
}
|
|
|
|
# See above.
|
|
with_test_prefix "complete label name with source file but no function" {
|
|
test_gdb_complete_unique \
|
|
"break -source explicit.c -label to" \
|
|
"break -source explicit.c -label top"
|
|
check_bp_locations_match_list \
|
|
"break -source explicit.c -label top" {
|
|
"-source explicit.c -function myfunction -label top"
|
|
}
|
|
}
|
|
|
|
with_test_prefix "complete label name with wrong source file" {
|
|
test_gdb_complete_none \
|
|
"break -source explicit2.c -function myfunction -label to"
|
|
check_setting_bp_fails \
|
|
"break -source explicit2.c -function myfunction -label top"
|
|
}
|
|
|
|
# Get rid of symbols from shared libraries, otherwise
|
|
# "b -source thr<tab>" could find some system library's
|
|
# source.
|
|
gdb_test_no_output "nosharedlibrary"
|
|
|
|
# Test that after a seemingly finished option argument,
|
|
# completion matches both the explicit location options and
|
|
# the linespec keywords.
|
|
set completions_list {
|
|
"-function"
|
|
"-label"
|
|
"-line"
|
|
"-qualified"
|
|
"-source"
|
|
"if"
|
|
"task"
|
|
"thread"
|
|
}
|
|
foreach what { "-function" "-label" "-line" "-source" } {
|
|
# Also test with "-qualified" appearing before the
|
|
# explicit location.
|
|
foreach prefix {"" "-qualified "} {
|
|
|
|
# ... and with "-qualified" appearing after the
|
|
# explicit location.
|
|
foreach suffix {"" " -qualified"} {
|
|
with_test_prefix "complete after $prefix$what$suffix" {
|
|
if {$what != "-line"} {
|
|
set w "$prefix$what argument$suffix "
|
|
test_gdb_complete_multiple \
|
|
"b $w" "" "" $completions_list
|
|
test_gdb_complete_unique \
|
|
"b $w thr" \
|
|
"b $w thread"
|
|
test_gdb_complete_unique \
|
|
"b $w -fun" \
|
|
"b $w -function"
|
|
} else {
|
|
# After -line, we expect a number / offset.
|
|
foreach line {"10" "+10" "-10"} {
|
|
set w "$prefix-line $line$suffix"
|
|
test_gdb_complete_multiple \
|
|
"b $w " "" "" $completions_list
|
|
test_gdb_complete_unique \
|
|
"b $w thr" \
|
|
"b $w thread"
|
|
test_gdb_complete_unique \
|
|
"b $w -fun" \
|
|
"b $w -function"
|
|
}
|
|
|
|
# With an invalid -line argument, we don't get any
|
|
# completions.
|
|
test_gdb_complete_none "b $prefix-line argument$suffix "
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# These tests don't make sense with "-qualified" after
|
|
# the location.
|
|
with_test_prefix "complete after $prefix$what" {
|
|
# Don't complete a linespec keyword ("thread") or
|
|
# another option name when expecting an option
|
|
# argument.
|
|
test_gdb_complete_none "b $prefix$what thr"
|
|
test_gdb_complete_none "b $prefix$what -fun"
|
|
}
|
|
}
|
|
}
|
|
|
|
# Tests that ensure that after "if" we complete on expressions
|
|
# are in cpcompletion.exp.
|
|
|
|
# Disable the completion limit for the rest of the testcase.
|
|
gdb_test_no_output "set max-completions unlimited"
|
|
|
|
# Get rid of symbols from shared libraries, otherwise the
|
|
# completions match list for "break <tab>" is huge and makes
|
|
# the test below quite long while the gdb_test_multiple loop
|
|
# below consumes the matches. Not doing this added ~20
|
|
# seconds at the time of writing. (Actually, already done above.)
|
|
# gdb_test_no_output "nosharedlibrary"
|
|
|
|
# Test completion with no input argument. We should see all
|
|
# the options, plus all the functions. To keep it simple, as
|
|
# proxy, we check for presence of one explicit location
|
|
# option, one probe location, and one function.
|
|
set saw_opt_function 0
|
|
set saw_opt_probe_stap 0
|
|
set saw_function 0
|
|
|
|
set tst "complete with no arguments"
|
|
send_gdb "break \t"
|
|
gdb_test_multiple "" $tst {
|
|
"break \\\x07" {
|
|
send_gdb "\t\t"
|
|
gdb_test_multiple "" $tst {
|
|
"Display all" {
|
|
send_gdb "y"
|
|
exp_continue
|
|
}
|
|
-re "-function" {
|
|
set saw_opt_function 1
|
|
exp_continue
|
|
}
|
|
-re "-probe-stap" {
|
|
set saw_opt_probe_stap 1
|
|
exp_continue
|
|
}
|
|
-re "myfunction4" {
|
|
set saw_function 1
|
|
exp_continue
|
|
}
|
|
-re "\r\n$gdb_prompt " {
|
|
gdb_assert {$saw_opt_function && $saw_opt_probe_stap && $saw_function} $tst
|
|
}
|
|
-re " " {
|
|
exp_continue
|
|
}
|
|
}
|
|
}
|
|
}
|
|
clear_input_line $tst
|
|
|
|
# NOTE: We don't bother testing more elaborate combinations of options,
|
|
# such as "-func main -sour 3ex\t" (main is defined in explicit.c).
|
|
# The completer cannot handle these yet.
|
|
|
|
# The following completion tests require having no symbols
|
|
# loaded.
|
|
gdb_exit
|
|
gdb_start
|
|
|
|
# The match list you get when you complete with no options
|
|
# specified at all.
|
|
set completion_list {
|
|
"-function"
|
|
"-label"
|
|
"-line"
|
|
"-probe"
|
|
"-probe-dtrace"
|
|
"-probe-stap"
|
|
"-qualified"
|
|
"-source"
|
|
}
|
|
with_test_prefix "complete with no arguments and no symbols" {
|
|
test_gdb_complete_multiple "b " "" "-" $completion_list
|
|
test_gdb_complete_multiple "b " "-" "" $completion_list
|
|
}
|
|
}
|
|
# End of completion tests.
|
|
|
|
# Test pending explicit breakpoints
|
|
gdb_exit
|
|
gdb_start
|
|
|
|
set tst "pending invalid conditional explicit breakpoint"
|
|
if {![gdb_breakpoint "-func myfunction if foofoofoo == 1" \
|
|
allow-pending]} {
|
|
fail "set $tst"
|
|
} else {
|
|
gdb_test "info break" ".*PENDING.*myfunction if foofoofoo == 1.*" $tst
|
|
}
|
|
|
|
gdb_exit
|
|
gdb_start
|
|
|
|
set tst "pending valid conditional explicit breakpoint"
|
|
if {![gdb_breakpoint "-func myfunction if arg == 0" \
|
|
allow-pending]} {
|
|
fail "set $tst"
|
|
} else {
|
|
gdb_test "info break" ".*PENDING.*myfunction if arg == 0" $tst
|
|
|
|
gdb_load [standard_output_file $exefile]
|
|
gdb_test "info break" \
|
|
".*in myfunction at .*$srcfile:.*stop only if arg == 0.*" \
|
|
"$tst resolved"
|
|
}
|
|
|
|
# Test interaction of condition command and explicit linespec conditons.
|
|
gdb_exit
|
|
gdb_start
|
|
gdb_load [standard_output_file $exefile]
|
|
|
|
set tst "condition_command overrides explicit linespec condition"
|
|
if {![runto main]} {
|
|
fail $tst
|
|
} else {
|
|
if {![gdb_breakpoint "-func myfunction if arg == 1"]} {
|
|
fail "set breakpoint with condition 'arg == 1'"
|
|
} else {
|
|
gdb_test_no_output "cond 2 arg == 0" \
|
|
"set new breakpoint condition for explicit linespec"
|
|
|
|
gdb_continue_to_breakpoint $tst $location(normal)
|
|
}
|
|
}
|
|
|
|
gdb_test "cond 2" [string_to_regexp "Breakpoint 2 now unconditional."] \
|
|
"clear condition for explicit breakpoint"
|
|
set tst "info break of cleared condition of explicit breakpoint"
|
|
gdb_test_multiple "info break" $tst {
|
|
-re ".*in myfunction at .*$srcfile:.*stop only if arg == 0.*" {
|
|
fail $tst
|
|
}
|
|
-re ".*in myfunction at .*$srcfile:.*$gdb_prompt $" {
|
|
pass $tst
|
|
}
|
|
}
|
|
|
|
# Test explicit "ranges." Make sure that using explicit
|
|
# locations doesn't alter the expected outcome.
|
|
gdb_test "list main" ".*" "list main 1"
|
|
set list_result [capture_command_output "list -,+" ""]
|
|
gdb_test "list main" ".*" "list main 2"
|
|
gdb_test "list -line -,-line +" [string_to_regexp $list_result]
|
|
|
|
# Ditto for the reverse (except that no output is expected).
|
|
gdb_test "list myfunction" ".*" "list myfunction 1"
|
|
gdb_test_no_output "list +,-"
|
|
gdb_test "list myfunction" ".*" "list myfunction 2"
|
|
gdb_test_no_output "list -line +, -line -"
|
|
}
|
|
|
|
namespace delete $testfile
|