简体   繁体   English

gdb 中的 nexti 和 stepi 有什么区别?

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

While debugging an executable using gdb , there are two commands which we can use to step through the execution:在使用gdb调试可执行文件时,我们可以使用两个命令来逐步执行:

  • stepi and stepi
  • nexti

What is/are the difference/s between these two and why would anyone choose one over the other?这两者之间有什么区别,为什么有人会选择一个而不是另一个?

using help in gdb says:在 gdb 中使用帮助 说:

stepi: Step one instruction exactly. stepi:准确的第一步指令。

nexti: Step one instruction, but proceed through subroutine calls. nexti:第一步指令,但继续执行子程序调用。

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.因为我们在这里处理指令和机器代码(正在执行的程序的最小部分),所以我无法弄清楚子程序调用是什么。

stepi is more detailed than nexti . stepinexti更详细。 if you call sum() from main() function then doing stepi reaches you inside the sum() function, but nexti doesn't.如果你从main()函数调用sum()然后在 sum() 函数中执行stepi到达你,但nexti没有。

Below is the screenshot when you call stepi when you were at call of sum() instruction (ie, => 0x08048403 <+40>: call 0x8048419 <sum> ).下面是在调用 sum()指令时调用stepi时的屏幕截图(即=> 0x08048403 <+40>: call 0x8048419 <sum> )。 The stepi instuction routes you inside the sum() . stepi指令将您路由到sum()

在此处输入图片说明

If you do nexti when you were at call of sum() instruction (ie, => 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.如果在调用 sum()指令时执行nexti (即=> 0x08048403 <+40>: call 0x8048419 <sum> ),则它使用 sum 方法的返回值并转到 main 方法的下一条指令,截图如下。

在此处输入图片说明

Conclusion : Use stepi if you want to see every machine instructions that happened in your processor.结论:如果您想查看处理器中发生的每条机器指令,请使用stepi Use nexti if you wanna see only the machine instructions executed at the main() .如果您只想查看在main()处执行的机器指令,请使用nexti

The difference is how call is treated:区别在于call的处理方式:

  • stepi dives into call stepi潜入call
  • nexti runs call but doesn't walk you through its code nexti运行call但不会nexti您完成其代码

Hence here's the semantical rule to remember it better: you are to step if you need to walk through因此,这里的语义规则,以更好地记住它:你是一步,如果你需要穿行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM