Android平台上GDB for MIPS晶片的構建

來源:互聯網
上載者:User

如需轉載,請註明出處!

薑江 linuxemacs@gmail.com

 

    因項目原因需要構建一個基於MIPS晶片的GDB,這裡簡單記錄一下構建過程以備以後使用。

 

一、目標

    1. 運信在MIPS晶片上的gdbserver

    2. 運行在MIPS晶片上的gdb

    3. 運行在x86晶片上的gdb

 

二、所需要環境

1. 工具鏈

    從CodeSourcery上下載用於MIPS晶片的工具鏈。第一次嘗試構建時,下載的是CodeSourcery G++ Lite版本,編譯過程中出現大量的標頭檔找不到的問題。解決這個問題,要麼自己重新構建一套完整的MIPS工具鏈,要麼下載CodeSourcery G++專業版,不過該專業版有30天的時間限制。但是,對構建的程式沒有任何影響。

    如下:

    http://www.codesourcery.com/sgpp/professional_edition.html

    下載並且安裝後,程式會提供兩個機器碼,使用這兩個串號在CodeSourcery G++網站上申請一個license並且設定,即可使用。

 

2. gdb源碼

    這裡使用的是目前最新的gdb 7.1源碼作為基礎,可以從下面網站下載

    http://ftp.gnu.org/gnu/gdb/

 

3. termcap庫

    在構建gdb時,需要termcap的支援,如下

    ftp://ftp.gnu.org/gnu/termcap

 

三、構建

1. 構建termcap

tar xvzf termcap-1.3.1.tar.gz

cd termcap

./configure --host=mips-linux-gnu --target=mips-linux-gnu

 

修改Makefile或者configure時候用CC指定mips-linux-gnu-gcc -EL(預設情況下編譯的是大端程式,這裡我需要的是小端,用-EL標誌指定)

a) CC = mips-linux-gnu-gcc 修改成 CC = mips-linux-gnu-gcc -EL

b) CFLAGS = 修改成

 

CFLAGS = -fno-exceptions /                

         -Wno-multichar /                             

         -Ulinux /                           

         -march=mips32r2 /                             

         -mtune=mips32r2 /                            

         -mhard-float /                                   

         -fpic /                        

         -ffunction-sections /                                   

         -funwind-tables /                    

         -fmessage-length=0 /                          

         -W -Wall -Wno-unused /                                    

         -Winit-self /                  

         -Wpointer-arith /                       

         -Werror=return-type /                           

         -Werror=non-virtual-dtor /                      

         -Werror=address /                                  

         -Werror=sequence-point  /                            

         -DNDEBUG -g /                   

         -Wstrict-aliasing=2 /                   

         -finline-functions /                                 

         -fno-inline-functions-called-once /                               

         -fgcse-after-reload /                    

         -frerun-cse-after-loop /                     

         -frename-registers /                  

         -UDEBUG -O2 /                           

         -fomit-frame-pointer /                                  

         -fstrict-aliasing /                   

         -funswitch-loops /                                    

         -finline-limit=300 /                             

         -MD -static             

 

b) make

編譯完畢後會在目前的目錄下產生libtermcap.a

 

2. 構建gdb for MIPS

tar xvzf gdb-7.1.tar.gz

cd gdb-7.1

 

a) 修改gdb/configure,手工設定termcap庫的位置

注視掉下面幾行(LINE:8639)

 

# Since GDB uses Readline, we need termcap functionality.  In many                                                        

# cases this will be provided by the curses library, but some systems                                                    

# have a seperate termcap library, or no curses library at all.                                            

#case $host_os in                                              

#  cygwin*)                                          

#    if test -d $srcdir/libtermcap; then                                                         

#      LIBS="../libtermcap/libtermcap.a $LIBS"                                                                 

#      ac_cv_search_tgetent="../libtermcap/libtermcap.a"                                                                   

#    fi ;;                                   

#  go32* | *djgpp*)                                                   

#    ac_cv_search_tgetent="none required"                                                           

#    ;;                                           

#  *mingw32*)                                                     

#    ac_cv_search_tgetent="none required"                                                              

#    CONFIG_OBS="$CONFIG_OBS windows-termcap.o"                                                                                 

#    ;;                                         

#esac        

 

設定ac_cv_search_tgetent

ac_cv_search_tgetent="/home/xxx/termcap-1.3.1/libtermcap.a" 

 

 

b) 執行configure

./configure --host=mips-linux-gnu --target=mips-linux-gnu --disable-shared

 

c) 修改Makefile

CC = mips-linux-gnu-gcc 修改成 CC = mips-linux-gnu-gcc -EL

CXX = mips-linux-gnu-g++ 修改成CXX = mips-linux-gnu-g++ -EL

 

LIBCXXFLAGS 加入-static標誌

 

 

CFLAGS = 修改成

 

CFLAGS = -fno-exceptions /                

         -Wno-multichar /                             

         -Ulinux /                           

         -march=mips32r2 /                             

         -mtune=mips32r2 /                            

         -mhard-float /                                   

         -fpic /                        

         -ffunction-sections /                                   

         -funwind-tables /                    

         -fmessage-length=0 /                          

         -W -Wall -Wno-unused /                                    

         -Winit-self /                  

         -Wpointer-arith /                       

         -Werror=return-type /                           

         -Werror=non-virtual-dtor /                      

         -Werror=address /                                  

         -Werror=sequence-point  /                            

         -DNDEBUG -g /                   

         -Wstrict-aliasing=2 /                   

         -finline-functions /                                 

         -fno-inline-functions-called-once /                               

         -fgcse-after-reload /                    

         -frerun-cse-after-loop /                     

         -frename-registers /                  

         -UDEBUG -O2 /                           

         -fomit-frame-pointer /                                  

         -fstrict-aliasing /                   

         -funswitch-loops /                                    

         -finline-limit=300 /                             

         -MD -static

 

 

 

CXXFLAGS = 修改成

CXXFLAGS = $(CFLAGS)

 

d) make

在make bfd過程中可能會遇到未初始設定變數或者沒有傳回值的錯誤,可以修改bfd/Makefile,將WARN_CFLAGS標誌的-Werror去掉,這樣就不會將警告當成錯誤。

 

等make完畢後,會在gdb目錄下產生用於mips的gdb,以及gdb/gbdserver下產生用於mips的gdbserver

 

3. 構建gdb for x86

gdb for x86編譯比較簡單,基本兩步搞定

./configure --target=mips-linux-gnu

make

 

這樣即可在gdb/目錄下產生x86平台上的gdb

 

四、使用

1. gdbserver的使用

a) 開發板上用使用下面方式監聽gdb串連

gdbserver ip:12345 hello

 

b) 主機上使用下面方式attach到開發板

gdb

target remote ip:12345

 

2. gdb for mips的使用

由於gdb預設的shell路徑是/bin/sh,但是android平台上的sh是在/system/bin下。因此,要麼修改gdb的配置,將預設的sh設定成/system/bin/sh,要麼就在根檔案系統中建立bin目錄,並且做一個sh的符號串連

mkdir /bin

cd /bin

ln -s /system/bin/sh sh

 

之後就可以開始調試過程:

gdb hello

 

五、參考資源

http://www.codesourcery.com/

http://ftp.gnu.org/gnu/gdb/

ftp://ftp.gnu.org/gnu/termcap

http://www.gnu.org/software/gdb/documentation/

http://www.gnu.org/software/termutils/manual/termcap-1.3/html_mono/termcap.html

 

~~~ END ~~~

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.