Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(13)

Delta Between Two Patch Sets: Objects/lnotab_notes.txt

Issue 15550: Trailing white spaces
Left Patch Set: Created 7 years, 6 months ago
Right Patch Set: Created 7 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « Modules/Setup.dist ('k') | Parser/Python.asdl » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 All about co_lnotab, the line number table. 1 All about co_lnotab, the line number table.
2 2
3 Code objects store a field named co_lnotab. This is an array of unsigned bytes 3 Code objects store a field named co_lnotab. This is an array of unsigned bytes
4 disguised as a Python string. It is used to map bytecode offsets to source code 4 disguised as a Python string. It is used to map bytecode offsets to source code
5 line #s for tracebacks and to identify line number boundaries for line tracing. 5 line #s for tracebacks and to identify line number boundaries for line tracing.
6 6
7 The array is conceptually a compressed list of 7 The array is conceptually a compressed list of
8 (bytecode offset increment, line number increment) 8 (bytecode offset increment, line number increment)
9 pairs. The details are important and delicate, best illustrated by example: 9 pairs. The details are important and delicate, best illustrated by example:
10 10
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 5: else: 83 5: else:
84 6: print 2, 84 6: print 2,
85 85
86 which compiles to this: 86 which compiles to this:
87 87
88 2 0 SETUP_LOOP 19 (to 22) 88 2 0 SETUP_LOOP 19 (to 22)
89 >> 3 LOAD_FAST 0 (a) 89 >> 3 LOAD_FAST 0 (a)
90 6 POP_JUMP_IF_FALSE 17 90 6 POP_JUMP_IF_FALSE 17
91 91
92 3 9 LOAD_CONST 1 (1) 92 3 9 LOAD_CONST 1 (1)
93 12 PRINT_ITEM 93 12 PRINT_ITEM
94 94
95 4 13 BREAK_LOOP 95 4 13 BREAK_LOOP
96 14 JUMP_ABSOLUTE 3 96 14 JUMP_ABSOLUTE 3
97 >> 17 POP_BLOCK 97 >> 17 POP_BLOCK
98 98
99 6 18 LOAD_CONST 2 (2) 99 6 18 LOAD_CONST 2 (2)
100 21 PRINT_ITEM 100 21 PRINT_ITEM
101 >> 22 LOAD_CONST 0 (None) 101 >> 22 LOAD_CONST 0 (None)
102 25 RETURN_VALUE 102 25 RETURN_VALUE
103 103
104 If 'a' is false, execution will jump to the POP_BLOCK instruction at offset 17 104 If 'a' is false, execution will jump to the POP_BLOCK instruction at offset 17
105 and the co_lnotab will claim that execution has moved to line 4, which is wrong. 105 and the co_lnotab will claim that execution has moved to line 4, which is wrong.
106 In this case, we could instead associate the POP_BLOCK with line 5, but that 106 In this case, we could instead associate the POP_BLOCK with line 5, but that
107 would break jumps around loops without else clauses. 107 would break jumps around loops without else clauses.
108 108
109 We fix this by only calling the line trace function for a forward jump if the 109 We fix this by only calling the line trace function for a forward jump if the
110 co_lnotab indicates we have jumped to the *start* of a line, i.e. if the current 110 co_lnotab indicates we have jumped to the *start* of a line, i.e. if the current
111 instruction offset matches the offset given for the start of a line by the 111 instruction offset matches the offset given for the start of a line by the
112 co_lnotab. For backward jumps, however, we always call the line trace function, 112 co_lnotab. For backward jumps, however, we always call the line trace function,
113 which lets a debugger stop on every evaluation of a loop guard (which usually 113 which lets a debugger stop on every evaluation of a loop guard (which usually
114 won't be the first opcode in a line). 114 won't be the first opcode in a line).
115 115
116 Why do we set f_lineno when tracing, and only just before calling the trace 116 Why do we set f_lineno when tracing, and only just before calling the trace
117 function? Well, consider the code above when 'a' is true. If stepping through 117 function? Well, consider the code above when 'a' is true. If stepping through
118 this with 'n' in pdb, you would stop at line 1 with a "call" type event, then 118 this with 'n' in pdb, you would stop at line 1 with a "call" type event, then
119 line events on lines 2, 3, and 4, then a "return" type event -- but because the 119 line events on lines 2, 3, and 4, then a "return" type event -- but because the
120 code for the return actually falls in the range of the "line 6" opcodes, you 120 code for the return actually falls in the range of the "line 6" opcodes, you
121 would be shown line 6 during this event. This is a change from the behaviour in 121 would be shown line 6 during this event. This is a change from the behaviour in
122 2.2 and before, and I've found it confusing in practice. By setting and using 122 2.2 and before, and I've found it confusing in practice. By setting and using
123 f_lineno when tracing, one can report a line number different from that 123 f_lineno when tracing, one can report a line number different from that
124 suggested by f_lasti on this one occasion where it's desirable. 124 suggested by f_lasti on this one occasion where it's desirable.
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+