[Lldb-commits] [lldb] 3d83a57 - [lldb] Support simplified template names when looking up functions
Arthur Eubanks via lldb-commits
lldb-commits at lists.llvm.org
Thu Nov 3 16:19:26 PDT 2022
Author: Arthur Eubanks
Date: 2022-11-03T16:19:15-07:00
New Revision: 3d83a57721def7aad227d68b1e5e0afa6a74a33f
URL: https://github.com/llvm/llvm-project/commit/3d83a57721def7aad227d68b1e5e0afa6a74a33f
DIFF: https://github.com/llvm/llvm-project/commit/3d83a57721def7aad227d68b1e5e0afa6a74a33f.diff
LOG: [lldb] Support simplified template names when looking up functions
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
Added:
Modified:
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
lldb/test/API/functionalities/breakpoint/cpp/TestCPPBreakpointLocations.py
lldb/test/API/functionalities/breakpoint/cpp/main.cpp
Removed:
################################################################################
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 5d5a47bc0c92c..066fc9f434cae 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -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;
diff --git a/lldb/test/API/functionalities/breakpoint/cpp/TestCPPBreakpointLocations.py b/lldb/test/API/functionalities/breakpoint/cpp/TestCPPBreakpointLocations.py
index 6c86f5016a606..1dedc5d7f9bbd 100644
--- a/lldb/test/API/functionalities/breakpoint/cpp/TestCPPBreakpointLocations.py
+++ b/lldb/test/API/functionalities/breakpoint/cpp/TestCPPBreakpointLocations.py
@@ -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):
@@ -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>>()']},
@@ -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:
diff --git a/lldb/test/API/functionalities/breakpoint/cpp/main.cpp b/lldb/test/API/functionalities/breakpoint/cpp/main.cpp
index 7ee61e92ffd57..b2cee995198ad 100644
--- a/lldb/test/API/functionalities/breakpoint/cpp/main.cpp
+++ b/lldb/test/API/functionalities/breakpoint/cpp/main.cpp
@@ -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[])
@@ -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;
}
More information about the lldb-commits
mailing list