utu2440 gdbserver 远程调试环境搭建

使用的是扬创的utu2440板,其他的页一样,板子配置:S3C2440+Linux2.6内核+yaffs根文件系统。

PC机配置:Vmware虚拟机+SlackWare12内核2.6,交叉编译器为arm-linux-gcc 3.4.1。
主要步骤都是在pc机端完成的。
1.首先从网上下载一个gdb源码包。
2.通过smb或者直接用共享文件夹复制到Linux虚拟机中。
# tar zxvf gdb-6.4.tar.gz    解压源码包
# cd gdb-6.4   进入文件夹
# ./configure --target=arm-linux --prefix=/usr/local/arm/gdb-6.4 -v  指定目标类型为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/
里面有这些文件夹,此时需要设置环境变量,因为我们需要的 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工具,接着编译开发板上使用的gdbserver。
方法:# cd gdb/gdbserver
      # ./configure --target=arm-linux --host=arm-linux
      # make
此时可以在gdbserver目录下生成gdbserver文件,这个文件只能在开发板上跑,用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  
到此环境搞定了!
接着就是测试了,随便写个函数,保存为hello.c
#include <stdio.h>
int main()
{
int i=0;
i = i + 1;
printf("Result is %d/n", i);
return 0;
}
在写个超级简单的Makefile,内容如下,保存为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可执行文件,用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表示用于开发板上运行的。
想要在PC机上运行则# make CC=gcc 编译时指定一下编译器即可。
再接着就是pc机和开发板挂载nfs网络了,这也是关键的地方。
方法:在PC机上添加一个nfs用户
# vi /etc/exports 打开文件,并加入一行
/home 192.168.1.*(rw,sync,no_root_squash)
表示将/home共享给192.168.1网段的所有机器,权限为rw(读/写)。
保存,重启一下机器吧~~~
起来后 # ps -ef | grep nfs   查看有nfs进程否?有就ok了,当然还得有
       # ps -ef | grep nfslock
       # ps -ef | grep portmap
上面三个进程都有后可以了。。。
我的虚拟机ip是192.168.1.223
开发板的ip是192.168.1.225
当然ip只要在一个网段即可。
将防火墙都关了,然后用ping命令互相ping通!
在开发板上输入命令:
# mount -t nfs 192.168.1.223:/home /mnt
说明一下,192.168.1.223是主机ip(即pc虚拟机),/home目录是exports文件中说明要共享的pc机端目录,/mnt是将/home挂载到开发板的mnt目录下,换其他的都行。
成功挂载后能在mnt下看到home中的东西了。
最后,就是正式调试了,将gdbserver和hello放到home里共享给开发板。
在开发板端输入命令:# ./gdbserver 192.168.1.223:1234 hello 
                                  这是pc机的ip       这是要调试的arm程序     端口号随便指定。
在虚拟机PC端:# arm-linux-gdb hello (要在当前有hello的文件夹中执行该命令)
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)
接下来在当前gdb中输入命令:target remote 192.168.1.225:1234 (注:端口号1234要和前面的一致!)
                                         这个ip是开发板的
(gdb) target remote 192.168.1.225:1234
Remote debugging using 192.168.1.225:1234
0x40000dd0 in ?? ()
(gdb)
这是就可以调试了,用c运行,b 加断点,l 查看代码。。。。。
调试结果都在开发板终端打印。
好了!over!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值