Android: How to strace an app using ADB shell am start

后端 未结 7 1242
予麋鹿
予麋鹿 2020-12-13 11:37

I need help on stracing Android apps in the SDK emulator.

Here is my setup:

I have an Android SDK emulator running the Android API 4.03 ADB shell connected t

7条回答
  •  臣服心动
    2020-12-13 11:57

    I've found a tricky way to do this and also guarantee that all the syscalls are going to be catch. It can be done even if the app is not debuggable:

    • Set the Activity Manager (am) to put the app in debug mode with a -w option that will halt its execution until it is attached to a debugger
    • Start the application manually (you can just click on the screen on its icon or call it with am start
    • With the application halted, obtain its PID
    • With its PID obtained, call strace to trace this process
    • Finally, attach the debugger so the execution start.

    Here are the steps:

    adb shell # shell into the device
    am set-debug-app -w com.package.name # put app to debug mode
    am start com.package.name/com.path.to.MainActivity # start the app
    ps -A | grep com.package.name # this will show you the PID
    strace -p  > appoutput.txt 2> appstrace.txt 
    # strace the program and record its output and strace in txt files
    

    Now just attach the debugger and enjoy, you can do it for example in Android Studio or Eclipse. From this point on the execution will begin and you will be able to trace it since the very first line of code.

提交回复
热议问题