Debugging Chromium on Android

Debugging Chromium on Android


Intro

Chrome on android has java and c/c++ code. Each "side" have its own set of tools for debugging. Here's some tips.

Setting up command line flags

Various commands below requires setting up command line flags.
# Content shell
adb_content_shell_command_line --flags --to-pass
# Chromum test shell
adb_chrome_shell_command_line --flags --to-pass

Launching the app

You can launch the app by using one of the wrappers. You can pass URLs directly too.
# Content shell
adb_run_content_shell 'data:text/html;utf-8,<html>Hello World!</html>'
# Chromium test shell
adb_run_chrome_shell 'data:text/html;utf-8,<html>Hello World!</html>'


Log output

Chromium logging from LOG(INFO) etc is directed to the android logcat logging facility. You can filter the messages, e.g. view chromium verbose logging, everything else at warning level with:

adb logcat chromium:V *:W

Take a screenshot

While your phone is plugged into USB, use the screenshot.py tool in build/android.  envsetup.sh should have put it in your path.
build/android/screenshot.py /tmp/screenshot.png

Debugging Java

  • In Eclipse, make a debug configuration of type "Remote Java Application". Choose a "Name" and set "Port" to 8700.
  • Make sure Eclipse Preferences > Run/Debug > Launching > "Build (if required) before launching" is unchecked.
  • Run Android Device Monitor:
src/third_party/android_tools/sdk/tools/monitor
  • Now select the process you want to debug in Device Monitor (the port column should now mention 8700 or xxxx/8700).
  • Run your debug configuration, and switch to the Debug perspective.

Waiting for Java Debugger on Early Startup

  • To debug early startup, pass --wait-for-java-debugger as a command line flag. 

Debugging C/C++


Under build/android, there are a few scripts:
# Convenient wrappers
adb_gdb_content_shell
adb_gdb_chrome_shell

# Underlying script, try --help for comprehensive list of options
adb_gdb

By default, these wrappers will attach to the browser process.
You can also attach to the renderer process by using --sandboxed. (You might need to be root on the phone for that. Run adb root if needed)

Waiting for Debugger on Early Startup

Set the target command line flag with --wait-for-debugger.
Launch the debugger using one of the "adb_gdb" scripts from above.
Type info threads and look for a line like:
11 Thread 2564  clock_gettime () at bionic/libc/arch-arm/syscalls/clock_gettime.S:11

We need to jump out of its sleep routine:
(gdb) thread 11
(gdb) up
(gdb) up
(gdb) return
Make base::debug::BreakDebugger() return now? (y or n) y
(gdb) continue


Symbolizing Crashstacks and Tombstones

If a crash has generated a tombstone in your device, use (from ${CHROME_SRC}):
build/android/tombstones.py

If you have a stack trace (from adb logcat) that needs to be symbolized, copy it into a text file and symbolize with the following command (run from ${CHROME_SRC}):
third_party/android_platform/development/scripts/stack [tombstone file | dump file]

stack can also take its input from stdin:
adb logcat -d | third_party/android_platform/development/scripts/stack

Example:
third_party/android_platform/development/scripts/stack ~/crashlogs/tombstone_07-build231.txt

Get WebKit code to output to the adb log

In your build environment:
adb root
adb shell stop
adb shell setprop log.redirect-stdio true
adb shell start

In the source itself, use fprintf(stderr, "message"); whenever you need to output a message.

Debug unit tests with GDB

To run unit tests use the following command
build/android/test_runner.py gtest -s <name_of_test_suite> -f <test_filter_if_any> \
 -a --wait-for-debugger -t 6000

That command will cause the test process to wait until a debugger is attached. To attach a debugger:
build/android/adb_gdb org.chromium.native_test

After attaching gdb to the process you need to return form the WaitForDebugger method:
(gdb) bt
#0  0x4018dc34 in system () from ... src/out/Debug/lib/libc.so
#1  0x5e93e4b2 in base::debug::BreakDebugger () at ../../base/debug/debugger_posix.cc:232
#2  0x5e93e39e in base::debug::WaitForDebugger (wait_seconds=<optimized out>, silent=<optimized out>) at ../../base/debug/debugger.cc:24
...
(gdb) f 2
#2  0x5e93e39e in base::debug::WaitForDebugger (wait_seconds=<optimized out>, silent=<optimized out>) at ../../base/debug/debugger.cc:24
24         BreakDebugger();
(gdb) return
Make base::debug::WaitForDebugger(int, bool) return now? (y or n) y
(gdb) continue


http://www.chromium.org/developers/how-tos/debugging-on-android

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章