• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""
2Test lldb data formatter subsystem.
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9import lldbutil
10
11class Radar10449092DataFormatterTestCase(TestBase):
12
13    # test for rdar://problem/10449092 ()
14    mydir = os.path.join("functionalities", "data-formatter", "rdar-10449092")
15
16    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
17    @dsym_test
18    def test_with_dsym_and_run_command(self):
19        """Test data formatter commands."""
20        self.buildDsym()
21        self.data_formatter_commands()
22
23    @dwarf_test
24    def test_with_dwarf_and_run_command(self):
25        """Test data formatter commands."""
26        self.buildDwarf()
27        self.data_formatter_commands()
28
29    def setUp(self):
30        # Call super's setUp().
31        TestBase.setUp(self)
32        # Find the line number to break at.
33        self.line = line_number('main.cpp', '// Set break point at this line.')
34
35    def data_formatter_commands(self):
36        """Test that that file and class static variables display correctly."""
37        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
38
39        lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
40
41        self.runCmd("run", RUN_SUCCEEDED)
42
43        # The stop reason of the thread should be breakpoint.
44        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
45            substrs = ['stopped',
46                       'stop reason = breakpoint'])
47
48        # This is the function to remove the custom formats in order to have a
49        # clean slate for the next test case.
50        def cleanup():
51            self.runCmd('type format delete hex', check=False)
52            self.runCmd('type summary clear', check=False)
53
54        # Execute the cleanup function during test case tear down.
55        self.addTearDownHook(cleanup)
56
57        self.runCmd("type format add -f uppercase int")
58
59        self.expect('frame variable mine',
60            substrs = ['mine = ',
61                       'first = 0x001122AA', 'second = 0x1122BB44'])
62
63        self.runCmd("type format add -f hex int")
64
65        self.expect('frame variable mine',
66            substrs = ['mine = ',
67                       'first = 0x001122aa', 'second = 0x1122bb44'])
68
69        self.runCmd("type format delete int")
70
71        self.runCmd("type summary add -s \"${var.first%X} and ${var.second%x}\" foo")
72
73        self.expect('frame variable mine',
74                    substrs = ['(foo) mine = 0x001122AA and 0x1122bb44'])
75
76        self.runCmd("type summary add -s \"${var.first%X} and ${var.second%X}\" foo")
77        self.runCmd("next")
78        self.expect('frame variable mine',
79                    substrs = ['(foo) mine = 0xAABBCCDD and 0x1122BB44'])
80
81        self.runCmd("type summary add -s \"${var.first%x} and ${var.second%X}\" foo")
82        self.expect('frame variable mine',
83                    substrs = ['(foo) mine = 0xaabbccdd and 0x1122BB44'])
84        self.runCmd("next")
85        self.runCmd("type summary add -s \"${var.first%x} and ${var.second%x}\" foo")
86        self.expect('frame variable mine',
87                    substrs = ['(foo) mine = 0xaabbccdd and 0xff00ff00'])
88        self.runCmd("type summary add -s \"${var.first%X} and ${var.second%X}\" foo")
89        self.expect('frame variable mine',
90                    substrs = ['(foo) mine = 0xAABBCCDD and 0xFF00FF00'])
91
92
93if __name__ == '__main__':
94    import atexit
95    lldb.SBDebugger.Initialize()
96    atexit.register(lambda: lldb.SBDebugger.Terminate())
97    unittest2.main()
98