199451b44SJordan Rupprecht"""Test that a dSYM can be found when a binary is in a deep bundle with multiple pathname components.""" 299451b44SJordan Rupprecht 399451b44SJordan Rupprecht 499451b44SJordan Rupprechtfrom time import sleep 599451b44SJordan Rupprecht 699451b44SJordan Rupprechtimport lldb 799451b44SJordan Rupprechtfrom lldbsuite.test.decorators import * 899451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import * 999451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil 1099451b44SJordan Rupprecht 1199451b44SJordan Rupprecht 122238dcc3SJonas Devlieghereexe_name = "deep-bundle" # must match Makefile 132238dcc3SJonas Devlieghere 1499451b44SJordan Rupprecht 1599451b44SJordan Rupprechtclass DeepBundleTestCase(TestBase): 1699451b44SJordan Rupprecht def setUp(self): 1799451b44SJordan Rupprecht TestBase.setUp(self) 182238dcc3SJonas Devlieghere self.source = "main.c" 1999451b44SJordan Rupprecht 2099451b44SJordan Rupprecht def tearDown(self): 2199451b44SJordan Rupprecht # Destroy process before TestBase.tearDown() 2299451b44SJordan Rupprecht self.dbg.GetSelectedTarget().GetProcess().Destroy() 2399451b44SJordan Rupprecht 2499451b44SJordan Rupprecht # Call super's tearDown(). 2599451b44SJordan Rupprecht TestBase.tearDown(self) 2699451b44SJordan Rupprecht 277e825abdSAdrian Prantl @skipIfRemote 287e825abdSAdrian Prantl @skipUnlessDarwin 297e825abdSAdrian Prantl # This test is explicitly a dSYM test, it doesn't need to run for any other config. 307e825abdSAdrian Prantl @skipIf(debug_info=no_match(["dsym"])) 3199451b44SJordan Rupprecht def test_attach_and_check_dsyms(self): 3299451b44SJordan Rupprecht """Test attach to binary, see if the framework dSYM is found""" 3399451b44SJordan Rupprecht exe = self.getBuildArtifact(exe_name) 3499451b44SJordan Rupprecht self.build() 3599451b44SJordan Rupprecht 3637ec83fcSJonas Devlieghere # Use a file as a synchronization point between test and inferior. 372238dcc3SJonas Devlieghere pid_file_path = lldbutil.append_to_process_working_directory( 382238dcc3SJonas Devlieghere self, "token_pid_%d" % (int(os.getpid())) 392238dcc3SJonas Devlieghere ) 4037ec83fcSJonas Devlieghere self.addTearDownHook( 412238dcc3SJonas Devlieghere lambda: self.run_platform_command("rm %s" % (pid_file_path)) 422238dcc3SJonas Devlieghere ) 4337ec83fcSJonas Devlieghere 4437ec83fcSJonas Devlieghere popen = self.spawnSubprocess(exe, [self.getBuildDir(), pid_file_path]) 4537ec83fcSJonas Devlieghere 4637ec83fcSJonas Devlieghere # Wait for the inferior to start up, dlopen a bundle, remove the bundle it linked in 4737ec83fcSJonas Devlieghere pid = lldbutil.wait_for_file_on_target(self, pid_file_path) 4899451b44SJordan Rupprecht 4999451b44SJordan Rupprecht # Since the library that was dlopen()'ed is now removed, lldb will need to find the 5099451b44SJordan Rupprecht # binary & dSYM via target.exec-search-paths 512238dcc3SJonas Devlieghere settings_str = ( 522238dcc3SJonas Devlieghere "settings set target.exec-search-paths " 532238dcc3SJonas Devlieghere + self.get_process_working_directory() 542238dcc3SJonas Devlieghere + "/hide.app" 552238dcc3SJonas Devlieghere ) 5699451b44SJordan Rupprecht self.runCmd(settings_str) 5799451b44SJordan Rupprecht self.runCmd("process attach -p " + str(popen.pid)) 5899451b44SJordan Rupprecht 5999451b44SJordan Rupprecht target = self.dbg.GetSelectedTarget() 602238dcc3SJonas Devlieghere self.assertTrue( 612238dcc3SJonas Devlieghere target.IsValid(), "Should have a valid Target after attaching to process" 622238dcc3SJonas Devlieghere ) 6399451b44SJordan Rupprecht 6499451b44SJordan Rupprecht setup_complete = target.FindFirstGlobalVariable("setup_is_complete") 65*80fcecb1SJonas Devlieghere self.assertEqual( 662238dcc3SJonas Devlieghere setup_complete.GetValueAsUnsigned(), 672238dcc3SJonas Devlieghere 1, 682238dcc3SJonas Devlieghere "Check that inferior process has completed setup", 692238dcc3SJonas Devlieghere ) 7099451b44SJordan Rupprecht 7199451b44SJordan Rupprecht # Find the bundle module, see if we found the dSYM too (they're both in "hide.app") 7299451b44SJordan Rupprecht i = 0 7399451b44SJordan Rupprecht found_module = False 7499451b44SJordan Rupprecht while i < target.GetNumModules(): 7599451b44SJordan Rupprecht mod = target.GetModuleAtIndex(i) 762238dcc3SJonas Devlieghere if mod.GetFileSpec().GetFilename() == "MyFramework": 7799451b44SJordan Rupprecht found_module = True 7899451b44SJordan Rupprecht dsym_name = mod.GetSymbolFileSpec().GetFilename() 792238dcc3SJonas Devlieghere self.assertEqual( 802238dcc3SJonas Devlieghere dsym_name, 812238dcc3SJonas Devlieghere "MyFramework", 822238dcc3SJonas Devlieghere "Check that we found the dSYM for the bundle that was loaded", 832238dcc3SJonas Devlieghere ) 8499451b44SJordan Rupprecht i = i + 1 8599451b44SJordan Rupprecht 862238dcc3SJonas Devlieghere self.assertTrue( 872238dcc3SJonas Devlieghere found_module, 882238dcc3SJonas Devlieghere "Check that we found the framework loaded in lldb's image list", 892238dcc3SJonas Devlieghere ) 90