android 核心調試

來源:互聯網
上載者:User

標籤:

這篇文檔給出使用android emulator 和 arm-linux-androideabi-gdb 調試 android kernel 的方法

 

1. checkout goldfish 源碼: 模擬器使用的kernel 是 goldfish 

 

git clone https://android.googlesource.com/kernel/goldfish.git gitcheckout -t origin/android-goldfish-3.4 -b goldfish3.4

  

2. 設定環境變數,主要是為了指定交叉編譯器到path路徑: 下述幾句可以儲存為一指令碼,需要的時候在shell裡執行

 

export PATH=$YOUR_ANDROID_SRC_PATH/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.8/bin/:$PATHexport ARCH=armexport SUBARCH=armexport CROSS_COMPILE=arm-eabi-make goldfish_armv7_defconfig

 

3. 增加核心config選項

 

預設的goldfish_armv7_defconfig配置沒有開啟調試,也沒有使用HIGHMEM,這裡我們手動開啟 goldfish/.config 目錄,將下面的幾個配置開啟:

 

CONFIG_HIGHMEM=y 開啟這個選項後,啟動模擬器時 emulator -memory 參數才能發揮作用,否則模擬器的記憶體總是700多MCONFIG_DEBUG_KERNEL=y 開啟這個選項後,vmlinux 才有符號CONFIG_KGDB=y 開啟kgdb

  

 

4. 開始編譯

make ARCH=arm CROSS_COMPILE=$YOUR_ANDROID_SRC_PATH/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.8/bin/arm-linux-androideabi- all

由於第3步開啟了幾個配置,所以編譯一開始會有提示讓選擇配置選項,記得相關的配置全部選Y就可以了 編譯之後在 goldfish/arch/arm/boot/zImage 出現,這個就是核心了

 

5. 啟動模擬器

 

emulator -no-window -no-audio -verbose -show-kernel -kernel goldfish/arch/arm/boot/zImage -memory 2048 -qemu -s -S

  

我一般調試核心不需要圖形介面,所以增加 -no-window, no-audio. 另外,希望看到核心的詳細輸出,增加了 -show-kernel, -verbose , 然後就是用 -kernel 參數指向剛剛編譯好的 zImage , -memory 設定記憶體,記憶體越大,調試起來效能好些, 最後是 -qemu -s -S 啟動調試監聽,就是核心啟動後會等待在 連接埠 1234 而不會一直啟動完畢,這時候需要在另外一個介面啟動gdb :

 

arm-linux-androideabi-gdb goldfish/vmlinux

  

然後在介面裡執行遠端偵錯:

 

參考:

https://gbrownmozilla.wordpress.com/2015/02/13/more-memory-for-the-android-emulator/

http://www.kgdb.info/kgdb/use_kgdb/using_kgdb_base_qemu/

http://yabinc.blogspot.com/2015/03/build-and-run-android-linux-kernel-in.html

http://www.joenchen.com/archives/1093

android 核心調試

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.