87 lines · python
1"""Test that a dSYM can be found when a binary is in a bundle hnd has dots in the filename."""2 3 4import os.path5from time import sleep6 7import lldb8from lldbsuite.test.decorators import *9from lldbsuite.test.lldbtest import *10from lldbsuite.test import lldbutil11 12 13exe_name = "find-bundle-with-dots-in-fn" # must match Makefile14 15 16class BundleWithDotInFilenameTestCase(TestBase):17 def setUp(self):18 TestBase.setUp(self)19 self.source = "main.c"20 21 def tearDown(self):22 # Destroy process before TestBase.tearDown()23 self.dbg.GetSelectedTarget().GetProcess().Destroy()24 25 # Call super's tearDown().26 TestBase.tearDown(self)27 28 @skipIfRemote29 @skipUnlessDarwin30 # This test is explicitly a dSYM test, it doesn't need to run for any other config.31 @skipIf(debug_info=no_match(["dsym"]))32 def test_attach_and_check_dsyms(self):33 """Test attach to binary, see if the bundle dSYM is found"""34 exe = self.getBuildArtifact(exe_name)35 self.build()36 os.chdir(self.getBuildDir())37 38 # Use a file as a synchronization point between test and inferior.39 pid_file_path = lldbutil.append_to_process_working_directory(40 self, "token_pid_%d" % (int(os.getpid()))41 )42 self.addTearDownHook(43 lambda: self.run_platform_command("rm %s" % (pid_file_path))44 )45 46 popen = self.spawnSubprocess(exe, [pid_file_path])47 48 # Wait for the inferior to start up, dlopen a bundle, remove the bundle it linked in49 pid = lldbutil.wait_for_file_on_target(self, pid_file_path)50 51 # Since the library that was dlopen()'ed is now removed, lldb will need to find the52 # binary & dSYM via target.exec-search-paths53 settings_str = (54 "settings set target.exec-search-paths "55 + self.get_process_working_directory()56 + "/hide.app"57 )58 self.runCmd(settings_str)59 60 self.runCmd("process attach -p " + str(popen.pid))61 62 target = self.dbg.GetSelectedTarget()63 self.assertTrue(64 target.IsValid(), "Should have a valid Target after attaching to process"65 )66 67 setup_complete = target.FindFirstGlobalVariable("setup_is_complete")68 self.assertEqual(69 setup_complete.GetValueAsUnsigned(),70 1,71 "Check that inferior process has completed setup",72 )73 74 # Find the bundle module, see if we found the dSYM too (they're both in "hide.app")75 i = 076 while i < target.GetNumModules():77 mod = target.GetModuleAtIndex(i)78 if mod.GetFileSpec().GetFilename() == "com.apple.sbd":79 dsym_name = mod.GetSymbolFileSpec().GetFilename()80 self.assertEqual(81 dsym_name,82 "com.apple.sbd",83 "Check that we found the dSYM for the bundle that was loaded",84 )85 i = i + 186 os.chdir(self.getSourceDir())87