1 2 3import lldb 4from lldbsuite.test.decorators import * 5from lldbsuite.test.lldbtest import * 6from lldbsuite.test import lldbutil 7 8 9class TestMacros(TestBase): 10 11 @expectedFailureAll( 12 compiler="clang", 13 bugnumber="clang does not emit .debug_macro[.dwo] sections.") 14 @expectedFailureAll( 15 debug_info="dwo", 16 bugnumber="GCC produces multiple .debug_macro.dwo sections and the spec is unclear as to what it means") 17 @expectedFailureAll( 18 hostoslist=["windows"], 19 compiler="gcc", 20 triple='.*-android') 21 @expectedFailureAll( 22 compiler="gcc", compiler_version=['<', '5.1'], 23 bugnumber=".debug_macro was introduced in DWARF 5, GCC supports it since version 5.1") 24 def test_expr_with_macros(self): 25 self.build() 26 27 # Get main source file 28 src_file = "main.cpp" 29 hdr_file = "macro1.h" 30 src_file_spec = lldb.SBFileSpec(src_file) 31 self.assertTrue(src_file_spec.IsValid(), "Main source file") 32 33 (target, process, thread, bp1) = lldbutil.run_to_source_breakpoint( 34 self, "Break here", src_file_spec) 35 36 # Get frame for current thread 37 frame = thread.GetSelectedFrame() 38 39 result = frame.EvaluateExpression("MACRO_1") 40 self.assertTrue( 41 result.IsValid() and result.GetValue() == "100", 42 "MACRO_1 = 100") 43 44 result = frame.EvaluateExpression("MACRO_2") 45 self.assertTrue( 46 result.IsValid() and result.GetValue() == "200", 47 "MACRO_2 = 200") 48 49 result = frame.EvaluateExpression("ONE") 50 self.assertTrue( 51 result.IsValid() and result.GetValue() == "1", 52 "ONE = 1") 53 54 result = frame.EvaluateExpression("TWO") 55 self.assertTrue( 56 result.IsValid() and result.GetValue() == "2", 57 "TWO = 2") 58 59 result = frame.EvaluateExpression("THREE") 60 self.assertTrue( 61 result.IsValid() and result.GetValue() == "3", 62 "THREE = 3") 63 64 result = frame.EvaluateExpression("FOUR") 65 self.assertTrue( 66 result.IsValid() and result.GetValue() == "4", 67 "FOUR = 4") 68 69 result = frame.EvaluateExpression("HUNDRED") 70 self.assertTrue( 71 result.IsValid() and result.GetValue() == "100", 72 "HUNDRED = 100") 73 74 result = frame.EvaluateExpression("THOUSAND") 75 self.assertTrue( 76 result.IsValid() and result.GetValue() == "1000", 77 "THOUSAND = 1000") 78 79 result = frame.EvaluateExpression("MILLION") 80 self.assertTrue(result.IsValid() and result.GetValue() 81 == "1000000", "MILLION = 1000000") 82 83 result = frame.EvaluateExpression("MAX(ONE, TWO)") 84 self.assertTrue( 85 result.IsValid() and result.GetValue() == "2", 86 "MAX(ONE, TWO) = 2") 87 88 result = frame.EvaluateExpression("MAX(THREE, TWO)") 89 self.assertTrue( 90 result.IsValid() and result.GetValue() == "3", 91 "MAX(THREE, TWO) = 3") 92 93 # Get the thread of the process 94 thread.StepOver() 95 96 # Get frame for current thread 97 frame = thread.GetSelectedFrame() 98 99 result = frame.EvaluateExpression("MACRO_2") 100 self.assertTrue( 101 result.GetError().Fail(), 102 "Printing MACRO_2 fails in the mail file") 103 104 result = frame.EvaluateExpression("FOUR") 105 self.assertTrue( 106 result.GetError().Fail(), 107 "Printing FOUR fails in the main file") 108 109 thread.StepInto() 110 111 # Get frame for current thread 112 frame = thread.GetSelectedFrame() 113 114 result = frame.EvaluateExpression("ONE") 115 self.assertTrue( 116 result.IsValid() and result.GetValue() == "1", 117 "ONE = 1") 118 119 result = frame.EvaluateExpression("MAX(ONE, TWO)") 120 self.assertTrue( 121 result.IsValid() and result.GetValue() == "2", 122 "MAX(ONE, TWO) = 2") 123 124 # This time, MACRO_1 and MACRO_2 are not visible. 125 result = frame.EvaluateExpression("MACRO_1") 126 self.assertTrue(result.GetError().Fail(), 127 "Printing MACRO_1 fails in the header file") 128 129 result = frame.EvaluateExpression("MACRO_2") 130 self.assertTrue(result.GetError().Fail(), 131 "Printing MACRO_2 fails in the header file") 132