1""" 2Test lldb data formatter subsystem. 3""" 4 5 6import lldb 7from lldbsuite.test.decorators import * 8from lldbsuite.test.lldbtest import * 9from lldbsuite.test import lldbutil 10 11 12class LibcxxVariantDataFormatterTestCase(TestBase): 13 @add_test_categories(["libc++"]) 14 ## Clang 7.0 is the oldest Clang that can reliably parse newer libc++ versions 15 ## with -std=c++17. 16 @skipIf( 17 oslist=no_match(["macosx"]), compiler="clang", compiler_version=["<", "7.0"] 18 ) 19 ## We are skipping gcc version less that 5.1 since this test requires -std=c++17 20 @skipIf(compiler="gcc", compiler_version=["<", "5.1"]) 21 ## std::get is unavailable for std::variant before macOS 10.14 22 @skipIf(macos_version=["<", "10.14"]) 23 def test_with_run_command(self): 24 """Test that that file and class static variables display correctly.""" 25 self.build() 26 27 (self.target, self.process, _, bkpt) = lldbutil.run_to_source_breakpoint( 28 self, "// break here", lldb.SBFileSpec("main.cpp", False) 29 ) 30 31 self.runCmd("frame variable has_variant") 32 33 output = self.res.GetOutput() 34 35 ## The variable has_variant tells us if the test program 36 ## detected we have a sufficient libc++ version to support variant 37 ## false means we do not and therefore should skip the test 38 if output.find("(bool) has_variant = false") != -1: 39 self.skipTest("std::variant not supported") 40 41 lldbutil.continue_to_breakpoint(self.process, bkpt) 42 43 self.expect( 44 "frame variable v1", 45 substrs=["v1 = Active Type = int {", "Value = 12", "}"], 46 ) 47 48 self.expect( 49 "frame variable v1_ref", 50 substrs=["v1_ref = Active Type = int : {", "Value = 12", "}"], 51 ) 52 53 self.expect( 54 "frame variable v_v1", 55 substrs=[ 56 "v_v1 = Active Type = std::variant<int, double, char> {", 57 "Value = Active Type = int {", 58 "Value = 12", 59 "}", 60 "}", 61 ], 62 ) 63 64 lldbutil.continue_to_breakpoint(self.process, bkpt) 65 66 self.expect( 67 "frame variable v1", 68 substrs=["v1 = Active Type = double {", "Value = 2", "}"], 69 ) 70 71 lldbutil.continue_to_breakpoint(self.process, bkpt) 72 73 self.expect( 74 "frame variable v2", 75 substrs=["v2 = Active Type = double {", "Value = 2", "}"], 76 ) 77 78 self.expect( 79 "frame variable v3", 80 substrs=["v3 = Active Type = char {", "Value = 'A'", "}"], 81 ) 82 83 self.expect("frame variable v_no_value", substrs=["v_no_value = No Value"]) 84 85 self.expect( 86 "frame variable v_300_types_no_value", 87 substrs=["v_300_types_no_value = No Value"], 88 ) 89