程序在断点处停止后,可能希望按一次执行一个源代码行的方式执行程序,在此时比较程序的实际状态与预期状态。可以使用 step 和 next 命令来执行此操作。这两个命令都是执行程序的一个源代码行,当执行完相应行时即停止。但在处理包含函数调用的源代码行时有所差别:step 命令步入函数,而 next 命令步过函数。
step up 命令会一直执行,直至当前函数将控制权返回给调用它的函数为止。
step to 命令会尝试步入当前源代码行中的指定函数;如果未指定任何函数,则尝试步入由当前源代码行的汇编代码确定调用的最后一个函数。
某些函数(特别是 printf 之类的库函数)可能未使用 -g 选项编译,因此 dbx 无法步入这些函数。在这种情况下,step 和 next 执行功能相似。
以下示例说明如何使用 step 和 next 命令以及在设置断点中设置的断点。
(dbx) stop at 13 (3) stop at "t.c":13 (dbx) run Running: a.out stopped in main at line 13 in file "t.c" 13 printit(msg); (dbx) next Hello world stopped in main at line 14 in file "t.c" 14 } (dbx) run Running: a.out stopped in main at line 13 in file "t.c" 13 printit(msg); (dbx) step stopped in printit at line 6 in file "t.c" 6 printf("%s\n", msg); (dbx) step up Hello world printit returns stopped in main at line 13 in file "t.c" 13 printit(msg); (dbx) |
有关单步执行程序的更多信息,请参见单步执行程序。有关 step 和 next 命令的更多信息,请参见step 命令和next 命令。