1page.title=ndk-stack
2@jd:body
3
4<div id="qv-wrapper">
5    <div id="qv">
6      <h2>On this page</h2>
7
8      <ol>
9        <li><a href="#use">Usage</a></li>
10      </ol>
11    </div>
12  </div>
13
14<p>The {@code ndk-stack} tool allows you to filter stack traces as they appear in the
15output of <a href="{@docRoot}tools/help/logcat.html">{@code adb logcat}</a>. It also replaces any
16address inside a shared library with the corresponding
17{@code &lt;source-file&gt;:&lt;line-number&gt;} values from your source code, making issues easier
18to pinpoint.</p>
19
20<p>For example, it translates something like:</p>
21
22<pre>
23I/DEBUG   (   31): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
24I/DEBUG   (   31): Build fingerprint: 'generic/google_sdk/generic/:2.2/FRF91/43546:eng/test-keys'
25I/DEBUG   (   31): pid: 351, tid: 351  %gt;%gt;%gt; /data/local/ndk-tests/crasher &lt;&lt;&lt;
26I/DEBUG   (   31): signal 11 (SIGSEGV), fault addr 0d9f00d8
27I/DEBUG   (   31):  r0 0000af88  r1 0000a008  r2 baadf00d  r3 0d9f00d8
28I/DEBUG   (   31):  r4 00000004  r5 0000a008  r6 0000af88  r7 00013c44
29I/DEBUG   (   31):  r8 00000000  r9 00000000  10 00000000  fp 00000000
30I/DEBUG   (   31):  ip 0000959c  sp be956cc8  lr 00008403  pc 0000841e  cpsr 60000030
31I/DEBUG   (   31):          #00  pc 0000841e  /data/local/ndk-tests/crasher
32I/DEBUG   (   31):          #01  pc 000083fe  /data/local/ndk-tests/crasher
33I/DEBUG   (   31):          #02  pc 000083f6  /data/local/ndk-tests/crasher
34I/DEBUG   (   31):          #03  pc 000191ac  /system/lib/libc.so
35I/DEBUG   (   31):          #04  pc 000083ea  /data/local/ndk-tests/crasher
36I/DEBUG   (   31):          #05  pc 00008458  /data/local/ndk-tests/crasher
37I/DEBUG   (   31):          #06  pc 0000d362  /system/lib/libc.so
38I/DEBUG   (   31):
39</pre>
40
41<p>into the more readable output: </p>
42
43<pre>
44********** Crash dump: **********
45Build fingerprint: 'generic/google_sdk/generic/:2.2/FRF91/43546:eng/test-keys'
46pid: 351, tid: 351  &gt;&gt;&gt; /data/local/ndk-tests/crasher &lt;&lt;&lt;
47signal 11 (SIGSEGV), fault addr 0d9f00d8
48Stack frame #00  pc 0000841e  /data/local/ndk-tests/crasher : Routine zoo in /tmp/foo/crasher/jni/zoo.c:13
49Stack frame #01  pc 000083fe  /data/local/ndk-tests/crasher : Routine bar in /tmp/foo/crasher/jni/bar.c:5
50Stack frame #02  pc 000083f6  /data/local/ndk-tests/crasher : Routine my_comparison in /tmp/foo/crasher/jni/foo.c:9
51Stack frame #03  pc 000191ac  /system/lib/libc.so
52Stack frame #04  pc 000083ea  /data/local/ndk-tests/crasher : Routine foo in /tmp/foo/crasher/jni/foo.c:14
53Stack frame #05  pc 00008458  /data/local/ndk-tests/crasher : Routine main in /tmp/foo/crasher/jni/main.c:19
54Stack frame #06  pc 0000d362  /system/lib/libc.so
55</pre>
56
57<h2>Usage</h2>
58<p>To use {@code ndk-stack}, you first need a directory containing symbolic versions of your app's
59shared libraries. If you use the NDK build system ({@code ndk-build}), these shared-library
60files reside under {@code $PROJECT_PATH/obj/local/&lt;abi&gt;}, where {@code &lt;abi&gt;} represents
61your device's ABI. By default, the system uses the {@code armeabi} ABI.</p>
62
63<p>There are two ways to use the tool. You can feed the logcat text as direct input to the program.
64For example:</p>
65
66<pre class="no-pretty-print">
67adb logcat | $NDK/ndk-stack -sym $PROJECT_PATH/obj/local/armeabi
68</pre>
69
70<p>You can also use the {@code -dump} option to specify the logcat as an input file. For example:
71</p>
72
73<pre class="no-pretty-print">
74adb logcat &gt; /tmp/foo.txt
75$NDK/ndk-stack -sym $PROJECT_PATH/obj/local/armeabi -dump foo.txt
76</pre>
77
78<p>When it begins parsing the logcat output, the tool looks for an initial line of asterisks.
79For example:</p>
80
81<pre class="no-pretty-print">
82*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
83</pre>
84
85<p class="note"><strong>Note: </strong>When copy/pasting traces, don't forget this line, or
86{@code ndk-stack} won't work correctly.</p>