79 lines · python
1from lldbsuite.test.decorators import *2from lldbsuite.test.lldbtest import *3from lldbsuite.test import lldbutil4 5 6class TestCase(TestBase):7 @add_test_categories(["libc++"])8 @skipIf(compiler=no_match("clang"))9 @skipIf(macos_version=["<", "15.0"])10 def test(self):11 self.build()12 13 lldbutil.run_to_source_breakpoint(14 self, "// Set break point at this line.", lldb.SBFileSpec("main.cpp")15 )16 17 if self.expectedCompiler(["clang"]) and self.expectedCompilerVersion(18 [">", "16.0"]19 ):20 vec_type = "std::vector<int>"21 else:22 vec_type = "std::vector<int, std::allocator<int> >"23 24 # Test printing the vector before enabling any C++ module setting.25 self.expect_expr("a", result_type=vec_type)26 27 # Set loading the import-std-module to 'fallback' which loads the module28 # and retries when an expression fails to parse.29 self.runCmd("settings set target.import-std-module fallback")30 31 # Printing the vector still works. This should return the same type32 # as before as this shouldn't use a C++ module type.33 self.expect_expr("a", result_type=vec_type)34 35 # This expression can only parse with a C++ module. LLDB should36 # automatically fall back to import the C++ module to get this working.37 self.expect_expr("std::max<std::size_t>(0U, a.size())", result_value="3")38 39 # The 'a' and 'local' part can be parsed without loading a C++ module and will40 # load type/runtime information. The 'std::max...' part will fail to41 # parse without a C++ module. Make sure we reset all the relevant parts of42 # the C++ parser so that we don't end up with for example a second43 # definition of 'local' when retrying.44 self.expect_expr(45 "a; local; std::max<std::size_t>(0U, a.size())", result_value="3"46 )47 48 # Try to declare top-level declarations that require a C++ module to parse.49 # Top-level expressions don't support importing the C++ module (yet), so50 # this should still fail as before.51 self.expect(52 "expr --top-level -- int i = std::max(1, 2);",53 error=True,54 substrs=["no member named 'max' in namespace 'std'"],55 )56 57 # The proper diagnostic however should be shown on the retry.58 self.expect(59 "expr std::max(1, 2); unknown_identifier",60 error=True,61 substrs=["use of undeclared identifier 'unknown_identifier'"],62 )63 64 # Turn on the 'import-std-module' setting and make sure we import the65 # C++ module.66 self.runCmd("settings set target.import-std-module true")67 # This is still expected to work.68 self.expect_expr("std::max<std::size_t>(0U, a.size())", result_value="3")69 70 # Turn of the 'import-std-module' setting and make sure we don't load71 # the module (which should prevent parsing the expression involving72 # 'std::max').73 self.runCmd("settings set target.import-std-module false")74 self.expect(75 "expr std::max(1, 2);",76 error=True,77 substrs=["no member named 'max' in namespace 'std'"],78 )79