Example #1
0
 def test_union_members(self):
     self.build()
     spec = lldb.SBModuleSpec()
     spec.SetFileSpec(lldb.SBFileSpec(self.getBuildArtifact("a.out")))
     module = lldb.SBModule(spec)
     self.assertTrue(module.IsValid())
     mytype = module.FindFirstType("foobár")
     self.assertTrue(mytype.IsValid())
     self.assertTrue(mytype.IsPointerType())
Example #2
0
    def test(self):
        self.build()

        # Extracts path of the interpreter.
        spec = lldb.SBModuleSpec()
        spec.SetFileSpec(lldb.SBFileSpec(self.getBuildArtifact("a.out")))
        interp_section = lldb.SBModule(spec).FindSection(".interp")
        if not interp_section:
            return
        section_data = interp_section.GetSectionData()
        error = lldb.SBError()
        exe = section_data.GetString(error, 0)
        if error.Fail():
            return

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        # Set breakpoints both on shared library function as well as on
        # main. Both of them will be pending breakpoints.
        breakpoint_main = target.BreakpointCreateBySourceRegex(
            "// Break here", lldb.SBFileSpec("main.cpp"))
        breakpoint_shared_library = target.BreakpointCreateBySourceRegex(
            "get_signal_crash", lldb.SBFileSpec("signal_file.cpp"))
        launch_info = lldb.SBLaunchInfo([
            "--library-path",
            self.get_process_working_directory(),
            self.getBuildArtifact("a.out")
        ])
        launch_info.SetWorkingDirectory(self.get_process_working_directory())
        error = lldb.SBError()
        process = target.Launch(launch_info, error)
        self.assertTrue(error.Success())

        # Stopped on main here.
        self.assertEqual(process.GetState(), lldb.eStateStopped)
        thread = process.GetSelectedThread()
        self.assertIn("main",
                      thread.GetFrameAtIndex(0).GetDisplayFunctionName())
        process.Continue()

        # Stopped on get_signal_crash function here.
        self.assertEqual(process.GetState(), lldb.eStateStopped)
        self.assertIn("get_signal_crash",
                      thread.GetFrameAtIndex(0).GetDisplayFunctionName())
        process.Continue()

        # Stopped because of generated signal.
        self.assertEqual(process.GetState(), lldb.eStateStopped)
        self.assertIn("raise",
                      thread.GetFrameAtIndex(0).GetDisplayFunctionName())
        self.assertIn("get_signal_crash",
                      thread.GetFrameAtIndex(1).GetDisplayFunctionName())
Example #3
0
    def _test(self):
        self.build()

        # Extracts path of the interpreter.
        exe = self.getBuildArtifact("a.out")

        spec = lldb.SBModuleSpec()
        spec.SetFileSpec(lldb.SBFileSpec(exe))
        interp_section = lldb.SBModule(spec).FindSection(".interp")
        if not interp_section:
            return
        section_data = interp_section.GetSectionData()
        error = lldb.SBError()
        dyld_path = section_data.GetString(error, 0)
        if error.Fail():
            return

        target = self.dbg.CreateTarget(exe)
        self.assertTrue(target, VALID_TARGET)

        # Set a breakpoint in the main function that will get hit after the
        # program exec's via the dynamic loader. The breakpoint will only get
        # hit if we can successfully read the shared library lists in the
        # DynamicLoaderPOSIXDYLD.cpp when we exec into the dynamic loader.
        breakpoint_main = target.BreakpointCreateBySourceRegex(
            "// Break here", lldb.SBFileSpec("main.cpp"))
        # Setup our launch info to supply the dynamic loader path to the
        # program so it gets two args:
        # - path to a.out
        # - path to dynamic loader
        launch_info = lldb.SBLaunchInfo([dyld_path])
        error = lldb.SBError()
        process = target.Launch(launch_info, error)
        self.assertSuccess(error)

        threads = lldbutil.get_stopped_threads(process, lldb.eStopReasonExec)
        self.assertEqual(len(threads), 1, "We got a thread stopped for exec.")

        process.Continue()

        # Stopped on main here.
        self.assertState(process.GetState(), lldb.eStateStopped)
        thread = process.GetSelectedThread()
        self.assertIn("main",
                      thread.GetFrameAtIndex(0).GetDisplayFunctionName())