88 lines · python
1"""Test that types defined in shared libraries with stripped symbols work correctly."""2 3 4import unittest5import lldb6from lldbsuite.test.decorators import *7from lldbsuite.test.lldbtest import *8from lldbsuite.test import lldbutil9 10 11class SharedLibStrippedTestCase(TestBase):12 @expectedFailureAll(oslist=["windows"])13 # Sometimes fails with:14 # error: Couldn't allocate space for materialized struct: Couldn't malloc: address space is full15 # On 32 bit Arm Linux.16 @skipIf(archs=["arm$"])17 def test_expr(self):18 """Test that types work when defined in a shared library and forward-declared in the main executable"""19 if "clang" in self.getCompiler() and "3.4" in self.getCompilerVersion():20 self.skipTest(21 "llvm.org/pr16214 -- clang emits partial DWARF for structures referenced via typedef"22 )23 24 self.build()25 self.common_setup()26 27 # This should display correctly.28 self.expect(29 "expression --show-types -- *my_foo_ptr",30 VARIABLES_DISPLAYED_CORRECTLY,31 substrs=["(foo)", "(sub_foo)", "other_element = 3"],32 )33 34 @expectedFailureAll(oslist=["windows"])35 @unittest.expectedFailure # llvm.org/PR3671236 def test_frame_variable(self):37 """Test that types work when defined in a shared library and forward-declared in the main executable"""38 self.build()39 self.common_setup()40 41 # This should display correctly.42 self.expect(43 "frame variable --show-types -- *my_foo_ptr",44 VARIABLES_DISPLAYED_CORRECTLY,45 substrs=["(foo)", "(sub_foo)", "other_element = 3"],46 )47 48 def setUp(self):49 # Call super's setUp().50 TestBase.setUp(self)51 # Find the line number to break inside main().52 self.source = "main.c"53 self.line = line_number(self.source, "// Set breakpoint 0 here.")54 self.shlib_names = ["foo"]55 56 def common_setup(self):57 # Run in synchronous mode58 self.dbg.SetAsync(False)59 60 # Create a target by the debugger.61 target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))62 self.assertTrue(target, VALID_TARGET)63 64 # Break inside the foo function which takes a bar_ptr argument.65 lldbutil.run_break_set_by_file_and_line(66 self, self.source, self.line, num_expected_locations=1, loc_exact=True67 )68 69 # Register our shared libraries for remote targets so they get70 # automatically uploaded71 environment = self.registerSharedLibrariesWithTarget(target, self.shlib_names)72 73 # Now launch the process, and do not stop at entry point.74 process = target.LaunchSimple(75 None, environment, self.get_process_working_directory()76 )77 self.assertTrue(process, PROCESS_IS_VALID)78 79 # The stop reason of the thread should be breakpoint.80 self.expect(81 "thread list",82 STOPPED_DUE_TO_BREAKPOINT,83 substrs=["stopped", "stop reason = breakpoint"],84 )85 86 # The breakpoint should have a hit count of 1.87 lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)88