147f79c60SJonas Devlieghereimport lldb 247f79c60SJonas Devliegherefrom lldbsuite.test.decorators import * 347f79c60SJonas Devliegherefrom lldbsuite.test.lldbtest import * 447f79c60SJonas Devliegherefrom lldbsuite.test import lldbutil 547f79c60SJonas Devlieghere 647f79c60SJonas Devlieghere 747f79c60SJonas Devlieghere@skipUnlessDarwin 847f79c60SJonas Devlieghereclass AddDsymDownload(TestBase): 9*2238dcc3SJonas Devlieghere dwarfdump_uuid_regex = re.compile("UUID: ([-0-9a-fA-F]+) \(([^\(]+)\) .*") 1047f79c60SJonas Devlieghere 1147f79c60SJonas Devlieghere def get_uuid(self): 1247f79c60SJonas Devlieghere dwarfdump_cmd_output = subprocess.check_output( 13*2238dcc3SJonas Devlieghere ('/usr/bin/dwarfdump --uuid "%s"' % self.exe), shell=True 14*2238dcc3SJonas Devlieghere ).decode("utf-8") 1547f79c60SJonas Devlieghere for line in dwarfdump_cmd_output.splitlines(): 1647f79c60SJonas Devlieghere match = self.dwarfdump_uuid_regex.search(line) 1747f79c60SJonas Devlieghere if match: 1847f79c60SJonas Devlieghere return match.group(1) 1947f79c60SJonas Devlieghere return None 2047f79c60SJonas Devlieghere 2147f79c60SJonas Devlieghere def create_dsym_for_uuid(self): 2247f79c60SJonas Devlieghere shell_cmds = [ 23*2238dcc3SJonas Devlieghere "#! /bin/sh", 24*2238dcc3SJonas Devlieghere "# the last argument is the uuid", 25*2238dcc3SJonas Devlieghere "while [ $# -gt 1 ]", 26*2238dcc3SJonas Devlieghere "do", 27*2238dcc3SJonas Devlieghere " shift", 28*2238dcc3SJonas Devlieghere "done", 29*2238dcc3SJonas Devlieghere "ret=0", 3047f79c60SJonas Devlieghere 'echo "<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>"', 3147f79c60SJonas Devlieghere 'echo "<!DOCTYPE plist PUBLIC \\"-//Apple//DTD PLIST 1.0//EN\\" \\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\\">"', 32*2238dcc3SJonas Devlieghere 'echo "<plist version=\\"1.0\\">"', 33*2238dcc3SJonas Devlieghere "", 34*2238dcc3SJonas Devlieghere 'if [ "$1" != "%s" ]' % (self.uuid), 35*2238dcc3SJonas Devlieghere "then", 3647f79c60SJonas Devlieghere ' echo "<key>DBGError</key><string>not found</string>"', 37*2238dcc3SJonas Devlieghere ' echo "</plist>"', 38*2238dcc3SJonas Devlieghere " exit 1", 39*2238dcc3SJonas Devlieghere "fi", 40*2238dcc3SJonas Devlieghere " uuid=%s" % self.uuid, 41*2238dcc3SJonas Devlieghere " bin=%s" % self.exe, 42*2238dcc3SJonas Devlieghere " dsym=%s" % self.dsym, 43*2238dcc3SJonas Devlieghere 'echo "<dict><key>$uuid</key><dict>"', 44*2238dcc3SJonas Devlieghere "", 4547f79c60SJonas Devlieghere 'echo "<key>DBGDSYMPath</key><string>$dsym</string>"', 4647f79c60SJonas Devlieghere 'echo "<key>DBGSymbolRichExecutable</key><string>$bin</string>"', 47*2238dcc3SJonas Devlieghere 'echo "</dict></dict></plist>"', 48*2238dcc3SJonas Devlieghere "exit $ret", 4947f79c60SJonas Devlieghere ] 5047f79c60SJonas Devlieghere 5147f79c60SJonas Devlieghere with open(self.dsym_for_uuid, "w") as writer: 5247f79c60SJonas Devlieghere for l in shell_cmds: 53*2238dcc3SJonas Devlieghere writer.write(l + "\n") 5447f79c60SJonas Devlieghere 5547f79c60SJonas Devlieghere os.chmod(self.dsym_for_uuid, 0o755) 5647f79c60SJonas Devlieghere 5747f79c60SJonas Devlieghere def setUp(self): 5847f79c60SJonas Devlieghere TestBase.setUp(self) 59*2238dcc3SJonas Devlieghere self.source = "main.c" 6047f79c60SJonas Devlieghere self.exe = self.getBuildArtifact("a.out") 6147f79c60SJonas Devlieghere self.dsym = os.path.join( 6247f79c60SJonas Devlieghere self.getBuildDir(), 6347f79c60SJonas Devlieghere "hide.app/Contents/a.out.dSYM/Contents/Resources/DWARF/", 64*2238dcc3SJonas Devlieghere os.path.basename(self.exe), 65*2238dcc3SJonas Devlieghere ) 6647f79c60SJonas Devlieghere self.dsym_for_uuid = self.getBuildArtifact("dsym-for-uuid.sh") 6747f79c60SJonas Devlieghere 688bac18beSPavel Labath self.build(debug_info="dsym") 6947f79c60SJonas Devlieghere self.assertTrue(os.path.exists(self.exe)) 7047f79c60SJonas Devlieghere self.assertTrue(os.path.exists(self.dsym)) 7147f79c60SJonas Devlieghere 7247f79c60SJonas Devlieghere self.uuid = self.get_uuid() 7347f79c60SJonas Devlieghere self.assertNotEqual(self.uuid, None, "Could not get uuid for a.out") 7447f79c60SJonas Devlieghere 7547f79c60SJonas Devlieghere self.create_dsym_for_uuid() 7647f79c60SJonas Devlieghere 77*2238dcc3SJonas Devlieghere os.environ["LLDB_APPLE_DSYMFORUUID_EXECUTABLE"] = self.dsym_for_uuid 7847f79c60SJonas Devlieghere self.addTearDownHook( 79*2238dcc3SJonas Devlieghere lambda: os.environ.pop("LLDB_APPLE_DSYMFORUUID_EXECUTABLE", None) 80*2238dcc3SJonas Devlieghere ) 8147f79c60SJonas Devlieghere 8247f79c60SJonas Devlieghere def do_test(self, command): 8347f79c60SJonas Devlieghere self.target = self.dbg.CreateTarget(self.exe) 8447f79c60SJonas Devlieghere self.assertTrue(self.target, VALID_TARGET) 8547f79c60SJonas Devlieghere 8647f79c60SJonas Devlieghere main_bp = self.target.BreakpointCreateByName("main", "a.out") 8747f79c60SJonas Devlieghere self.assertTrue(main_bp, VALID_BREAKPOINT) 8847f79c60SJonas Devlieghere 8947f79c60SJonas Devlieghere self.process = self.target.LaunchSimple( 90*2238dcc3SJonas Devlieghere None, None, self.get_process_working_directory() 91*2238dcc3SJonas Devlieghere ) 9247f79c60SJonas Devlieghere self.assertTrue(self.process, PROCESS_IS_VALID) 9347f79c60SJonas Devlieghere 9447f79c60SJonas Devlieghere # The stop reason of the thread should be breakpoint. 95*2238dcc3SJonas Devlieghere self.assertState( 96*2238dcc3SJonas Devlieghere self.process.GetState(), lldb.eStateStopped, STOPPED_DUE_TO_BREAKPOINT 97*2238dcc3SJonas Devlieghere ) 9847f79c60SJonas Devlieghere 9947f79c60SJonas Devlieghere self.runCmd(command) 100*2238dcc3SJonas Devlieghere self.expect("frame select", substrs=["a.out`main at main.c"]) 10147f79c60SJonas Devlieghere 10247f79c60SJonas Devlieghere @no_debug_info_test 10347f79c60SJonas Devlieghere def test_frame(self): 10447f79c60SJonas Devlieghere self.do_test("add-dsym --frame") 10547f79c60SJonas Devlieghere 10647f79c60SJonas Devlieghere @no_debug_info_test 10747f79c60SJonas Devlieghere def test_uuid(self): 10847f79c60SJonas Devlieghere self.do_test("add-dsym --uuid {}".format(self.uuid)) 10947f79c60SJonas Devlieghere 11047f79c60SJonas Devlieghere @no_debug_info_test 11147f79c60SJonas Devlieghere def test_stack(self): 11247f79c60SJonas Devlieghere self.do_test("add-dsym --stack") 113