Valgrinding fennec in the android emulator



All timestamps are based on your local time of:

Posted by: stak
Tags: mozilla
Posted on: 2012-09-05 09:55:18

I recently got around to running Fennec in valgrind on the Android emulator, and figured it might be useful to post the instructions so that others can do the same. For the most part this is a blatant rehash of sewardj's 2011 blog post about valgrind on android, but with some updates and tweaks. In particular, I did not bother to build a custom ROM or kernel to get this going (although doing that will probably provide better data).

First, make sure that you can run Fennec in the Android emulator. For this, you will need to download the latest version of the Android SDK (I'm using version 16) and create an AVD in the SDK manager. I created an AVD targeting "Android 4.1 - API Level 16" as this seemed to be the most recent non-proprietary-flavoured image. With this target, ARM emulation is the only one available, so I went with that. Note that using a target of level 15 gives you the choice of ARM or x86 emulation, but since Fennec on x86 seems to be still in-progress (see bug 723713) I decided not to try that approach.

Make sure you give the AVD plenty of space on the SD card and RAM (I used 1 GiB for both, but you may want to go even higher) and ensure that you have GPU emulation turned on in the hardware properties. Boot the emulator, install the APK (the emulator should show up under adb devices, and be usable like a normal device) and make sure Fennec runs.

Once you have that set up, you need to build Valgrind. Unfortunately the release tarballs available on the Valgrind website seem to be missing some files (bug 306310), so I had to check out the SVN repository and work with that directly. Grab the code using svn co svn://svn.valgrind.org/valgrind/trunk valgrind and follow the build instructions in the README.android file to build Valgrind. Note in particular the caveats with Android NDK versions; I used the latest Android NDK available for my platform (r8).

Once you have built Valgrind into the Inst folder, start the emulator AVD image you created previously, and push the Inst folder using adb push Inst / (this is also described in the README.android and README.android_emulator files).

The final piece of the puzzle needed is the Zygote/exec hook that sewardj described in his blog post. Create a start_valgrind_fennec file that looks like this, updating the package name and valgrind parameters with your specific package name and requirements.

#!/system/bin/sh
export TMPDIR=/data/data/org.mozilla.fennec_kats
exec /data/local/Inst/bin/valgrind --log-file=/sdcard/valgrind.log --error-limit=no $*

Put it in /data/local and make sure it is executable via chmod 777. Then, tell the Android system to use it as a wrapper by running the following command on the adb shell (again replacing the username with your own):

setprop wrap.org.mozilla.fennec_kats "logwrapper /data/local/start_valgrind_fennec"


Now that all the pieces are in place, you can start Fennec using am start -n org.mozilla.fennec_kats/.App and it will be running under Valgrind. If all goes well, you should see a line in adb logcat from dalvikvm executing logwrapper, and Valgrind output should start appearing in /mnt/sdcard/valgrind.log. Also, Fennec will take a really long time to start up and do anything (this is pretty much expected).

Update: When I tried running it just now as I was writing this, Valgrind crashed because it couldn't decode some instructions. I have filed bug 306297 to track this.

Update 2 (Sep 17, 2012): The above-mentioned bug has been fixed in the latest Valgrind trunk and should be included in Valgrind 3.8.1.

[ Add a new comment ]

 
 
(c) Kartikaya Gupta, 2004-2025. User comments owned by their respective posters. All rights reserved.
You are accessing this website via IPv4. Consider upgrading to IPv6!