用arm-linux-gdb调试ARM上的应用程序

我根据arm-linux-gdb的调试对象,把调试分为二大类。即底层代码的调试,如u-boot、裸机程序等;或者应用程序的调试,即elf格式的可执行文件。根据我的经验,应用程序的调试相对要容易很多。下面,详细阐述调试经历……

 

应用篇:用arm-linux-gdb调试应用程序

开发机,即我电脑虚拟机中的ubuntu;目标机,即跑有linux系统的arm开发板。开发机和目标机通过网线连接在一个局域网内,一个网段,确保相互要ping得通。

在开发机中,通过minicom、ssh或者telnet登录开发板,要能看到开发板的文件系统。步骤如下:(ubuntuIP192.168.16.200 arm板的IP192.168.16.40,两者均使用2015端口通信

【1 打开终端,远程登录开发板】

wuxian@ubuntu:~$ ssh  root@192.168.16.40   

root@192.168.16.40's password: 123                

#                                      

 

【2 另启终端,编译elf可执行文件】

wuxian@ubuntu:~$ touch hello.c

1       #include<stdio.h>

2      

3       intmain(int argc, char *argv[])

4       {

5                for(inti=0; i<100; i++)

6                {

7                          printf("hello,world!\n");

8                }

9                return0;

11 }

wuxian@ubuntu:~$ arm-linux-gcc -g hello.c -o hello --std=c99

 

【3 拷贝文件到目标开发板】

wuxian@ubuntu:~$ scp ./hello root@192.168.16.40:/root

root@192.168.16.40's password:

hello                                         100%6200     6.1KB/s   00:00

 

【4 上目标机查看拷贝情况】

# ls

hello

# pwd

/root

#

 

【5 在目标机上打开gdbserver】准备为客户端arm-linux-gdb服务

# gdbserver 192.168.16.200:2015 hello  //192.168.16.200是开发机的ip2015是监听端口,

Process hello created; pid = 27991      //提示信息

Listening on port 2015

 

【6 在开发机上打开arm-linux-gdb】准备调试

wuxian@ubuntu:/opt/arm/4.3.2/bin$ ./arm-linux-gdb ~/hello

GNU gdb (Sourcery G++ Lite 2008q3-72)6.8.50.20080821-cvs

Copyright (C) 2008 Free SoftwareFoundation, Inc.

License GPLv3+: GNU GPL version 3 orlater <http://gnu.org/licenses/gpl.html>

This is free software: you are free tochange and redistribute it.

There is NO WARRANTY, to the extentpermitted by law.  Type "showcopying"

and "show warranty" fordetails.

This GDB was configured as "--host=i686-pc-linux-gnu--target=arm-none-linux-gnueabi".

For bug reporting instructions, pleasesee:

<https://support.codesourcery.com/GNUToolchain/>...

(gdb) target remote 192.168.16.40:2015

Remote debugging using192.168.16.40:2015

warning: Unable to find dynamic linkerbreakpoint function.

GDB will be unable to debug sharedlibrary initializers

and track explicitly loaded dynamiccode.

0x400cc8c0 in ?? ()

(gdb) l 1

1       #include<stdio.h>

2      

3       intmain(int argc, char *argv[])

4       {

5                for(inti=0; i<100; i++)

6                {

7                          printf("hello,world!\n");

8                }

9      

10              return0;

(gdb)

11     }

(gdb) b main

Breakpoint 1 at 0x8480: file hello.c,line 5.

(gdb) c

Continuing.

Error while mapping shared librarysections:

/lib/libc.so.0: No such file ordirectory.

Error while mapping shared librarysections:

/lib/ld-uClibc.so.0: No such file ordirectory.

 

Breakpoint 1, main (argc=1,argv=0xbe9bad74) at hello.c:5

5                for(inti=0; i<100; i++)

(gdb) n

7                          printf("hello,world!\n");

(gdb) n

5                for(inti=0; i<100; i++)

(gdb)

 

【7 再看看目标机上的反应

# gdbserver 192.168.16.200:2015 hello

Process hello created; pid = 27991

Listening on port 2015

Remote debugging from host 192.168.16.200

hello,world!

 

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值