diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -2389,6 +2389,24 @@ ResolveFunction(die, include_inlines, sc_list); return true; }); + // With -gsimple-template-names, a templated type's DW_AT_name will not + // contain the template parameters. Try again stripping '<' and anything + // after, filtering out entries with template parameters that don't match. + { + const llvm::StringRef name_ref = name.GetStringRef(); + auto it = name_ref.find('<'); + if (it != llvm::StringRef::npos) { + const llvm::StringRef name_no_template_params = name_ref.slice(0, it); + + Module::LookupInfo no_tp_lookup_info(lookup_info); + no_tp_lookup_info.SetLookupName(ConstString(name_no_template_params)); + m_index->GetFunctions(no_tp_lookup_info, *this, parent_decl_ctx, [&](DWARFDIE die) { + if (resolved_dies.insert(die.GetDIE()).second) + ResolveFunction(die, include_inlines, sc_list); + return true; + }); + } + } // Return the number of variable that were appended to the list const uint32_t num_matches = sc_list.GetSize() - original_size; diff --git a/lldb/test/API/functionalities/breakpoint/cpp/TestCPPBreakpointLocations.py b/lldb/test/API/functionalities/breakpoint/cpp/TestCPPBreakpointLocations.py --- a/lldb/test/API/functionalities/breakpoint/cpp/TestCPPBreakpointLocations.py +++ b/lldb/test/API/functionalities/breakpoint/cpp/TestCPPBreakpointLocations.py @@ -12,7 +12,16 @@ @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24764") def test(self): - self.build() + self.do_test(dict()) + + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24764") + @skipIf(compiler=no_match("clang")) + @skipIf(compiler_version=["<", "15.0"]) + def test_simple_template_names(self): + self.do_test(dict(CFLAGS_EXTRAS="-gsimple-template-names")) + + def do_test(self, debug_flags): + self.build(dictionary=debug_flags) self.breakpoint_id_tests() def verify_breakpoint_locations(self, target, bp_dict): @@ -57,7 +66,11 @@ # Template cases {'name': 'func', 'loc_names': []}, + {'name': 'Foo::func', 'loc_names': []}, + {'name': 'ns::Foo::func', 'loc_names': []}, {'name': 'func', 'loc_names': ['auto ns::Foo::func()']}, + {'name': 'Foo::func', 'loc_names': ['auto ns::Foo::func()']}, + {'name': 'ns::Foo::func', 'loc_names': ['auto ns::Foo::func()']}, {'name': 'func', 'loc_names': ['auto ns::Foo::func()', 'auto ns::Foo::func>()']}, @@ -71,6 +84,15 @@ {'name': 'operator<<', 'loc_names': ['void ns::Foo::operator<<(int)']}, {'name': 'ns::Foo::operator<<', 'loc_names': ['void ns::Foo::operator<<(int)', 'void ns::Foo::operator<<>(ns::Foo)']}, + + {'name': 'g', 'loc_names': []}, + {'name': 'g', 'loc_names': ['void ns::g()']}, + {'name': 'g', 'loc_names': ['void ns::g()']}, + {'name': 'g', 'loc_names': ['void ns::g()', 'void ns::g()']}, + {'name': 'ns::g', 'loc_names': []}, + {'name': 'ns::g', 'loc_names': ['void ns::g()']}, + {'name': 'ns::g', 'loc_names': ['void ns::g()']}, + {'name': 'ns::g', 'loc_names': ['void ns::g()', 'void ns::g()']}, ] for bp_dict in bp_dicts: diff --git a/lldb/test/API/functionalities/breakpoint/cpp/main.cpp b/lldb/test/API/functionalities/breakpoint/cpp/main.cpp --- a/lldb/test/API/functionalities/breakpoint/cpp/main.cpp +++ b/lldb/test/API/functionalities/breakpoint/cpp/main.cpp @@ -94,6 +94,8 @@ template void operator<<(T t) {} }; + +template void g() {} } // namespace ns int main (int argc, char const *argv[]) @@ -123,5 +125,8 @@ f.operator<<(5); f.operator<< >({}); + ns::g(); + ns::g(); + return 0; }