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

Search This thread

E:V:A

Inactive Recognized Developer
Dec 6, 2011
1,447
2,222
-∇ϕ
How about socat or reptyr?

@alireza7991

strace is a great developer tool, but as already mentioned it is already present in most stock phones. However, there are two more fantastic utilities I cannot find the Android (ARM) binaries for. They are: socat and reptyr.

Could you please have a look at these, and see if you could make some binaries?

Sorry for being direct. But it would also help everyone if you provide something not already common. Thanks in advance.

socat:
http://technostuff.blogspot.com/2008/10/some-useful-socat-commands.html
https://github.com/craSH/socat
http://stackoverflow.com/questions/9234242/socat-in-android

reptyr:
https://blog.nelhage.com/2011/01/reptyr-attach-a-running-process-to-a-new-terminal/
https://blog.nelhage.com/2011/02/changing-ctty/
https://github.com/nelhage/reptyr/

EDIT: Sorry my bad, I had that binary, from another place, probably my root kit. So I guess it's not part of the standard stock stuff.
 
Last edited:

sordna

Senior Member
Dec 12, 2012
1,262
647
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!
 

Attachments

  • strace-4.8-armv7-a.zip
    364.2 KB · Views: 850
Last edited:

E:V:A

Inactive Recognized Developer
Dec 6, 2011
1,447
2,222
-∇ϕ
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?
As I edited, my mistake...

Thank you very much for this build! Very useful.
Would you be willing to give socat a compilation try?
I just can't find any Android binaries anywhere.

You probably have to change the "/dev/net/tun" in sources to
Android's "/dev/tun" to use that, which is why this is very useful.
 

sordna

Senior Member
Dec 12, 2012
1,262
647
Would you be willing to give socat a compilation try?
I just can't find any Android binaries anywhere.

You probably have to change the "/dev/net/tun" in sources to
Android's "/dev/tun" to use that, which is why this is very useful.

Ok, I tried compiling socat and got errors. It needs some patching, so I'll try again over the weekend if I have time. Some pointer that seems helpful is here:

http://gumstix.8.x6.nabble.com/Re-cross-compiling-bitbake-headaches-SOLVED-td562502.html
 
  • Like
Reactions: E:V:A

E:V:A

Inactive Recognized Developer
Dec 6, 2011
1,447
2,222
-∇ϕ
Ok, I tried compiling socat and got errors. It needs some patching, so I'll try again over the weekend if I have time.

Thank you very much for trying. I assume you tried the latest version 1.7.2.4?

To help you compiling, I also looked around and found these.

http://stackoverflow.com/a/9778406

http://xdaforums.com/showpost.php?p=6930947&postcount=3 + his subsequent post

Dan Brown have apparently been able to patch 1.7.1.3 and include it in his OPKG tools package. But, not built independently.

Also look at these, since I'm not sure what he's doing.
http://dan.drown.org/android/src/
http://dan.drown.org/android/src/socat/
 

sordna

Senior Member
Dec 12, 2012
1,262
647
I tried both the latest 1.7 (failed in the configure script) and the latest 2.0 beta (configure script runs OK, but fails during make).
 
  • Like
Reactions: E:V:A

sordna

Senior Member
Dec 12, 2012
1,262
647
socat for android

Thank you very much for trying. I assume you tried the latest version 1.7.2.4?

To help you compiling, I also looked around and found these.

http://stackoverflow.com/a/9778406

http://xdaforums.com/showpost.php?p=6930947&postcount=3 + his subsequent post

Dan Brown have apparently been able to patch 1.7.1.3 and include it in his OPKG tools package. But, not built independently.

Also look at these, since I'm not sure what he's doing.
http://dan.drown.org/android/src/
http://dan.drown.org/android/src/socat/


Ok, I was able to compile socat-2.0.0-b7 by doing:
./configure --host=arm-linux --disable-ssl --prefix=/data/local

and then editing config.h and adding values to the following #define statements:
#define CRDLY_SHIFT 9
#define TABDLY_SHIFT 11
#define CSIZE_SHIFT 4

I also added #define ISPEED_OFFSET 13 which is needed for TERMIOS support.

See attachment!
 

Attachments

  • socat-2.0.0-b7-armv7-a.zip
    1 MB · Views: 3,643
Last edited:

E:V:A

Inactive Recognized Developer
Dec 6, 2011
1,447
2,222
-∇ϕ
Ok, I was able to compile socat-2.0.0-b7 by ...
Some places mention the need for #define ISPEED_OFFSET 13 but I didn't have to do that.

Absolutely gold! Thank you so much!

BTW. Not sure it's necessary but did you also change this?

You probably have to change the "/dev/net/tun" in sources to
Android's "/dev/tun" to use that...


For everyone's information:
There are two other binaries in there as well: filan and procan .

Code:
[SIZE=2]
/ # filan -h
filan by Gerhard Rieger - see http://www.dest-unreach.org/socat/
Analyze file descriptors of the process
Usage:
filan [options]
   options:
      -?|-h          print this help text
      -d             increase verbosity (use up to 4 times)
      -i<fdnum>      only analyze this fd
      -n<fdnum>      analyze all fds from 0 up to fdnum-1 (default: 1024)
      -s             simple output with just type and socket address or path
      -f<filename>   analyze file system entry
      -T<seconds>    wait before analyzing, useful to connect with debugger
      -r             raw output for time stamps and rdev
      -L             show symlink properties instead of following it
      -o<filename>   output goes to filename, that can be:
                     a regular file name, the output goes to that
                     +<filedes> , output goes to the file descriptor (which must be open writable)
                     the 3 special names stdin stdout and stderr

======================

/ # procan -h
procan by Gerhard Rieger - send bug reports to socat@dest-unreach.org
Analyze system parameters of process
Usage:
procan [options]
   options:
      -?|-h  print a help text describing command line options
      -c     print values of compile time C defines
[/SIZE]

However, filan gives me the following error:
Code:
*** stack smashing detected ***: filan terminated
Not sure what's causing this. Also it lists FD's until then, but refuses afterwards. But doing "filan -i<FD>" works.

Here are the compile time C-defines:
Code:
[SIZE=2]/ # procan -c
#define FD_SETSIZE 1024
#define NFDBITS 32
#define O_RDONLY 0
#define O_WRONLY 1
#define O_RDWR 2
#define SHUT_RD 0
#define SHUT_WR 1
#define SHUT_RDWR 2
#define CRDLY 000000003000
#define CR0 000000000000
#define CR1 000000001000
#define CR2 000000002000
#define CR3 000000003000
#define TABDLY 000000014000
#define TAB0 000000000000
#define TAB1 000000004000
#define TAB2 000000010000
#define TAB3 000000014000
#define CSIZE 000000000060
#define TIOCEXCL 0x540c
#define FOPEN_MAX 16
#define PF_UNIX 1
#define PF_INET 2
#define PF_INET6 10
#define PF_APPLETALK 5
#define PF_PACKET 17
#define SOCK_STREAM 1
#define SOCK_DGRAM 2
#define SOCK_RAW 3
#define SOCK_SEQPACKET 5
#define SOCK_PACKET 10
#define IPPROTO_IP 0
#define IPPROTO_TCP 6
#define IPPROTO_UDP 17
#define IPPROTO_SCTP 132
#define IPPROTO_DCCP 33
#define SOL_SOCKET 0x1
#define SOL_PACKET 0x107
#define SOL_IP 0x0
#define SOL_IPV6 0x29
#define SOL_TCP 0x6
#define SO_REUSEADDR 2
[/SIZE]

And the feature information for socat:

Code:
[SIZE=2]features:
  #define WITH_STDIO 1
  #define WITH_FDNUM 1
  #define WITH_FILE 1
  #define WITH_CREAT 1
  #define WITH_GOPEN 1
  [B][COLOR=Red]#undef WITH_TERMIOS[/COLOR][/B]
  #define WITH_PIPE 1
  #define WITH_UNIX 1
  #define WITH_ABSTRACT_UNIXSOCKET 1
  #define WITH_IP4 1
  #define WITH_IP6 1
  #define WITH_RAWIP 1
  #define WITH_GENERICSOCKET 1
  #define WITH_INTERFACE 1
  #define WITH_TCP 1
  #define WITH_UDP 1
  #define WITH_SCTP 1
  #define WITH_LISTEN 1
  #define WITH_SOCKS4 1
  #define WITH_SOCKS4A 1
  #define WITH_PROXY 1
  #define WITH_SYSTEM 1
  #define WITH_EXEC 1
  [COLOR=Red][B]#undef WITH_READLINE[/B][/COLOR]
  #define WITH_TUN 1
  #define WITH_PTY 1
[COLOR=Red][B]  #undef WITH_OPENSSL
  #undef WITH_FIPS
  #undef WITH_LIBWRAP[/B][/COLOR]
  #define WITH_SYCLS 1
  #define WITH_FILAN 1
  #define WITH_RETRY 1
  #define WITH_MSGLEVEL 0 /*debug*/
[/SIZE]
I haven't properly tried socat yet. I'll get back here if there are any problems.

Thanks again.
 
Last edited:

sordna

Senior Member
Dec 12, 2012
1,262
647
Absolutely gold! Thank you so much!

BTW. Not sure it's necessary but did you also change this?

I had not done the tun device path change earlier. You could actually have answered your own question by looking at the binary:
strings socat | grep '/dev/.*tun'

Ok, I recompiled and uploaded an updated zip in my previous post. I changed /dev/net/tun to /dev/tun and also added the #define ISPEED_OFFSET 13 which allows TERMIOS support to be enabled, and now you can see it when you do socat -V

readline is not there because I don't have a readline library for android. Not sure of the impact, if any. I did notice you cannot say "stdin" or "stdout" like you can on the normal linux version, but you can use the dash "-" instead.
Anyway, download the zip again.

By the way, why don't you install ubuntu or some other linux distro so you can easily cross compile stuff for android ? Even if you don't have a spare computer, you can do it in a VM... A virtual disk image of only 4-5 gigabytes is enough for a server installation with compilers and development libraries.
 
Last edited:

ranchu-panchu

Senior Member
Nov 16, 2016
144
4
Hi,

I try to understand which device is called and how when doing "input keyevent 26" (shutdown screen),
so I did
strace input keyevent 26

But I get the following error:
root@mako:/ # strace input keyevent 26
execve("/system/bin/input", ["input", "keyevent", "26"], [/* 22 vars */]) = -1 ENOEXEC (Exec format error)
write(2, "strace: exec: Exec format error\n", 32strace: exec: Exec format error
) = 32
exit_group(1) = ?
+++ exited with 1 +++

Is it not legal to strace "input" script ?

ubuntu@ubuntu-laptop:/media/sdi/fs/hw$ cat /media/sf_shared/input
# Script to start "input" on the device, which has a very rudimentary
# shell.
#
base=/system
export CLASSPATH=$base/framework/input.jar
exec app_process $base/bin com.android.commands.input.Input $*

ubuntu@ubuntu-laptop:/media/sdi/fs/hw$


Thanks,
Ranchug
 
Last edited:

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 ?!