1"""
2Test lldb data formatter subsystem.
3"""
4
5
6
7import lldb
8from lldbsuite.test.lldbtest import *
9import lldbsuite.test.lldbutil as lldbutil
10
11
12class DataFormatterHexCapsTestCase(TestBase):
13
14    def setUp(self):
15        # Call super's setUp().
16        TestBase.setUp(self)
17        # Find the line number to break at.
18        self.line = line_number('main.cpp', '// Set break point at this line.')
19
20    def test_with_run_command(self):
21        """Test that that file and class static variables display correctly."""
22        self.build()
23        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
24
25        lldbutil.run_break_set_by_file_and_line(
26            self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
27
28        self.runCmd("run", RUN_SUCCEEDED)
29
30        # The stop reason of the thread should be breakpoint.
31        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
32                    substrs=['stopped',
33                             'stop reason = breakpoint'])
34
35        # This is the function to remove the custom formats in order to have a
36        # clean slate for the next test case.
37        def cleanup():
38            self.runCmd('type format delete hex', check=False)
39            self.runCmd('type summary clear', check=False)
40
41        # Execute the cleanup function during test case tear down.
42        self.addTearDownHook(cleanup)
43
44        self.runCmd("type format add -f uppercase int")
45
46        self.expect('frame variable mine',
47                    substrs=['mine = ',
48                             'first = 0x001122AA', 'second = 0x1122BB44'])
49
50        self.runCmd("type format add -f hex int")
51
52        self.expect('frame variable mine',
53                    substrs=['mine = ',
54                             'first = 0x001122aa', 'second = 0x1122bb44'])
55
56        self.runCmd("type format delete int")
57
58        self.runCmd(
59            "type summary add -s \"${var.first%X} and ${var.second%x}\" foo")
60
61        self.expect('frame variable mine',
62                    substrs=['(foo) mine = 0x001122AA and 0x1122bb44'])
63
64        self.runCmd(
65            "type summary add -s \"${var.first%X} and ${var.second%X}\" foo")
66        self.runCmd("next")
67        self.runCmd("next")
68        self.expect('frame variable mine',
69                    substrs=['(foo) mine = 0xAABBCCDD and 0x1122BB44'])
70
71        self.runCmd(
72            "type summary add -s \"${var.first%x} and ${var.second%X}\" foo")
73        self.expect('frame variable mine',
74                    substrs=['(foo) mine = 0xaabbccdd and 0x1122BB44'])
75        self.runCmd("next")
76        self.runCmd("next")
77        self.runCmd(
78            "type summary add -s \"${var.first%x} and ${var.second%x}\" foo")
79        self.expect('frame variable mine',
80                    substrs=['(foo) mine = 0xaabbccdd and 0xff00ff00'])
81        self.runCmd(
82            "type summary add -s \"${var.first%X} and ${var.second%X}\" foo")
83        self.expect('frame variable mine',
84                    substrs=['(foo) mine = 0xAABBCCDD and 0xFF00FF00'])
85