================
@@ -0,0 +1,118 @@
+"""
+Test the SBTarget API's to retrieve persistent types
+and values.
+"""
+
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+
+
+class TestPersistentDecls(TestBase):
+    NO_DEBUG_INFO_TESTCASE = True
+
+    def test_persistent_types(self):
+        """Define some types in the expression evaluator and find them."""
+        self.build()
+        self.main_source_file = lldb.SBFileSpec("main.c")
+        self.types_test()
+
+    def test_persistent_values(self):
+        """Define some values in the expression evaluator and find them."""
+        self.build()
+        self.main_source_file = lldb.SBFileSpec("main.c")
+        self.values_test()
+
+    def types_test(self):
+        (target, _, _, _) = lldbutil.run_to_source_breakpoint(
+            self, "Set a breakpoint here", self.main_source_file
+        )
+
+        # Make some types so we aren't succeeding in gettting the only one.
+
+        typename = "$firstStruct"
+
+        self.expect(f"expr struct $SomeType {{ int b; int a; int c;}}")
+        self.expect(f"expr struct {typename} {{ int a; int b; char *c;}}")
+        self.expect(f"expr struct $AnotherType {{ int a; char *b; int c;}}")
+        self.expect(f"expr struct $YetAnotherType {{ char *a; int b; int c;}}")
+
+        language = lldb.eLanguageTypeC_plus_plus
+        error = lldb.SBError()
+        type = target.FindExpressionTypeForLanguage(typename, language, error)
+        self.assertSuccess(error, "Got the right error")
+        self.assertTrue(type.IsValid(), "Got a valid type")
+
+        # Make sure we got the type we expected:
+        self.assertEqual(type.name, typename, "Got the right type.")
+        # Now check that the fields are right:
+        self.assertEqual(type.num_fields, 3, "Right number of fields")
+
+        ivar_a = type.fields[0]
+        self.assertEqual(ivar_a.name, "a", "a name is right")
+        self.assertEqual(ivar_a.type.name, "int", "Right type")
+
+        ivar_b = type.fields[1]
+        self.assertEqual(ivar_b.name, "b", "b name is right")
+        self.assertEqual(ivar_b.type.name, "int", "Right type")
+
+        ivar_c = type.fields[2]
+        self.assertEqual(ivar_c.name, "c", "c name is right")
+        self.assertEqual(ivar_c.type.name, "char *", "Right type")
+
+        # Also test the error returns:
+        # type = target.FindExpressionTypeForLanguage(typename, 
lldb.eLanguageTypeUnknown, error)
+        # self.assertFalse(error, "unknown doesn't support expression types")
+        # self.assertFalse(type.IsValid(), "Type is also invalid.")
----------------
jimingham wrote:

Oh, right.  I found you have to explicitly reject eLanguageTypeUnknown, since 
otherwise the Find*ForLanguage methods would promote it to C++, which I found 
to be confusing.  I commented out the tests while I was figuring that out and 
forgot to uncomment them...  They do pass uncommented.

https://github.com/llvm/llvm-project/pull/203128
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to