gdb和gcc的使用概述和例子

[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) 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值