forked from realm/realm-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunroll_stacktrace.sh
More file actions
executable file
·107 lines (90 loc) · 3.08 KB
/
unroll_stacktrace.sh
File metadata and controls
executable file
·107 lines (90 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env bash
# This script will attempt to manually unroll a stack trace using the unstripped jni libs that are available on S3.
# It will do so using ndk-stack, so read https://developer.android.com/ndk/guides/ndk-stack.html first
#
# The location of ndk-stack will be infered from the ndk.dir property in `<root>/realm/local.properties`.
#
# Usage: > sh unroll_stacktrace.sh <version> <abi> <stacktrace_file>
# Example: > sh unroll_stacktrace.sh 5.0.0 armeabi-v7a ./dump.txt
#
set -euo pipefail
IFS=$'\n\t'
usage() {
cat <<EOF
Usage: $0 ( <buildid> | <flavor> <version> <abi> ) <stacktrace>
- buildid: realm java build id
- flavor: base, objectServer
- version: version number on Maven Central
- abi: armeabi, armeabi-v7a, arm64-v8a, x86, x86_64, mips
- stacktrace: absolute or relative path to file with dump information
Example with build id: $0 6ad7f63d64a38561c8e8c41f3d5d36021f8749c5 ./dump.txt
Example without build id: $0 base 5.0.0 armeabi-v7a ./dump.txt
EOF
}
######################################
# Input Validation
######################################
if [ "$#" -ne 2 ] && [ "$#" -ne 4 ] ; then
usage
exit 1
fi
HERE=$(pwd)
REALM_JAVA_TOOLS_DIR=$(dirname "$0")
if [ "$#" -eq 2 ]; then
DATA=`grep $1 buildids.txt | cut -c43-`
if [ -z $DATA ]; then
echo "build id not found"
exit 1
else
IFS=' ' read -r VERSION FLAVOR ABI <<< "$DATA"
STACKTRACE="$HERE/$2"
fi
elif [ "$#" -eq 4 ]; then
FLAVOR="$1"
VERSION="$2"
ABI="$3"
STACKTRACE="$HERE/$4"
fi
NDK_STACK=""
STRIPPED_LIBS_DIR=""
find_ndkstack() {
PROPS_FILE="$REALM_JAVA_TOOLS_DIR/../realm/local.properties"
if [ ! -f "$PROPS_FILE" ]; then
echo "$PROPS_FILE not found! NDK location cannot be determined"
exit 1
fi
NDK_STACK=$(grep "ndk.dir" "$PROPS_FILE" | cut -d = -f2)/ndk-stack
}
download_and_unzip_stripped_libs() {
# Define location for unstripped libs.
# Use the standard REALM_CORE if defined, otherwise treat it as a temporary file.
CACHED_LIBS_DIR="$REALM_CORE_DOWNLOAD_DIR"
if [[ -z "${REALM_CORE_DOWNLOAD_DIR}" ]]; then
CACHED_LIBS_DIR="/tmp"
fi
# Check if we already have the unstripped libs downloaded
STRIPPED_LIBS_FILE="$CACHED_LIBS_DIR/realm-java-jni-libs-unstripped-$VERSION.zip"
if [ ! -f "$STRIPPED_LIBS_FILE" ]; then
echo "$STRIPPED_LIBS_FILE not found! Downloading from S3"
STRIPPED_LIBS_DOWNLOAD_LOCATION="https://static.realm.io/downloads/java/realm-java-jni-libs-unstripped-$VERSION.zip"
curl -o "$STRIPPED_LIBS_FILE" "$STRIPPED_LIBS_DOWNLOAD_LOCATION"
fi
# Exact files if needed
STRIPPED_LIBS_DIR="$CACHED_LIBS_DIR/realm-java-jni-libs-unstripped-$VERSION"
if [ ! -d "$STRIPPED_LIBS_DIR" ]; then
echo "Extracting archive file with unstripped libraries"
unzip "$STRIPPED_LIBS_FILE" -d "$STRIPPED_LIBS_DIR"
fi
}
unroll_stacktrace() {
DIR="$STRIPPED_LIBS_DIR/$FLAVOR/$ABI"
if [ ! -d "$DIR" ]; then
echo "Directory containing .so file could not be found: ${DIR}"
exit 1
fi
$NDK_STACK -sym "$DIR" -dump "$STACKTRACE"
}
echo "Unrolling $STACKTRACE from Realm Java $VERSION ($FLAVOR) using ABI $ABI"
find_ndkstack
download_and_unzip_stripped_libs
unroll_stacktrace