1 #!/bin/sh 2 # 3 # Run the code in test.jar on the device. The jar should contain a top-level 4 # class named Main to run. 5 6 msg() { 7 if [ "$QUIET" = "n" ]; then 8 echo "$@" 9 fi 10 } 11 12 RELOCATE="y" 13 GDB="n" 14 DEBUGGER="n" 15 INTERPRETER="n" 16 VERIFY="y" 17 OPTIMIZE="y" 18 ZYGOTE="" 19 QUIET="n" 20 DEV_MODE="n" 21 INVOKE_WITH="" 22 FLAGS="" 23 TARGET_SUFFIX="32" 24 GDB_TARGET_SUFFIX="" 25 26 while true; do 27 if [ "x$1" = "x--quiet" ]; then 28 QUIET="y" 29 shift 30 elif [ "x$1" = "x--lib" ]; then 31 shift 32 if [ "x$1" = "x" ]; then 33 echo "$0 missing argument to --lib" 1>&2 34 exit 1 35 fi 36 LIB="$1" 37 shift 38 elif [ "x$1" = "x-Xcompiler-option" ]; then 39 shift 40 option="$1" 41 FLAGS="${FLAGS} -Xcompiler-option $option" 42 shift 43 elif [ "x$1" = "x--runtime-option" ]; then 44 shift 45 option="$1" 46 FLAGS="${FLAGS} $option" 47 shift 48 elif [ "x$1" = "x--boot" ]; then 49 shift 50 BOOT_OPT="$1" 51 shift 52 elif [ "x$1" = "x--debug" ]; then 53 DEBUGGER="y" 54 shift 55 elif [ "x$1" = "x--gdb" ]; then 56 GDB="y" 57 DEV_MODE="y" 58 shift 59 elif [ "x$1" = "x--zygote" ]; then 60 ZYGOTE="--zygote" 61 msg "Spawning from zygote" 62 shift 63 elif [ "x$1" = "x--dev" ]; then 64 DEV_MODE="y" 65 shift 66 elif [ "x$1" = "x--relocate" ]; then 67 RELOCATE="y" 68 shift 69 elif [ "x$1" = "x--no-relocate" ]; then 70 RELOCATE="n" 71 shift 72 elif [ "x$1" = "x--interpreter" ]; then 73 INTERPRETER="y" 74 shift 75 elif [ "x$1" = "x--invoke-with" ]; then 76 shift 77 if [ "x$1" = "x" ]; then 78 echo "$0 missing argument to --invoke-with" 1>&2 79 exit 1 80 fi 81 if [ "x$INVOKE_WITH" = "x" ]; then 82 INVOKE_WITH="$1" 83 else 84 INVOKE_WITH="$INVOKE_WITH $1" 85 fi 86 shift 87 elif [ "x$1" = "x--no-verify" ]; then 88 VERIFY="n" 89 shift 90 elif [ "x$1" = "x--no-optimize" ]; then 91 OPTIMIZE="n" 92 shift 93 elif [ "x$1" = "x--" ]; then 94 shift 95 break 96 elif [ "x$1" = "x--64" ]; then 97 TARGET_SUFFIX="64" 98 GDB_TARGET_SUFFIX="64" 99 shift 100 elif expr "x$1" : "x--" >/dev/null 2>&1; then 101 echo "unknown $0 option: $1" 1>&2 102 exit 1 103 else 104 break 105 fi 106 done 107 108 if [ "$ZYGOTE" = "" ]; then 109 if [ "$OPTIMIZE" = "y" ]; then 110 if [ "$VERIFY" = "y" ]; then 111 DEX_OPTIMIZE="-Xdexopt:verified" 112 else 113 DEX_OPTIMIZE="-Xdexopt:all" 114 fi 115 msg "Performing optimizations" 116 else 117 DEX_OPTIMIZE="-Xdexopt:none" 118 msg "Skipping optimizations" 119 fi 120 121 if [ "$VERIFY" = "y" ]; then 122 DEX_VERIFY="" 123 msg "Performing verification" 124 else 125 DEX_VERIFY="-Xverify:none" 126 msg "Skipping verification" 127 fi 128 fi 129 130 msg "------------------------------" 131 132 if [ "$QUIET" = "n" ]; then 133 adb shell rm -r $DEX_LOCATION 134 adb shell mkdir -p $DEX_LOCATION 135 adb push $TEST_NAME.jar $DEX_LOCATION 136 adb push $TEST_NAME-ex.jar $DEX_LOCATION 137 else 138 adb shell rm -r $DEX_LOCATION >/dev/null 2>&1 139 adb shell mkdir -p $DEX_LOCATION >/dev/null 2>&1 140 adb push $TEST_NAME.jar $DEX_LOCATION >/dev/null 2>&1 141 adb push $TEST_NAME-ex.jar $DEX_LOCATION >/dev/null 2>&1 142 fi 143 144 if [ "$DEBUGGER" = "y" ]; then 145 # Use this instead for ddms and connect by running 'ddms': 146 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y" 147 # TODO: add a separate --ddms option? 148 149 PORT=12345 150 msg "Waiting for jdb to connect:" 151 msg " adb forward tcp:$PORT tcp:$PORT" 152 msg " jdb -attach localhost:$PORT" 153 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y" 154 fi 155 156 if [ "$GDB" = "y" ]; then 157 gdb="gdbserver$GDB_TARGET_SUFFIX :5039" 158 gdbargs="$exe" 159 fi 160 161 if [ "$INTERPRETER" = "y" ]; then 162 INT_OPTS="-Xint" 163 fi 164 165 JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni" 166 167 if [ "$RELOCATE" = "y" ]; then 168 RELOCATE_OPT="-Xrelocate" 169 FLAGS="${FLAGS} -Xcompiler-option --include-patch-information" 170 else 171 RELOCATE_OPT="-Xnorelocate" 172 fi 173 174 cmdline="cd $DEX_LOCATION && export ANDROID_DATA=$DEX_LOCATION && export DEX_LOCATION=$DEX_LOCATION && \ 175 $INVOKE_WITH $gdb /system/bin/dalvikvm$TARGET_SUFFIX $FLAGS $gdbargs -XXlib:$LIB $ZYGOTE $JNI_OPTS $RELOCATE_OPT $INT_OPTS $DEBUGGER_OPTS $BOOT_OPT -cp $DEX_LOCATION/$TEST_NAME.jar Main" 176 if [ "$DEV_MODE" = "y" ]; then 177 echo $cmdline "$@" 178 fi 179 180 adb shell $cmdline "$@" 181