接触 GDB——调试器

GDB调试器的调试功能强大,缺点是没有图形调试界面。

把test.c通过gcc进行编译,然后通过gdb命令调试,然后在命令创建偶输入l查看

[root@jsetc home]# gcc -g test.c -o test
[root@jsetc home]# ls
b.c  b.h  fst  fstfstfst  fstttttt  makefile  test  test1  test.c  test.o
[root@jsetc home]# gdb test
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 warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1".

(gdb) l
1       #include <stdio.h>
2
3       int main()
4       {
5               printf("Hello World!\n");
6               return 0;
7       }
(gdb) 

设置断点:

(gdb) b 5
Breakpoint 1 at 0x8048395: file test.c, line 5.

查看断点:

(gdb) info b
Num Type           Disp Enb Address    What
1   breakpoint     keep y   0x08048395 in main at test.c:5

运行程序:

(gdb) r
Starting program: /home/test 

Breakpoint 1, main () at test.c:5
5               printf("Hello World!\n");

输p+变量名可查看变量数值。

输入c可以继续执行程序:

(gdb) c
Continuing.
Hello World!

Program exited normally.

输入s可以单步运行。

猜你喜欢

转载自blog.csdn.net/qq_43257912/article/details/82886627