Debugging

如何使用 GDB 進行步入、跨步和退出?

  • December 5, 2021

我在 GDB 中輸入了內容help,但沒有找到任何有關 step-into、step-over 和 step-out 的資訊。_start我在( break _start)中的彙程式序中放置了一個斷點。之後我輸入next並完成了調試。我想這是因為它完成了_start,並沒有按我的意願介入。

help running提供一些提示:

stepnext指令(還有nextistepi)。

(gdb) help next
Step program, proceeding through subroutine calls.
Usage: next [N]
Unlike "step", if the current source line calls a subroutine,
this command does not enter the subroutine, but instead steps over
the call, in effect treating it as a single source line.

所以我們可以看到進入step子程序,但會越過子程序。next

stepand stepi(和nextand )通過nexti“行”或“指令”增量來區分。

step -- Step program until it reaches a different source line
stepi -- Step one instruction exactly

相關的是finish

(gdb) help finish
Execute until selected stack frame returns.
Usage: finish
Upon return, the value returned is printed and put in the value history.

更多有用的資訊位於https://sourceware.org/gdb/onlinedocs/gdb/Continuing-and-Stepping.html

引用自:https://unix.stackexchange.com/questions/297982