1"""Test that a dSYM can be found when a binary is in a bundle hnd has dots in the filename."""
2
3
4#import unittest2
5import os.path
6from time import sleep
7
8import lldb
9from lldbsuite.test.decorators import *
10from lldbsuite.test.lldbtest import *
11from lldbsuite.test import lldbutil
12
13
14exe_name = 'find-bundle-with-dots-in-fn'  # must match Makefile
15
16class BundleWithDotInFilenameTestCase(TestBase):
17
18    mydir = TestBase.compute_mydir(__file__)
19
20    @skipIfRemote
21    @skipUnlessDarwin
22    # This test is explicitly a dSYM test, it doesn't need to run for any other config, but
23    # the following doesn't work, fixme.
24    # @skipIf(debug_info=no_match(["dsym"]), bugnumber="This test is looking explicitly for a dSYM")
25
26    def setUp(self):
27        TestBase.setUp(self)
28        self.source = 'main.c'
29
30    def tearDown(self):
31        # Destroy process before TestBase.tearDown()
32        self.dbg.GetSelectedTarget().GetProcess().Destroy()
33
34        # Call super's tearDown().
35        TestBase.tearDown(self)
36
37    def test_attach_and_check_dsyms(self):
38        """Test attach to binary, see if the bundle dSYM is found"""
39        exe = self.getBuildArtifact(exe_name)
40        self.build()
41        os.chdir(self.getBuildDir());
42        popen = self.spawnSubprocess(exe)
43        self.addTearDownHook(self.cleanupSubprocesses)
44
45        # Give the inferior time to start up, dlopen a bundle, remove the bundle it linked in
46        sleep(5)
47
48        # Since the library that was dlopen()'ed is now removed, lldb will need to find the
49        # binary & dSYM via target.exec-search-paths
50        settings_str = "settings set target.exec-search-paths " + self.get_process_working_directory() + "/hide.app"
51        self.runCmd(settings_str)
52
53        self.runCmd("process attach -p " + str(popen.pid))
54
55        target = self.dbg.GetSelectedTarget()
56        self.assertTrue(target.IsValid(), 'Should have a valid Target after attaching to process')
57
58        setup_complete = target.FindFirstGlobalVariable("setup_is_complete")
59        self.assertEquals(setup_complete.GetValueAsUnsigned(), 1, 'Check that inferior process has completed setup')
60
61        # Find the bundle module, see if we found the dSYM too (they're both in "hide.app")
62        i = 0
63        while i < target.GetNumModules():
64            mod = target.GetModuleAtIndex(i)
65            if mod.GetFileSpec().GetFilename() == 'com.apple.sbd':
66                dsym_name = mod.GetSymbolFileSpec().GetFilename()
67                self.assertTrue (dsym_name == 'com.apple.sbd', "Check that we found the dSYM for the bundle that was loaded")
68            i=i+1
69        os.chdir(self.getSourceDir());
70
71if __name__ == '__main__':
72    unittest.main()
73