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