pdb 中 "next" 和 "until" 有什么区别
what is the difference between "next" and "until" in pdb
我用的是Python 2.6.6,用pdb调试我的Python程序,但不清楚"next"和[=15有什么区别=] 在 pdb 中,似乎它们都将继续执行到当前函数的下一行。
pdb 帮助文档是这样描述的:
(Pdb) help next
n(ext)
Continue execution until the next line in the current function
is reached or it returns.
(Pdb) help until
unt(il)
Continue execution until the line with a number greater than the current
one is reached or until the current frame returns
更有帮助的是,Doug Hellman 在他的 Python 模块教程中给出了一个示例
Week 说明了差异:
The until command is like next, except it explicitly continues until execution
reaches a line in the same function with a line number higher than the current
value. That means, for example, that until can be used to step past the end of
a loop.
pdb_next.py
import pdb
def calc(i, n):
j = i * n
return j
def f(n):
for i in range(n):
j = calc(i, n)
print i, j
return
if __name__ == '__main__':
pdb.set_trace()
f(5)
$ python pdb_next.py
> .../pdb_next.py(21)<module>()
-> f(5)
(Pdb) step
--Call--
> .../pdb_next.py(13)f()
-> def f(n):
(Pdb) step
> .../pdb_next.py(14)f()
-> for i in range(n):
(Pdb) step
> .../pdb_next.py(15)f()
-> j = calc(i, n)
(Pdb) next
> .../pdb_next.py(16)f()
-> print i, j
(Pdb) until
0 0
1 5
2 10
3 15
4 20
> .../pdb_next.py(17)f()
-> return
(Pdb)
Before until was run, the current line was 16, the last line of the
loop. After until ran, execution was on line 17, and the loop had been
exhausted.
until
的目的与 eponymous gdb command 相同:
until
Continue running until a source line past the current line, in the current stack frame, is reached. This command is used to avoid single
stepping through a loop more than once. It is like the next command,
except that when until encounters a jump, it automatically continues
execution until the program counter is greater than the address of the
jump. This means that when you reach the end of a loop after single
stepping though it, until makes your program continue execution until
it exits the loop. In contrast, a next command at the end of a loop
simply steps back to the beginning of the loop, which forces you to
step through the next iteration.
我用的是Python 2.6.6,用pdb调试我的Python程序,但不清楚"next"和[=15有什么区别=] 在 pdb 中,似乎它们都将继续执行到当前函数的下一行。
pdb 帮助文档是这样描述的:
(Pdb) help next
n(ext)
Continue execution until the next line in the current function
is reached or it returns.
(Pdb) help until
unt(il)
Continue execution until the line with a number greater than the current
one is reached or until the current frame returns
更有帮助的是,Doug Hellman 在他的 Python 模块教程中给出了一个示例 Week 说明了差异:
The until command is like next, except it explicitly continues until execution reaches a line in the same function with a line number higher than the current value. That means, for example, that until can be used to step past the end of a loop.
pdb_next.py
import pdb
def calc(i, n):
j = i * n
return j
def f(n):
for i in range(n):
j = calc(i, n)
print i, j
return
if __name__ == '__main__':
pdb.set_trace()
f(5)
$ python pdb_next.py
> .../pdb_next.py(21)<module>()
-> f(5)
(Pdb) step
--Call--
> .../pdb_next.py(13)f()
-> def f(n):
(Pdb) step
> .../pdb_next.py(14)f()
-> for i in range(n):
(Pdb) step
> .../pdb_next.py(15)f()
-> j = calc(i, n)
(Pdb) next
> .../pdb_next.py(16)f()
-> print i, j
(Pdb) until
0 0
1 5
2 10
3 15
4 20
> .../pdb_next.py(17)f()
-> return
(Pdb)
Before until was run, the current line was 16, the last line of the loop. After until ran, execution was on line 17, and the loop had been exhausted.
until
的目的与 eponymous gdb command 相同:
until
Continue running until a source line past the current line, in the current stack frame, is reached. This command is used to avoid single stepping through a loop more than once. It is like the next command, except that when until encounters a jump, it automatically continues execution until the program counter is greater than the address of the jump. This means that when you reach the end of a loop after single stepping though it, until makes your program continue execution until it exits the loop. In contrast, a next command at the end of a loop simply steps back to the beginning of the loop, which forces you to step through the next iteration.