utu2440 gdbserver 搭建
生活随笔
收集整理的這篇文章主要介紹了
utu2440 gdbserver 搭建
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
使用的是揚創(chuàng)的utu2440板,其他的頁一樣,板子配置:S3C2440+Linux2.6內(nèi)核+yaffs根文件系統(tǒng)。
PC機配置:Vmware虛擬機+SlackWare12內(nèi)核2.6,交叉編譯器為arm-linux-gcc 3.4.1。 主要步驟都是在pc機端完成的。 1.首先從網(wǎng)上下載一個gdb源碼包。 地址: http://ftp.gnu.org/gnu/gdb/gdb-6.4.tar.gz 2.通過smb或者直接用共享文件夾復(fù)制到Linux虛擬機中。 # tar zxvf gdb-6.4.tar.gz ???解壓源碼包 # cd gdb-6.4 ??進入文件夾 # ./configure --target=arm-linux --prefix=/usr/local/arm/gdb-6.4 -v ?指定目標(biāo)類型為arm,指定gdb的安裝路徑為/usr/local/arm/gdb-6.4 如果沒有可以先建立一個,# mkdir?/usr/local/arm/gdb-6.4 # make 編譯 # make install 安裝到指定目錄 # cd?/usr/local/arm/gdb-6.4/ ; ls ?查看是否有東西 root@chrissie:/usr/local/arm/gdb-6.4# ls bin/ ?info/ ?lib/ ?man/ ?share/ 里面有這些文件夾,此時需要設(shè)置環(huán)境變量,因為我們需要的 arm-linux-gdb(類似于arm-linux-gcc)在這里的bin文件夾中,方法:# vi /etc/profile 打開配置文件,并在最后加上? export PATH=/usr/local/arm/gdb-6.4/bin:$PATH 在使之生效 ??????????????# source /etc/profile # arm-linux-gdb -v 再用查看一下,有信息則說明成功安裝了。 以上安裝的是Linux PC端的gdb工具,接著編譯開發(fā)板上使用的gdbserver。 方法:# cd gdb/gdbserver #?./configure --target=arm-linux --host=arm-linux # make 此時可以在gdbserver目錄下生成gdbserver文件,這個文件只能在開發(fā)板上跑,用ls查看一下: root@chrissie:/home/gdb/gdb-6.4/gdb/gdbserver# ls acinclude.m4 ???gdbreplay* ??????linux-arm-low.o ?????linux-mips-low.c ???mem-break.o ????remote-utils.o ?thread-db.c aclocal.m4 ?????gdbreplay.c ?????linux-cris-low.c ????linux-ppc64-low.c ??proc-service.c ?server.c ???????thread-db.o ChangeLog ??????gdbreplay.o ?????linux-crisv32-low.c ?linux-ppc-low.c ????proc-service.o ?server.h ???????utils.c config.h ??????? gdbserver*???????linux-i386-low.c ????linux-s390-low.c ???README ?????????server.o ???????utils.o config.in ??????gdbserver.1 ?????linux-ia64-low.c ????linux-sh-low.c ?????reg-arm.c ??????signals.o config.log ?????i387-fp.c ???????linux-low.c ?????????linux-x86-64-low.c ?reg-arm.o ??????stamp-h config.status* ?i387-fp.h ???????linux-low.h ?????????Makefile ???????????regcache.c ?????target.c configure* ?????inferiors.c ?????linux-low.o ?????????Makefile.in ????????regcache.h ?????target.h configure.ac ???inferiors.o ?????linux-m32r-low.c ????mem-break.c ????????regcache.o ?????target.o configure.srv ??linux-arm-low.c ?linux-m68k-low.c ????mem-break.h ????????remote-utils.c ?terminal.h?? 到此環(huán)境搞定了! 接著就是測試了,隨便寫個函數(shù),保存為hello.c #include <stdio.h> int main() { int i=0; i = i + 1; printf("Result is %d/n", i); return 0; } 在寫個超級簡單的Makefile,內(nèi)容如下,保存為Makefile #!/bin/sh CC = arm-linux-gcc CFLAGS = -Wall -g hello: hello.o $(CC) $(CFLAGS) hello.c -o hello clean: rm -f *.o hello Makefile~ 在終端輸入make編譯。 # make root@chrissie:/home/gdb/app# make arm-linux-gcc -Wall -g ??-c -o hello.o hello.c arm-linux-gcc -Wall -g hello.c -o hello # ls 查看一下生成了hello可執(zhí)行文件,用file看看屬性。 # file hello root@chrissie:/home/gdb/app# file hello hello: ELF 32-bit LSB executable, ARM, version 1, dynamically linked (uses shared libs), not stripped 其中有ARM表示用于開發(fā)板上運行的。 想要在PC機上運行則# make CC=gcc 編譯時指定一下編譯器即可。 再接著就是pc機和開發(fā)板掛載nfs網(wǎng)絡(luò)了,這也是關(guān)鍵的地方。 方法:在PC機上添加一個nfs用戶 # vi /etc/exports 打開文件,并加入一行 /home 192.168.1.*(rw,sync,no_root_squash) 表示將/home共享給192.168.1網(wǎng)段的所有機器,權(quán)限為rw(讀/寫)。 保存,重啟一下機器吧~~~ 起來后 # ps -ef | grep nfs ??查看有nfs進程否?有就ok了,當(dāng)然還得有 # ps -ef | grep nfslock # ps -ef | grep portmap 上面三個進程都有后可以了。。。 我的虛擬機ip是192.168.1.223 開發(fā)板的ip是192.168.1.225 當(dāng)然ip只要在一個網(wǎng)段即可。 將防火墻都關(guān)了,然后用ping命令互相ping通! 在開發(fā)板上輸入命令: # mount -t nfs 192.168.1.223:/home /mnt 說明一下,192.168.1.223是主機ip(即pc虛擬機),/home目錄是exports文件中說明要共享的pc機端目錄,/mnt是將/home掛載到開發(fā)板的mnt目錄下,換其他的都行。 成功掛載后能在mnt下看到home中的東西了。 最后,就是正式調(diào)試了,將gdbserver和hello放到home里共享給開發(fā)板。 在開發(fā)板端輸入命令:# ./gdbserver 192.168.1.223:1234 hello? 這是pc機的ip ??????這是要調(diào)試的arm程序 ????端口號隨便指定。 在虛擬機PC端:# arm-linux-gdb hello (要在當(dāng)前有hello的文件夾中執(zhí)行該命令) root@chrissie:/home/gdb/app# arm-linux-gdb hello GNU gdb 6.4 Copyright 2005 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. ?Type "show warranty" for details. This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-linux"... (gdb) 接下來在當(dāng)前gdb中輸入命令:target remote 192.168.1.225:1234 (注:端口號1234要和前面的一致!) 這個ip是開發(fā)板的 (gdb) target remote 192.168.1.225:1234 Remote debugging using 192.168.1.225:1234 0x40000dd0 in ?? () (gdb) 這是就可以調(diào)試了,用c運行,b 加斷點,l 查看代碼。。。。。 調(diào)試結(jié)果都在開發(fā)板終端打印。 好了!over!總結(jié)
以上是生活随笔為你收集整理的utu2440 gdbserver 搭建的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CNCF大使预测:2024年云原生面临倦
- 下一篇: Android gradle depen