Android平台上GDB for MIPS的构建

2010
04.28

如需转载,请注明出处!
WebSite: http://www.jjos.org/
作者: 姜江 linuxemacs@gmail.com
QQ: 457283

因项目原因需要构建一个基于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 ~~~

Post Footer automatically generated by wp-posturl plugin for wordpress.

Tags: , ,

Your Reply