1 """Test that types defined in shared libraries work correctly."""
5 from lldbsuite
.test
.decorators
import *
6 from lldbsuite
.test
.lldbtest
import *
7 import lldbsuite
.test
.lldbutil
as lldbutil
10 class SharedLibTestCase(TestBase
):
12 # Call super's setUp().
14 # Find the line number to break inside main().
15 self
.source
= "shared.c"
16 self
.line
= line_number(self
.source
, "// Set breakpoint 0 here.")
17 self
.shlib_names
= ["foo"]
19 def common_setup(self
):
20 # Run in synchronous mode
21 self
.dbg
.SetAsync(False)
22 self
.runCmd("settings set symbols.load-on-demand true")
24 # Create a target by the debugger.
25 self
.target
= self
.dbg
.CreateTarget(self
.getBuildArtifact("a.out"))
26 self
.assertTrue(self
.target
, VALID_TARGET
)
28 # Register our shared libraries for remote targets so they get
29 # automatically uploaded
30 self
.environment
= self
.registerSharedLibrariesWithTarget(
31 self
.target
, self
.shlib_names
34 ctx
= self
.platformContext
35 self
.shared_lib_name
= ctx
.shlib_prefix
+ "foo." + ctx
.shlib_extension
38 def test_source_line_breakpoint(self
):
42 lldbutil
.run_break_set_by_file_and_line(
43 self
, "foo.c", 4, num_expected_locations
=1, loc_exact
=True
46 # Now launch the process, and do not stop at entry point.
47 process
= self
.target
.LaunchSimple(
48 None, self
.environment
, self
.get_process_working_directory()
50 self
.assertTrue(process
, PROCESS_IS_VALID
)
52 # The stop reason of the thread should be breakpoint.
55 STOPPED_DUE_TO_BREAKPOINT
,
56 substrs
=["stopped", "stop reason = breakpoint"],
58 # The breakpoint should have a hit count of 1.
59 lldbutil
.check_breakpoint(self
, bpno
=1, expected_hit_count
=1)
61 thread
= process
.GetSelectedThread()
62 stack_frames
= thread
.frames
63 self
.assertGreater(len(stack_frames
), 2)
65 leaf_frame
= stack_frames
[0]
66 self
.assertEqual("foo.c", leaf_frame
.GetLineEntry().GetFileSpec().GetFilename())
67 self
.assertEqual(4, leaf_frame
.GetLineEntry().GetLine())
69 parent_frame
= stack_frames
[1]
71 "shared.c", parent_frame
.GetLineEntry().GetFileSpec().GetFilename()
73 self
.assertEqual(7, parent_frame
.GetLineEntry().GetLine())
76 def test_symbolic_breakpoint(self
):
80 lldbutil
.run_break_set_by_symbol(
81 self
, "foo", sym_exact
=True, num_expected_locations
=1
84 # Now launch the process, and do not stop at entry point.
85 process
= self
.target
.LaunchSimple(
86 None, self
.environment
, self
.get_process_working_directory()
88 self
.assertTrue(process
, PROCESS_IS_VALID
)
90 # The stop reason of the thread should be breakpoint.
93 STOPPED_DUE_TO_BREAKPOINT
,
94 substrs
=["stopped", "stop reason = breakpoint"],
96 # The breakpoint should have a hit count of 1.
97 lldbutil
.check_breakpoint(self
, bpno
=1, expected_hit_count
=1)
99 thread
= process
.GetSelectedThread()
100 stack_frames
= thread
.frames
101 self
.assertGreater(len(stack_frames
), 2)
103 leaf_frame
= stack_frames
[0]
104 self
.assertEqual("foo.c", leaf_frame
.GetLineEntry().GetFileSpec().GetFilename())
105 self
.assertEqual(4, leaf_frame
.GetLineEntry().GetLine())
107 parent_frame
= stack_frames
[1]
109 "shared.c", parent_frame
.GetLineEntry().GetFileSpec().GetFilename()
111 self
.assertEqual(7, parent_frame
.GetLineEntry().GetLine())
114 def test_global_variable_hydration(self
):
118 lldbutil
.run_break_set_by_file_and_line(
119 self
, self
.source
, self
.line
, num_expected_locations
=1, loc_exact
=True
122 # Now launch the process, and do not stop at entry point.
123 process
= self
.target
.LaunchSimple(
124 None, self
.environment
, self
.get_process_working_directory()
126 self
.assertTrue(process
, PROCESS_IS_VALID
)
128 # The stop reason of the thread should be breakpoint.
131 STOPPED_DUE_TO_BREAKPOINT
,
132 substrs
=["stopped", "stop reason = breakpoint"],
135 # The breakpoint should have a hit count of 1.
136 lldbutil
.check_breakpoint(self
, bpno
=1, expected_hit_count
=1)
139 "target variable --shlib a.out",
140 "Breakpoint in a.out should have hydrated the debug info",
141 substrs
=["global_shared = 897"],
145 "target variable --shlib " + self
.shared_lib_name
,
146 "shared library should not have debug info by default",
148 substrs
=["global_foo"],
152 "target variable global_foo --shlib " + self
.shared_lib_name
,
153 "Match global_foo in symbol table should hydrate debug info",
155 substrs
=["global_foo = 321"],