Skip to content

Commit

Permalink
[lldb] Support simplified template names when looking up functions
Browse files Browse the repository at this point in the history
This makes setting breakpoints work with -gsimple-template-names.

Assume that callers handle false positives. For example, `Module::LookupInfo::Prune` removes wrong template instantiations when setting a breakpoint.

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D137098
  • Loading branch information
aeubanks committed Nov 3, 2022
1 parent 3310fe5 commit 3d83a57
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
18 changes: 18 additions & 0 deletions lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
Expand Up @@ -2389,6 +2389,24 @@ void SymbolFileDWARF::FindFunctions(const Module::LookupInfo &lookup_info,
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;
Expand Down
Expand Up @@ -12,7 +12,16 @@ class TestCPPBreakpointLocations(TestBase):

@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):
Expand Down Expand Up @@ -57,7 +66,11 @@ def breakpoint_id_tests(self):

# Template cases
{'name': 'func<float>', 'loc_names': []},
{'name': 'Foo::func<float>', 'loc_names': []},
{'name': 'ns::Foo::func<float>', 'loc_names': []},
{'name': 'func<int>', 'loc_names': ['auto ns::Foo<double>::func<int>()']},
{'name': 'Foo<double>::func<int>', 'loc_names': ['auto ns::Foo<double>::func<int>()']},
{'name': 'ns::Foo<double>::func<int>', 'loc_names': ['auto ns::Foo<double>::func<int>()']},
{'name': 'func', 'loc_names': ['auto ns::Foo<double>::func<int>()',
'auto ns::Foo<double>::func<ns::Foo<int>>()']},

Expand All @@ -71,6 +84,15 @@ def breakpoint_id_tests(self):
{'name': 'operator<<<int>', 'loc_names': ['void ns::Foo<double>::operator<<<int>(int)']},
{'name': 'ns::Foo<double>::operator<<', 'loc_names': ['void ns::Foo<double>::operator<<<int>(int)',
'void ns::Foo<double>::operator<<<ns::Foo<int>>(ns::Foo<int>)']},

{'name': 'g<float>', 'loc_names': []},
{'name': 'g<int>', 'loc_names': ['void ns::g<int>()']},
{'name': 'g<char>', 'loc_names': ['void ns::g<char>()']},
{'name': 'g', 'loc_names': ['void ns::g<int>()', 'void ns::g<char>()']},
{'name': 'ns::g<float>', 'loc_names': []},
{'name': 'ns::g<int>', 'loc_names': ['void ns::g<int>()']},
{'name': 'ns::g<char>', 'loc_names': ['void ns::g<char>()']},
{'name': 'ns::g', 'loc_names': ['void ns::g<int>()', 'void ns::g<char>()']},
]

for bp_dict in bp_dicts:
Expand Down
5 changes: 5 additions & 0 deletions lldb/test/API/functionalities/breakpoint/cpp/main.cpp
Expand Up @@ -94,6 +94,8 @@ template <typename Type> struct Foo {

template <typename T> void operator<<(T t) {}
};

template <typename Type> void g() {}
} // namespace ns

int main (int argc, char const *argv[])
Expand Down Expand Up @@ -123,5 +125,8 @@ int main (int argc, char const *argv[])
f.operator<<(5);
f.operator<< <ns::Foo<int>>({});

ns::g<int>();
ns::g<char>();

return 0;
}

0 comments on commit 3d83a57

Please sign in to comment.