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

版权声明:欢迎转发,转发请标明出处 https://blog.csdn.net/weixin_39465823/article/details/88933409

 同样的操作,

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

猜你喜欢

转载自blog.csdn.net/weixin_39465823/article/details/88933409
今日推荐