[root@test]# cat test1.c
#include <stdio.h>
void main()
{
int a =10;
printf("%d",a);
int b=11;
printf("%d",b);
}
1,使用gcc -g test1.c生成 的a.out是可以使用gdb查看的模式
#gcc -g test1
2,使用gdb能进入调试模式
1)#gdb a.out
2)gdb的四个基本命令
(1)l 查看源程序,可以看程序的行号,
(gdb)l 2,4查看第2行到第4行的代码。
(2)b在某行设置断点
(3)r运行程序
(4)s一步步运行
(5)c 继续往下运行
(6)p显示某个变量
(gdb) l
1 #include <stdio.h>
2 void main()
3 {
4 int a =10;
5 printf("%d",a);
6 int b=11;
7 printf("%d",b);
8 }
(gdb) b 4
Breakpoint 1 at 0x4004cc: file test1.c, line 4.
(gdb) b 6
Breakpoint 2 at 0x4004ea: file test1.c, line 6.
(gdb) b 7
Breakpoint 3 at 0x4004f1: file test1.c, line 7.
(gdb) r
Starting program: /root/tty/dns_test/udp/test/a.out
Breakpoint 1, main () at test1.c:4
4 int a =10;
Missing separate debuginfos, use: debuginfo-install glibc-2.11.2-3.x86_64
(gdb) p a
$1 = 0
(gdb) s
5 printf("%d",a);
(gdb) p a
$2 = 10
(gdb) p b
$3 = 0
(gdb) s
Breakpoint 2, main () at test1.c:6
6 int b=11;
(gdb) p b
$4 = 0
(gdb) s
Breakpoint 3, main () at test1.c:7
7 printf("%d",b);
(gdb) p b
$5 = 11
(gdb)