SlideShare a Scribd company logo
1
Android Platform
Debugging and
Development
AnDevCon Boston 2015
Karim Yaghmour
@karimyaghmour
karim.yaghmour@opersys.com
2
These slides are made available to you under a Creative Commons Share-
Alike 3.0 license. The full terms of this license are here:
https://creativecommons.org/licenses/by-sa/3.0/
Attribution requirements and misc., PLEASE READ:
● This slide must remain as-is in this specific location (slide #2), everything
else you are free to change; including the logo :-)
● Use of figures in other documents must feature the below “Originals at”
URL immediately under that figure and the below copyright notice where
appropriate.
● You are free to fill in the “Delivered and/or customized by” space on the
right as you see fit.
● You are FORBIDEN from using the default “About” slide as-is or any of its
contents.
●
You are FORBIDEN from using any content provided by 3rd
parties without
the EXPLICIT consent from those parties.
(C) Copyright 2013-2015, Opersys inc.
These slides created by: Karim Yaghmour
Originals at: www.opersys.com/community/docs
Delivered and/or customized by
3
About
●
Author of:
●
Introduced Linux Trace Toolkit in 1999
●
Originated Adeos and relayfs (kernel/relay.c)
●
Ara Android Arch Oversight
●
Training, Custom Dev, Consulting, ...
4
Agenda
1. Architecture Basics
2. Development environment
3. Observing and monitoring
4. Interfacing with the framework
5. Working with the AOSP sources
6. Symbolic debugging
7. Detailed dynamic data collection
8. Benchmarking
9. Summing up
5
1. Architecture Basics
● Hardware used to run Android
● AOSP
● Binder
● System Services
● HAL
6
7
8
9
10
11
/frameworks/base/services/java/...
/frameworks/base/services/jni/
/hardware/libhardware/
/device/[MANUF.]/[DEVICE]
/sdk/emulator/
Kernel or module
/frameworks/base/core/...
AOSP-provided
ASL
Manuf.-provided
Manuf. license
Manuf.-provided
GPL-license
12
2. Development Environment
● Host / Target setup
● IDE / Editor
● Android Studio setup
13
2.1. Host / Target setup
14
15
2.2. IDE / Editor
Logos belong to their respective owners. This slide isn't CC-BY-SA.
16
2.3. Android Studio Setup
● Preparation
● Project importing
● Browsing the sources
17
2.3.1. Preparation
● AOSP Basics:
● Get AOSP ... from Google or otherwise
● Extract if needed
● Configure, build, etc.
● Android Studio:
● Get Android Studio from developer.android.com
● Extract
● Start and update and if needed
18
● Creating AOSP project files for Studio:
[aosp]$ make idegen && development/tools/idegen/idegen.sh
● Sometimes you also need to fix an issue with
"res.java":
[aosp]$ cd out/target/product/generic/obj/GYP/shared_intermediates
[aosp]$ mv res.java res.j && croot
19
2.3.2. Project importing
● Start Android Studio:
● Choose "Open an Existing Android Studio Project"
● Select android.ipr from AOSP
● Let it finish indexing
● To force framework detection -- if no auto-detect:
● Close Studio
● Restart Studio
● Click on "Framework Detected" bubble
20
● Edit
packages/apps/Launcher/src/com/android/launcher
2/DragLayer.java and modify:
    private boolean isLayoutRtl() {
● to
    public boolean isLayoutRtl() {
● Now: right-click on project and select "Refresh"
● It might still show "x" on some parts until it's done
rebuilding the project
21
2.3.3. Browsing the sources
● Right-click object type to be taken to declaration
● Browse classes through “Structure”
● Right-click "Find Usages"
● Toggle open files (Alt-left, Alt-right)
● Many other shortcuts, see:
https://developer.android.com/sdk/installing/studio-tips.htm
● Issues:
● Can't compile with Studio ... still need “make”
● For Java only
22
3. Observing and Monitoring
● Native
● Framework
● Overall
● Apps / Add-ons
23
3.1. Native
● schedtop
● librank
● procmem
● procrank
● showmap
● latencytop
24
3.2. Framework
● dumpsys
● service
25
3.3 Overall
● logcat
● dumpstate / bugreport
● watchprop / getprop
26
27
3.4. Apps / Add-ons
● Google Play:
● Process Manager
● Process Monitor
● Task Manager
● Process Tracker
● ...
28
3.5. Process Explorer
github.com/opersys
29
4. Interfacing With the Framework
● start / stop
● service call
● am
● pm
● wm
● svc
● monkey
● setprop
● raidl
30
5. Working with the AOSP Sources
● You really need to check build/envsetup.sh
● Some tricks:
● godir
● croot
● mm
● m
● jgrep
● cgrep
● resgrep
● It takes time to wrap your head around the tree
31
6. Symbolic Debugging - basics
32
6.1. Studio / Monitor integration
● Beware of libgail18 in Ubuntu
● Start Studio
● Start Monitor
● ("Android" icon on toolbar)
● Each process has a separate host-side socket
● Select the process you want to debug:
● It'll get port 8700
33
● Go back to Studio:
● Run->Edit Configurations->"+"
● Remote->Port: 8700
● Apply & Debug
● Go back to Monitor:
● Check that the little green bug is beside your process
in ddms
● You're now ready to debug
34
35
6.2. Debugging multiple processes
● Select process in Monitor
● Go back to Studio and start a new debugging
session
● Each process will now have a green bug beside
it
36
6.4. gdbserver - target side
● AOSP already takes care of debug:
● “-g” flag added to all native binaries
● Unstripped binaries in out/target/product/.../symbols/...
● Attaching to running process
# gdbserver ­­attach locahost:2345 30
● Start app for debugging with gdbserver prepended
# gdbserver localhost:2345 service list
● Forward the port on the host:
$ adb forward tcp:2345 tcp:2345
37
6.5. gdb - host side
● Load file **FIRST** and then attach on host side
$ prebuilts/gcc/linux­x86/arm/arm­eabi­4.7/bin/arm­eabi­gdb
GNU gdb (GDB) 7.3.1­gg2
Copyright (C) 2011 Free Software Foundation, Inc.
...
(gdb) file out/target/product/generic/symbols/system/bin/service
(gdb) target remote localhost:2345
(gdb) b main
Cannot access memory at address 0x0
Breakpoint 1 at 0x2a00146c: file frameworks/native/cmds/service/service.cpp, line 59.
(gdb) cont
Continuing.
warning: Could not load shared library symbols for 11 libraries, e.g. /system/bin/linker.
...
Breakpoint 1, main (argc=2, argv=0xbe882b74) at frameworks/native/cmds/service/service.cpp:59
59 {
(gdb) n
60     sp<IServiceManager> sm = defaultServiceManager();
(gdb) n
59 {
(gdb) n
60     sp<IServiceManager> sm = defaultServiceManager();
(gdb) n
61     fflush(stdout);
38
6.6. JNI debugging
$ prebuilts/gcc/linux­x86/arm/arm­eabi­4.7/bin/arm­eabi­gdb
(gdb) target remote localhost:2345
(gdb) file out/target/product/msm8960/symbols/system/bin/app_process 
(gdb) set solib­absolute­prefix out/target/product/msm8960/symbols/
(gdb) set solib­search­path out/target/product/msm8960/symbols/system/lib/
(gdb) b com_android_server_OpersysService.cpp:70
(gdb) cont
Continuing.
­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
root@android:/ # service call opersys 2 s16 adfasd
­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
[New Thread 576]
[Switching to Thread 576]
Breakpoint 1, write_native (env=0x5c94ad40, clazz=<value optimized out>, 
    ptr=<value optimized out>, buffer=0xa4f00005)
    at frameworks/base/services/jni/com_android_server_OpersysService.cpp:72
72     if (dev == NULL) {
(gdb) 
39
6.7. JTAG
● Requires hardware device
● Sometimes interfaces with gdb
● Not Android specific
● Some allow transparent kernel/user-space debug
● Don't know of any that go all the way up to Dalvik
40
7. Detailed Dynamic Data Collection
● Logging
● strace
● ftrace
● perf
41
7.1. Logging
● logcat is the most rapid/consistent way to
observe dynamic behavior.
● Trivial to add instrumentation points
● It just works ...
42
7.2. strace
● Same as Linux
● Use man page if need be
43
7.3. ftrace
● With 4.1, Google introduced systrace/atrace
● systrace is a Python script running on host side
● atrace is native Android binary
● systrace calls atrace via ADB
● atrace uses ftrace to capture kernel events
● Stack instrumented to feed events to ftrace
● Google's doc:
● https://developer.android.com/tools/help/systrace.html
● https://developer.android.com/tools/debugging/systrace.html
44
45
... trouble is ...
● Finicky -- notes from my attempts with 4.3:
● I can't get it to work !*!@#$&!#*$!
● Default goldfish kernel doesn't have ftrace
● Able to build ftrace-enabled kernel for goldfish
● Can trace that system ... so long as I don't use
atrace/systrace ... WTF1
?
● Not all Android kernels have ftrace enabled
● Generates HTML file that can only be read by
Chrome ... it doesn't work in Firefox. NIH?
1: The AOSP sources define WTF as “What a Terrible Failure”. We
trust they've done their research.
46
... still ...
● Have a look at these files:
● /external/chromium-trace/systrace.py
● /frameworks/native/cmds/atrace
● /frameworks/base/core/java/android/os/Trace.java
● /erameworks/native/include/utils/Trace.h
● /system/core/include/cutils/trace.h
● /frameworks/native/libs/utils/Trace.cpp
● Look for:
● ATRACE* in c/cpp files
● Trace.traceBegin()/trace.traceEnd() in Java files
47
# atrace ­­help
usage: atrace [options] [categories...]
options include:
  ­a appname      enable app­level tracing for a comma separated list of 
cmdlines
  ­b N            use a trace buffer size of N KB
  ­c              trace into a circular buffer
  ­k fname,...    trace the listed kernel functions
  ­n              ignore signals
  ­s N            sleep for N seconds before tracing [default 0]
  ­t N            trace for N seconds [defualt 5]
  ­z              compress the trace dump
  ­­async_start   start circular trace and return immediatly
  ­­async_dump    dump the current contents of circular trace buffer
  ­­async_stop    stop tracing and dump the current contents of circular
                    trace buffer
  ­­list_categories
                  list the available tracing categories
48
# atrace ­­list_categories                      
         gfx ­ Graphics
       input ­ Input
        view ­ View System
     webview ­ WebView
          wm ­ Window Manager
          am ­ Activity Manager
       audio ­ Audio
       video ­ Video
      camera ­ Camera
         hal ­ Hardware Modules
         res ­ Resource Loading
      dalvik ­ Dalvik VM
49
7.3. perf on Android on ARM
50
8. Benchmarking
51
0xbench
AnTuTu
Passmark
Vellamo
Geekbench2
SunSpider
GLBenchmakr
Quadrant Standard Edition
Linpack
Neocore
3DMark
Epic Citadel
Androbench
CF-bench
SD Tools
RL Benchmark: SQL
Benchmark & Tunning
A1 SD Bench
Quick Benchmark Lite
3DRating benchmark
Smartbench 2011
NenaMark
Rightware Browsermark
An3DBenchXL
CaffeineMark
NBench
Methanol
AndEBench
SmartBench 2012
RealPi
52
●
Works relatively well:
● logcat
●
Studio / Monitor
● Framework tools
●
Works ok:
● gdb/gdbserver
● native tools
● ftrace
●
Finicky:
●
systrace/atrace
● perf
9. Summing Up
53
10. Loose ends
● debuggerd
● tombstones
● anr traces
54
Thank you ...
karim.yaghmour@opersys.com

More Related Content

PDF
Android Platform Debugging and Development
PDF
Android Platform Debugging and Development
PDF
Android Platform Debugging and Development
PDF
Embedded Android Workshop
PDF
Android Platform Debugging and Development
ODP
Enhancing and modifying_the_core_android_os
PDF
Android Platform Debugging and Development
PDF
Android Platform Debugging and Development
Android Platform Debugging and Development
Android Platform Debugging and Development
Android Platform Debugging and Development
Embedded Android Workshop
Android Platform Debugging and Development
Enhancing and modifying_the_core_android_os
Android Platform Debugging and Development
Android Platform Debugging and Development

What's hot (19)

PDF
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
PDF
Embedded Android Workshop with Marshmallow
PDF
Developing Android Platform Tools
PDF
Android Platform Debugging & Development
PDF
Embedded Android Workshop with Marshmallow
PDF
Extending Android's Platform Toolsuite
PDF
Android Treble: Blessing or Trouble?
PDF
Brillo / Weave Internals
PDF
Customizing Android's UI
PDF
Memory Management in Android
PDF
Android Things: Android for IoT
PDF
Brillo / Weave Internals
PDF
Embedded Android Workshop with Nougat
PDF
Android Internals
PDF
Embedded Android Workshop with Nougat
PDF
Android Things Internals
PDF
Running Code in the Android Stack at ABS 2014
PDF
Android Security Internals
PDF
Android's HIDL: Treble in the HAL
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Embedded Android Workshop with Marshmallow
Developing Android Platform Tools
Android Platform Debugging & Development
Embedded Android Workshop with Marshmallow
Extending Android's Platform Toolsuite
Android Treble: Blessing or Trouble?
Brillo / Weave Internals
Customizing Android's UI
Memory Management in Android
Android Things: Android for IoT
Brillo / Weave Internals
Embedded Android Workshop with Nougat
Android Internals
Embedded Android Workshop with Nougat
Android Things Internals
Running Code in the Android Stack at ABS 2014
Android Security Internals
Android's HIDL: Treble in the HAL
Ad

Similar to Android Platform Debugging and Development (20)

PDF
Android Platform Debugging and Development
PDF
Android Platform Debugging and Development
PDF
Android Platform Debugging and Development at ABS 2014
PDF
Android Platform Debugging and Development at ELCE 2013
PDF
Working with the AOSP - Linaro Connect Asia 2013
PDF
Inside Android's UI at AnDevCon VI
PDF
Inside Android's UI at AnDevCon V
PDF
Inside Android's UI at AnDevCon IV
PDF
Inside Android's UI / ABS 2013
PDF
Customizing Android's UI
PDF
Running Code in the Android Stack at ELCE 2013
PDF
Inside Android's UI
PDF
Customizing Android's UI
PDF
Headless Android
PDF
Is Android the New King of Embedded OSes at Embedded World 2014
PDF
Android Things Internals
PDF
Security Issues in Android Custom Rom
PDF
Security Issues in Android Custom ROM
PDF
Is Android the New Embedded Linux? at AnDevCon VI
PPTX
Android build on windows
Android Platform Debugging and Development
Android Platform Debugging and Development
Android Platform Debugging and Development at ABS 2014
Android Platform Debugging and Development at ELCE 2013
Working with the AOSP - Linaro Connect Asia 2013
Inside Android's UI at AnDevCon VI
Inside Android's UI at AnDevCon V
Inside Android's UI at AnDevCon IV
Inside Android's UI / ABS 2013
Customizing Android's UI
Running Code in the Android Stack at ELCE 2013
Inside Android's UI
Customizing Android's UI
Headless Android
Is Android the New King of Embedded OSes at Embedded World 2014
Android Things Internals
Security Issues in Android Custom Rom
Security Issues in Android Custom ROM
Is Android the New Embedded Linux? at AnDevCon VI
Android build on windows
Ad

More from Opersys inc. (13)

PDF
Android Automotive
PDF
Android 10 Internals Update
PDF
Embedded Android Workshop with Pie
PDF
Embedded Android Workshop with Oreo
PDF
Scheduling in Android
PDF
Scheduling in Android
PDF
Memory Management in Android
PDF
Embedded Android Workshop with Nougat
PDF
Project Ara
PDF
Brillo/Weave Internals
PDF
Embedded Android Workshop with Marshmallow
PDF
Memory Management in Android
PDF
Project Ara
Android Automotive
Android 10 Internals Update
Embedded Android Workshop with Pie
Embedded Android Workshop with Oreo
Scheduling in Android
Scheduling in Android
Memory Management in Android
Embedded Android Workshop with Nougat
Project Ara
Brillo/Weave Internals
Embedded Android Workshop with Marshmallow
Memory Management in Android
Project Ara

Recently uploaded (20)

PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
System and Network Administration Chapter 2
PPTX
history of c programming in notes for students .pptx
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
Introduction to Artificial Intelligence
PPTX
ai tools demonstartion for schools and inter college
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Nekopoi APK 2025 free lastest update
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
top salesforce developer skills in 2025.pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
Online Work Permit System for Fast Permit Processing
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Odoo POS Development Services by CandidRoot Solutions
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
System and Network Administration Chapter 2
history of c programming in notes for students .pptx
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Introduction to Artificial Intelligence
ai tools demonstartion for schools and inter college
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Design an Analysis of Algorithms II-SECS-1021-03
Nekopoi APK 2025 free lastest update
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Adobe Illustrator 28.6 Crack My Vision of Vector Design
top salesforce developer skills in 2025.pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
2025 Textile ERP Trends: SAP, Odoo & Oracle
Online Work Permit System for Fast Permit Processing
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025

Android Platform Debugging and Development