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

发布了277 篇原创文章 · 获赞 215 · 访问量 35万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 书香水墨 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览