What's the difference between nexti and stepi in gdb?

扶醉桌前 提交于 2019-12-30 04:56:27

问题


While debugging an executable using gdb, there are two commands which we can use to step through the execution:

  • stepi and
  • nexti

What is/are the difference/s between these two and why would anyone choose one over the other?

using help in gdb says:

stepi: Step one instruction exactly.

nexti: Step one instruction, but proceed through subroutine calls.

since we are dealing with instructions and machine code here (the smallest part of a program in execution) I can't figure out what the subroutine calls are.


回答1:


stepi is more detailed than nexti. if you call sum() from main() function then doing stepi reaches you inside the sum() function, but nexti doesn't.

Below is the screenshot when you call stepi when you were at call of sum() instruction (i.e., => 0x08048403 <+40>: call 0x8048419 <sum>). The stepi instuction routes you inside the sum().

If you do nexti when you were at call of sum() instruction (i.e., => 0x08048403 <+40>: call 0x8048419 <sum>) then it uses the returned value from sum method and goes to the next instruction of main method, screenshot as below.

Conclusion: Use stepi if you want to see every machine instructions that happened in your processor. Use nexti if you wanna see only the machine instructions executed at the main().




回答2:


The difference is how call is treated:

  • stepi dives into call
  • nexti runs call but doesn't walk you through its code


来源:https://stackoverflow.com/questions/52024529/whats-the-difference-between-nexti-and-stepi-in-gdb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!