How to compile strace for use on an Android phone (running an ARM CPU)

The instructions are very precise, following them you get your statically linked strace.

Just to be safe (in case the original source disappears), I'll back up the instructions for myself:

  1. Prerequisite: you already have downloaded Sourcery CodeBench Lite (which includes a free GNU toolchain and cross-compiler), make sure you select ARM GNU/Linux and then IA32 GNU/Linux.
  2. Download the strace source distribution from the SourceForge strace project.
  3. Extract the strace package on your linux machine.
  4. Set your compiler information:
    export CC=your_cross_compiler_folder/bin/arm-none-linux-gnueabi-gcc
    export STRIP=your_cross_compiler_folder/bin/arm-none-linux-gnueabi-strip
    export CFLAGS="-O2 -static"
    Note: CFLAGS is by default -g -O2, but we need static linking and (optionally) no debug information. You can even leave out -static, but in that case you'll have to ship the compiled executable with all the referenced shared libs from the cross compiler!
  5. Add your_cross_compiler_folder/bin into your $PATH.
  6. Change your current folder to the strace folder (where you extracted the source), use command:
    ./configure --host=arm-linux
    Optionally you might want to specify a prefix with --prefix=/data/local.
  7. Compile:
    make
  8. Verify the result (eg. static linking) with the command:
    file strace
    You shall see:
    strace: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.14, statically linked, not stripped
  9. Optionally you can strip symbols from it with:
    $STRIP strace
    (if you only need the executable)
    Or package it into a TGZ:
    tmpdir="$(mktemp -d)"
    mkdir -p "$tmpdir/data/local"
    make install-strip prefix="$tmpdir/data/local"
    dir="$(dirname "$(pwd)")"
    packagefile="$dir/$(basename "$(pwd)")-bin.tgz"
    cd "$tmpdir"
    fakeroot -- sh -c "chmod -R a+rX,u+w,go-w data && chown -R root:root data && tar czf \"$packagefile\" data"
    cd "$dir"
    rm -rf "$tmpdir"
Done, you have another powerful tool for your Android.

To use it to trace an already running app (APK), run ps to get the PID of the process, then use the -p switch.
Eg. /data/local/bin/strace -p 4132

P.S.: I've made a few changes (imho optimizations) to the original instructions.

Update (2013.05.23): I've reapplied the same instructions to compile strace v4.7 with Sourcery CodeBench Lite 2013.05-24. I installed the latter with the linux installer (arm-2013.05-24-arm-none-linux-gnueabi.bin) in my user home directory on a 32-bit Ubuntu 10.10 (x86) server. I've attached the compiled TGZ package that you can simply extract into your filesystem and it'll put all strace files into /data/local.

Update (2014.01.25): I've reapplied the same instructions to compile strace v4.8 with Sourcery CodeBench Lite 2013.05-24 (note that the compilation failed with the latest version -which was 2013.11-33 at the time of writing-, so I reverted back to 2013.05-24). This time I used a 32-bit Ubuntu 12.04 (x86) virtual machine. I've attached the compiled TGZ package that you can simply extract into your filesystem and it'll put all strace files into /data/local.

AttachmentSize
strace-4.8-arm-bin.tgz377.86 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

How to use strace-4.6 to see binder ioctl logs?

Hi,

I tried this version. It seems almost same with strace 4.6. Could you tell me how to use this version to see /dev/binder ioctl buffers?


Thanks
-Leon

Please help me about Strace at android emulator

hi dear
I download adnroid ndk and copy it inti C drive

I push strace folder into data/local/tmp and
set chnod 777 to ./configure and strace folder!

now i must set
export STRIP=C:\android-ndk-r8b\toolchains\arm-linux-androideabi-4.4.3\prebuilt\windows\arm-linux-androideabi\bin/strip ????

and when i run ./configure at adb root
after set chmod 777 i get error that configure not fonud!
and before this show only permission denide !

Re: Please help me about Strace at android emulator

I don't think you'll be able to compile strace in an Android emulator like that.

I want use strace at android

I want use strace at android emulator !
I download strace binary and push it into android ! /xbin
but I think this binary dosnt work truely!

I need use strace into android emulator (armeabi) emergency!
can you get me binary of strace !

Re: I want use strace at android emulator!

Unfortunately I cannot help you. I've never tried to compile strace for PCs (x86 CPUs) and probably it'd take a lot of trial and error to get it to work.