GDB 调试入门
gdb 调试有两种方式,一种是本地调试,一种是远程调试。本地调试需要有
和本地架构一致的 gdb 客户端;而远程调试由两部分组成,gdb 服务器部署在设
备上,交叉编译的 gdb 客户端部署在编译服务器上。本地调试时,在设备上直接
运行 gdb 程序,将要调试的程序文件名作为参数传入;远程调试时,将要调试的
程序文件名作为参数分别传给服务器和客户端,两个程序文件必须一致,使用同
一个程序文件也可以。
被调试的程序文件不能被 strip 过,否则无法调试。如果调试的源文件的编译
选项中加了-g 选项,调试时可以跟踪到代码行和看到参数的值,否则只能跟踪
到函数名。达芬奇项目在编译时默认都会把没有 strip 的程序拷贝到服务器上用
户的共享目录,比如/home/share/wang_jun,可以直接调试。
调试步骤如下:
1. 如果是本地调试,在板子上运行 gdb 客户端程序,然后输入 gdb 命令 run,启
动调试程序。gdb 客户端程序和 sonia 调试程序可能会比较大,可以放在调试服
务器上,然后设备挂载到服务器运行 gdb 客户端。
# ./gdb ./sonia(其中 sonia 是需要调试的程序)
dlopen failed on 'libthread_db.so.1' - File not found
GDB will not be able to debug pthreads.
GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "arm-uclibc-linux"...
(gdb) run
如果所调试的程序需要命令行参数,可以通过两种方式来设置,不同的 gdb
版本支持的可能不同。
# ./gdb ./sonia(其中 sonia 是需要调试的程序)
dlopen failed on 'libthread_db.so.1' - File not found
GDB will not be able to debug pthreads.
GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.