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