Skip to content

Instantly share code, notes, and snippets.

@steadfasterX
Last active November 13, 2020 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steadfasterX/0b3a747e017ee222c769552865f5ccc8 to your computer and use it in GitHub Desktop.
Save steadfasterX/0b3a747e017ee222c769552865f5ccc8 to your computer and use it in GitHub Desktop.
(s)tracing an android service is not straight forward but possible and needed in order to get all from the start
If it is required to debug a service from its very start, the sigstop service option is added.
This option will send SIGSTOP to a service immediately before calling exec.
This gives a window where developers can attach a debugger, strace, etc before continuing the service with SIGCONT.
This flag can also be dynamically controlled via the ctl.sigstop_on and ctl.sigstop_off properties.
Below is an example of dynamically debugging logd via the above:
# prepare service, yes even start it!
stop <service-name>
setprop ctl.sigstop_on <service-name>
start <service-name>
# find sigstopped init and attach strace to it
ps -A |grep init (find the sigstopped init PID : "do_signal_stop")
strace -tt -y -a 120 -s 600 -ff -p <PID>
# continue starting the service
# OPEN ANOTHER terminal or adb shell and type:
kill -SIGCONT <pid of the above sigstopped init>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment