debugging (still work in progress)

android Boot Time Analysis & logging & debugging

Enable bootchart

http://elinux.org/Using_Bootchart_on_Android

  1. 准备
    Host
    apt-get install bootchart pybootchartgui
    Target
    设置环境变量INIT_BOOTCHART=true, 重编init

  2. 打开
    adb shell ‘echo 120 > /data/bootchart-start’
    或者使用kernel commandline:
    androidboot.bootchart=120

  3. 抓取日志
    system/core/init/grab-bootchart.sh

  4. 生成png
    bootchart bootchart.tgz

Lollipop上的hack:
如果bootchart_init时/data分区未mount,需要hack代码:把/data/bootchart改为/dev/bootchart (同时修改bootchart.c和grab-bootchart.sh)
此时只能用kenel commandline传递timeout.

logging

kernel logging

kernel has a ring buffer which can be dumped via command dmesg. Default loglevel in init.rc is 3, you can change it to 8(higest).
loglevel 8

android logging

The Android application framework has a built-in logging system – logcat, which goes through a special driver in the kernel.

tracing

strace : trace system calls and signals

android has strace in external/strace, strace can be enabled in init.rc or hot attach.

init.rc
service xxx /system/xbin/strace -tt -o/data/boot.strace /system/bin/vold

hot attach
strace -tt -p <PID>

ltrace : A library call tracer

debian has this package

debugging

advanced method

start gdbserver on board: find PID of vold, then
    gdbserver :1234 --attach 1264
map port on PC: map 1234 on PC to 123 on board
    adb forward tcp:1234 tcp:1234
start arm-eabi-gdb
    arm-eabi-gdb
    (gdb) target remote :1234
    (gdb) file out/target/product/$TARGET_PRODUCT/symbols/system/bin/vold
    (gdb) set solib-search-path out/target/product/$TARGET_PRODUCT/symbols/system/lib
    (gdb) bt
    (gdb) info threads
    (gdb) thread 3
    (gdb) p <var>

quick method

gdbclient <PID>

debuggerd

Android crash logcat can be fed to development/scripts/stack to get more detailed info.

Run program inside:
gdbserver
gdbserver :5039 /system/bin/my_test_app
valgrind

attach crash programs:
$ adb shell setprop debug.db.uid 999999 # <= M
$ adb shell setprop debug.debuggerd.wait_for_gdb true # > M

AddressSanitizer (ASan)
dumpsys: provides information about the status of system services.
DDMS - native memory tracking: libc.debug.malloc

procstatsanalyze application memory usage over time
meminfo: analyze mem usage in time
$ adb shell dumpsys procstats –hours 3
network use