Beruflich Dokumente
Kultur Dokumente
Summary
Overview
Debugging Environment
ADB
Logcat
Progress
Overview
Debugging Environment
ADB
Logcat
Overview (1/3)
The Android SDK provides most of the tools that you need to debug your
applications
If you are using another IDE, you can use the debugger that comes with it
and attach the debugger to a special port so it can communicate with the
application VMs on your devices
Overview (2/3)
adb - acts as a middleman between a device and your development system. It provides
various device management capabilities, including moving and syncing files to the emulator,
running a UNIX shell on the device or emulator, and providing a general means to
communicate with connected emulators and devices.
Dalvik Debug Monitor Server - DDMS is a graphical program that communicates with your
devices through adb. DDMS can capture screenshots, gather thread and stack information,
spoof incoming calls and SMS messages, and has many other features.
Device/Android Virtual Device - Your application must run in a device or in an AVD so that
it can be debugged. An adb device daemon runs on the device or emulator and provides a
means for the adb host daemon to communicate with the device or emulator.
JDWP - The Dalvik VM (Virtual Machine) supports the JDWP protocol to allow debuggers to
attach to a VM. Each application runs in a VM and exposes a unique port that you can attach
a debugger to via DDMS. Most modern Java IDEs include a JDWP debugger, or you can use
a command line debugger such as jdb.
Overview (3/3)
Locating the problem using one of the (or usually all of the) following:
adb
Progress
Overview
Debugging Environment
ADB
Logcat
Debugging Environment
Progress
Overview
Debugging Environment
ADB
Logcat
Android Debug Bridge (adb) is a versatile tool lets you manage the state of
an emulator instance or Android-powered device. It is a client-server
program that includes three components:
A client, which runs on your development machine. You can invoke a client from a shell by
issuing an adb command. Other Android tools such as the ADT plugin and DDMS also create
adb clients.
A server, which runs as a background process on your development machine. The server
manages communication between the client and the adb daemon running on an emulator or
device.
When you start an adb client, the client first checks whether there is an adb
server process already running.
If there isn't, it starts the server process. When the server starts, it binds to
local TCP port 5037 and listens for commands sent from adb clientsall
adb clients use port 5037 to communicate with the adb server.
ADB
Issuing adb Commands
You can issue adb commands from a command line on your development
machine or from a script. The usage is:
adb [-d|-e|-s <serialNumber>] <command>
ADB
Emulator/Device Instances
list
of
attached
emulators/devices
adb devices
using
ADB
Directing Commands to a Specific
Emulator/Device Instance
To do so, use the -s option in the commands. The usage for the -s option is:
adb -s <serialNumber> <command>
As shown, you specify the target instance for a command using its adbassigned serial number. You can use the devices command to obtain the
serial numbers of running emulator/device instances.
Here is an example:
adb -s emulator-5556 install helloWorld.apk
ADB
More useful tips
Forwarding Ports
You can use the forward command to set up arbitrary port forwarding
forwarding of requests on a specific host port to a different port on an
emulator/device instance.
ADB
More useful tips
Copying Files to or from an Emulator/Device Instance
You can use the adb commands pull and push to copy files to and from an
emulator/device instance's data file. The pull and push commands let you
copy arbitrary directories and files to any location in an emulator/device
instance.
In the commands, <local> and <remote> refer to the paths to the target
files/directory on your development machine (local) and on the
emulator/device instance (remote).
Here's an example:
adb push foo.txt /sdcard/foo.txt
ADB
More useful tips
Issuing Shell Commands
Adb provides an ash shell that you can use to run a variety of commands on
an emulator or device. The command binaries are stored in the file system
of the emulator or device, in this location:
/system/bin/...
You can use the shell command to issue commands, with or without
entering the adb remote shell on the emulator/device.
To issue a single command without entering a remote shell, use
the shell command like this:
adb [-d|-e|-s {<serialNumber>}] shell <shellCommand>
When you are ready to exit the remote shell, use CTRL+D or exit to end the
shell session.
ADB
Other Shell Commands
The list below shows several of the adb shell commands available. For a
complete list of commands and programs, start an emulator instance and
use the adb -help command.
dumpsys
dumpstate
logcat [<option>]... [<filter-spec>]... - Enables radio logging and prints output to the screen.
dmesg
start
stop
Progress
Overview
Debugging Environment
ADB
Logcat
You can run LogCat through ADB or from DDMS, which allows you to read
the messages in real time.
Log is a logging class that you can utilize in your code to print out messages
to the LogCat.
v(String, String)
(verbose)
d(String, String)
(debug)
i(String, String)
(information)
w(String, String)
(warning)
e(String, String)
(error)
For example:
Log.i("MyActivity", "MyClass.getView() get item number " + position);
Progress
Overview
Debugging Environment
ADB
Logcat
Using LogCat
Basics
You can use LogCat from within DDMS or call it on an ADB shell.
To run LogCat, through the ADB shell, the general usage is:
[adb] logcat [<option>] ... [<filter-spec>] ...
You can use the logcat command from your development computer or from
a remote adb shell in an emulator/device instance. To view log output in
your development computer, you use:
$ adb logcat
Using LogCat
Commands
-c,
-d,
-g,
-n <count>,
Sets the maximum number of rotated logs to <count>. Requires the -r option.
-r <kbytes>, Rotates the log file every <kbytes> of output. Requires the -f option.
-s,
-v <format>, Sets the output format for log messages. The default is brief format.
Using LogCat
Filtering log output
Every Android log message has a tag and a priority associated with it.
The tag of a log message is a short string indicating the system component
from which the message originates (for example, "View" for the view
system).
The priority is one of the following character values, ordered from lowest to
highest priority:
V
D
I
W
E
F
S
To reduce the log output to a manageable level, you can restrict log output
using filter expressions.
Using LogCat
Filtering log output
The final element in the above expression, *:S, sets the priority level for all
tags to "silent", thus ensuring only log messages with "View" and "MyApp"
are displayed.
Using *:S is an excellent way to ensure that log output is restricted to the
filters that you have explicitly specified it lets your filters serve as a
"whitelist" for log output.
The following filter expression displays all log messages with priority level
"warning" and higher, on all tags:
adb logcat *:W
Using LogCat
Viewing stdout and stderr
By default, the Android system sends stdout and stderr (System.out and
System.err) output to /dev/null.
In processes that run the Dalvik VM, you can have the system write a copy
of the output to the log file. In this case, the system writes the messages to
the log using the log tags stdout and stderr, both with priority I.
To route the output in this way, you stop a running emulator/device instance
and then use the shell command setprop to enable the redirection of output.
Here's how you do it:
$ adb shell stop
$ adb shell setprop log.redirect-stdio true
$ adb shell start
The system retains this setting until you terminate the emulator/device
instance. To use the setting as a default on the emulator/device instance,
you can add an entry to /data/local.prop on the device.
Using LogCat
Crash caught in logcat
I/DEBUG
( 1326): stack:
I/DEBUG
( 1326):
3028f7d0
7b64dea0
/system/lib/libwebcore.so
Using LogCat
Crash caught in logcat
What to do then?
We need binary that has all of the symbols in it:
./out/target/product/generic/symbols/system/lib/libwebcore.so
Dump the symbols to a file, and look four our relative address:
This will give us the correct line in code that caused the crash
./prebuilt/linux-x86/toolchain/mips-4.4.3/bin/mips-linux-gnu-objdump DSgltC
./out/target/product/generic/symbols/system/lib/libwebcore.so > objdump.log
References/Usefull links
http://developer.android.com/guide/developing/debugging/index.html
http://androidcore.com/android-programming-tutorials/
http://www.kandroid.org/online-pdk/guide/debugging_gdb.html