1"""
2Test example snippets from the lldb 'help expression' output.
3"""
4
5
6
7import lldb
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11
12
13class Radar9673644TestCase(TestBase):
14
15    def setUp(self):
16        # Call super's setUp().
17        TestBase.setUp(self)
18        # Find the line number to break inside main().
19        self.main_source = "main.c"
20        self.line = line_number(self.main_source, '// Set breakpoint here.')
21
22    def test_expr_commands(self):
23        """The following expression commands should just work."""
24        self.build()
25
26        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
27
28        lldbutil.run_break_set_by_file_and_line(
29            self,
30            self.main_source,
31            self.line,
32            num_expected_locations=1,
33            loc_exact=True)
34
35        self.runCmd("run", RUN_SUCCEEDED)
36
37        # rdar://problem/9673664 lldb expression evaluation problem
38
39        self.expect('expr char str[] = "foo"; str[0]',
40                    substrs=["'f'"])
41        # runCmd: expr char c[] = "foo"; c[0]
42        # output: (char) $0 = 'f'
43