brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.7 KiB · 8ff72c9 Raw
113 lines · python
1import lldb2from lldbsuite.test.decorators import *3from lldbsuite.test.lldbtest import *4from lldbsuite.test import lldbutil5 6 7@skipUnlessDarwin8class AddDsymDownload(TestBase):9    dwarfdump_uuid_regex = re.compile(r"UUID: ([-0-9a-fA-F]+) \(([^\(]+)\) .*")10 11    def get_uuid(self):12        dwarfdump_cmd_output = subprocess.check_output(13            ('/usr/bin/dwarfdump --uuid "%s"' % self.exe), shell=True14        ).decode("utf-8")15        for line in dwarfdump_cmd_output.splitlines():16            match = self.dwarfdump_uuid_regex.search(line)17            if match:18                return match.group(1)19        return None20 21    def create_dsym_for_uuid(self):22        shell_cmds = [23            "#! /bin/sh",24            "# the last argument is the uuid",25            "while [ $# -gt 1 ]",26            "do",27            "  shift",28            "done",29            "ret=0",30            'echo "<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>"',31            'echo "<!DOCTYPE plist PUBLIC \\"-//Apple//DTD PLIST 1.0//EN\\" \\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\\">"',32            'echo "<plist version=\\"1.0\\">"',33            "",34            'if [ "$1" != "%s" ]' % (self.uuid),35            "then",36            '  echo "<key>DBGError</key><string>not found</string>"',37            '  echo "</plist>"',38            "  exit 1",39            "fi",40            "  uuid=%s" % self.uuid,41            "  bin=%s" % self.exe,42            "  dsym=%s" % self.dsym,43            'echo "<dict><key>$uuid</key><dict>"',44            "",45            'echo "<key>DBGDSYMPath</key><string>$dsym</string>"',46            'echo "<key>DBGSymbolRichExecutable</key><string>$bin</string>"',47            'echo "</dict></dict></plist>"',48            "exit $ret",49        ]50 51        with open(self.dsym_for_uuid, "w") as writer:52            for l in shell_cmds:53                writer.write(l + "\n")54 55        os.chmod(self.dsym_for_uuid, 0o755)56 57    def setUp(self):58        TestBase.setUp(self)59        self.source = "main.c"60        self.exe = self.getBuildArtifact("a.out")61        self.dsym = os.path.join(62            self.getBuildDir(),63            "hide.app/Contents/a.out.dSYM/Contents/Resources/DWARF/",64            os.path.basename(self.exe),65        )66        self.dsym_for_uuid = self.getBuildArtifact("dsym-for-uuid.sh")67 68        self.build(debug_info="dsym")69        self.assertTrue(os.path.exists(self.exe))70        self.assertTrue(os.path.exists(self.dsym))71 72        self.uuid = self.get_uuid()73        self.assertNotEqual(self.uuid, None, "Could not get uuid for a.out")74 75        self.create_dsym_for_uuid()76 77        os.environ["LLDB_APPLE_DSYMFORUUID_EXECUTABLE"] = self.dsym_for_uuid78        self.addTearDownHook(79            lambda: os.environ.pop("LLDB_APPLE_DSYMFORUUID_EXECUTABLE", None)80        )81 82    def do_test(self, command):83        self.target = self.dbg.CreateTarget(self.exe)84        self.assertTrue(self.target, VALID_TARGET)85 86        main_bp = self.target.BreakpointCreateByName("main", "a.out")87        self.assertTrue(main_bp, VALID_BREAKPOINT)88 89        self.process = self.target.LaunchSimple(90            None, None, self.get_process_working_directory()91        )92        self.assertTrue(self.process, PROCESS_IS_VALID)93 94        # The stop reason of the thread should be breakpoint.95        self.assertState(96            self.process.GetState(), lldb.eStateStopped, STOPPED_DUE_TO_BREAKPOINT97        )98 99        self.runCmd(command)100        self.expect("frame select", substrs=["a.out`main at main.c"])101 102    @no_debug_info_test103    def test_frame(self):104        self.do_test("add-dsym --frame")105 106    @no_debug_info_test107    def test_uuid(self):108        self.do_test("add-dsym --uuid {}".format(self.uuid))109 110    @no_debug_info_test111    def test_stack(self):112        self.do_test("add-dsym --stack")113