Generally, the program fails at a certain point. We can use adb shell ps to find the PID and then use gdbserver attach on the target side, finally, use gdb to connect to the host. But the program will not crash so perfectly, and in many cases the program will crash together. At this time, there are two possible cases: 1. It will be suspended when it comes together. 2. If you come together, you will miss it a little later.
Here, I use the following system:
Host: Ubuntu x64
Target: Android ICS
Method 1: For the first case. First, run Dev Tools> Development Settings in target's Android system. Click "None" and select the program you want to call (for example, flashplayer ), select Wait for debugger to exit.
At this time, the program to be tuned will be stopped:
Of course, at this time, wait for debugger is not wait gdb, It is DDMS. However, because we finally use gdb, we should take the opportunity to use gdb attach. For more information about how to set up and use gdb, see another blog post (http://www.bkjia.com/kf/201203/124820.html ). Generally, you will see something similar to the following:
Jzj @ jzj-laptop :~ /Debug $ gdb-x init. gdb
GNU gdb (GDB) 7.1-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
...
_ Futex_syscall4 () at bionic/libc/arch-x86/bionic/atomics_x86.S: 73
73 popl % esi
Created trace state variable $ trace_timestamp for target's variable 1 ."
(Gdb)
After gdb is started, you can set a breakpoint to check the variables. After the breakpoint is set, enter continue to continue running. However, as mentioned above, wait for debugger is not wait gdb, therefore, gdb says that continue cannot continue. Open DDMS
A red bug indicates that the program has stopped. Click the green bug program above to continue running the program. Then you can switch to gdb for debugging.
Method 2: For the second case. Start the target program with a script and attach it immediately. Script is always faster than human input, so sometimes you can use this method to check whether it is crash or attach first. The advantage is that it is relatively simple. The following is a simple example (called Adobe reader). Note that the grep string depends on the situation. In reality, you can print the PID first, or automatically determines whether it is unique.
#! /Bin/bash
ACTION = android. intent. action. MAIN
COM = com. adobe. reader/com. adobe. reader. AdobeReader
Adb root
Adb shell am start-a $ ACTION-n $ COM
PID = 'adb shell ps | grep "reader" | awk '{print $2 }''
CMD = "adb shell/data/gdbserver: 1234 -- attach $ PID"
Echo $ CMD
Eval $ CMD
From Jin Zhuo Jun's blog @ CSDN
Excerpt from