GDB + gdbserver 遠程調試mediaserver進程


遠程調試步驟

Android設備上啟動gdbserverattach你想調試的進程,並指定監聽調試命令的端口(此端口是TV上的端口)

$ adb shell

# ps |grep media  #查看要調試進程的PID,mediaserver進程為例

# gdbserver :1234 --attach 96   #:1234是端口號,96 是進程ID

如果設備上沒有gdbserver,可以由google ndk中獲取,在ndk的如下目錄可以找到這個文件:

android-ndk-r8/toolchains/arm-linux-androideabi-4.9/prebuilt/android-arm

 

可以將此文件先推送到設備上。

 

 

進入源碼服務器,比如5520編譯服務器地址10.9.44.42

進入到源碼工程目錄下,進行環境配置,執行build文件夾下的envsetup.shchoosecombo xx xx xx 命令,這時就可以使用gdbclient了。

adb connect 電視,成功后執行端口映射,將pc機的1234端口映射到電視1234端口

 

$ adb forward tcp:1234 tcp:1234   #端口映射,將pc機的1234端口映射到電視的1234端口

pc端的源碼根目錄下,執行 gdbclient -e mediaserver -p 1234 #1234端口調試mediaserver

 

$ target remote:1234

 

接下來通過file命令來加載將要調試的可執行文件,對於android application來說,均為 out/target/product/generic/symbols/system/bin/app_process 這個文件,及設置搜索solib的搜索路徑。

 $file /home/luckychou/share/workspace/MT5520_DEV_Q3/release/android/l-pdk/out/target/product/mt5520_ll/symbols/system/bin/app_process32

 $ set solib-search-path /home/luckychou/share/workspace/MT5520_DEV_Q3/release/android/l-pdk/out/target/product/mt5520_ll/symbols/system/lib

 $ set solib-absolute-prefix /home/luckychou/share/workspace/MT5520_DEV_Q3/release/android/l-pdk/out/target/product/mt5520_ll/symbols/system/lib

之后,即可如調試PC端的C/C++ code一樣,下斷點,執行,查看內存內容,查看back trace等,來進行對librarydebug工作:

 

 

If the program youre backtracing is multi-threaded, you might want to get a backtrace for all threads:

 

 (gdb) thread apply all bt

Another thing which is quite helpful to report is what variables were set locally at each point in the stack:

 

 (gdb) bt full

You might want to report the output of the combination of the preceding options:

 

 (gdb) thread apply all bt full

And if this is too much irrelevant output, you might want to keep only a few calls, such as the top 10:

 

 (gdb) thread apply all bt full 10

If you have a large backtrace, you can log gdb output to a file (the default is gdb.txt):

 

 (gdb) set logging on

 (gdb) set logging file myfile.txt

 

還有很多其他gdb有用的命令,可以參考下網上的。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM