adbs路径:
build/tools/中发现了它——adbs!
adbs是一个用python写的命令行工具,利用了adb,addr2line, objdump这三个工具,大家看了这三个工具,可能就能猜到,adbs是用来分析应用程序尤其是与函数库相关的crash问题:)
具体的代码就不多看了,无外乎是一些运行环境的设定。
下面就来看一下如何使用它:
1. 设定好ANDROID_PRODUCT_OUT环境变量
ANDROID_PRODUCT_OUT="[your_path]/mydroid/out/target/product/generic",因为adbs需要使用到编译好的symbols,所以你需要编译整个android的source,得到与你调试环境一致的symbols文件
2. 直接运行adbs
adbs logcat
我特意准备了一个会crash的jni测试程序,得出的结果如下:
I/DEBUG ( 170): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG ( 170): Build fingerprint: 'tmous/htc_pyramid/pyramid:2.3.4/GRJ22/125597.1:user/release-keys'
I/DEBUG ( 170): pid: 20715, tid: 20727 >>> [your product name] <<<
I/DEBUG ( 170): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad
....
I/DEBUG ( 170): scr 80000010
I/DEBUG ( 170):
I/DEBUG ( 170): #00 execle /[your_path]/mydroid/bionic/libc/unistd/exec.c:84
I/DEBUG ( 170): #01 tmalloc_small.clone.10
I/DEBUG ( 170): #02 get_malloc_leak_info /[your_path]/mydroid/bionic/libc/bionic/malloc_debug_common.c:168
./prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-objdump: '/[your_path]/xxxxxx
./prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-addr2line: '[your_path]/xxxxxx
I/DEBUG ( 170): #03 (unknown) (unknown)
I/DEBUG ( 170): #04 dvmPlatformInvoke DexDataMap.c:0
I/DEBUG ( 170):
这里明显可以看出adbs给出了有用的黑体部分的信息,即做了一些地址到具体程序函数名和行数的转换,方便我们定位问题。
为了给大家看得更清楚,下面是单纯使用logcat看到的crash信息:
11-02 17:18:40.438: INFO/DEBUG(170): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
11-02 17:18:40.438: INFO/DEBUG(170): Build fingerprint: 'tmous/htc_pyramid/pyramid:2.3.4/GRJ22/125597.1:user/release-keys'
11-02 17:18:40.448: INFO/DEBUG(170): pid: 20715, tid: 20727 >>> [your product name]<<<
11-02 17:18:40.448: INFO/DEBUG(170): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad
...
11-02 17:18:40.448: INFO/DEBUG(170): scr 80000010
11-02 17:18:40.618: INFO/DEBUG(170): #00 pc 000161c8 /system/lib/libc.so (__libc_android_abort)
11-02 17:18:40.618: INFO/DEBUG(170): #01 pc 00013bf0 /system/lib/libc.so (dlfree)
11-02 17:18:40.618: INFO/DEBUG(170): #02 pc 00014a72 /system/lib/libc.so (free)
11-02 17:18:40.618: INFO/DEBUG(170): #03 pc 0000664e [your crash app name]
11-02 17:18:40.618: INFO/DEBUG(170): #04 pc 00011e74 /system/lib/libdvm.so
11-02 17:18:40.618: INFO/DEBUG(170): code around pc:
11-02 17:18:40.618: INFO/DEBUG(170): afd161a8 2c006824 e028d1fb b13368db c064f8df
以下内容转自:http://hi.baidu.com/xiongjinxi/item/9b4205a95550a1cf5bf1910c
使用adb启动acitivity
am start -a action android:name="android.intent.action.VIEW" -d 输入的数据 -n package="com.android.gallery"/activity android:name="com.android.camera.MovieView
也就是 am -a "action" -d data -n "package/activity"
例如:
am start -a android.intent.action.VIEW -d /mnt/video/aaa.mkv -n
com.android.gallery/com.android.camera.MovieView
usage: am [subcommand] [options] usage: am start [-D] [-W] [-P ] [--start-profiler ] [--R COUNT] [-S] am startservice am force-stop am kill am kill-all am broadcast am instrument [-r] [-e ] [-p ] [-w] [--no-window-animation] am profile [looper] start am profile [looper] stop [] am dumpheap [flags] am set-debug-app [-w] [--persistent] am clear-debug-app am monitor [--gdb ] am screen-compat [on|off] am display-size [reset|MxN] am to-uri [INTENT] am to-intent-uri [INTENT] am start: start an Activity. Options are: -D: enable debugging -W: wait for launch to complete --start-profiler : start profiler and send results to -P : like above, but profiling stops when app goes idle -R: repeat the activity launch times. Prior to each repeat, the top activity will be finished. -S: force stop the target app before starting the activity am startservice: start a Service. am force-stop: force stop everything associated with . am kill: Kill all processes associated with . Only kills. processes that are safe to kill -- that is, will not impact the user experience. am kill-all: Kill all background processes. am broadcast: send a broadcast Intent. am instrument: start an Instrumentation. Typically this target is the form /. Options are: -r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT). Use with [-e perf true] to generate raw output for performance measurements. -e : set argument to . For test runners a common form is [-e [,...]]. -p : write profiling data to -w: wait for instrumentation to finish before returning. Required for test runners. --no-window-animation: turn off window animations will running. am profile: start and stop profiler on a process. am dumpheap: dump the heap of a process. Options are: -n: dump native heap instead of managed heap am set-debug-app: set application to debug. Options are: -w: wait for debugger when application starts --persistent: retain this value am clear-debug-app: clear the previously set-debug-app. am monitor: start monitoring for crashes or ANRs. --gdb: start gdbserv on the given port at crash/ANR am screen-compat: control screen compatibility mode of . am display-size: override display size. am to-uri: print the given Intent specification as a URI. am to-intent-uri: print the given Intent specification as an intent: URI. specifications include these flags and arguments: [-a ] [-d ] [-t ] [-c [-c ] ...] [-e|--es ...] [--esn ...] [--ez ...] [--ei ...] [--el ...] [--eu ...] [--eia [, [,] [-f ] [--grant-read-uri-permission] [--grant-write-uri-permission] [--debug-log-resolution] [--exclude-stopped-packages] [--include-stopped-packages] [--activity-brought-to-front] [--activity-clear-top] [--activity-clear-when-task-reset] [--activity-exclude-from-recents] [--activity-launched-from-history] [--activity-multiple-task] [--activity-no-animation] [--activity-no-history] [--activity-no-user-action] [--activity-previous-is-top] [--activity-reorder-to-front] [--activity-reset-task-if-needed] [--activity-single-top] [--activity-clear-task] [--activity-task-on-home] [--receiver-registered-only] [--receiver-replace-pending] [--selector] [ | | ]