1. 程式人生 > >【轉】GDB除錯opencore原始碼

【轉】GDB除錯opencore原始碼

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

就可以顯示斷點出的原始碼