symbolize.sh revision e0021c5de333061750a377d8d021e0a81f7ff5fe
154fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe#!/bin/sh 254fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe# Copyright (C) 2014 The Android Open Source Project 354fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe# 454fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe# Licensed under the Apache License, Version 2.0 (the "License"); 554fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe# you may not use this file except in compliance with the License. 654fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe# You may obtain a copy of the License at 754fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe# 854fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe# http://www.apache.org/licenses/LICENSE-2.0 954fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe# 1054fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe# Unless required by applicable law or agreed to in writing, software 1154fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe# distributed under the License is distributed on an "AS IS" BASIS, 1254fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1354fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe# See the License for the specific language governing permissions and 1454fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe# limitations under the License. 1554fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe# 1654fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe# 1754fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe# Symbolize oat files from the dalvik cache of a device. 1854fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe# 1954fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe# By default, pulls everything from the dalvik cache. A simple yes/no/quit prompt for each file can 2054fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe# be requested by giving "--interactive" as a parameter. 2154fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe 2254fc26c7350beb782d042ba61cb06284b3a367e4Andreas GampeINTERACTIVE="no" 2354fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampeif [ "x$1" = "x--interactive" ] ; then 2454fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe INTERACTIVE="yes" 25e0021c5de333061750a377d8d021e0a81f7ff5feAndreas Gampe shift 2654fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampefi 2754fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe 2854fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe# Pull the file from the device and symbolize it. 2954fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampefunction one() { 3054fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe echo $1 $2 3154fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe if [ "x$INTERACTIVE" = "xyes" ] ; then 3254fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe echo -n "What to do? [Y/n/q] " 3354fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe read -e input 3454fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe if [ "x$input" = "xn" ] ; then 3554fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe return 3654fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe fi 3754fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe if [ "x$input" = "xq" ] ; then 3854fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe exit 0 3954fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe fi 4054fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe fi 41468bcf63207420f18c0c8a8621aa2d774393c155Zheng Xu adb pull $1/$2 /tmp || exit 1 42468bcf63207420f18c0c8a8621aa2d774393c155Zheng Xu mkdir -p $OUT/symbols/$1 43468bcf63207420f18c0c8a8621aa2d774393c155Zheng Xu oatdump --symbolize=/tmp/$2 --output=$OUT/symbols/$1/$2 4454fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe} 4554fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe 46468bcf63207420f18c0c8a8621aa2d774393c155Zheng Xu# adb shell find seems to output in DOS format (CRLF), which messes up scripting 47468bcf63207420f18c0c8a8621aa2d774393c155Zheng Xufunction adbshellstrip() { 48468bcf63207420f18c0c8a8621aa2d774393c155Zheng Xu adb shell $@ | sed 's/\r$//' 4954fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe} 5054fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe 51468bcf63207420f18c0c8a8621aa2d774393c155Zheng Xu# Search in all of /data on device. 5254fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampefunction all() { 53468bcf63207420f18c0c8a8621aa2d774393c155Zheng Xu FILES=$(adbshellstrip find /data -name "'*.oat'" -o -name "'*.dex'" -o -name "'*.odex'") 54468bcf63207420f18c0c8a8621aa2d774393c155Zheng Xu for FILE in $FILES ; do 55468bcf63207420f18c0c8a8621aa2d774393c155Zheng Xu DIR=$(dirname $FILE) 56468bcf63207420f18c0c8a8621aa2d774393c155Zheng Xu NAME=$(basename $FILE) 57468bcf63207420f18c0c8a8621aa2d774393c155Zheng Xu one $DIR $NAME 5854fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe done 5954fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe} 6054fc26c7350beb782d042ba61cb06284b3a367e4Andreas Gampe 61e0021c5de333061750a377d8d021e0a81f7ff5feAndreas Gampeif [ "x$1" = "x" ] ; then 62e0021c5de333061750a377d8d021e0a81f7ff5feAndreas Gampe # No further arguments, iterate over all oat files on device. 63e0021c5de333061750a377d8d021e0a81f7ff5feAndreas Gampe all 64e0021c5de333061750a377d8d021e0a81f7ff5feAndreas Gampeelse 65e0021c5de333061750a377d8d021e0a81f7ff5feAndreas Gampe # Take the parameters as a list of paths on device. 66e0021c5de333061750a377d8d021e0a81f7ff5feAndreas Gampe while (($#)); do 67e0021c5de333061750a377d8d021e0a81f7ff5feAndreas Gampe DIR=$(dirname $1) 68e0021c5de333061750a377d8d021e0a81f7ff5feAndreas Gampe NAME=$(basename $1) 69e0021c5de333061750a377d8d021e0a81f7ff5feAndreas Gampe one $DIR $NAME 70e0021c5de333061750a377d8d021e0a81f7ff5feAndreas Gampe shift 71e0021c5de333061750a377d8d021e0a81f7ff5feAndreas Gampe done 72e0021c5de333061750a377d8d021e0a81f7ff5feAndreas Gampefi 73