-#!/bin/sh
+#!/bin/sh -x
SUBSTRING_START_POSITION=2
echo "Usage: $0 [options]"
echo " -s, --serial <serial number>\t\tdirects command to the USB device or emulator with"
echo "\t\t\t\t\tthe given serial number."
- echo " -a, --appid <appid>\t\t\tdebug this app on target."
- echo " -b, --binary <executable file>\t\tdebug this binary on target."
+ echo " -a, --appid <appid>\t\t\tdebugs the application on target."
+ echo " -b, --binary <executable file>\t\tdebugs this binary on target."
+}
+
+getBinaryFile() {
+ SDB_GET_BINARY_COMMAND="$SDB_COMMAND shell ls /opt/apps/$appid/bin/"
+ count=0
+ extension=".exe"
+ extension_length=4
+ result_list=`$SDB_GET_BINARY_COMMAND`
+ for i in ${result_list}
+ do
+ length=`expr match "$i" '.*[.]exe'`
+ start_pos=`expr $length - "$extension_length" + 1`
+ str=`expr substr "$i" "$start_pos" "$extension_length"`
+ if [ "$str" = "$extension" ]
+ then
+ BINARY=$i
+ if [ -z "$binary_list" ]
+ then
+ binary_list=$i
+ else
+ binary_list="$binary_list, $i"
+
+ fi
+ count=`expr "$count" + 1`
+ fi
+ done
+
+ if [ "$count" -eq "0" ]
+ then
+ echo "error: not found executable file of \"$appid\"."
+ exit 2;
+ elif [ "$count" -gt "1" ]
+ then
+ echo "error: more then one executable file of \"$appid\"."
+ echo "executable files: $binary_list"
+ exit 2;
+ fi
}
parse_param() {
case "$1"
in
-h)
- usage
+ usage;
exit;
;;
-s|--serial)
usage
exit 1;
fi
- binary=$2
+ BINARY=$2
shift 2;
;;
*)
esac
done
- if [ -z "$appid" ]
- then
- usage
- exit 1;
- fi
-
- if [ -z "$binary" ]
- then
- usage
- exit 1;
- fi
-
devices=`sdb devices | wc -l`
if [ "$devices" -lt 2 ]
then
exit 2;
fi
fi
-}
-
-launch_gdbserver() {
- target_install_path=/opt/apps/$appid/bin/$binary
- gdbserver_command="/home/developer/sdk_tools/gdbserver/gdbserver :26102 $target_install_path"
SDB_COMMAND="$SDB"
if [ -n "$serial" ]
then
- SDB_COMMAND="$SDB_COMMAND -s $serial"
+ SDB_COMMAND="$SDB -s $serial"
+ fi
+
+ if [ -z "$appid" ]
+ then
+ usage
+ exit 1;
+ fi
+
+ if [ -z "$BINARY" ]
+ then
+ getBinaryFile
fi
+}
+
+launch_gdbserver() {
+ target_install_path=/opt/apps/$appid/bin/$BINARY
+ gdbserver_command="/home/developer/sdk_tools/gdbserver/gdbserver :26102 $target_install_path"
+
sdb_gdbserver_command="$SDB_COMMAND shell $gdbserver_command"
$sdb_gdbserver_command 2> /dev/null &
sleep 1
gdb="$TOOLS_HOME/i386-linux-gnueabi-gdb-7.2/bin/i386-linux-gnueabi-gdb"
fi
- $gdb $binary '--eval-command=target remote:7123'
+ $gdb $BINARY '--eval-command=target remote:7123'
echo "";
}
--- /dev/null
+#!/bin/sh -x
+
+SUBSTRING_START_POSITION=2
+
+SCRIPT="$0"
+while [ -h "$SCRIPT" ] ; do
+ ls=`ls -ld "$SCRIPT"`
+
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ SCRIPT="$link"
+ else
+ SCRIPT=`dirname "$SCRIPT"`/"$link"
+ fi
+done
+
+DIR_BIN=`dirname $SCRIPT`
+TOOLS_HOME="$DIR_BIN/../.."
+SDB="$TOOLS_HOME/sdb"
+LAUNCH_APP="launch_app"
+
+usage()
+{
+ echo "Usage: $0 [options]"
+ echo " -s, --serial <serial number>\t\tdirects command to the USB device or emulator with"
+ echo "\t\t\t\t\tthe given serial number."
+ echo " -a, --appid <appid>\t\t\tlaunches the application on target."
+ echo " -b, --binary <executable file>\t\tlaunches this binary on target."
+}
+
+getBinaryFile() {
+ SDB_GET_BINARY_COMMAND="$SDB_COMMAND shell ls /opt/apps/$appid/bin/"
+ count=0
+ extension=".exe"
+ extension_length=4
+ result_list=`$SDB_GET_BINARY_COMMAND`
+ for i in ${result_list}
+ do
+ length=`expr match "$i" '.*[.]exe'`
+ start_pos=`expr $length - "$extension_length" + 1`
+ str=`expr substr "$i" "$start_pos" "$extension_length"`
+ if [ "$str" != "$extension" ]
+ then
+ BINARY=$i
+ if [ -z "$binary_list" ]
+ then
+ binary_list=$i
+ else
+ binary_list="$binary_list, $i"
+
+ fi
+ count=`expr "$count" + 1`
+ fi
+ done
+
+ if [ "$count" -eq "0" ]
+ then
+ echo "error: not found executable file of \"$appid\"."
+ exit 2;
+ elif [ "$count" -gt "1" ]
+ then
+ echo "error: more then one executable file of \"$appid\"."
+ echo "executable files: $binary_list"
+ exit 2;
+ fi
+}
+
+until [ -z "$1" ]
+do
+ case "$1"
+ in
+ -h)
+ usage
+ exit;
+ ;;
+ -s|--serial)
+ if [ -z "$2" ]
+ then
+ usage
+ exit 1;
+ fi
+ serial=$2
+ shift 2;
+ ;;
+ -a|--appid)
+ if [ -z "$2" ]
+ then
+ usage
+ exit 1;
+ fi
+ appid=$2
+ shift 2;
+ ;;
+ -b|--binary)
+ if [ -z "$2" ]
+ then
+ usage
+ exit 1;
+ fi
+ BINARY=$2
+ ;;
+ *)
+ usage
+ exit;
+ ;;
+ esac
+done
+
+SDB_COMMAND="$SDB"
+if [ -n "$serial" ]
+then
+ SDB_COMMAND="$SDB -s $serial"
+fi
+
+if [ -z "$appid" ]
+then
+ usage
+ exit 1;
+fi
+
+if [ -z "$BINARY" ]
+then
+ getBinaryFile
+fi
+
+
+devices=`$SDB_COMMAND devices | wc -l`
+if [ "$devices" -lt 2 ]
+then
+ echo "error: device not found"
+ exit 2;
+fi
+if [ "$devices" -gt 2 ]
+then
+ if [ -z "$serial" ]
+ then
+ echo "error: more than one device and emulator"
+ exit 2;
+ fi
+fi
+
+command="$SDB_COMMAND shell $LAUNCH_APP $appid.$BINARY"
+
+$command
+