Commit 591e5064 authored by David 'Digit' Turner's avatar David 'Digit' Turner Committed by Commit Bot

android: apk_native_libs.py: New Python helper functions.

This CL introduces a new Python script providing various
functions to make it easier to parse Android APK files
for symbolization, i.e.:

- ApkReader: convenience class to read the content of an APK,
  especially information related to uncompressed native shared
  libraries. Mostly useful because it can be easily mocked
  for unit-testing purpose.

- ApkNativeLibrariesMap: convenience class to build a map
  of native shared libraries contained in an APK.

- ApkLibraryPathTranslator: convenience class used to translate
  on-device APK file paths and offsets (as found in stack traces
  or tombstones) into a virtual device library path + offset.

+ Add unit-tests for all features.

+ Add a small apk_lib_dump.py script used to dump the list of
  uncompressed native libraries inside an APK and their file
  start/end offsets and sizes. This is mostly useful for debugging
  symbolization issues.

NOTE: This is a partial rewrite of the corresponding code from
      the following patch, which shows how this will be used in
      the future to better symbolize tombstones:

    https://chromium-review.googlesource.com/c/chromium/src/+/1034054

BUG=755225
R=agrieve@chromium.org, jduborick@chromium.org, pasko@chromium.org, lizeb@chromium.org

Change-Id: If71e0048fa88c859e5f256d8c960134b6b88d06f
Reviewed-on: https://chromium-review.googlesource.com/1047211
Commit-Queue: David Turner <digit@chromium.org>
Reviewed-by: default avatarEgor Pasko <pasko@chromium.org>
Reviewed-by: default avataragrieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576193}
parent 9579e5a1
......@@ -72,6 +72,7 @@ def CommonChecks(input_api, output_api):
J('pylib', 'output', 'noop_output_manager_test.py'),
J('pylib', 'output', 'remote_output_manager_test.py'),
J('pylib', 'results', 'json_results_test.py'),
J('pylib', 'symbols', 'apk_native_libs_unittest.py'),
J('pylib', 'symbols', 'elf_symbolizer_unittest.py'),
J('pylib', 'utils', 'decorators_test.py'),
J('pylib', 'utils', 'device_dependencies_test.py'),
......
#!/usr/bin/env python
# Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Dump shared library information from an APK file.
This script is used to dump which *uncompressed* native shared libraries an
APK contains, as well as their position within the file. This is mostly useful
to diagnose logcat and tombstone symbolization issues when the libraries are
loaded directly from the APK at runtime.
The default format will print one line per uncompressed shared library with the
following format:
0x<start-offset> 0x<end-offset> 0x<file-size> <file-path>
The --format=python option can be used to dump the same information that is
easy to use in a Python script, e.g. with a line like:
(0x<start-offset>, 0x<end-offset>, 0x<file-size>, <file-path>),
"""
import argparse
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
from pylib.symbols import apk_native_libs
def main():
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('apk', help='Input APK file path.')
parser.add_argument('--format', help='Select output format',
default='default', choices=['default', 'python'])
args = parser.parse_args()
apk_reader = apk_native_libs.ApkReader(args.apk)
lib_map = apk_native_libs.ApkNativeLibraries(apk_reader)
for lib_path, file_offset, file_size in lib_map.GetDumpList():
if args.format == 'python':
print '(0x%08x, 0x%08x, 0x%08x, \'%s\'),' % (
file_offset, file_offset + file_size, file_size, lib_path)
else:
print '0x%08x 0x%08x 0x%08x %s' % (
file_offset, file_offset + file_size, file_size, lib_path)
return 0
if __name__ == '__main__':
sys.exit(main())
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment