What is the difference between "next" and "before" in pdb

I am using Python 2.6.6 and using pdb to debug my Python program, but I don’t understand what is the difference between β€œnext” and β€œuntil” in pdb, it seems that both of them will continue to run until the next line in current function.

+5
source share
1 answer

The help pdb document describes it as follows:

(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 

More helpfully, Doug Hellman gives an example in his Python module tutorial Week , which illustrates the difference:

Until the command is next, except that it clearly continues until execution reaches the line in the same function with the line number higher than the current value. This means, for example, that until they are used for the cycle.

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 it was launched, the current line was 16, the last line is a loop. After the escape, execution was on line 17, and the cycle was exhausted.

The until target is shared with the eponymous gdb command :

before

Continue to work until you reach the source line passing through the current line in the current frame frame. This command is used to avoid single ones going through a loop more than once. This is similar to the following command, except that until a jump occurs, it will automatically continue until the program counter is larger than the Jump address. This means that when you reach the end of the loop after a single step by step, until your program continues to run until it exits the loop. In contrast, the next command at the end of the loop simply returns to the beginning of the loop, which forces you to perform the next iteration.

+3
source

Source: https://habr.com/ru/post/1210292/


All Articles