User:Blassey/Notes/Android: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 35: Line 35:
   adb shell am start -a android.activity.MAIN -n org.mozilla.fennec/org.mozilla.fennec.App --es env0 NSPR_LOG_MODULES=all:5
   adb shell am start -a android.activity.MAIN -n org.mozilla.fennec/org.mozilla.fennec.App --es env0 NSPR_LOG_MODULES=all:5


== debugging without rooting ==
== debugging without rooting ==
 
with Froyo you can debug without rooting your phone. Instructions are below. See also [[Mobile/Fennec/Android/GDBNoRoot|Fennec/Android/GDBNoRoot]] for another guide on how to do this.
 


with Froyo you can debug without rooting your phone. Instructions are below. See also [[Mobile/Fennec/Android/GDBNoRoot|Fennec/Android/GDBNoRoot]] for another guide on how to do this.<br>


First thing, to make this work with the nvidia gdb (which I found more reliable than the android r3 gdb) you need to modify install.sh and debug.sh.  
First thing, to make this work with the nvidia gdb (which I found more reliable than the android r3 gdb) you need to modify install.sh and debug.sh.  
Line 54: Line 52:
  adb shell chmod 755 /data/local/gdbserver
  adb shell chmod 755 /data/local/gdbserver
  for file in $(adb shell ls /system/lib | tr "\n" " " | tr "\r" " "); do
  for file in $(adb shell ls /system/lib | tr "\n" " " | tr "\r" " "); do
    adb pull /system/lib/$file lib
    adb pull /system/lib/$file lib
  done
  done
  adb pull /system/bin/app_process lib  
  adb pull /system/bin/app_process lib  
Line 63: Line 61:
  if [ $# -ne 2 ]
  if [ $# -ne 2 ]
  then
  then
    echo "usage: $0 /path/to/your/library.so packagename.of.your.activity"
    echo "usage: $0 /path/to/your/library.so packagename.of.your.activity"
    echo "for example:"
    echo "for example:"
    echo "  $0 /code/mydemo/libs/armeabi/libmydemo.so com.nvidia.devtech.mydemo"
    echo "  $0 /code/mydemo/libs/armeabi/libmydemo.so com.nvidia.devtech.mydemo"
    exit
    exit
  fi
  fi
   
   
  if [&nbsp;! -f $1 ]
  if [&nbsp;! -f $1 ]
  then
  then
    echo "ERROR: That library file doesn't exist"
    echo "ERROR: That library file doesn't exist"
    exit
    exit
  fi
  fi
   
   
Line 80: Line 78:
  if [ "$p" = "" ];
  if [ "$p" = "" ];
  then
  then
    echo "ERROR: That doesn't seem to be a running process. Please make sure your"
    echo "ERROR: That doesn't seem to be a running process. Please make sure your"
    echo "application has been started and that you are using the correct"
    echo "application has been started and that you are using the correct"
    echo "namespace argument."
    echo "namespace argument."
    exit
    exit
  fi
  fi
   
   

Revision as of 00:15, 21 June 2011

Build Env

After normal linux build pre-reqs:

 wget ftp://ftp.mozilla.org/pub/mobile/source/android-ndk-r4c-0moz3.tar.bz2
 wget http://dl.google.com/android/android-sdk_r06-linux_86.tgz
 tar -xf android-sdk_r06-linux_86.tgz
 tar -xjf android-ndk-r4c-0moz3.tar.bz2
 ./android-sdk-linux_86/tools/android update sdk

And already set up VM can be found here: http://lassey.us/droid-vm.7z

Debugging

Nvidia's gdb is better: http://developer.download.nvidia.com/tegra/files/tegra-gdb-20100902.zip

In order to attach before things get running, launch with:

  adb shell am start -a org.mozilla.gecko.DEBUG -n org.mozilla.fennec/org.mozilla.fennec.App

and just click launch once gdb is attached. If you need to debug a crash that happens before XRE_Main is called, the patch on bug 572247 may be useful.

this script [1] will attach gdbserver for you

Env Vars

If you need to set and env var at run time, use append --es env# VAR=VAL to your activity manager command where # is the ordered number of variables for example:

 adb shell am start -a android.activity.MAIN -n org.mozilla.fennec/org.mozilla.fennec.App --es env0 VAR=val --es env1 FOO=bar

You may need bug 578493 if the env var you're using is tested before XRE_Main is called

PR Logging

You can use the env vars as described above to make logging work (along with bug 578493). With just that you can log to a file

 adb shell am start -a android.activity.MAIN -n org.mozilla.fennec/org.mozilla.fennec.App --es env0 NSPR_LOG_MODULES=all:5 --es env1 NSPR_LOG_FILE=/mnt/sdcard/log.txt

With the patch on bug 578496 you can have the logging directed to the android logs and as such only need:

 adb shell am start -a android.activity.MAIN -n org.mozilla.fennec/org.mozilla.fennec.App --es env0 NSPR_LOG_MODULES=all:5

debugging without rooting

with Froyo you can debug without rooting your phone. Instructions are below. See also Fennec/Android/GDBNoRoot for another guide on how to do this.

First thing, to make this work with the nvidia gdb (which I found more reliable than the android r3 gdb) you need to modify install.sh and debug.sh.

first, change the location where install.sh copies gdbserver to somewhere writable by a non-root process. I used /data/local. Be sure to update that both in the push command and the chmod command.

second, update debug.sh with the new location of gdbserver.

finally, you'll need to add run-as $2 to the adb shell command that launches gdbserver. In the end you should have: install.sh:

 #!/bin/sh
mkdir lib
adb push prebuilt/gdbserver /data/local
adb shell chmod 755 /data/local/gdbserver
for file in $(adb shell ls /system/lib | tr "\n" " " | tr "\r" " "); do
   adb pull /system/lib/$file lib
done
adb pull /system/bin/app_process lib 

debug.sh:

 !/bin/sh
if [ $# -ne 2 ]
then
   echo "usage: $0 /path/to/your/library.so packagename.of.your.activity"
   echo "for example:"
   echo "  $0 /code/mydemo/libs/armeabi/libmydemo.so com.nvidia.devtech.mydemo"
   exit
fi

if [ ! -f $1 ]
then
   echo "ERROR: That library file doesn't exist"
   exit
fi

cp $1 lib

p=`adb shell ps | grep $2 | awk '{print $2}'`
if [ "$p" = "" ];
then
   echo "ERROR: That doesn't seem to be a running process. Please make sure your"
   echo "application has been started and that you are using the correct"
   echo "namespace argument."
   exit
fi

adb forward tcp:12345 tcp:12345
adb shell run-as $2 /data/local/gdbserver --attach :12345 $p

killer script

 #!/bin/sh
 if [ $# -ne 1 ]
 then
     echo "usage: $0  packagename.of.your.activity"
     echo "for example:"
     echo "  $0 org.mozilla.fennec"
     exit
 fi
 
 p=`adb shell ps | grep $1 | awk '{print $2}'`
 if [ "$p" = "" ];
 then
     echo "ERROR: That doesn't seem to be a running process. Please make sure your"
     echo "application has been started and that you are using the correct"
     echo "namespace argument."
     exit
 fi
 
 adb shell run-as $1 kill $p

.gdbinit

this is an example .gdbinit that uses the symbols from a locally built rom and automatically attaches to gdbserver

 set solib-search-path /home/blassey/android/system/out/target/product/passion/symbols/system/bin:/home/blassey/android/system/out/target/product/passion/symbols/system/lib/:/home/blassey/src/ndk5-m-c/objdir-droid-dbg/dist/bin
 set solib-absolute-prefix /home/blassey/android/system/out/target/product/passion/symbols/system/lib/
 target remote localhost:12345