#文中arm-926ejs-linux-gnueabi-gcc爲筆者使用crosstool-ng製做的工具鏈
#請注意交叉工具鏈的搜索路徑html
【一】下載源碼包linux
gdb官網下載,這裏下載的是gdb-7.8.2.tar.xz,放在~/Downloads下。
http://www.gnu.org/software/gdb/數據庫
依賴庫ncurses,這裏下載的是ncurses-5.9.tar.gz,放在~/Downloads下。
https://www.gnu.org/software/ncurses/ubuntu
依賴庫termcap,這裏下載的是termcap-1.3.1.tar.gz,放在~/Downloads下。
http://ftp.gnu.org/gnu/termcap/app
【二】宿主機準備個人PC的操做系統爲ubuntu 14.04 x64,非debian系的請自行解決。
# 1.運行庫和工具準備
sudo apt-get install bison flex expect-dev build-essential m4 autoconf automake texi2html
# 2.建立安裝目錄,並增長寫入權限,方便安裝。全部交叉編譯的庫和軟件都會被安裝在這裏
mkdir /opt/arm_root
sudo chmod a+w /opt/arm_root
# 3.建立編譯目錄
mkdir ~/buildspaceide
【三】交叉編譯在ARM上運行的gdb和gdbserver
#1.termcap工具
cd ~buildspace tar xf ~/Downloads/termcap-1.3.1.tar.gz cd termcap-1.3.1 CC=arm-926ejs-linux-gnueabi-gcc ./configure --prefix=/opt/arm_root make make install
make install的時候報錯/usr/bin/install: cannot remove ‘/usr/include/termcap.h’: Permission denied 不用理它……都指定了prefix,還往默認目錄寫頭文件
# 2.ncurses測試
cd ~/buildspace tar xf ~/Downloads/ncurses-5.9.tar.gz cd ncurses-5.9 ./configure --prefix=/opt/arm_root --host=arm-926ejs-linux-gnueabi --with-shared #--host=交叉編譯器前綴。 make
make install
# 3.gdbflex
cd ~/buildspace tar xf ~/Downloads/gdb-7.8.2.tar.xz
mv gdb-7.8.2 gdb-7.8.2_arm cd gdb-7.8.2_arm ./configure --host=arm-926ejs-linux-gnueabi --target=arm-926ejs-linux-gnueabi --prefix=/opt/arm_root --enable-static LDFLAGS="-L/opt/arm_root/lib" CFLAGS="-I/opt/arm_root/include" #指定庫和頭文件的路徑 make
make install
完成後在/opt/arm_root/bin下就有在ARM上運行的gdb和gdbserver了。ui
【四】編譯pc上運行,與gdbserver相同版本的gdb
實際上不一樣版本也能用,只是可能出現兼容性問題
從新解壓一份gdb源碼,用pc的gcc編譯,指定target爲咱們的交叉工具鏈前綴便可
cd ~/buildspace tar xf ~/Downloads/gdb-7.8.2.tar.xzmv gdb-7.8.2 gdb-7.8.2_arm cd gdb-7.8.2 ./configure --target=arm-926ejs-linux-gnueabi --enable-static #使用操做系統的庫 make
cp gdb/gdb ~/arm-none-linux-gnueabi-gdb
編譯完成後,就能在~/buildspace/gdb-7.8.2/gdb下找到生成的gdb文件,拷貝出來重命名便可。
【五】配置嵌入式設備
#1.拷貝文件
#動態庫
cp /opt/arm_root/lib/*.so* /home/rootfs/lib
#可執行文件
cd /opt/arm_root/bin
cp gdb gdbserver gcore /home/rootfs/usr/local/bin
#去除可執行文件的符號信息,減少體積
cd /home/rootfs/usr/local/bin/
arm-926ejs-linux-gnueabi-strip gdb
arm-926ejs-linux-gnueabi-strip gdbserver
#拷貝終端類型數據庫
mkdir /home/rootfs/usr/share -p
cp /opt/arm_root/share/terminfo /home/rootfs/usr/share
#2.配置環境變量
修改/etc/profile,確保有如下兩行
export TERM=vt102
export TERMINFO=/usr/share/terminfo
#3.測試
更新文件系統後,啓動gdb,輸入ctrl+x a(就是先按一次CTRL+X,鬆開再按一下A)切換到TUI模式。經過串口(minicom)運行就是以下這種樣子,行號左側B+表示有斷點,>爲當前行且會被高亮
lqqvin.cqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x25 // x x26 //} x x27 #define VIDIOCSPREVIEW _IOR('v',43, int) x x28 int main() x x29 { x B+>x30 int fd = open("/dev/video0", O_RDWR); x x31 if(fd == 0) x x32 { x x33 printf("open failed\n"); x x34 return -1; x x35 } x x36 struct video_capability cap; x x37 int ret = ioctl(fd,VIDIOCGCAP,&cap); x mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj native process 419 In: main Line: 30 PC: 0x85c4 (gdb) b main Breakpoint 1 at 0x85c4: file vin.c, line 30. (gdb) r Starting program: /mnt/nfs/626_app/vin Breakpoint 1, main () at vin.c:30 (gdb)
須要注意,程序自己的輸出可能破壞TUI的顯示
如下是在用omapl138時編寫的腳本
################################################################ PATH_CROSS=/opt/arm-linux-gcc/omap_4.3.3/bin; echo $PATH > /tmp/path_; touch /tmp/path; if [ -z `grep $PATH_CROSS /tmp/path` ]; then echo $PATH:$PATH_CROSS > /tmp/path; fi; PATH=`cat /tmp/path`; rm /tmp/path; rm /tmp/path_; ################################################################ TOP=`pwd`; TARGET=arm-none-linux-gnueabi; ARMROOT=/opt/omapl138_root ################################################################ TERMCAP=termcap-1.3.1 echo -n "building termcap ..." if true; then cd $TOP; if [ -d $TERMCAP ]; then rm -rf $TERMCAP; fi; tar xf $TERMCAP.tar.*; cd $TERMCAP; CC=$TARGET-gcc ./configure --prefix=$ARMROOT; make -j4; make install; fi > $TOP/termcap.log 2>&1; echo "done" ############################################################# NCURSES=ncurses-5.9 echo -n "building ncurses ..." if true; then cd $TOP; if [ -d $NCURSES ]; then rm -rf $NCURSES; fi; tar xf $NCURSES.tar.*; cd $NCURSES; ./configure --prefix=$ARMROOT --host=$TARGET --with-shared make -j4 make install fi > $TOP/ncurses.log 2>&1; echo "done" ############################################################### GDB=gdb-7.9.1 echo "building gdb ..." echo -ne "\t decompressing ..." cd $TOP; if [ -d gdb_arm ]; then rm -rf gdb_arm; fi; if [ -d gdb_pc ]; then rm -rf gdb_pc; fi; tar xf $GDB.tar.*; cp $GDB -r gdb_arm; mv $GDB gdb_pc; echo "done" echo -ne "\t building gdb running on arm ..." if true; then cd $TOP/gdb_arm; ./configure --host=$TARGET --target=$TARGET --prefix=$ARMROOT --enable-static LDFLAGS="-L$ARMROOT/lib" CFLAGS="-I$ARMROOT/include" make -j4 make install fi > $TOP/gdb_arm.log 2>&1 echo "done" echo -ne "\t building "$TARGET-gdb" running on pc ..." if true; then cd $TOP/gdb_pc; ./configure --target=$TARGET --enable-static make -j4 cp gdb/gdb $TOP/$TARGET-gdb; fi > $TOP/gdb_pc.log 2>&1; echo "done" echo -e "\t done" ###############################################################