用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  [email protected]   

[email protected]'s password: 123                

#                                      

 

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

wuxian@ubuntu:~$ touch hello.c

1       #include

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 [email protected]:/root

[email protected]'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

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:

...

(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

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!

你可能感兴趣的:(arm)