[UTILITY] STrace 4.8 - Ultimate debugging utility now ported to Android !

Search This thread

alireza7991

Senior Member
Sep 2, 2012
772
2,319
24
Shahrekord
alirezafn.net
about Strace

Android provides Logcat for tracing and debugging Apps , Logcat provides too short information and limited apps also programs has to support logcat or there wo'nt be any log ! this makes Android logcar be completely un-useful in large/advanced programs .

strace is a debugging utility to monitor a program system calls or signals it receives . strace is used while we want to find the reason a program crashes or finding out what causes a process not to work as expected .

strace is much more powerful than Android Logcat . unlike logcat , any process may be monitored by strace also there is no need to rewrite a program for support of strace

usage & downloading

I have ported strace to Android and it works without any bugs

download the lastest binary from this post , move it to /system/bin and set permissions to 755 .

strace has a lot of options you can find by running it using :

Code:
strace --help

most common functions are :

1- using strace to monitor a command :

Code:
strace echo hello

2- using strace to monitor an App/process :

Code:
strace -p 123

(123 is a example , use any other PID you wish )

here is an example of running strace with hello command :

Code:
ALIREZA | strace echo hello
execve("/system/xbin/echo", ["echo", "hello"], [/* 26 vars */]) = 0
mprotect(0x4005d000, 75164, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
mprotect(0x4005d000, 77824, PROT_READ|PROT_EXEC) = 0
mprotect(0x40070000, 4096, PROT_READ)   = 0
gettid()                                = 31648
set_tls(0x40080f6c, 0x40080f30, 0x40081068, 0x40, 0x40080f30) = 0
getpid()                                = 31648
sigaction(SIGILL, {0x40062ba1, [], SA_RESTART|SA_SIGINFO}, NULL, 0x397a4) = 0
sigaction(SIGABRT, {0x40062ba1, [], SA_RESTART|SA_SIGINFO}, NULL, 0x397a4) = 0
sigaction(SIGBUS, {0x40062ba1, [], SA_RESTART|SA_SIGINFO}, NULL, 0x397a4) = 0
sigaction(SIGFPE, {0x40062ba1, [], SA_RESTART|SA_SIGINFO}, NULL, 0x397a4) = 0
sigaction(SIGSEGV, {0x40062ba1, [], SA_RESTART|SA_SIGINFO}, NULL, 0x397a4) = 0
sigaction(SIGSTKFLT, {0x40062ba1, [], SA_RESTART|SA_SIGINFO}, NULL, 0x397a4) = 0
sigaction(SIGPIPE, {0x40062ba1, [], SA_RESTART|SA_SIGINFO}, NULL, 0x397a4) = 0
mprotect(0x8000, 500100, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
stat64("/vendor/lib/libc.so", 0xbea736b8) = -1 ENOENT (No such file or directory)
stat64("/system/lib/libc.so", {st_mode=S_IFREG|0644, st_size=286596, ...}) = 0
open("/system/lib/libc.so", O_RDONLY)   = 7
lseek(7, 0, SEEK_SET)                   = 0
read(7, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\0\0\0\0004\0\0\0"..., 4096) = 4096
lseek(7, -8, SEEK_END)                  = 286588
read(7, "\1\0\0\0\0\0\0\0", 8)          = 8
mmap2(NULL, 331776, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x400f7000
madvise(0x400f7000, 331776, 0xc /* MADV_??? */) = 0
mmap2(0x400f7000, 271932, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 7, 0) = 0x400f7000
madvise(0x400f7000, 271932, 0xc /* MADV_??? */) = 0
mprotect(0x400f7000, 274432, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
mmap2(0x4013a000, 10344, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 7, 0x43) = 0x4013a000
madvise(0x4013a000, 10344, 0xc /* MADV_??? */) = 0
mmap2(0x4013d000, 45051, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x4013d000
madvise(0x4013d000, 45051, 0xc /* MADV_??? */) = 0
close(7)                                = 0
mprotect(0x400f7000, 274432, PROT_READ|PROT_EXEC) = 0
stat64("/vendor/lib/liblog.so", 0xbea736b8) = -1 ENOENT (No such file or directory)
stat64("/system/lib/liblog.so", {st_mode=S_IFREG|0644, st_size=13536, ...}) = 0
open("/system/lib/liblog.so", O_RDONLY) = 7
lseek(7, 0, SEEK_SET)                   = 0
read(7, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\0\0\0\0004\0\0\0"..., 4096) = 4096
lseek(7, -8, SEEK_END)                  = 13528
read(7, "\1\0\0\0\0\0\0\0", 8)          = 8
mmap2(NULL, 20480, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x4000d000
madvise(0x4000d000, 20480, 0xc /* MADV_??? */) = 0
mmap2(0x4000d000, 11235, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 7, 0) = 0x4000d000
madvise(0x4000d000, 11235, 0xc /* MADV_??? */) = 0
mprotect(0x4000d000, 12288, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
mmap2(0x40010000, 4116, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 7, 0x2) = 0x40010000
madvise(0x40010000, 4116, 0xc /* MADV_??? */) = 0
close(7)                                = 0
stat64("/vendor/lib/libstdc++.so", 0xbea73618) = -1 ENOENT (No such file or directory)
stat64("/system/lib/libstdc++.so", {st_mode=S_IFREG|0644, st_size=5336, ...}) = 0
open("/system/lib/libstdc++.so", O_RDONLY) = 7
lseek(7, 0, SEEK_SET)                   = 0
read(7, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\0\0\0\0004\0\0\0"..., 4096) = 4096
lseek(7, -8, SEEK_END)                  = 5328
read(7, "\1\0\0\0\0\0\0\0", 8)          = 8
mmap2(NULL, 12288, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40082000
madvise(0x40082000, 12288, 0xc /* MADV_??? */) = 0
mmap2(0x40082000, 2656, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 7, 0) = 0x40082000
madvise(0x40082000, 2656, 0xc /* MADV_??? */) = 0
mprotect(0x40082000, 4096, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
mmap2(0x40083000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 7, 0) = 0x40083000
madvise(0x40083000, 4096, 0xc /* MADV_??? */) = 0
mmap2(0x40084000, 16, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x40084000
madvise(0x40084000, 16, 0xc /* MADV_??? */) = 0
close(7)                                = 0
mprotect(0x40082000, 4096, PROT_READ|PROT_EXEC) = 0
mprotect(0x40083000, 4096, PROT_READ)   = 0
stat64("/vendor/lib/libm.so", 0xbea73618) = -1 ENOENT (No such file or directory)
stat64("/system/lib/libm.so", {st_mode=S_IFREG|0644, st_size=91288, ...}) = 0
open("/system/lib/libm.so", O_RDONLY)   = 7
lseek(7, 0, SEEK_SET)                   = 0
read(7, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\0\0\0\0004\0\0\0"..., 4096) = 4096
lseek(7, -8, SEEK_END)                  = 91280
read(7, "\1\0\0\0\0\0\0\0", 8)          = 8
mmap2(NULL, 98304, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x400d8000
madvise(0x400d8000, 98304, 0xc /* MADV_??? */) = 0
mmap2(0x400d8000, 85924, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 7, 0) = 0x400d8000
madvise(0x400d8000, 85924, 0xc /* MADV_??? */) = 0
mprotect(0x400d8000, 86016, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
mmap2(0x400ee000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 7, 0x15) = 0x400ee000
madvise(0x400ee000, 4096, 0xc /* MADV_??? */) = 0
mmap2(0x400ef000, 32, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x400ef000
madvise(0x400ef000, 32, 0xc /* MADV_??? */) = 0
close(7)                                = 0
mprotect(0x400d8000, 86016, PROT_READ|PROT_EXEC) = 0
mprotect(0x400ee000, 4096, PROT_READ)   = 0
mprotect(0x4000d000, 12288, PROT_READ|PROT_EXEC) = 0
mprotect(0x40010000, 4096, PROT_READ)   = 0
stat64("/vendor/lib/libcutils.so", 0xbea736b8) = -1 ENOENT (No such file or directory)
stat64("/system/lib/libcutils.so", {st_mode=S_IFREG|0644, st_size=63252, ...}) = 0
open("/system/lib/libcutils.so", O_RDONLY) = 7
lseek(7, 0, SEEK_SET)                   = 0
read(7, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\0\0\0\0004\0\0\0"..., 4096) = 4096
lseek(7, -8, SEEK_END)                  = 63244
read(7, "\1\0\0\0\0\0\0\0", 8)          = 8
mmap2(NULL, 126976, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40148000
madvise(0x40148000, 126976, 0xc /* MADV_??? */) = 0
mmap2(0x40148000, 58972, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 7, 0) = 0x40148000
madvise(0x40148000, 58972, 0xc /* MADV_??? */) = 0
mprotect(0x40148000, 61440, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
mmap2(0x40157000, 4620, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 7, 0xe) = 0x40157000
madvise(0x40157000, 4620, 0xc /* MADV_??? */) = 0
mmap2(0x40159000, 57096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x40159000
madvise(0x40159000, 57096, 0xc /* MADV_??? */) = 0
close(7)                                = 0
mprotect(0x40148000, 61440, PROT_READ|PROT_EXEC) = 0
mprotect(0x40157000, 4096, PROT_READ)   = 0
mprotect(0x8000, 503808, PROT_READ|PROT_EXEC) = 0
mmap2(NULL, 49152, PROT_READ, MAP_SHARED, 8, 0) = 0x400a4000
futex(0x40140734, FUTEX_WAKE_PRIVATE, 2147483647) = 0
open("/dev/urandom", O_RDONLY)          = 7
read(7, "@\236", 4)                   = 4
close(7)                                = 0
clock_gettime(CLOCK_MONOTONIC, {29544, 299349465}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40167000
madvise(0x40167000, 4096, 0xc /* MADV_??? */) = 0
mprotect(0x40167000, 4096, PROT_READ)   = 0
getuid32()                              = 0
brk(0)                                  = 0xf0d000
brk(0xf0d000)                           = 0xf0d000
brk(0xf0e000)                           = 0xf0e000
write(1, "hello\n", 6hello
)                  = 6
mprotect(0x40167000, 4096, PROT_READ|PROT_WRITE) = 0
mprotect(0x40167000, 4096, PROT_READ)   = 0
futex(0x4014072c, FUTEX_WAKE_PRIVATE, 2147483647) = 0
munmap(0x40167000, 4096)                = 0
exit_group(0)                           = ?

and now lastest download link :

Download Strace 4.8 from here

license

strace is a free software, you may download source of strace from here
 

Dovidhalevi

Senior Member
Jun 26, 2012
2,729
1,171
Segfault any attemp to use it!

Running on LG P500 (ARMv6) cm-10.2

OK, guess what? Already have it on /system/xbin and that does work.
 
Last edited:

kmandel

Senior Member
Aug 13, 2010
368
6
Would like to try it, but the download link requires me to sign up for an account. Can't you make this available some other way?
 

alireza7991

Senior Member
Sep 2, 2012
772
2,319
24
Shahrekord
alirezafn.net
Once i run strace -p 123 it will come back
Code:
strace: attach: ptrace(PTRACE_ATTACH, ...): Operation not permitted

I said :

(123 is a example , use any other PID you wish )

You must use the a valid PID , 123 is an example .

For getting PID of an APP/Process , use the this command in terminal :

Code:
ps | grep "abc"

instead of abc , write the process name you want ! for example :

Code:
ps | grep "com.android.acore"

then search for PID in the output and use it with strace !
 

rovo89

Senior Recognized Developer
Jan 4, 2012
2,585
81,351
Once i run strace -p 123 it will come back
Code:
strace: attach: ptrace(PTRACE_ATTACH, ...): Operation not permitted

You need to be root to attach to already running processes.

I also find the "-f" option useful for more complex executables (which fork new processes). "-o" to write the output to a file can be useful if there is much output.
 

alireza7991

Senior Member
Sep 2, 2012
772
2,319
24
Shahrekord
alirezafn.net
Huh? It's a well-known, standard unix utility, being a part of Android distribution since Android 1.6 (although, only in debug builds)...
See https://android.googlesource.com/platform/external/strace/ (note all the branches on the left)

It's good to make people aware of it, though, as it's a very useful tool for debugging some kinds of issues.

I haven't seen it, but its just in android sources and only in debug builds for debugging the android but This is a standalone build of latest STrace suitable for developers to debug their APPs . Developers will not download and compile whole android for just having a dynamicly linked strace .

Another thing , why most of you are saying its a well-known/popular linux utility ... , did I say it is not ????
 
Last edited:
  • Like
Reactions: M0RT3ZA

FBis251

Senior Member
Mar 21, 2011
3,419
3,716
www.fernandobarillas.com
I haven't seen it, but its just in android sources and only in debug builds for debugging the android but This is a standalone build of latest STrace suitable for developers to debug their APPs . Developers will not download and compile whole android for just having a dynamicly linked strace .

Another thing , why most of you are saying its a well-known/popular linux utility ... , did I say it is not ????

But that's something that's popular to do here, a lot of people download the sources and compile the ROMs they run from source. Additionally, this is probably included in every custom ROM out there. My CM10.2 install has the utility built in.

There's no need to be defensive, the RD that's replying to you is just providing links for more reading. The better informed the users of this site are, the more cool stuff we'll see in the future.

Thanks for your strace build!
 

Top Liked Posts

  • There are no posts matching your filters.
  • 58
    about Strace

    Android provides Logcat for tracing and debugging Apps , Logcat provides too short information and limited apps also programs has to support logcat or there wo'nt be any log ! this makes Android logcar be completely un-useful in large/advanced programs .

    strace is a debugging utility to monitor a program system calls or signals it receives . strace is used while we want to find the reason a program crashes or finding out what causes a process not to work as expected .

    strace is much more powerful than Android Logcat . unlike logcat , any process may be monitored by strace also there is no need to rewrite a program for support of strace

    usage & downloading

    I have ported strace to Android and it works without any bugs

    download the lastest binary from this post , move it to /system/bin and set permissions to 755 .

    strace has a lot of options you can find by running it using :

    Code:
    strace --help

    most common functions are :

    1- using strace to monitor a command :

    Code:
    strace echo hello

    2- using strace to monitor an App/process :

    Code:
    strace -p 123

    (123 is a example , use any other PID you wish )

    here is an example of running strace with hello command :

    Code:
    ALIREZA | strace echo hello
    execve("/system/xbin/echo", ["echo", "hello"], [/* 26 vars */]) = 0
    mprotect(0x4005d000, 75164, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
    mprotect(0x4005d000, 77824, PROT_READ|PROT_EXEC) = 0
    mprotect(0x40070000, 4096, PROT_READ)   = 0
    gettid()                                = 31648
    set_tls(0x40080f6c, 0x40080f30, 0x40081068, 0x40, 0x40080f30) = 0
    getpid()                                = 31648
    sigaction(SIGILL, {0x40062ba1, [], SA_RESTART|SA_SIGINFO}, NULL, 0x397a4) = 0
    sigaction(SIGABRT, {0x40062ba1, [], SA_RESTART|SA_SIGINFO}, NULL, 0x397a4) = 0
    sigaction(SIGBUS, {0x40062ba1, [], SA_RESTART|SA_SIGINFO}, NULL, 0x397a4) = 0
    sigaction(SIGFPE, {0x40062ba1, [], SA_RESTART|SA_SIGINFO}, NULL, 0x397a4) = 0
    sigaction(SIGSEGV, {0x40062ba1, [], SA_RESTART|SA_SIGINFO}, NULL, 0x397a4) = 0
    sigaction(SIGSTKFLT, {0x40062ba1, [], SA_RESTART|SA_SIGINFO}, NULL, 0x397a4) = 0
    sigaction(SIGPIPE, {0x40062ba1, [], SA_RESTART|SA_SIGINFO}, NULL, 0x397a4) = 0
    mprotect(0x8000, 500100, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
    stat64("/vendor/lib/libc.so", 0xbea736b8) = -1 ENOENT (No such file or directory)
    stat64("/system/lib/libc.so", {st_mode=S_IFREG|0644, st_size=286596, ...}) = 0
    open("/system/lib/libc.so", O_RDONLY)   = 7
    lseek(7, 0, SEEK_SET)                   = 0
    read(7, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\0\0\0\0004\0\0\0"..., 4096) = 4096
    lseek(7, -8, SEEK_END)                  = 286588
    read(7, "\1\0\0\0\0\0\0\0", 8)          = 8
    mmap2(NULL, 331776, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x400f7000
    madvise(0x400f7000, 331776, 0xc /* MADV_??? */) = 0
    mmap2(0x400f7000, 271932, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 7, 0) = 0x400f7000
    madvise(0x400f7000, 271932, 0xc /* MADV_??? */) = 0
    mprotect(0x400f7000, 274432, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
    mmap2(0x4013a000, 10344, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 7, 0x43) = 0x4013a000
    madvise(0x4013a000, 10344, 0xc /* MADV_??? */) = 0
    mmap2(0x4013d000, 45051, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x4013d000
    madvise(0x4013d000, 45051, 0xc /* MADV_??? */) = 0
    close(7)                                = 0
    mprotect(0x400f7000, 274432, PROT_READ|PROT_EXEC) = 0
    stat64("/vendor/lib/liblog.so", 0xbea736b8) = -1 ENOENT (No such file or directory)
    stat64("/system/lib/liblog.so", {st_mode=S_IFREG|0644, st_size=13536, ...}) = 0
    open("/system/lib/liblog.so", O_RDONLY) = 7
    lseek(7, 0, SEEK_SET)                   = 0
    read(7, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\0\0\0\0004\0\0\0"..., 4096) = 4096
    lseek(7, -8, SEEK_END)                  = 13528
    read(7, "\1\0\0\0\0\0\0\0", 8)          = 8
    mmap2(NULL, 20480, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x4000d000
    madvise(0x4000d000, 20480, 0xc /* MADV_??? */) = 0
    mmap2(0x4000d000, 11235, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 7, 0) = 0x4000d000
    madvise(0x4000d000, 11235, 0xc /* MADV_??? */) = 0
    mprotect(0x4000d000, 12288, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
    mmap2(0x40010000, 4116, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 7, 0x2) = 0x40010000
    madvise(0x40010000, 4116, 0xc /* MADV_??? */) = 0
    close(7)                                = 0
    stat64("/vendor/lib/libstdc++.so", 0xbea73618) = -1 ENOENT (No such file or directory)
    stat64("/system/lib/libstdc++.so", {st_mode=S_IFREG|0644, st_size=5336, ...}) = 0
    open("/system/lib/libstdc++.so", O_RDONLY) = 7
    lseek(7, 0, SEEK_SET)                   = 0
    read(7, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\0\0\0\0004\0\0\0"..., 4096) = 4096
    lseek(7, -8, SEEK_END)                  = 5328
    read(7, "\1\0\0\0\0\0\0\0", 8)          = 8
    mmap2(NULL, 12288, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40082000
    madvise(0x40082000, 12288, 0xc /* MADV_??? */) = 0
    mmap2(0x40082000, 2656, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 7, 0) = 0x40082000
    madvise(0x40082000, 2656, 0xc /* MADV_??? */) = 0
    mprotect(0x40082000, 4096, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
    mmap2(0x40083000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 7, 0) = 0x40083000
    madvise(0x40083000, 4096, 0xc /* MADV_??? */) = 0
    mmap2(0x40084000, 16, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x40084000
    madvise(0x40084000, 16, 0xc /* MADV_??? */) = 0
    close(7)                                = 0
    mprotect(0x40082000, 4096, PROT_READ|PROT_EXEC) = 0
    mprotect(0x40083000, 4096, PROT_READ)   = 0
    stat64("/vendor/lib/libm.so", 0xbea73618) = -1 ENOENT (No such file or directory)
    stat64("/system/lib/libm.so", {st_mode=S_IFREG|0644, st_size=91288, ...}) = 0
    open("/system/lib/libm.so", O_RDONLY)   = 7
    lseek(7, 0, SEEK_SET)                   = 0
    read(7, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\0\0\0\0004\0\0\0"..., 4096) = 4096
    lseek(7, -8, SEEK_END)                  = 91280
    read(7, "\1\0\0\0\0\0\0\0", 8)          = 8
    mmap2(NULL, 98304, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x400d8000
    madvise(0x400d8000, 98304, 0xc /* MADV_??? */) = 0
    mmap2(0x400d8000, 85924, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 7, 0) = 0x400d8000
    madvise(0x400d8000, 85924, 0xc /* MADV_??? */) = 0
    mprotect(0x400d8000, 86016, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
    mmap2(0x400ee000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 7, 0x15) = 0x400ee000
    madvise(0x400ee000, 4096, 0xc /* MADV_??? */) = 0
    mmap2(0x400ef000, 32, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x400ef000
    madvise(0x400ef000, 32, 0xc /* MADV_??? */) = 0
    close(7)                                = 0
    mprotect(0x400d8000, 86016, PROT_READ|PROT_EXEC) = 0
    mprotect(0x400ee000, 4096, PROT_READ)   = 0
    mprotect(0x4000d000, 12288, PROT_READ|PROT_EXEC) = 0
    mprotect(0x40010000, 4096, PROT_READ)   = 0
    stat64("/vendor/lib/libcutils.so", 0xbea736b8) = -1 ENOENT (No such file or directory)
    stat64("/system/lib/libcutils.so", {st_mode=S_IFREG|0644, st_size=63252, ...}) = 0
    open("/system/lib/libcutils.so", O_RDONLY) = 7
    lseek(7, 0, SEEK_SET)                   = 0
    read(7, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\0\0\0\0004\0\0\0"..., 4096) = 4096
    lseek(7, -8, SEEK_END)                  = 63244
    read(7, "\1\0\0\0\0\0\0\0", 8)          = 8
    mmap2(NULL, 126976, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40148000
    madvise(0x40148000, 126976, 0xc /* MADV_??? */) = 0
    mmap2(0x40148000, 58972, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 7, 0) = 0x40148000
    madvise(0x40148000, 58972, 0xc /* MADV_??? */) = 0
    mprotect(0x40148000, 61440, PROT_READ|PROT_WRITE|PROT_EXEC) = 0
    mmap2(0x40157000, 4620, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 7, 0xe) = 0x40157000
    madvise(0x40157000, 4620, 0xc /* MADV_??? */) = 0
    mmap2(0x40159000, 57096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x40159000
    madvise(0x40159000, 57096, 0xc /* MADV_??? */) = 0
    close(7)                                = 0
    mprotect(0x40148000, 61440, PROT_READ|PROT_EXEC) = 0
    mprotect(0x40157000, 4096, PROT_READ)   = 0
    mprotect(0x8000, 503808, PROT_READ|PROT_EXEC) = 0
    mmap2(NULL, 49152, PROT_READ, MAP_SHARED, 8, 0) = 0x400a4000
    futex(0x40140734, FUTEX_WAKE_PRIVATE, 2147483647) = 0
    open("/dev/urandom", O_RDONLY)          = 7
    read(7, "@\236", 4)                   = 4
    close(7)                                = 0
    clock_gettime(CLOCK_MONOTONIC, {29544, 299349465}) = 0
    mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40167000
    madvise(0x40167000, 4096, 0xc /* MADV_??? */) = 0
    mprotect(0x40167000, 4096, PROT_READ)   = 0
    getuid32()                              = 0
    brk(0)                                  = 0xf0d000
    brk(0xf0d000)                           = 0xf0d000
    brk(0xf0e000)                           = 0xf0e000
    write(1, "hello\n", 6hello
    )                  = 6
    mprotect(0x40167000, 4096, PROT_READ|PROT_WRITE) = 0
    mprotect(0x40167000, 4096, PROT_READ)   = 0
    futex(0x4014072c, FUTEX_WAKE_PRIVATE, 2147483647) = 0
    munmap(0x40167000, 4096)                = 0
    exit_group(0)                           = ?

    and now lastest download link :

    Download Strace 4.8 from here

    license

    strace is a free software, you may download source of strace from here
    5
    How to cross compile strace for android on Ubuntu

    @alireza7991

    strace is a great developer tool, but as already mentioned it is already present in most stock phones.

    Really? What is the path to it? I'm on stock nexus 4, rooted 4.4.2, and can't find it anywhere. Which phones have it in the stock ROM, and what is the usual location of this binary?

    EDIT: I now built strace myself on Ubuntu, with the help of pointers bit2 linked in an earlier post, and by searching the web to resolve initial compilation problems.

    Here is what worked for me:

    - Install android cross compiler: sudo apt-get install gcc-arm-linux-gnueabi
    - Download strace source package: http://sourceforge.net/projects/strace/files/latest/download
    - Extract and go into the sources directory, ie: tar xf strace-4.8.tar.xz; cd strace-4.8
    - Apply the following patch with something like: "patch -p1 < /tmp/strace-arm.patch
    Code:
    diff -upr strace-4.8/signal.c strace-4.8-arm/signal.c
    --- strace-4.8/signal.c	2013-05-23 06:41:23.000000000 -0700
    +++ strace-4.8-arm/signal.c	2014-04-06 19:00:27.000000000 -0700
    @@ -60,6 +60,10 @@
     # include <asm/ptrace_offsets.h>
     #endif
     
    +#if defined(ARM)
    +#include <asm/ptrace.h>
    +#endif
    +
     #if defined(SPARC) || defined(SPARC64) || defined(MIPS)
     typedef struct {
     	struct pt_regs		si_regs;
    diff -upr strace-4.8/syscall.c strace-4.8-arm/syscall.c
    --- strace-4.8/syscall.c	2013-05-14 07:10:42.000000000 -0700
    +++ strace-4.8-arm/syscall.c	2014-04-06 19:00:53.000000000 -0700
    @@ -80,6 +80,10 @@
     # include <asm/ptrace.h>
     #endif
     
    +#if defined(ARM)
    +#include <asm/ptrace.h>
    +#endif
    +
     #ifndef ERESTARTSYS
     # define ERESTARTSYS	512
     #endif

    or simply add with an editor near the top of both signal.c and syscall.c the line: #include <asm/ptrace.h>

    Set some variables for the cross-compilation, and build for android (I'm building for armv7-a but you can specify armv5 or any other)
    Code:
    export CC=/usr/bin/arm-linux-gnueabi-gcc
    export STRIP=arm-linux-gnueabi-strip
    export CFLAGS="-march=armv7-a -O2 -static"
    ./configure --host=arm-linux
    make
    $STRIP strace
    unset CC STRIP CFLAGS
    That results in an strace executable that you can then push to your device, put the file in /system/xbin/ or /data/local/ and chmod 755 strace

    Hope this helps someone! Also attaching it in a zip file here, so that everything is available right here on XDA.
    Thanks to alireza7991 for starting this useful thread!
    5
    Once i run strace -p 123 it will come back
    Code:
    strace: attach: ptrace(PTRACE_ATTACH, ...): Operation not permitted

    I said :

    (123 is a example , use any other PID you wish )

    You must use the a valid PID , 123 is an example .

    For getting PID of an APP/Process , use the this command in terminal :

    Code:
    ps | grep "abc"

    instead of abc , write the process name you want ! for example :

    Code:
    ps | grep "com.android.acore"

    then search for PID in the output and use it with strace !
    5
    Once i run strace -p 123 it will come back
    Code:
    strace: attach: ptrace(PTRACE_ATTACH, ...): Operation not permitted

    You need to be root to attach to already running processes.

    I also find the "-f" option useful for more complex executables (which fork new processes). "-o" to write the output to a file can be useful if there is much output.
    3
    Only 4 downloads ?!