199451b44SJordan Rupprecht"""Test that a dSYM can be found when a binary is in a bundle hnd has dots in the filename.""" 299451b44SJordan Rupprecht 399451b44SJordan Rupprecht 499451b44SJordan Rupprechtimport os.path 599451b44SJordan Rupprechtfrom time import sleep 699451b44SJordan Rupprecht 799451b44SJordan Rupprechtimport lldb 899451b44SJordan Rupprechtfrom lldbsuite.test.decorators import * 999451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import * 1099451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil 1199451b44SJordan Rupprecht 1299451b44SJordan Rupprecht 132238dcc3SJonas Devlieghereexe_name = "find-bundle-with-dots-in-fn" # must match Makefile 142238dcc3SJonas Devlieghere 1599451b44SJordan Rupprecht 1699451b44SJordan Rupprechtclass BundleWithDotInFilenameTestCase(TestBase): 1799451b44SJordan Rupprecht def setUp(self): 1899451b44SJordan Rupprecht TestBase.setUp(self) 192238dcc3SJonas Devlieghere self.source = "main.c" 2099451b44SJordan Rupprecht 2199451b44SJordan Rupprecht def tearDown(self): 2299451b44SJordan Rupprecht # Destroy process before TestBase.tearDown() 2399451b44SJordan Rupprecht self.dbg.GetSelectedTarget().GetProcess().Destroy() 2499451b44SJordan Rupprecht 2599451b44SJordan Rupprecht # Call super's tearDown(). 2699451b44SJordan Rupprecht TestBase.tearDown(self) 2799451b44SJordan Rupprecht 287e825abdSAdrian Prantl @skipIfRemote 297e825abdSAdrian Prantl @skipUnlessDarwin 307e825abdSAdrian Prantl # This test is explicitly a dSYM test, it doesn't need to run for any other config. 317e825abdSAdrian Prantl @skipIf(debug_info=no_match(["dsym"])) 3299451b44SJordan Rupprecht def test_attach_and_check_dsyms(self): 3399451b44SJordan Rupprecht """Test attach to binary, see if the bundle dSYM is found""" 3499451b44SJordan Rupprecht exe = self.getBuildArtifact(exe_name) 3599451b44SJordan Rupprecht self.build() 362238dcc3SJonas Devlieghere os.chdir(self.getBuildDir()) 3799451b44SJordan Rupprecht 3837ec83fcSJonas Devlieghere # Use a file as a synchronization point between test and inferior. 392238dcc3SJonas Devlieghere pid_file_path = lldbutil.append_to_process_working_directory( 402238dcc3SJonas Devlieghere self, "token_pid_%d" % (int(os.getpid())) 412238dcc3SJonas Devlieghere ) 4237ec83fcSJonas Devlieghere self.addTearDownHook( 432238dcc3SJonas Devlieghere lambda: self.run_platform_command("rm %s" % (pid_file_path)) 442238dcc3SJonas Devlieghere ) 4537ec83fcSJonas Devlieghere 4637ec83fcSJonas Devlieghere popen = self.spawnSubprocess(exe, [pid_file_path]) 4737ec83fcSJonas Devlieghere 4837ec83fcSJonas Devlieghere # Wait for the inferior to start up, dlopen a bundle, remove the bundle it linked in 4937ec83fcSJonas Devlieghere pid = lldbutil.wait_for_file_on_target(self, pid_file_path) 5099451b44SJordan Rupprecht 5199451b44SJordan Rupprecht # Since the library that was dlopen()'ed is now removed, lldb will need to find the 5299451b44SJordan Rupprecht # binary & dSYM via target.exec-search-paths 532238dcc3SJonas Devlieghere settings_str = ( 542238dcc3SJonas Devlieghere "settings set target.exec-search-paths " 552238dcc3SJonas Devlieghere + self.get_process_working_directory() 562238dcc3SJonas Devlieghere + "/hide.app" 572238dcc3SJonas Devlieghere ) 5899451b44SJordan Rupprecht self.runCmd(settings_str) 5999451b44SJordan Rupprecht 6099451b44SJordan Rupprecht self.runCmd("process attach -p " + str(popen.pid)) 6199451b44SJordan Rupprecht 6299451b44SJordan Rupprecht target = self.dbg.GetSelectedTarget() 632238dcc3SJonas Devlieghere self.assertTrue( 642238dcc3SJonas Devlieghere target.IsValid(), "Should have a valid Target after attaching to process" 652238dcc3SJonas Devlieghere ) 6699451b44SJordan Rupprecht 6799451b44SJordan Rupprecht setup_complete = target.FindFirstGlobalVariable("setup_is_complete") 68*80fcecb1SJonas Devlieghere self.assertEqual( 692238dcc3SJonas Devlieghere setup_complete.GetValueAsUnsigned(), 702238dcc3SJonas Devlieghere 1, 712238dcc3SJonas Devlieghere "Check that inferior process has completed setup", 722238dcc3SJonas Devlieghere ) 7399451b44SJordan Rupprecht 7499451b44SJordan Rupprecht # Find the bundle module, see if we found the dSYM too (they're both in "hide.app") 7599451b44SJordan Rupprecht i = 0 7699451b44SJordan Rupprecht while i < target.GetNumModules(): 7799451b44SJordan Rupprecht mod = target.GetModuleAtIndex(i) 782238dcc3SJonas Devlieghere if mod.GetFileSpec().GetFilename() == "com.apple.sbd": 7999451b44SJordan Rupprecht dsym_name = mod.GetSymbolFileSpec().GetFilename() 802238dcc3SJonas Devlieghere self.assertEqual( 812238dcc3SJonas Devlieghere dsym_name, 822238dcc3SJonas Devlieghere "com.apple.sbd", 832238dcc3SJonas Devlieghere "Check that we found the dSYM for the bundle that was loaded", 842238dcc3SJonas Devlieghere ) 8599451b44SJordan Rupprecht i = i + 1 862238dcc3SJonas Devlieghere os.chdir(self.getSourceDir()) 87