Document directory
- 1. Print related Java calls in the specified function
- 2. General JAVA process stack
- 3. kernel process stack
- 4. Print the current stack when an exception occurs.
- 5. output the stack of the specified process
- 1. callstack
- 1. Print the stack of the specified Java Process to the file.
- 2. Print the stack of the specified process to logcat.
- 3. Print the system call of the specified process
Android debugging technology
Bob1. Java layer single-step debugging
See "using eclipse to debug laucher in one step"
See "compile and debug the browser of adnroid with Eclipse"
2. Native layer single-step debugging
Refer to "using GDB to debug Android local code in one step"
3. Java layer stack printing 1. Print related Java calls in the specified function
Log.d(TAG,Log.getStackTraceString(new Throwable()));
2. General JAVA process stack
ActivityManagerService.dumpStackTraces
Save it in the data/ANR/traces.txt file specified by Dalvik. VM. Stack-trace-file in the system settings. It can contain information about multiple process stacks.
3. kernel process stack
Dumpkernelstacktraces, which is a private function and cannot be called.
Code in frameworks/base/services/Java/COM/Android/Server/watchdog. Java
Save it in the data/ANR/traces.txt file specified by Dalvik. VM. Stack-trace-file in the system settings.
4. Print the current stack when an exception occurs.
Exception: printstacktrace ()
try { ... } catch (RemoteException e) { e.printStackTrace(); ... }5. output the stack of the specified process
Process.sendSignal(pid, Process.SIGNAL_QUIT)
Save it in data/ANR/traces.txt.
This is only valid for Java processes and is handled by signalcatcher. C of dalvikvm.
4. Native layer stack printing 1. callstack
Usage:
#include <utils/CallStack.h> ... CallStack stack; stack.update(); stack.dump(""); // the parameter is prefix of dump
Before use, modifySystem/CORE/include/ARCH/Linux-arm/androidconfig. h
#define HAVE_DLADDR 1 #define HAVE_CXXABI 1
And in the fileFrameworks/base/libs/utils/Android. mkAdd
ifeq ($(TARGET_OS),linux) LOCAL_SHARED_LIBRARIES += libdl endif
Re-compile, push the libutils. So generated to the/system/lib/directory, and restart the device.
V. Java exception Analysis
This android will output information to logcat. Easy to analyze.
6. natvie exception Analysis
Native process exceptions may cause
Debugadh will output information to logcat and save it to/data/tombstones.
You can modify the dump_stack_and_code code in system/CORE/debugadh. C to meet deeper debugging information requirements.
VII. Log System
Use in Java
import android.util.Log; ... Log.d(TAG,"log info");
Use in native code
#define LOG_TAG "YOUR_LOGTAG" ... #include <utils/Log.h> #define LOG_NDEBUG 0 ... LOGD("log info");
Or
Log.d(LOG_TAG,“log info”);
When using ADB logcat, you can only display logs of a specific category. You can also use the-V threadtime parameter to display thread numbers and time information.
Convert standard output to logcat
# System/bin/logwrapper process name
8. Other debugging methods (command line) 1. Print the stack of the specified Java Process to the file
#kill -3 pid
Here 3 is the process. signal_quit in section 3.5.
Output in the data/ANR/traces.txt file.
This is only valid for Java processes and is handled by dalvikvm.
2. Print the stack of the specified process to logcat.
# Kill-11 PID or # Kill-7 PID
This is sometimes valid. The principle is to use the (6) mechanism.
You can use ADB logcat to view the stack call output.
3. Print the system call of the specified process
#strace -f -p pid -o output
Mainly output file, socket, lock and other system operation information.
-F indicates that all sub-processes are tracked.
-O outputs the log to the specified file.
Original article:
Http://www.bobbog.com/archives/19