1 首先在終端執行:
emulator –show-kernel -memory 1024
打開模擬器
2 開啓另一個終端,執行:
adb shell
進入模擬器shell,
3 在模擬器shell中執行
ps mediaserver
查看進程mediaserver的PID
4 查看PID後,接着執行:
gdbserver :5039 –attach PID(上面查看的mediaserver的PID)
5 再開啓一個終端,設置模擬器端口轉發:
adb forward tcp:5039 tcp:5039
6 啓動arm-eabi-gdb,
arm-eabi-gdb位於androidsrc/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin下,此文件夾下存放着android的編譯器等工具
命令格式:
arm-eabi-gdb 可執行文件(在此是mediaserver,別忘了指定路徑)
例: arm-eabi-gdb /androidsrc/out/target/product/generic/symbols/system/bin/mediaserver
這樣就會進入GDB環境
7 設置gdb中的來那個壞境變量:
(gdb) set solib-absolute-prefix /androidsrc/out/target/product/generic/symbols/
(gdb) set solib-search-path /androidsrc/out/target/product/generic/symbols/system/lib/
關於這兩個變量:
solib-absolute-prefix :設置查找共享庫的前綴,作爲查找so庫路徑的前綴;
If this variable is set, path will be used as a prefix for any absolute shared library paths; many runtime loaders store the absolute paths to the shared library in the target program's memory. If you use `solib-absolute-prefix' to find shared libraries, they need to be laid out in the same way that they are on the target, with e.g. a `/usr/lib' hierarchy under path. You can set the default value of `solib-absolute-prefix' by using the configure-time `--with-sysroot' option.
solib-search-path :設置so庫的查找路徑,它是在根據solib-absolute-prefix 查找庫失敗後使用
If this variable is set, path is a colon-separated list of directories to search for shared libraries. `solib-search-path' is used after `solib-absolute-prefix' fails to locate the library, or if the path to the library is relative instead of absolute. If you want to use `solib-search-path' instead of `solib-absolute-prefix', be sure to set `solib-absolute-prefix' to a nonexistant directory to prevent GDB from finding your host's libraries.
Connect to the device by issuing the gdb command:
(gdb)target remote :5039
8 進行GDB調試
此時就可以使用GDB來調試源碼了,首先設置斷點:
(gdb) b createPlayer
(gdb) c
然後再到模擬器播放文件可以了
播放會在斷點處卡住,
(gdb) l
就可以顯示斷點出的源碼