• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""Test that forward declaration of a data structure gets resolved correctly."""
2
3import os, time
4import unittest2
5import lldb
6from lldbtest import *
7import lldbutil
8
9class ForwardDeclarationTestCase(TestBase):
10
11    mydir = os.path.join("lang", "c", "forward")
12
13    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
14    @dsym_test
15    def test_with_dsym_and_run_command(self):
16        """Display *bar_ptr when stopped on a function with forward declaration of struct bar."""
17        self.buildDsym()
18        self.forward_declaration()
19
20    # rdar://problem/8648070
21    # 'expression *bar_ptr' seg faults
22    # rdar://problem/8546815
23    # './dotest.py -v -t forward' fails for test_with_dwarf_and_run_command
24    @dwarf_test
25    def test_with_dwarf_and_run_command(self):
26        """Display *bar_ptr when stopped on a function with forward declaration of struct bar."""
27        self.buildDwarf()
28        self.forward_declaration()
29
30    def forward_declaration(self):
31        """Display *bar_ptr when stopped on a function with forward declaration of struct bar."""
32        exe = os.path.join(os.getcwd(), "a.out")
33        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
34
35        # Break inside the foo function which takes a bar_ptr argument.
36        lldbutil.run_break_set_by_symbol (self, "foo", num_expected_locations=1, sym_exact=True)
37
38        self.runCmd("run", RUN_SUCCEEDED)
39
40        # The stop reason of the thread should be breakpoint.
41        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
42            substrs = ['stopped',
43                       'stop reason = breakpoint'])
44
45        # The breakpoint should have a hit count of 1.
46        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
47            substrs = [' resolved, hit count = 1'])
48
49        # This should display correctly.
50        # Note that the member fields of a = 1 and b = 2 is by design.
51        self.expect("frame variable --show-types *bar_ptr", VARIABLES_DISPLAYED_CORRECTLY,
52            substrs = ['(bar) *bar_ptr = ',
53                       '(int) a = 1',
54                       '(int) b = 2'])
55
56        # And so should this.
57        self.expect("expression --show-types -- *bar_ptr", VARIABLES_DISPLAYED_CORRECTLY,
58            substrs = ['(bar)',
59                       '(int) a = 1',
60                       '(int) b = 2'])
61
62
63if __name__ == '__main__':
64    import atexit
65    lldb.SBDebugger.Initialize()
66    atexit.register(lambda: lldb.SBDebugger.Terminate())
67    unittest2.main()
68