建立嵌入式gdb调试环境

来源:互联网 发布:老汉卖羊c语言 编辑:程序博客网 时间:2024/04/29 10:13

.下载gdb-6.4.tar.gz源代码

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

 

二.编译 GDB

#tar zxvf gdb-6.4.tar.gz

 

2.1 编译GDB Server

#cd gdb-6.4

#./configure --target=arm-linux --prefix=/usr/local/arm-gdb

#make

注意: 这里如果你用的是gcc-4.3.2的话,编译可能会出错!你可以改成 gcc-4.1 就可以顺利编译通过

编译ARM用的GDB时出现error: no termcap library found错误的解决方法20090328 星期六 21:55Ubuntu下编译gdb时出现如下错误:

 

........

 

checking for library containing gethostbyname... none required

checking for library containing socketpair... none required

checking for library containing waddstr... no

checking for library containing dlgetmodinfo... no

checking for library containing tgetent... no

configure: error: no termcap library found

make[1]: *** [configure-gdb] 错误 1

 

解决方法:sudo apt-get install libncurses5-dev

 

安装完后,在makeOK了!

 

#make install           // 生成/usr/local/arm-gdb/bin

 

2.2 编译GDB Client

#cd ./gdb/gdbserver

#export PATH=$PATH:/usr/local/arm-gdb/bin

#./configure --target=arm-linux --host=arm-linux

#vi config.h

    //#define HAVA_SYS_REG_H    //注释此句

#make CC=arm-softfloat-linux-gnu-gcc       //编译用于目标机的stub程序  生成gdbserverGDB客户端程序,在板子上运行。

 

三.实战调试

1.编辑文件

# vi gdbtest.c

1 #include <stdio.h>

2

3 int

4 func(int n){

5     int   sum=0, i;

6     for (i=0; i<n; i++){

7         sum += i;

8     }

9     return sum;

10 }

11

12 int

13 main(void)

14 {

15    int   i;

16    long result = 0;

17    for (i=0; i<=100; i++){

18        result += i;

19    }

20 

21    printf("result[1-100] = %d /n", result);

22    printf("resutl[1-225] = %d /n", func(255));

23

24    return 0;

25 }

# arm-linux-gcc -g gdbtest.c -o gdbtest         // 交叉编译

2.下载文件到目标板: gdbtestgdbserver

假设 host pc ip:192.168.1.45

     board   ip:192.168.1.180   

将文件拷贝到目标板上:

先将gdbtestgdbserver两个文件拷贝到主机的/tftpboot目录下

在目标板的Linux中运行:

#mount 192.168.1.108:/tftpboot /mnt/nfs

#cd /mnt/nfs

#ls

看是否有gdbtestgdbserver两个文件。

3.运行调试

client board

#./gdbserver 192.168.1.45:1234 gdbtest  // 目标板上运行gdbtest 监听端口1234

 

host pc

#cd /usr/local/arm-gdb/bin/

#copy gdbtest /usr/local/arm-gdb/bin/   // 将前面编译的文件gdbtest拷贝到此目录

#./arm-linux-gdb gdbtest

(gdb)target remote 192.168.1.180:1234   // 连接到开发板 成功后就可以进行调试             

(gdb)list   or l

(gdb)break func

(gdb)break 22

(gdb)info br   

(gdb)continue   or c    // 这里不能用 run

(gdb)next   or n

(gdb)print or p    result 

(gdb) finish        // 跳出func函数

(gdb) next

(gdb) quit

建立连接后进行gdb远程调试和gdb本地调试方法相同