aboutsummaryrefslogtreecommitdiff
path: root/lldb/test/API/python_api
diff options
context:
space:
mode:
authorPavel Labath <pavel@labath.sk>2024-05-10 08:34:42 +0200
committerGitHub <noreply@github.com>2024-05-10 08:34:42 +0200
commit5bde2aa1080ba90021f8f5e0c48744ddfc0d6f15 (patch)
treef83a498ee294d00ecafac355189b250cfb8a5d59 /lldb/test/API/python_api
parent0ebe48f068c0ca69f76ed68b621c9294acd75f76 (diff)
downloadllvm-5bde2aa1080ba90021f8f5e0c48744ddfc0d6f15.zip
llvm-5bde2aa1080ba90021f8f5e0c48744ddfc0d6f15.tar.gz
llvm-5bde2aa1080ba90021f8f5e0c48744ddfc0d6f15.tar.bz2
[lldb] Improve type name parsing (#91586)
Parsing of '::' scopes in TypeQuery was very naive and failed for names with '::''s in template arguments. Interestingly, one of the functions it was calling (Type::GetTypeScopeAndBasename) was already doing the same thing, and getting it (mostly (*)) right. This refactors the function so that it can return the scope results, fixing the parsing of names like std::vector<int, std::allocator<int>>::iterator. Two callers of GetTypeScopeAndBasename are deleted as the functions are not used (I presume they stopped being used once we started pruning type search results more eagerly). (*) This implementation is still not correct when one takes c++ operators into account -- e.g., something like `X<&A::operator<>::T` is a legitimate type name. We do have an implementation that is able to handle names like these (CPlusPlusLanguage::MethodName), but using it is not trivial, because it is hidden in a language plugin and specific to method name parsing. --------- Co-authored-by: Michael Buch <michaelbuch12@gmail.com>
Diffstat (limited to 'lldb/test/API/python_api')
-rw-r--r--lldb/test/API/python_api/sbmodule/FindTypes/Makefile3
-rw-r--r--lldb/test/API/python_api/sbmodule/FindTypes/TestSBModuleFindTypes.py40
-rw-r--r--lldb/test/API/python_api/sbmodule/FindTypes/main.cpp17
3 files changed, 60 insertions, 0 deletions
diff --git a/lldb/test/API/python_api/sbmodule/FindTypes/Makefile b/lldb/test/API/python_api/sbmodule/FindTypes/Makefile
new file mode 100644
index 0000000..99998b2
--- /dev/null
+++ b/lldb/test/API/python_api/sbmodule/FindTypes/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
diff --git a/lldb/test/API/python_api/sbmodule/FindTypes/TestSBModuleFindTypes.py b/lldb/test/API/python_api/sbmodule/FindTypes/TestSBModuleFindTypes.py
new file mode 100644
index 0000000..5c3d2b41
--- /dev/null
+++ b/lldb/test/API/python_api/sbmodule/FindTypes/TestSBModuleFindTypes.py
@@ -0,0 +1,40 @@
+"""Test the SBModule::FindTypes."""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestSBModuleFindTypes(TestBase):
+ def test_lookup_in_template_scopes(self):
+ self.build()
+ spec = lldb.SBModuleSpec()
+ spec.SetFileSpec(lldb.SBFileSpec(self.getBuildArtifact()))
+ module = lldb.SBModule(spec)
+
+ self.assertEqual(
+ set([t.GetName() for t in module.FindTypes("LookMeUp")]),
+ set(
+ [
+ "ns1::Foo<void>::LookMeUp",
+ "ns2::Bar<void>::LookMeUp",
+ "ns1::Foo<ns2::Bar<void> >::LookMeUp",
+ ]
+ ),
+ )
+
+ self.assertEqual(
+ set([t.GetName() for t in module.FindTypes("ns1::Foo<void>::LookMeUp")]),
+ set(["ns1::Foo<void>::LookMeUp"]),
+ )
+
+ self.assertEqual(
+ set(
+ [
+ t.GetName()
+ for t in module.FindTypes("ns1::Foo<ns2::Bar<void> >::LookMeUp")
+ ]
+ ),
+ set(["ns1::Foo<ns2::Bar<void> >::LookMeUp"]),
+ )
diff --git a/lldb/test/API/python_api/sbmodule/FindTypes/main.cpp b/lldb/test/API/python_api/sbmodule/FindTypes/main.cpp
new file mode 100644
index 0000000..cb2646c
--- /dev/null
+++ b/lldb/test/API/python_api/sbmodule/FindTypes/main.cpp
@@ -0,0 +1,17 @@
+namespace ns1 {
+template <typename T> struct Foo {
+ struct LookMeUp {};
+};
+} // namespace ns1
+
+namespace ns2 {
+template <typename T> struct Bar {
+ struct LookMeUp {};
+};
+} // namespace ns2
+
+ns1::Foo<void>::LookMeUp l1;
+ns2::Bar<void>::LookMeUp l2;
+ns1::Foo<ns2::Bar<void>>::LookMeUp l3;
+
+int main() {}