gdb学习15:退出函数,finish和return的区别

 同样的操作,

finish的结果:

(gdb) info b
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x000055555555488f in main at mystrcopy.c:33
	breakpoint already hit 1 time
2       breakpoint     keep y   0x00005555555547a0 in PrintNumbers 
                                                   at mystrcopy.c:19
	stop only if n=10
(gdb) r
Starting program: /home/gyz/mc/mystrcopy 
copying string!
this is an empty string
copying string!

Breakpoint 1, main (argv=1, argc=0x7fffffffe228) at mystrcopy.c:33
33		PrintNumbers(1000);
(gdb) c
Continuing.

Breakpoint 2, PrintNumbers (n=10) at mystrcopy.c:19
19		while(n--)
(gdb) finish 
Run till exit from #0  PrintNumbers (n=10) at mystrcopy.c:19
number is :9
number is :8
number is :7
number is :6
number is :5
number is :4
number is :3
number is :2
number is :1
number is :0
main (argv=1, argc=0x7fffffffe228) at mystrcopy.c:34
34		return 0;
(gdb) 

return的结果: 

(gdb) info b
No breakpoints or watchpoints.
(gdb) b 33
Breakpoint 1 at 0x88f: file mystrcopy.c, line 33.
(gdb) b 19 if n=10
Breakpoint 2 at 0x7a0: file mystrcopy.c, line 19.
(gdb) r
Starting program: /home/gyz/mc/mystrcopy 
copying string!
this is an empty string
copying string!

Breakpoint 1, main (argv=1, argc=0x7fffffffe228) at mystrcopy.c:33
33		PrintNumbers(1000);
(gdb) c
Continuing.

Breakpoint 2, PrintNumbers (n=10) at mystrcopy.c:19
19		while(n--)
(gdb) return
Make PrintNumbers return now? (y or n) y
#0  main (argv=1, argc=0x7fffffffe228) at mystrcopy.c:34
34		return 0;
(gdb) 

参考: https://blog.csdn.net/dadalan/article/details/3758025

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值