Linux中的GDB调试器
2018-03-23 13:05
176 查看
在编译时如果我们仅仅依靠gcc发出的警告或错误信息来进行修改,调试的效率非常低,也不容易发现错误的所在。为此,GNU开发了GDB调试器。
下面我们就来简单认识一下GDB调试器:
[root@promote 1118]# gcc -g 14.c -o 14
[root@promote 1118]# gdb 14
GNU gdb Red Hat Linux (6.5-25.el5rh)
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type “show copying” to see the conditions.
There is absolutely no warranty for GDB. Type “show w
4000
arranty” for details.
This GDB was configured as “i386-redhat-linux-gnu”…Using host libthread_db library “/lib/libthread_db.so.1”.
(gdb) l
10 int cal(int n)
11 {
12 if(n == 1)
13 return 1;
14 else
15 return n * cal(n - 1);
16 }
17 int main(int argc, char **argv)
18 {
19 int n = 5;
(gdb) b 15
Breakpoint 1 at 0x8048399: file 14.c, line 15.
(gdb) r
Starting program: /tjy/C语言/1118/14
Breakpoint 1, cal (n=5) at 14.c:15
15 return n * cal(n - 1);
(gdb) p n
$1 = 5
(gdb) c
Continuing.
Breakpoint 1, cal (n=4) at 14.c:15
15 return n * cal(n - 1);
(gdb) p n
$2 = 4
(gdb) n
Breakpoint 1, cal (n=3) at 14.c:15
15 return n * cal(n - 1);
(gdb) n
Breakpoint 1, cal (n=2) at 14.c:15
15 return n * cal(n - 1);
(gdb) s
cal (n=1) at 14.c:12
12 if(n == 1)
(gdb) s
13 return 1;
(gdb) q
The program is running. Exit anyway? (y or n) y
[root@promote 1118]#
这就是GDB调试器的运行过程。
主要的几个操作如下:
1.gcc -g 15.c -o 15:把调试信息加入到可执行文件中
2.gdb 15:启动GDB进行调试
3.gdb l:查看所有的代码行数
4.gdb b 15:设置断点
5.gdb info b:查看断点情况
6.gdb r:运行程序,在断点前一行暂停
7:gdb p n:查看变量值
8.gdb c:继续运行程序
9:gdb s:让程序一步一步的往下运行
下面我们就来简单认识一下GDB调试器:
[root@promote 1118]# gcc -g 14.c -o 14
[root@promote 1118]# gdb 14
GNU gdb Red Hat Linux (6.5-25.el5rh)
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type “show copying” to see the conditions.
There is absolutely no warranty for GDB. Type “show w
4000
arranty” for details.
This GDB was configured as “i386-redhat-linux-gnu”…Using host libthread_db library “/lib/libthread_db.so.1”.
(gdb) l
10 int cal(int n)
11 {
12 if(n == 1)
13 return 1;
14 else
15 return n * cal(n - 1);
16 }
17 int main(int argc, char **argv)
18 {
19 int n = 5;
(gdb) b 15
Breakpoint 1 at 0x8048399: file 14.c, line 15.
(gdb) r
Starting program: /tjy/C语言/1118/14
Breakpoint 1, cal (n=5) at 14.c:15
15 return n * cal(n - 1);
(gdb) p n
$1 = 5
(gdb) c
Continuing.
Breakpoint 1, cal (n=4) at 14.c:15
15 return n * cal(n - 1);
(gdb) p n
$2 = 4
(gdb) n
Breakpoint 1, cal (n=3) at 14.c:15
15 return n * cal(n - 1);
(gdb) n
Breakpoint 1, cal (n=2) at 14.c:15
15 return n * cal(n - 1);
(gdb) s
cal (n=1) at 14.c:12
12 if(n == 1)
(gdb) s
13 return 1;
(gdb) q
The program is running. Exit anyway? (y or n) y
[root@promote 1118]#
这就是GDB调试器的运行过程。
主要的几个操作如下:
1.gcc -g 15.c -o 15:把调试信息加入到可执行文件中
2.gdb 15:启动GDB进行调试
3.gdb l:查看所有的代码行数
4.gdb b 15:设置断点
5.gdb info b:查看断点情况
6.gdb r:运行程序,在断点前一行暂停
7:gdb p n:查看变量值
8.gdb c:继续运行程序
9:gdb s:让程序一步一步的往下运行
相关文章推荐
- linux下的c/c++调试器gdb
- 【linux GDB】linux下GDB调试器_学习笔记_003
- linux基础2——gdb调试器
- Linux下的调试器GDB
- Linux上的C/C++调试器GDB
- linux下对gdb调试器的基本了解
- 嵌入式LINUX调试器GDB
- linux下gdb调试器使用学习-01
- Linux gdb调试器用法全面解析
- Linux下C语言的调试器 Gdb
- Linux gdb调试器用法全面解析
- 据说,VIM(编辑器)+GCC(编译器)+GDB(调试器)是Linux下最常用的开发工具链
- linux编程器GCC及调试器GDB
- Linux gdb调试器用法全面解析
- GDB_Linux调试器
- [转] linux下的c/c++调试器gdb
- Linux开发工具之调试器gdb
- 断点命令【Linux学习】GDB调试器基本命令必知必会(一)
- Linux教程 - Linux - GDB调试器使用手册(七)
- linux 环境下GDB调试器基本用法