brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.5 KiB · 9216cf2 Raw
72 lines · python
1"""2Test that we read don't read the nlist symbols for a specially marked dylib3when read from memory.4"""5 6import os7import lldb8from lldbsuite.test.decorators import *9from lldbsuite.test.lldbtest import *10from lldbsuite.test import lldbutil11from time import sleep12 13 14class NoNlistsTestCase(TestBase):15    NO_DEBUG_INFO_TESTCASE = True16 17    @skipIfRemote18    @skipUnlessDarwin19    def test_no_nlist_symbols(self):20        self.build()21 22        exe = os.path.realpath(self.getBuildArtifact("a.out"))23 24        # Use a file as a synchronization point between test and inferior.25        pid_file_path = lldbutil.append_to_process_working_directory(26            self, "pid_file_%d" % (int(time.time()))27        )28        self.addTearDownHook(29            lambda: self.run_platform_command("rm %s" % (pid_file_path))30        )31 32        # Spawn a new process33        popen = self.spawnSubprocess(exe, [pid_file_path])34 35        pid = lldbutil.wait_for_file_on_target(self, pid_file_path)36 37        os.unlink(self.getBuildArtifact("libno-nlists.dylib"))38        os.unlink(self.getBuildArtifact("libhas-nlists.dylib"))39 40        self.runCmd("process attach -p " + str(pid))41        target = self.dbg.GetSelectedTarget()42        process = target.GetProcess()43        m_no_nlist = target.FindModule(lldb.SBFileSpec("libno-nlists.dylib"))44        m_has_nlist = target.FindModule(lldb.SBFileSpec("libhas-nlists.dylib"))45 46        self.assertTrue(process, PROCESS_IS_VALID)47 48        if self.TraceOn():49            self.runCmd("image list")50            self.runCmd("target modules dump symtab libno-nlists.dylib")51            self.runCmd("target modules dump symtab libhas-nlists.dylib")52 53        # Test that we found libno-nlists.dylib, it is a memory54        # module, and that it has no symbols.55        self.assertTrue(m_no_nlist.IsValid())56        self.assertFalse(m_no_nlist.IsFileBacked())57        self.assertEqual(m_no_nlist.GetNumSymbols(), 0)58 59        # Test that we found libhas-nlists.dylib, it is a memory60        # module, and that it has more than zero symbols.61        self.assertTrue(m_has_nlist.IsValid())62        self.assertFalse(m_has_nlist.IsFileBacked())63        self.assertGreater(m_has_nlist.GetNumSymbols(), 0)64 65        # And as a sanity check, get the main binary's module,66        # test that it is file backed and that it has more than67        # zero symbols.68        m_exe = target.FindModule(lldb.SBFileSpec("a.out"))69        self.assertTrue(m_exe.IsValid())70        self.assertTrue(m_exe.IsFileBacked())71        self.assertGreater(m_exe.GetNumSymbols(), 0)72