예제 #1
0
    def _ElfPathAndToolPrefixForSymbol(self, symbol, elf_path, tool_prefix):
        size_info = None
        size_path = None
        for size_info, size_path in zip(self._size_infos, self._size_paths):
            if symbol in size_info.raw_symbols:
                break
        else:
            # If symbols is from a diff(), use its address+name to find it.
            for size_info, size_path in zip(self._size_infos,
                                            self._size_paths):
                matched = size_info.raw_symbols.WhereAddressInRange(
                    symbol.address)
                # Use last matched symbol to skip over padding-only symbols.
                if len(matched
                       ) > 0 and matched[-1].full_name == symbol.full_name:
                    symbol = matched[-1]
                    break
            else:
                assert False, 'Symbol does not belong to a size_info.'

        orig_tool_prefix = size_info.metadata.get(models.METADATA_TOOL_PREFIX)
        if orig_tool_prefix:
            orig_tool_prefix = paths.FromSrcRootRelative(orig_tool_prefix)
            if os.path.exists(orig_tool_prefix + 'objdump'):
                tool_prefix = orig_tool_prefix

        # TODO(agrieve): Would be even better to use objdump --info to check that
        #     the toolchain is for the correct architecture.
        assert tool_prefix is not None, (
            'Could not determine --tool-prefix. Possible fixes include setting '
            '--tool-prefix, or setting --output-directory')

        if elf_path is None:
            filename = size_info.metadata.get(models.METADATA_ELF_FILENAME)
            output_dir = self._lazy_paths.output_directory
            size_path = self._size_paths[self._size_infos.index(size_info)]
            if output_dir:
                # Local build: File is located in output directory.
                path = os.path.normpath(os.path.join(output_dir, filename))
            if not output_dir or not os.path.exists(path):
                # Downloaded build: File is located beside .size file.
                path = os.path.normpath(
                    os.path.join(os.path.dirname(size_path),
                                 os.path.basename(filename)))

            assert os.path.exists(path), (
                'Could locate ELF file. If binary was built locally, ensure '
                '--output-directory is set. If output directory is unavailable, '
                'ensure {} is located beside {}, or pass its path explicitly using '
                'elf_path=').format(os.path.basename(filename), size_path)

        found_build_id = archive.BuildIdFromElf(path, tool_prefix)
        expected_build_id = size_info.metadata.get(
            models.METADATA_ELF_BUILD_ID)
        assert found_build_id == expected_build_id, (
            'Build ID does not match for %s' % path)
        return path, tool_prefix
예제 #2
0
 def build_id_matches(elf_path):
     found_build_id = archive.BuildIdFromElf(elf_path, tool_prefix)
     expected_build_id = size_info.metadata.get(
         models.METADATA_ELF_BUILD_ID)
     return found_build_id == expected_build_id