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