diff options
author | Pedro Alves <palves@redhat.com> | 2017-11-29 19:33:24 +0000 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2017-11-29 19:46:41 +0000 |
commit | bd69330db86b2367aac8aac5915f1686451c9d5d (patch) | |
tree | b5eb5bd097e439561f74f8d2bf440a99104c0ce9 /gdb/testsuite/gdb.linespec | |
parent | a20714ff39f621961151d0c204e89062ab2107eb (diff) | |
download | fsf-binutils-gdb-bd69330db86b2367aac8aac5915f1686451c9d5d.zip fsf-binutils-gdb-bd69330db86b2367aac8aac5915f1686451c9d5d.tar.gz fsf-binutils-gdb-bd69330db86b2367aac8aac5915f1686451c9d5d.tar.bz2 |
Breakpoints in symbols with ABI tags (PR c++/19436)
Trying to set a breakpoint in a function with an ABI tag does not work
currently. E.g., debugging gdb itself, we see this with the
"string_printf" function:
(top-gdb) b string_print [TAB]
(top-gdb) b string_printf[abi:cxx11](char const*, ...) [RET]
No source file named string_printf[abi.
Make breakpoint pending on future shared library load? (y or [n])
Quoting doesn't help:
(top-gdb) b 'string_printf[abi:cxx11]'(char const*, ...)
malformed linespec error: unexpected string, "(char const*, ...)"
(top-gdb) b 'string_printf[abi:cxx11](char const*, ...)'
No source file named string_printf[abi.
Make breakpoint pending on future shared library load? (y or [n]) n
This patch fixes this, and takes it a bit further.
The actual symbol name as demangled by libiberty's demangler is really
string_printf[abi:cxx11](char const*, ...)
however, this patch makes it possible to set the breakpoint with
string_printf(char const*, ...)
too. I.e., ignoring the ABI tag.
And to match, it teaches the completer to complete the symbol name
without the ABI tag, i.e.,
"string_pri<TAB>" -> "string_printf(char const*, ...)"
If however, you really want to break on a symbol with the tag, then
you simply start writing the tag, and GDB will preserve it, like:
"string_printf[a<TAB>" -> "string_printf[abi:cxx11](char const*, ...)"
Grows the gdb.linespec/ tests like this:
-# of expected passes 8977
+# of expected passes 9176
gdb/ChangeLog:
2017-11-29 Pedro Alves <palves@redhat.com>
PR c++/19436
* NEWS: Mention setting breakpoints on functions with C++ ABI
tags.
* completer.h (completion_match_for_lcd) <match,
mark_ignored_range>: New methods.
<finish>: Consider ignored ranges.
<clear>: Clear ignored ranges.
<m_ignored_ranges, m_finished_storage>: New fields.
* cp-support.c (cp_search_name_hash): Ignore ABI tags.
(cp_symbol_name_matches_1, cp_fq_symbol_name_matches): Pass the
completion_match_for_lcd pointer to strncmp_iw_with_mode.
(test_cp_symbol_name_cmp): Add [abi:...] tags unit tests.
* language.c (default_symbol_name_matcher): Pass the
completion_match_for_lcd pointer to strncmp_iw_with_mode.
* linespec.c (linespec_lexer_lex_string): Don't tokenize ABI tags.
* utils.c (skip_abi_tag): New function.
(strncmp_iw_with_mode): Add completion_match_for_lcd parameter.
Handle ABI tags.
* utils.h (strncmp_iw_with_mode): Add completion_match_for_lcd
parameter.
gdb/testsuite/ChangeLog:
2017-11-29 Pedro Alves <palves@redhat.com>
PR c++/19436
* gdb.linespec/cpls-abi-tag.cc: New file.
* gdb.linespec/cpls-abi-tag.exp: New file.
gdb/doc/ChangeLog:
2017-11-29 Pedro Alves <palves@redhat.com>
PR c++/19436
* gdb.texinfo (Debugging C Plus Plus): Document setting
breakpoints in functions with ABI tags.
Diffstat (limited to 'gdb/testsuite/gdb.linespec')
-rw-r--r-- | gdb/testsuite/gdb.linespec/cpls-abi-tag.cc | 93 | ||||
-rw-r--r-- | gdb/testsuite/gdb.linespec/cpls-abi-tag.exp | 286 |
2 files changed, 379 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.linespec/cpls-abi-tag.cc b/gdb/testsuite/gdb.linespec/cpls-abi-tag.cc new file mode 100644 index 0000000..3916eda --- /dev/null +++ b/gdb/testsuite/gdb.linespec/cpls-abi-tag.cc @@ -0,0 +1,93 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 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/>. */ + +#define ABI1 __attribute__ ((abi_tag ("tag1"))) +#define ABI2 __attribute__ ((abi_tag ("tag2"))) +#define ABI3 __attribute__ ((abi_tag ("tag3"))) + +void ABI1 +test_abi_tag_function (int) +{ +} + +void ABI1 +test_abi_tag_ovld_function () +{ +} + +void ABI1 +test_abi_tag_ovld_function (int) +{ +} + +/* Code for the overload functions, different ABI tag test. */ + +void +test_abi_tag_ovld2_function () +{ +} + +void ABI1 +test_abi_tag_ovld2_function (short) +{ +} + +void ABI2 +test_abi_tag_ovld2_function (int) +{ +} + +void ABI2 +test_abi_tag_ovld2_function (long) +{ +} + +struct ABI1 test_abi_tag_struct +{ + ABI2 test_abi_tag_struct (); + ABI2 ~test_abi_tag_struct (); +}; + +test_abi_tag_struct::test_abi_tag_struct () +{} + +test_abi_tag_struct::~test_abi_tag_struct () +{} + +ABI3 test_abi_tag_struct s; + +/* Code for the abi-tag in parameters test. */ + +struct ABI2 abi_tag_param_struct1 +{}; + +struct ABI2 abi_tag_param_struct2 +{}; + +void +test_abi_tag_in_params (abi_tag_param_struct1) +{} + +void +test_abi_tag_in_params (abi_tag_param_struct1, abi_tag_param_struct2) +{} + +int +main () +{ + return 0; +} diff --git a/gdb/testsuite/gdb.linespec/cpls-abi-tag.exp b/gdb/testsuite/gdb.linespec/cpls-abi-tag.exp new file mode 100644 index 0000000..9a0dab3 --- /dev/null +++ b/gdb/testsuite/gdb.linespec/cpls-abi-tag.exp @@ -0,0 +1,286 @@ +# Copyright 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/>. + +# This file is part of the gdb testsuite. + +# Test ABI tag support in linespecs. + +load_lib completion-support.exp + +standard_testfile cpls-abi-tag.cc + +if {[prepare_for_testing "failed to prepare" $testfile \ + [list $srcfile] {c++ debug}]} { + return -1 +} + +gdb_test_no_output "set max-completions unlimited" + +# Check that the explicit location completer manages to find the next +# option name after a -function option, when the -function's argument +# is a function with an ABI tag. + +proc check_explicit_skips_function_argument {function} { + test_gdb_complete_unique \ + "b -function $function -sour" \ + "b -function $function -source" +} + +# The ABI tag tests. + +proc_with_prefix test_abi_tag {} { + with_test_prefix "completion" { + foreach cmd_prefix {"b" "b -function"} { + # Complete all prefixes between "_funcio" and the full + # prototype. The ABI tag is not considered for actual + # completion. + + with_test_prefix "skip tag" { + # set location "test_abi_tag_function\[abi:tag1\](int)" + set location "test_abi_tag_function(int)" + set line "$cmd_prefix $location" + set start [index_after "_functio" $line] + test_complete_prefix_range $line $start + } + + # Now the same, but start completing at the [. In that case, + # GDB considers the ABI tag as part of actual completion. + with_test_prefix "at tag" { + set location "test_abi_tag_function\[abi:tag1\](int)" + set line "$cmd_prefix $location" + set start [index_after "_function" $line] + test_complete_prefix_range $line $start + } + + # Same, but with extra spaces. Note that the original spaces in + # the input line are preserved after completion. + + with_test_prefix "spaces" { + test_gdb_complete_unique \ + "$cmd_prefix test_abi_tag_function \[abi:tag1\] (" \ + "$cmd_prefix test_abi_tag_function \[abi:tag1\] (int)" + + test_gdb_complete_unique \ + "$cmd_prefix test_abi_tag_function \[abi:tag1\] ( int " \ + "$cmd_prefix test_abi_tag_function \[abi:tag1\] ( int )" + } + } + } + + with_test_prefix "set breakpoints" { + foreach cmd_prefix {"b" "b -function"} { + # Test setting breakpoints. If the symbol name has an ABI + # tag, but the input linespec doesn't, then the ABI tag in the + # symbol name is ignored. + set linespec_list { + "test_abi_tag_function" + "test_abi_tag_function[abi:tag1]" + "test_abi_tag_function[abi:tag1](int)" + "test_abi_tag_function [abi:tag1]" + "test_abi_tag_function [abi:tag1] ( int )" + "test_abi_tag_function(int)" + "test_abi_tag_function (int)" + "test_abi_tag_function ( int )" + } + foreach linespec $linespec_list { + check_bp_locations_match_list \ + "$cmd_prefix $linespec" [list $location] + } + } + } + + with_test_prefix "set breakpoints wrong ABI tag" { + foreach cmd_prefix {"b" "b -function"} { + # Test setting breakpoints with the wrong ABI tag. Should + # fail to create the breakpoints. Completion should not find + # any match either. + set linespec_list { + "test_abi_tag_function[abi:tag2]" + "test_abi_tag_function[abi:tag2](int)" + "test_abi_tag_function [abi:tag2]" + "test_abi_tag_function [abi:tag2] ( int )" + } + foreach linespec $linespec_list { + check_setting_bp_fails "$cmd_prefix $linespec" + test_gdb_complete_none "$cmd_prefix $linespec" + } + + } + } + + # Test completion of overloaded functions with ABI tags. + with_test_prefix "completion of overloaded functions" { + foreach cmd_prefix {"b" "b -function"} { + set completion_list { + "test_abi_tag_ovld_function[abi:tag1]()" + "test_abi_tag_ovld_function[abi:tag1](int)" + } + + # If the input string does not include the ABI tag, then + # actual completion ignores it. + test_gdb_complete_multiple \ + "$cmd_prefix " "test_abi_tag_ovld_f" "unction(" \ + $completion_list + + # Otherwise, it's considered. + test_gdb_complete_multiple \ + "$cmd_prefix " "test_abi_tag_ovld_function\[" "abi:tag1\](" \ + $completion_list + + } + } + + # Test setting breakpoints on overloaded functions with ABI tags. + with_test_prefix "breakpoints on overloaded functions" { + foreach cmd_prefix {"b" "b -function"} { + set completion_list { + "test_abi_tag_ovld_function[abi:tag1]()" + "test_abi_tag_ovld_function[abi:tag1](int)" + } + set location_list { + "test_abi_tag_ovld_function" + "test_abi_tag_ovld_function[abi:tag1]" + } + foreach linespec $location_list { + check_bp_locations_match_list \ + "$cmd_prefix $linespec" $completion_list + } + + } + } + + with_test_prefix "completion of overloaded functions different abi" { + foreach cmd_prefix {"b" "b -function"} { + # Test completion of overloaded functions with ABI tags. + set completion_list { + "test_abi_tag_ovld2_function()" + "test_abi_tag_ovld2_function[abi:tag1](short)" + "test_abi_tag_ovld2_function[abi:tag2](int)" + "test_abi_tag_ovld2_function[abi:tag2](long)" + } + + # If the input string does not include the ABI tag, then + # actual completion ignores it. + test_gdb_complete_multiple \ + "$cmd_prefix " "test_abi_tag_ovld2_f" "unction(" \ + $completion_list + + # Otherwise, it's considered. Match stops at the part of + # the tag that diverges, and the completion list only + # shows matches with ABI tags. + set completion_list { + "test_abi_tag_ovld2_function[abi:tag1](short)" + "test_abi_tag_ovld2_function[abi:tag2](int)" + "test_abi_tag_ovld2_function[abi:tag2](long)" + } + test_gdb_complete_multiple \ + "$cmd_prefix " "test_abi_tag_ovld2_function\[" "abi:tag" \ + $completion_list + + # If you disambiguate, matches include only locations for + # the specified tag. + set completion_list { + "test_abi_tag_ovld2_function[abi:tag2](int)" + "test_abi_tag_ovld2_function[abi:tag2](long)" + } + test_gdb_complete_multiple \ + "$cmd_prefix " "test_abi_tag_ovld2_function\[abi:tag2" "\](" \ + $completion_list + + test_gdb_complete_unique \ + "$cmd_prefix test_abi_tag_ovld2_function\[abi:tag1" \ + "$cmd_prefix test_abi_tag_ovld2_function\[abi:tag1\](short)" + } + } + + with_test_prefix "completion of struct prefixes with tags" { + foreach cmd_prefix {"b" "b -function"} { + # Test completion of methods of structs with ABI tags. + set completion_list { + "test_abi_tag_struct[abi:tag1]::test_abi_tag_struct[abi:tag2]()" + "test_abi_tag_struct[abi:tag1]::~test_abi_tag_struct[abi:tag2]()" + } + + # If the input string does not include the ABI tag, then + # actual completion ignores it. + test_gdb_complete_multiple \ + "$cmd_prefix " "test_abi_tag_struc" "t::" \ + $completion_list + + # Otherwise, it's considered. + test_gdb_complete_multiple \ + "$cmd_prefix " "test_abi_tag_struct\[" "abi:tag1\]::" \ + $completion_list + + # Mix and match different abi tag positions. + test_gdb_complete_unique \ + "$cmd_prefix test_abi_tag_struct::t" \ + "$cmd_prefix test_abi_tag_struct::test_abi_tag_struct()" + + test_gdb_complete_unique \ + "$cmd_prefix test_abi_tag_struct\[abi:tag1\]::t" \ + "$cmd_prefix test_abi_tag_struct\[abi:tag1\]::test_abi_tag_struct()" + + test_gdb_complete_unique \ + "$cmd_prefix test_abi_tag_struct\[abi:tag1\]::test_abi_tag_struct\[" \ + "$cmd_prefix test_abi_tag_struct\[abi:tag1\]::test_abi_tag_struct\[abi:tag2\]()" + } + } + + with_test_prefix "abi tag in parameters" { + foreach cmd_prefix {"b" "b -function"} { + # Complete all prefixes between "_funcio" and the full + # prototype. The ABI tag is not considered for actual + # completion. + + set completion_list { + "test_abi_tag_in_params(abi_tag_param_struct1[abi:tag2])" + "test_abi_tag_in_params(abi_tag_param_struct1[abi:tag2], abi_tag_param_struct2[abi:tag2])" + } + # If the input string does not include the ABI tag, then + # actual completion ignores it. + test_gdb_complete_multiple \ + "$cmd_prefix " "test_abi_tag_in_para" "ms(abi_tag_param_struct1" \ + $completion_list + + # If OTOH the input string includes the ABI tag, then it + # is considered. + test_gdb_complete_multiple \ + "$cmd_prefix " "test_abi_tag_in_params(abi_tag_param_struct1\[ab" "i:tag2\]"\ + $completion_list + + set location_list { + "test_abi_tag_in_params(abi_tag_param_struct1[abi:tag2], abi_tag_param_struct2[abi:tag2])" + } + + set tags {"" "\[abi:tag2\]"} + foreach tag1 $tags { + foreach tag2 $tags { + set linespec "test_abi_tag_in_params(abi_tag_param_struct1${tag1}, abi_tag_param_struct2${tag2})" + check_bp_locations_match_list \ + "$cmd_prefix $linespec" $location_list + } + } + } + } + + # Check that the explicit location completer manages to find the + # option name after -function, when the -function's argument is a + # function with an ABI tag. + check_explicit_skips_function_argument \ + "test_abi_tag_function\[abi:unknown\](int)" +} + +test_abi_tag |