def test_SBModule(self):
     obj = lldb.SBModule()
     if self.TraceOn():
         print obj
     self.assertFalse(obj)
     # Do fuzz testing on the invalid obj, it should not crash lldb.
     import sb_module
     sb_module.fuzz_obj(obj)
 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())
Exemple #3
0
def modules_loaded(sbmodule_addrs, assign_sbmodule_addr):
    assign_sbmodule = ASSIGN_SBMODULE(assign_sbmodule_addr)
    # SWIG does not provide a method for wrapping raw pointers from Python,
    # so we create a dummy module object, then call back into Rust code to
    # overwrite it with the module we need wrapped.
    for addr in sbmodule_addrs:
        sbmodule = lldb.SBModule(
        )  # Recreate, because sbmodule.compile_units will cache the list
        assign_sbmodule(long(sbmodule.this), addr)
        analyze_module(sbmodule)
Exemple #4
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())
Exemple #5
0
    def find_module(self, target, name):
        num_modules = target.GetNumModules()
        index = 0
        result = lldb.SBModule()

        while index < num_modules:
            module = target.GetModuleAtIndex(index)
            if module.GetFileSpec().GetFilename() == name:
                result = module
                break

            index += 1

        self.assertTrue(result.IsValid())
        return result
Exemple #6
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())
    def test_is_loaded(self):
        """Exercise SBTarget.IsLoaded(SBModule&) API."""
        d = {'EXE': 'b.out'}
        self.build(dictionary=d)
        self.setTearDownCleanup(dictionary=d)
        target = self.create_simple_target('b.out')

        self.assertFalse(target.IsLoaded(lldb.SBModule()))

        num_modules = target.GetNumModules()
        for i in range(num_modules):
            module = target.GetModuleAtIndex(i)
            self.assertFalse(target.IsLoaded(module), "Target that isn't "
                             "running shouldn't have any module loaded.")

        process = target.LaunchSimple(None, None,
                                      self.get_process_working_directory())

        for i in range(num_modules):
            module = target.GetModuleAtIndex(i)
            self.assertTrue(target.IsLoaded(module), "Running the target should "
                            "have loaded its modules.")