[PATCH v2 4/4] Fix parameter-less template regression in new DWARF reader

Simon Marchi simark@simark.ca
Tue Jan 17 18:09:44 GMT 2023


On 1/10/23 13:33, Tom Tromey via Gdb-patches wrote:
> PR c++/29896 points out a regression in the new DWARF reader.  It does
> not properly handle a case like "break fn", where "fn" is a template
> function.
> 
> This happens because the new index uses strncasecmp to compare.
> However, to make this work correctly, we need a custom function that
> ignores template parameters.
> 
> This patch adds a custom comparison function and fixes the bug.  A new
> test case is included.
> 
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29896

Starting with this patch, I get (using _GLIBCXX_DEBUG):

$83 = {void (void)} 0x555555556a82 <flubber<short, int, short, int, short>()>
(gdb) PASS: gdb.cp/cpexprs-debug-types.exp: print flubber<short, int, short, int, short>
print policy1::function
/usr/include/c++/11/bits/stl_algo.h:2105:
In function:
    _FIter std::upper_bound(_FIter, _FIter, const _Tp&, _Compare) [with
    _FIter = gnu_debug::_Safe_iterator<gnu_cxx::
    normal_iterator<cooked_index_entry**, std::vector<cooked_index_entry*,
    std::allocator<cooked_index_entry*> > >, std::
    debug::vector<cooked_index_entry*>, std::random_access_iterator_tag>;
    _Tp = std::cxx11::basic_string<char>; _Compare =
    cooked_index::find(const string&, bool)::<lambda(const string&, const
    cooked_index_entry*)>]

Error: elements in iterator range [first, last) are not partitioned by the
predicate __comp and value __val.

Objects involved in the operation:
    iterator "first" @ 0x7ffcb7cf5430 {
      type = gnu_cxx::normal_iterator<cooked_index_entry**, std::vector<cooked_index_entry*, std::allocator<cooked_index_entry*> > > (mutable iterator);
      state = dereferenceable (start-of-sequence);
      references sequence with type 'std::debug::vector<cooked_index_entry*, std::allocator<cooked_index_entry*> >' @ 0x611000098758
    }
    iterator "last" @ 0x7ffcb7cf5480 {
      type = gnu_cxx::normal_iterator<cooked_index_entry**, std::vector<cooked_index_entry*, std::allocator<cooked_index_entry*> > > (mutable iterator);
      state = past-the-end;
      references sequence with type 'std::debug::vector<cooked_index_entry*, std::allocator<cooked_index_entry*> >' @ 0x611000098758
    }


Fatal signal: Aborted
----- Backtrace -----
0x560e18f13e2f gdb_internal_backtrace_1
        /home/smarchi/src/binutils-gdb/gdb/bt-utils.c:122
0x560e18f14325 _Z22gdb_internal_backtracev
        /home/smarchi/src/binutils-gdb/gdb/bt-utils.c:168
0x560e19b71251 handle_fatal_signal
        /home/smarchi/src/binutils-gdb/gdb/event-top.c:956
0x7f0ac36a251f ???
0x7f0ac36f6a7c ???
0x7f0ac36a2475 ???
0x7f0ac36887f2 ???
0x7f0ac4069240 ???
0x560e1956f665 upper_bound<__gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<cooked_index_entry**, std::__cxx1998::vector<cooked_index_entry*, std::allocator<cooked_index_entry*> > >, std::__debug::vector<cooked_index_entry*>, std::random_access_iterator_tag>, std::__cxx11::basic_string<char>, cooked_index::find(const string&, bool)::<lambda(const string&, const cooked_index_entry*)> >
        /usr/include/c++/11/bits/stl_algo.h:2105
0x560e1956bd41 _ZN12cooked_index4findERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb
        /home/smarchi/src/binutils-gdb/gdb/dwarf2/cooked-index.c:376
0x560e1956d664 _ZN19cooked_index_vector4findERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb
        /home/smarchi/src/binutils-gdb/gdb/dwarf2/cooked-index.c:421
0x560e198a9748 _ZN22cooked_index_functions23expand_symtabs_matchingEP7objfileN3gdb13function_viewIFbPKcbEEEPK16lookup_name_infoNS3_IFbS5_EEENS3_IFbP15compunit_symtabEEE10enum_flagsI24block_search_flag_valuesE11domain_enum13search_domain
        /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:18747
0x560e1adc12c6 _ZN7objfile13lookup_symbolE10block_enumPKc11domain_enum
        /home/smarchi/src/binutils-gdb/gdb/symfile-debug.c:276
0x560e1ae99109 lookup_symbol_via_quick_fns
        /home/smarchi/src/binutils-gdb/gdb/symtab.c:2414
0x560e1ae99c80 lookup_symbol_in_objfile
        /home/smarchi/src/binutils-gdb/gdb/symtab.c:2543
0x560e1ae9a10a operator()
        /home/smarchi/src/binutils-gdb/gdb/symtab.c:2589
0x560e1aecff72 operator()
        /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/function-view.h:305
0x560e1aed000c _FUN
        /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/function-view.h:299
0x560e1a5cb694 _ZNK3gdb13function_viewIFbP7objfileEEclES2_
        /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/function-view.h:289
0x560e1ac74071 svr4_iterate_over_objfiles_in_search_order
        /home/smarchi/src/binutils-gdb/gdb/solib-svr4.c:3456
0x560e18b8b7a1 _Z45gdbarch_iterate_over_objfiles_in_search_orderP7gdbarchN3gdb13function_viewIFbP7objfileEEES4_
        /home/smarchi/src/binutils-gdb/gdb/gdbarch.c:4981
0x560e1ae9a8b3 lookup_global_or_static_symbol
        /home/smarchi/src/binutils-gdb/gdb/symtab.c:2586
0x560e1ae9ade2 _Z20lookup_global_symbolPKcPK5block11domain_enum
        /home/smarchi/src/binutils-gdb/gdb/symtab.c:2641
0x560e193f3f86 cp_basic_lookup_symbol
        /home/smarchi/src/binutils-gdb/gdb/cp-namespace.c:155
0x560e193fba75 cp_lookup_nested_symbol_1
        /home/smarchi/src/binutils-gdb/gdb/cp-namespace.c:884
0x560e193fc85a _Z23cp_lookup_nested_symbolP4typePKcPK5block11domain_enum
        /home/smarchi/src/binutils-gdb/gdb/cp-namespace.c:975
0x560e1900fcb0 classify_inner_name
        /home/smarchi/src/binutils-gdb/gdb/c-exp.y:3172
0x560e1901136e c_yylex
        /home/smarchi/src/binutils-gdb/gdb/c-exp.y:3322
0x560e18fe729c _Z9c_yyparsev
        /home/smarchi/build/binutils-gdb/gdb/c-exp.c.tmp:2023
0x560e1901349a _Z7c_parseP12parser_state
        /home/smarchi/src/binutils-gdb/gdb/c-exp.y:3420
0x560e1a096ec5 _ZNK13language_defn6parserEP12parser_state
        /home/smarchi/src/binutils-gdb/gdb/language.c:618
0x560e1a637374 parse_exp_in_context
        /home/smarchi/src/binutils-gdb/gdb/parse.c:515
0x560e1a637b81 _Z16parse_expressionPKcP23innermost_block_trackerb
        /home/smarchi/src/binutils-gdb/gdb/parse.c:551
0x560e1a64ea7c process_print_command_args
        /home/smarchi/src/binutils-gdb/gdb/printcmd.c:1305
0x560e1a64ec7c print_command_1
        /home/smarchi/src/binutils-gdb/gdb/printcmd.c:1319
0x560e1a64fb18 print_command
        /home/smarchi/src/binutils-gdb/gdb/printcmd.c:1452

Simon


More information about the Gdb-patches mailing list