1ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen"""
2ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny ChenTest example snippets from the lldb 'help expression' output.
3ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen"""
4ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen
5ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chenimport os, time
6ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chenimport unittest2
7ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chenimport lldb
8ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chenfrom lldbtest import *
9431d839a33e9a274e705f7a268a1c9de2ffc2da2Jim Inghamimport lldbutil
10ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen
11ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chenclass Radar9673644TestCase(TestBase):
12ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen
13ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen    mydir = os.path.join("expression_command", "radar_9673664")
14ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen
15ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen    def setUp(self):
16ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen        # Call super's setUp().
17ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen        TestBase.setUp(self)
18ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen        # Find the line number to break inside main().
19ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen        self.main_source = "main.c"
20ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen        self.line = line_number(self.main_source, '// Set breakpoint here.')
21ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen
22ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen    # rdar://problem/9673664
23ccfb499c8e1989a37a1976a4f1ec662f89816b28Ed Maste    @expectedFailureFreeBSD # llvm.org/pr16697
246bc4dcdfbcdfa455299d2123011b82a77351ee72Daniel Malea    @skipIfLinux # llvm.org/pr14805: expressions that require memory allocation evaluate incorrectly on Linux
25ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen    def test_expr_commands(self):
26ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen        """The following expression commands should just work."""
27ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen        self.buildDefault()
28ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen
29ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
30ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen
31431d839a33e9a274e705f7a268a1c9de2ffc2da2Jim Ingham        lldbutil.run_break_set_by_file_and_line (self, self.main_source, self.line, num_expected_locations=1, loc_exact=True)
32ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen
33ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen        self.runCmd("run", RUN_SUCCEEDED)
34ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen
35ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen        # rdar://problem/9673664 lldb expression evaluation problem
36ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen
373bd643399e22bdf8ce856bcd2e465ea594913830Johnny Chen        self.expect('expr char c[] = "foo"; c[0]',
383bd643399e22bdf8ce856bcd2e465ea594913830Johnny Chen            substrs = ["'f'"])
393bd643399e22bdf8ce856bcd2e465ea594913830Johnny Chen        # runCmd: expr char c[] = "foo"; c[0]
403bd643399e22bdf8ce856bcd2e465ea594913830Johnny Chen        # output: (char) $0 = 'f'
41ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen
42ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen
43ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chenif __name__ == '__main__':
44ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen    import atexit
45ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen    lldb.SBDebugger.Initialize()
46ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen    atexit.register(lambda: lldb.SBDebugger.Terminate())
47ca8a206aae9c17ec100fa1996b7ebe4ec2c886baJohnny Chen    unittest2.main()
48