SlideShare ist ein Scribd-Unternehmen logo
1 von 8
Downloaden Sie, um offline zu lesen
Android Debugging

William.L
wiliwe@gmail.com

2010-11-19
Version
Add Debugging Messages

2
For Java Codes
在Android的Java程式中加入除錯訊息,可使用android.util.Log
類別中提供的靜態(static)函式來達成

Log.v (String tag, String msg) for Verbose message.
(Highest level)
Log.d (String tag, String msg) for Debugging message
Log.i (String tag, String msg) for Info message
Log.w (String tag, String msg) for Warrning message
Log.e (String tag, String msg) for Error message (Lowest
level)
tag是一個標識,可以是任意字串,通常可用 「ClassName +
MethodName」 規則來命名
Version

3
For C++/C Codes
在Android的C/C++程式中加入除錯訊息,可使用cutils 函式庫中
提供的函式來達成

LOGV (String tag, String msg) for Verbose message.
(Highest level)
LOGD (String tag, String msg) for Debugging message
LOGI (String tag, String msg) for Info message
LOGW (String tag, String msg) for Warrning message
LOGE (String tag, String msg) for Error message (Lowest
level)
程式中加標頭檔<cutils/log.h>
在Android.mk中中指定 libcutils 共享函式庫
LOCAL_SHARED_LIBRARIES := libcutils
How to see debugging messages?
查看除錯訊息,可在console下使用下列指令
logcat -s tagName:I[/V/D/W/E] 查詢特定標識的某一種類訊
息

logcat -s tagName:*
查詢特定標識的所有類型
的訊息
logcat 
查詢所有類型的訊息且
不區分標識
也可使用DDMS的 Logcat View 察看除錯訊息

Version

5
Using GDB(1/2)

Android 2.2(Froyo)源碼目錄中,prebuild目錄下有現成的GDB程式
(目前使用的 ARM EABI版本為 4.4.0)
AndroidSrc/prebuilt/linux-x86/toolchain/arm-eabi4.4.0/bin/arm-eabi-gdb
GDB用法 : arm-eabi-gdb ExecutableWithDebugSymbol
ExecutableWithDebugSymbol 位在目錄 –
out/target/product/BoardModel/symbols/system/bin/

主要使用步驟 (AndroidSrc使用 絕對路徑
絕對路徑)
GDB Server 端 (Android裝置)
adb shell 登入遠端Android裝置
裝置後執行指令
#> gdbserver :5039 /data/Executable & 或
#> gdbserver :5039 --attach ExecutablePID &

Port number 5039, 可自行替換其它數字,
但不可跟其它網路服務使用的衝突
Using GDB(2/2)
主要使用步驟

GDB Client 端 (自己的電腦)
arm-eabi-gdb ExecutableWithDebugSymbol ,進入GDB
GDB中設定偵錯用函式庫搜路徑(AndroidSrc 使用 絕對路徑
絕對路徑)
set solib-absolute-prefix
AndroidSrc/out/target/product/BoardModel/symbols/
set solib-search-path
AndroidSrc/out/target/product/BoardModel/symbols/system/lib:An
droidSrc/out/target/product/ventana/symbols/system/bin

target remote :5039 此port number需跟GDB Server使用的
相同
執行 GDB 指令做偵錯動作
b – 設中斷點(breakpoint)
display – 檢視(watch)變數/暫存器內容
c – continue
n –單步執行(不進入函式)
s –單步執行(進入函式)
Reference
Android Official Site http://developer.android.com/guide/developing/debug-tasks.html
NV’s http://developer.download.nvidia.com/tegra/docs/android_gdb_debuggi
ng.pdf
GDB usage –

http://tetralet.luna.com.tw/index.php?op=ViewArticle&article
Id=187&blogId=1
http://www.cmlab.csie.ntu.edu.tw/~daniel/linux/gdb.html

Weitere ähnliche Inhalte

Andere mochten auch

Android Logging System
Android Logging SystemAndroid Logging System
Android Logging SystemWilliam Lee
 
Asterisk (IP-PBX) CDR Log Rotation
Asterisk (IP-PBX) CDR Log RotationAsterisk (IP-PBX) CDR Log Rotation
Asterisk (IP-PBX) CDR Log RotationWilliam Lee
 
Android Storage - Internal and External Storages
Android Storage - Internal and External StoragesAndroid Storage - Internal and External Storages
Android Storage - Internal and External StoragesWilliam Lee
 
Introduction to SIP(Session Initiation Protocol)
Introduction to SIP(Session Initiation Protocol)Introduction to SIP(Session Initiation Protocol)
Introduction to SIP(Session Initiation Protocol)William Lee
 
Usage Note of Apache Thrift for C++ Java PHP Languages
Usage Note of Apache Thrift for C++ Java PHP LanguagesUsage Note of Apache Thrift for C++ Java PHP Languages
Usage Note of Apache Thrift for C++ Java PHP LanguagesWilliam Lee
 
Android Storage - Vold
Android Storage - VoldAndroid Storage - Vold
Android Storage - VoldWilliam Lee
 

Andere mochten auch (9)

Android Logging System
Android Logging SystemAndroid Logging System
Android Logging System
 
IPv6 Overview
IPv6 OverviewIPv6 Overview
IPv6 Overview
 
Asterisk (IP-PBX) CDR Log Rotation
Asterisk (IP-PBX) CDR Log RotationAsterisk (IP-PBX) CDR Log Rotation
Asterisk (IP-PBX) CDR Log Rotation
 
MGCP Overview
MGCP OverviewMGCP Overview
MGCP Overview
 
Android Storage - Internal and External Storages
Android Storage - Internal and External StoragesAndroid Storage - Internal and External Storages
Android Storage - Internal and External Storages
 
Introduction to SIP(Session Initiation Protocol)
Introduction to SIP(Session Initiation Protocol)Introduction to SIP(Session Initiation Protocol)
Introduction to SIP(Session Initiation Protocol)
 
MTP & PTP
MTP & PTPMTP & PTP
MTP & PTP
 
Usage Note of Apache Thrift for C++ Java PHP Languages
Usage Note of Apache Thrift for C++ Java PHP LanguagesUsage Note of Apache Thrift for C++ Java PHP Languages
Usage Note of Apache Thrift for C++ Java PHP Languages
 
Android Storage - Vold
Android Storage - VoldAndroid Storage - Vold
Android Storage - Vold
 

Mehr von William Lee

Usage Note of SWIG for PHP
Usage Note of SWIG for PHPUsage Note of SWIG for PHP
Usage Note of SWIG for PHPWilliam Lee
 
Upgrade GCC & Install Qt 5.4 on CentOS 6.5
Upgrade GCC & Install Qt 5.4 on CentOS 6.5 Upgrade GCC & Install Qt 5.4 on CentOS 6.5
Upgrade GCC & Install Qt 5.4 on CentOS 6.5 William Lee
 
Usage Notes of The Bro 2.2 / 2.3
Usage Notes of The Bro 2.2 / 2.3Usage Notes of The Bro 2.2 / 2.3
Usage Notes of The Bro 2.2 / 2.3William Lee
 
Viewing Android Source Files in Eclipse (Chinese)
Viewing Android Source Files in Eclipse  (Chinese)Viewing Android Source Files in Eclipse  (Chinese)
Viewing Android Source Files in Eclipse (Chinese)William Lee
 
Usage Note of Microsoft Dependency Walker
Usage Note of Microsoft Dependency WalkerUsage Note of Microsoft Dependency Walker
Usage Note of Microsoft Dependency WalkerWilliam Lee
 
Usage Note of PlayCap
Usage Note of PlayCapUsage Note of PlayCap
Usage Note of PlayCapWilliam Lee
 
Qt4 App - Sliding Window
Qt4 App - Sliding WindowQt4 App - Sliding Window
Qt4 App - Sliding WindowWilliam Lee
 
GTK+ 2.0 App - Desktop App Chooser
GTK+ 2.0 App - Desktop App ChooserGTK+ 2.0 App - Desktop App Chooser
GTK+ 2.0 App - Desktop App ChooserWilliam Lee
 
GTK+ 2.0 App - Icon Chooser
GTK+ 2.0 App - Icon ChooserGTK+ 2.0 App - Icon Chooser
GTK+ 2.0 App - Icon ChooserWilliam Lee
 
Note of CGI and ASP
Note of CGI and ASPNote of CGI and ASP
Note of CGI and ASPWilliam Lee
 
L.A.M.P Installation Note --- CentOS 6.5
L.A.M.P Installation Note --- CentOS 6.5L.A.M.P Installation Note --- CentOS 6.5
L.A.M.P Installation Note --- CentOS 6.5William Lee
 
C Program Runs on Wrong Target Platform(CPU Architecture)
C Program Runs on Wrong Target Platform(CPU Architecture)C Program Runs on Wrong Target Platform(CPU Architecture)
C Program Runs on Wrong Target Platform(CPU Architecture)William Lee
 
Internationalization(i18n) of Web Page
Internationalization(i18n) of Web PageInternationalization(i18n) of Web Page
Internationalization(i18n) of Web PageWilliam Lee
 
Notes for SQLite3 Usage
Notes for SQLite3 UsageNotes for SQLite3 Usage
Notes for SQLite3 UsageWilliam Lee
 
Cygwin Install How-To (Chinese)
Cygwin Install How-To (Chinese)Cygwin Install How-To (Chinese)
Cygwin Install How-To (Chinese)William Lee
 
Study of Chromium OS
Study of Chromium OSStudy of Chromium OS
Study of Chromium OSWilliam Lee
 
More Details about TR-069 (CPE WAN Management Protocol)
More Details about TR-069 (CPE WAN Management Protocol)More Details about TR-069 (CPE WAN Management Protocol)
More Details about TR-069 (CPE WAN Management Protocol)William Lee
 
Introdunction to Network Management Protocols - SNMP & TR-069
Introdunction to Network Management Protocols - SNMP & TR-069Introdunction to Network Management Protocols - SNMP & TR-069
Introdunction to Network Management Protocols - SNMP & TR-069William Lee
 

Mehr von William Lee (19)

Usage Note of SWIG for PHP
Usage Note of SWIG for PHPUsage Note of SWIG for PHP
Usage Note of SWIG for PHP
 
Upgrade GCC & Install Qt 5.4 on CentOS 6.5
Upgrade GCC & Install Qt 5.4 on CentOS 6.5 Upgrade GCC & Install Qt 5.4 on CentOS 6.5
Upgrade GCC & Install Qt 5.4 on CentOS 6.5
 
Usage Notes of The Bro 2.2 / 2.3
Usage Notes of The Bro 2.2 / 2.3Usage Notes of The Bro 2.2 / 2.3
Usage Notes of The Bro 2.2 / 2.3
 
Viewing Android Source Files in Eclipse (Chinese)
Viewing Android Source Files in Eclipse  (Chinese)Viewing Android Source Files in Eclipse  (Chinese)
Viewing Android Source Files in Eclipse (Chinese)
 
Usage Note of Microsoft Dependency Walker
Usage Note of Microsoft Dependency WalkerUsage Note of Microsoft Dependency Walker
Usage Note of Microsoft Dependency Walker
 
Usage Note of PlayCap
Usage Note of PlayCapUsage Note of PlayCap
Usage Note of PlayCap
 
Qt4 App - Sliding Window
Qt4 App - Sliding WindowQt4 App - Sliding Window
Qt4 App - Sliding Window
 
GTK+ 2.0 App - Desktop App Chooser
GTK+ 2.0 App - Desktop App ChooserGTK+ 2.0 App - Desktop App Chooser
GTK+ 2.0 App - Desktop App Chooser
 
GTK+ 2.0 App - Icon Chooser
GTK+ 2.0 App - Icon ChooserGTK+ 2.0 App - Icon Chooser
GTK+ 2.0 App - Icon Chooser
 
Note of CGI and ASP
Note of CGI and ASPNote of CGI and ASP
Note of CGI and ASP
 
L.A.M.P Installation Note --- CentOS 6.5
L.A.M.P Installation Note --- CentOS 6.5L.A.M.P Installation Note --- CentOS 6.5
L.A.M.P Installation Note --- CentOS 6.5
 
C Program Runs on Wrong Target Platform(CPU Architecture)
C Program Runs on Wrong Target Platform(CPU Architecture)C Program Runs on Wrong Target Platform(CPU Architecture)
C Program Runs on Wrong Target Platform(CPU Architecture)
 
Internationalization(i18n) of Web Page
Internationalization(i18n) of Web PageInternationalization(i18n) of Web Page
Internationalization(i18n) of Web Page
 
Notes for SQLite3 Usage
Notes for SQLite3 UsageNotes for SQLite3 Usage
Notes for SQLite3 Usage
 
Cygwin Install How-To (Chinese)
Cygwin Install How-To (Chinese)Cygwin Install How-To (Chinese)
Cygwin Install How-To (Chinese)
 
Study of Chromium OS
Study of Chromium OSStudy of Chromium OS
Study of Chromium OS
 
More Details about TR-069 (CPE WAN Management Protocol)
More Details about TR-069 (CPE WAN Management Protocol)More Details about TR-069 (CPE WAN Management Protocol)
More Details about TR-069 (CPE WAN Management Protocol)
 
Introdunction to Network Management Protocols - SNMP & TR-069
Introdunction to Network Management Protocols - SNMP & TR-069Introdunction to Network Management Protocols - SNMP & TR-069
Introdunction to Network Management Protocols - SNMP & TR-069
 
Qt Animation
Qt AnimationQt Animation
Qt Animation
 

Android Debugging (Chinese)

  • 3. For Java Codes 在Android的Java程式中加入除錯訊息,可使用android.util.Log 類別中提供的靜態(static)函式來達成 Log.v (String tag, String msg) for Verbose message. (Highest level) Log.d (String tag, String msg) for Debugging message Log.i (String tag, String msg) for Info message Log.w (String tag, String msg) for Warrning message Log.e (String tag, String msg) for Error message (Lowest level) tag是一個標識,可以是任意字串,通常可用 「ClassName + MethodName」 規則來命名 Version 3
  • 4. For C++/C Codes 在Android的C/C++程式中加入除錯訊息,可使用cutils 函式庫中 提供的函式來達成 LOGV (String tag, String msg) for Verbose message. (Highest level) LOGD (String tag, String msg) for Debugging message LOGI (String tag, String msg) for Info message LOGW (String tag, String msg) for Warrning message LOGE (String tag, String msg) for Error message (Lowest level) 程式中加標頭檔<cutils/log.h> 在Android.mk中中指定 libcutils 共享函式庫 LOCAL_SHARED_LIBRARIES := libcutils
  • 5. How to see debugging messages? 查看除錯訊息,可在console下使用下列指令 logcat -s tagName:I[/V/D/W/E] 查詢特定標識的某一種類訊 息 logcat -s tagName:* 查詢特定標識的所有類型 的訊息 logcat  查詢所有類型的訊息且 不區分標識 也可使用DDMS的 Logcat View 察看除錯訊息 Version 5
  • 6. Using GDB(1/2) Android 2.2(Froyo)源碼目錄中,prebuild目錄下有現成的GDB程式 (目前使用的 ARM EABI版本為 4.4.0) AndroidSrc/prebuilt/linux-x86/toolchain/arm-eabi4.4.0/bin/arm-eabi-gdb GDB用法 : arm-eabi-gdb ExecutableWithDebugSymbol ExecutableWithDebugSymbol 位在目錄 – out/target/product/BoardModel/symbols/system/bin/ 主要使用步驟 (AndroidSrc使用 絕對路徑 絕對路徑) GDB Server 端 (Android裝置) adb shell 登入遠端Android裝置 裝置後執行指令 #> gdbserver :5039 /data/Executable & 或 #> gdbserver :5039 --attach ExecutablePID & Port number 5039, 可自行替換其它數字, 但不可跟其它網路服務使用的衝突
  • 7. Using GDB(2/2) 主要使用步驟 GDB Client 端 (自己的電腦) arm-eabi-gdb ExecutableWithDebugSymbol ,進入GDB GDB中設定偵錯用函式庫搜路徑(AndroidSrc 使用 絕對路徑 絕對路徑) set solib-absolute-prefix AndroidSrc/out/target/product/BoardModel/symbols/ set solib-search-path AndroidSrc/out/target/product/BoardModel/symbols/system/lib:An droidSrc/out/target/product/ventana/symbols/system/bin target remote :5039 此port number需跟GDB Server使用的 相同 執行 GDB 指令做偵錯動作 b – 設中斷點(breakpoint) display – 檢視(watch)變數/暫存器內容 c – continue n –單步執行(不進入函式) s –單步執行(進入函式)
  • 8. Reference Android Official Site http://developer.android.com/guide/developing/debug-tasks.html NV’s http://developer.download.nvidia.com/tegra/docs/android_gdb_debuggi ng.pdf GDB usage – http://tetralet.luna.com.tw/index.php?op=ViewArticle&article Id=187&blogId=1 http://www.cmlab.csie.ntu.edu.tw/~daniel/linux/gdb.html