Debugging Native Android Platform Code

Source: Internet
Author: User
Tags valgrind

From:

Http://source.android.com/devices/tech/debug/index.html

This page contains a summary of useful tools and related commands for debugging, tracing, and profiling native Android pla Tform code. The pages within this section contain detailed information on other debugging tools for use during development of platform -level features.

For example, the learn how to explore system services with Dumpsys and evaluate network and RAM use. See the subpages for tools and methods not described below.

Debuggerd

When a dynamically-linked executable starts, several signal handlers is registered that connect to debuggerd (or in the debuggerd64) Event that signal was sent to the process. The debuggerd process dumps registers and unwinds the stack. Here are example output (with timestamps and extraneous information removed):

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
BuildFingerprint: ' Android/aosp_flounder/flounder:5.1.51/aosp/enh08201009:eng/test-keys '
Revision: ' 0 '
Abi: ' Arm '
Pid: 1656,Tid: 1656,Name:Crasher>>>Crasher<<<
Signal6 (Sigabrt),Code-6 (Si_tkill),Fault addr--------
AbortMessage: ' Some_file.c:123:some_function:assertion ' false ' failed '
R000000000R100000678R200000006R3 F70B6DC8
R4 f70b6dd0 R5 F70b6d80 R600000002R70000010c
R8 Ffffffed R900000000Sl00000000FP ff96ae1c
Ip00000006SP ff96ad18 lr f700ced5 pc f700dc98 CPSR400b0010
BackTrace:
#00 pc 00042c98/system/lib/libc.so (tgkill+12)
#01 pc 00041ed1/system/lib/libc.so (pthread_kill+32)
#02 pc 0001bb87/system/lib/libc.so (raise+10)
#03 pc 00018cad/system/lib/libc.so (__libc_android_abort+34)
    #04 pc 000168e8  /system/lib/libc.so (abort+4)
    #05 pc 0001a78f  /system/lib/libc.so (__libc_fatal+16)
    #06 pc 00018d35  /system/lib/libc.so (__assert2+20)
    #07 pc 00000f21  /system/xbin/crasher
    #08 pc 00016795  /system/lib/libc.so (__libc_init+44)
    #09 pc 00000abc  /system/xbin/crasher
Tombstone written to: /data/ tombstones/tombstone_06

This can is pasted into to development/scripts/stack get a more detailed unwind with line number information (assuming the unstripped binaries can be found).

Some libraries on the system is built with to LOCAL_STRIP_MODULE := keep_symbols provide usable backtraces directly from Debuggerd. This makes your library or executable slightly larger, and not nearly as large as a unstripped version.

Note also the last line debuggerd of output---in addition to dumping a summary to the log, debuggerd writes a full "tombstone" t o disk. This contains a lot of extra information so can be helpful in debugging a crash, in particular the stack traces for all The threads in the crashing process (not just the thread, the caught the signal) and a full memory map.

Native debugging with GDB debugging a running app

To connect to a already-running app or native daemon, use gdbclient .

Current versions of Gdbclient just require the process ID (PID). So-to-debug a process with PID 1234, simply run:

1234

The script would set up port forwarding, start the appropriate on gdbserver the device, start the appropriate on the gdb host , configure to gdb find symbols, and connect to the gdb remote gdbserver .

debugging a native process as it starts

If you want to debug a process as it starts, you'll need to the use gdbserver or gdbserver64 manually, but that's easy too:

:5039/system/bin/My_test_app
Process My_test_app created; =3460
Listening5039

Identify the app ' s PID from gdbserver the output, and then in another window:

<app pid> 

Then enter continue at the gdb prompt.

Note that to the debug a 64-bit process, you'll need to the use gdbserver64 . The error messages from gdb If you made the wrong choice is unhelpful (along the lines of Reply contains invalid hex digit 59 ).

debugging processes that crash

If you want debuggerd to suspend crashed processes so can attach gdb , set the appropriate property:

$ adb shell setprop Debug.  DB.  999999# <= M
$ adb shell setprop Debug. Debuggerd. True# > M

At the end of the usual crash output, would give you instructions on how to debuggerd connect gdb using the typical command :

<pid>
Debugging without Symbols

If you don't have symbols, sometimes'll gdb get confused about the instruction set it's disassembling (ARM or Thumb). The instruction set is chosen as the default when symbol information is missing can be switched between ARM or Thumb Like so:

Set arm fallback-# or ' thumb '  
Other Tools Valgrind

The following steps show do you have Valgrind on Android. This tool suite contains a number of tools including Memcheck for detecting memory-related errors in C and C + +.

  1. To install Valgrind, run:
    -J6 External/valgrind  
  2. Push Valgrind to the device:
    $ adb remount
    $ adb Sync
  3. /data/local/ tmp
    $ adb shell chmod 777 / data/local/tmp
  4. run the System server with Valgrind:
    $ adb root 
    $ adb shell SetProp wrap. System_server "Logwrapper Valgrind"
    $ adb shell stop & & adb shell start
  5. for debug symbols, push unstripped libraries to /data/local /symbols :
    $ adb shell mkdir /data/local /symbols 
    $ adb push $OUT /symbols /data/local/ symbols
  6. To use Valgrind during boot up, edit and change out/target/product/XXXX/root/init.rc :
    service example /system/bin/foo --arg1 --arg2
    To:
    service example /system/bin/logwrapper /system/bin/valgrind /system/bin/foo --arg1 --arg2
    To see the effects, you need to create a and boot.img reflash the device.
Systrace

See Systrace ondeveloper.android.com for deriving execution times of applications Andother Android system processes.

Debugging Native Android Platform Code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.