• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""
2Test lldb logging.
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9
10class LogTestCase(TestBase):
11
12    mydir = "logging"
13
14    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
15    @dsym_test
16    def test_with_dsym (self):
17        self.buildDsym ()
18        self.command_log_tests ("dsym")
19
20    @dwarf_test
21    def test_with_dwarf (self):
22        self.buildDwarf ()
23        self.command_log_tests ("dwarf")
24
25    def command_log_tests (self, type):
26        exe = os.path.join (os.getcwd(), "a.out")
27        self.expect("file " + exe,
28                    patterns = [ "Current executable set to .*a.out" ])
29
30        log_file = os.path.join (os.getcwd(), "lldb-commands-log-%s-%s-%s.txt" % (type,
31                                                                                  os.path.basename(self.getCompiler()),
32                                                                                  self.getArchitecture()))
33
34        if (os.path.exists (log_file)):
35            os.remove (log_file)
36
37        # By default, Debugger::EnableLog() will set log options to
38        # PREPEND_THREAD_NAME + OPTION_THREADSAFE. We don't want the
39        # threadnames here, so we enable just threadsafe (-t).
40        self.runCmd ("log enable -t -f '%s' lldb commands" % (log_file))
41
42        self.runCmd ("command alias bp breakpoint")
43
44        self.runCmd ("bp set -n main")
45
46        self.runCmd ("bp l")
47
48        expected_log_lines = [
49            "Processing command: command alias bp breakpoint\n",
50            "HandleCommand, cmd_obj : 'command alias'\n",
51            "HandleCommand, revised_command_line: 'command alias bp breakpoint'\n",
52            "HandleCommand, wants_raw_input:'True'\n",
53            "HandleCommand, command line after removing command name(s): 'bp breakpoint'\n",
54            "HandleCommand, command succeeded\n",
55            "Processing command: bp set -n main\n",
56            "HandleCommand, cmd_obj : 'breakpoint set'\n",
57            "HandleCommand, revised_command_line: 'breakpoint set -n main'\n",
58            "HandleCommand, wants_raw_input:'False'\n",
59            "HandleCommand, command line after removing command name(s): '-n main'\n",
60            "HandleCommand, command succeeded\n",
61            "Processing command: bp l\n",
62            "HandleCommand, cmd_obj : 'breakpoint list'\n",
63            "HandleCommand, revised_command_line: 'breakpoint l'\n",
64            "HandleCommand, wants_raw_input:'False'\n",
65            "HandleCommand, command line after removing command name(s): ''\n",
66            "HandleCommand, command succeeded\n",
67            ]
68
69        self.assertTrue (os.path.isfile (log_file))
70
71        idx = 0
72        end = len (expected_log_lines)
73        f = open (log_file)
74        log_lines = f.readlines()
75        f.close ()
76        self.runCmd("log disable lldb")
77        os.remove (log_file)
78
79        err_msg = ""
80        success = True
81
82        if len (log_lines) != len (expected_log_lines):
83            success = False
84            err_msg = "Wrong number of lines in log file; expected: " + repr (len (expected_log_lines)) + " found: " + repr(len (log_lines))
85        else:
86            for line1, line2 in zip (log_lines, expected_log_lines):
87                if line1 != line2:
88                    success = False
89                    err_msg = "Expected '" + line2 + "'; Found '" + line1 + "'"
90                    break
91
92        if not success:
93            self.fail (err_msg)
94
95
96if __name__ == '__main__':
97    import atexit
98    lldb.SBDebugger.Initialize()
99    atexit.register(lambda: lldb.SBDebugger.Terminate())
100    unittest2.main()
101
102