def _ElfPathAndToolPrefixForSymbol(self, size_info, elf_path): tool_prefix = self._tool_prefix_finder.Tentative() orig_tool_prefix = size_info.metadata.get(models.METADATA_TOOL_PREFIX) if orig_tool_prefix: orig_tool_prefix = path_util.FromSrcRootRelative(orig_tool_prefix) if os.path.exists(path_util.GetObjDumpPath(orig_tool_prefix)): 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') 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 filename = size_info.metadata.get(models.METADATA_ELF_FILENAME) paths_to_try = [] if elf_path: paths_to_try.append(elf_path) else: auto_output_directory_finders = [ path_util.OutputDirectoryFinder( any_path_within_output_directory=s.size_path) for s in self._size_infos ] + [self._output_directory_finder] for output_directory_finder in auto_output_directory_finders: output_dir = output_directory_finder.Tentative() if output_dir: # Local build: File is located in output directory. paths_to_try.append( os.path.normpath(os.path.join(output_dir, filename))) # Downloaded build: File is located beside .size file. paths_to_try.append( os.path.normpath( os.path.join(os.path.dirname(size_info.size_path), os.path.basename(filename)))) paths_to_try = [p for p in paths_to_try if os.path.exists(p)] for i, elf_path in enumerate(paths_to_try): if build_id_matches(elf_path): return elf_path, tool_prefix # Show an error only once all paths are tried. if i + 1 == len(paths_to_try): assert False, 'Build ID does not match for %s' % elf_path assert False, ( 'Could not 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_info.size_path)
def _ToolPrefixForSymbol(self, size_info): tool_prefix = self._tool_prefix_finder.Tentative() orig_tool_prefix = size_info.metadata.get(models.METADATA_TOOL_PREFIX) if orig_tool_prefix: orig_tool_prefix = path_util.FromSrcRootRelative(orig_tool_prefix) if os.path.exists(path_util.GetObjDumpPath(orig_tool_prefix)): 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') return tool_prefix