当前位置:Gxlcms > 数据库问题 > 使用GDB进行嵌入式远程调试

使用GDB进行嵌入式远程调试

时间:2021-07-01 10:21:17 帮助过:2人阅读

 
  1. #include <stdio.h>  
  2.   
  3. void main()  
  4. {  
  5.     printf("hello world\n");  
  6.     printf("hello world\n");  
  7. }  

使用交叉编译器编译该文件,使用-g参数,生成hello。将gdbserver和hello复制到NFS的挂载点,我的挂载点为/home/yj423/nfswork。

 

yj423@ubuntu:~/nfswork$ ls
bin   dev  gdbserver  home  linuxrc  proc  sbin  tmp  var
boot  etc  hello      lib   mnt      root  sys   usr  welcome

可以看到gdbserver和hello。

接着,在开发板上使用NFS:
[root@yj423 /]#mount -o nolock 192.168.1.103:/home/yj423/nfswork /mnt/nfs
[root@yj423 /]#cd /mnt/nfs
[root@yj423 nfs]#ls
bin        dev        gdbserver  home       linuxrc    proc       sbin       tmp        var
boot       etc        hello      lib        mnt        root       sys        usr        welcome

然后执行gdbserver:

[root@yj423 nfs]#./gdbserver localhost:2001 hello
Process hello created; pid = 948
Listening on port 2001

2001为端口号,hello表示要调试的程序。此时gdbserver等待PC机进行链接。

 

在PC机上执行gdb:

 

yj423@ubuntu:~$ ./armgdb -q /home/yj423/nfswork/hello

Reading symbols from /home/yj423/nfswork/hello...done.

执行远程链接:

(gdb) target remote 192.168.1.6:2001
Remote debugging using 192.168.1.6:2001
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.
0x400007b0 in ?? ()
(gdb)

这里的192.168.1.6为开发板的IP地址。

至此PC端的gdb和开发板的gdbserver已经建立连接,接下来可以调试。

(gdb) b main
Cannot access memory at address 0x0
Breakpoint 1 at 0x83e0: file hello.c, line 5.
(gdb) c
Continuing.
warning: `/lib/libc.so.6‘: Shared library architecture unknown is not compatible with target architecture arm.
warning: Could not load shared library symbols for /lib/ld-linux.so.3.
Do you need "set solib-search-path" or "set sysroot"?
Breakpoint 1, main () at hello.c:5
5        printf("hello world\n");
(gdb) n
6        printf("hello world\n");
(gdb) n
7    }

这里只是简单的调试。后面还会有共享库调试和多进程调试,尽请期待!

未完待续~~~~~~~~~

使用GDB进行嵌入式远程调试

标签:

人气教程排行