• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""Test that types defined in shared libraries work correctly."""
2
3
4
5import unittest2
6import lldb
7from lldbsuite.test.decorators import *
8from lldbsuite.test.lldbtest import *
9import lldbsuite.test.lldbutil as lldbutil
10
11
12class SharedLibTestCase(TestBase):
13
14    mydir = TestBase.compute_mydir(__file__)
15
16    def common_test_expr(self, preload_symbols):
17        if "clang" in self.getCompiler() and "3.4" in self.getCompilerVersion():
18            self.skipTest(
19                "llvm.org/pr16214 -- clang emits partial DWARF for structures referenced via typedef")
20
21        self.build()
22        self.common_setup(preload_symbols)
23
24        # This should display correctly.
25        self.expect(
26            "expression --show-types -- *my_foo_ptr",
27            VARIABLES_DISPLAYED_CORRECTLY,
28            substrs=[
29                "(foo)",
30                "(sub_foo)",
31                "other_element = 3"])
32
33        self.expect(
34            "expression GetMeASubFoo(my_foo_ptr)",
35            startstr="(sub_foo *) $")
36
37    @expectedFailureNetBSD
38    def test_expr(self):
39        """Test that types work when defined in a shared library and forward-declared in the main executable"""
40        self.common_test_expr(True)
41
42    @expectedFailureNetBSD
43    def test_expr_no_preload(self):
44        """Test that types work when defined in a shared library and forward-declared in the main executable, but with preloading disabled"""
45        self.common_test_expr(False)
46
47    @expectedFailure("llvm.org/PR36712")
48    def test_frame_variable(self):
49        """Test that types work when defined in a shared library and forward-declared in the main executable"""
50        self.build()
51        self.common_setup()
52
53        # This should display correctly.
54        self.expect(
55            "frame variable --show-types -- *my_foo_ptr",
56            VARIABLES_DISPLAYED_CORRECTLY,
57            substrs=[
58                "(foo)",
59                "(sub_foo)",
60                "other_element = 3"])
61
62    def setUp(self):
63        # Call super's setUp().
64        TestBase.setUp(self)
65        # Find the line number to break inside main().
66        self.source = 'main.c'
67        self.line = line_number(self.source, '// Set breakpoint 0 here.')
68        self.shlib_names = ["foo"]
69
70    def common_setup(self, preload_symbols = True):
71        # Run in synchronous mode
72        self.dbg.SetAsync(False)
73
74        # Create a target by the debugger.
75        target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
76        self.assertTrue(target, VALID_TARGET)
77
78        self.runCmd("settings set target.preload-symbols " + str(preload_symbols).lower())
79
80        # Break inside the foo function which takes a bar_ptr argument.
81        lldbutil.run_break_set_by_file_and_line(
82            self, self.source, self.line, num_expected_locations=1, loc_exact=True)
83
84        # Register our shared libraries for remote targets so they get
85        # automatically uploaded
86        environment = self.registerSharedLibrariesWithTarget(
87            target, self.shlib_names)
88
89        # Now launch the process, and do not stop at entry point.
90        process = target.LaunchSimple(
91            None, environment, self.get_process_working_directory())
92        self.assertTrue(process, PROCESS_IS_VALID)
93
94        # The stop reason of the thread should be breakpoint.
95        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
96                    substrs=['stopped',
97                             'stop reason = breakpoint'])
98
99        # The breakpoint should have a hit count of 1.
100        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
101                    substrs=[' resolved, hit count = 1'])
102