[New-bugs-announce] [issue17277] incorrect line numbers in backtrace after removing a trace function

Xavier de Gaye report at bugs.python.org
Fri Feb 22 17:42:49 CET 2013


New submission from Xavier de Gaye:

It seems that using f_trace in the f_lineno getter PyFrame_GetLineNumber(), as
the condition to decide when tracing is active, is incorrect.
See the following two examples.

In the backtrace printed by tracer.py running with python 3.3,
the last entry should be line 12 instead of line 10:

$ python3 /tmp/tracer.py
Traceback (most recent call last):
  File "/tmp/tracer.py", line 15, in <module>
    foo()
  File "/tmp/tracer.py", line 10, in foo
    bar()
ZeroDivisionError: division by zero


This simple case does not occur with pdb, because pdb takes care of deleting
the f_trace attribute of all the frames in the call stack when removing the
trace function (see set_continue() in bdb.py). But this is not good enough when
a generator is involved as can be seen when running generator.py. In the
backtrace the last entry should be line 6 instead of line 8:

$ python3 /tmp/generator.py
> /tmp/generator.py(16)<module>()
-> foo()
(Pdb) step
--Call--
> /tmp/generator.py(10)foo()
-> def foo():
(Pdb) step
> /tmp/generator.py(11)foo()
-> it = gen()
(Pdb) step
> /tmp/generator.py(12)foo()
-> next(it)
(Pdb) step
--Call--
> /tmp/generator.py(3)gen()
-> def gen():
(Pdb) return
--Return--
> /tmp/generator.py(8)gen()->0
-> yield i
(Pdb) step
> /tmp/generator.py(13)foo()
-> next(it)
(Pdb) continue
Traceback (most recent call last):
  File "/tmp/generator.py", line 16, in <module>
    foo()
  File "/tmp/generator.py", line 13, in foo
    next(it)
  File "/tmp/generator.py", line 8, in gen
    yield i
ZeroDivisionError: division by zero


It seems that it could be possible to fix this issue by replacing the test for
f->f_trace in PyFrame_GetLineNumber, by a test for f->f_tstate->use_tracing,
and updating accordingly the f_lineno and f_trace setters.

----------
components: Interpreter Core
files: tracer.py
messages: 182672
nosy: xdegaye
priority: normal
severity: normal
status: open
title: incorrect line numbers in backtrace after removing a trace function
type: behavior
versions: Python 2.7, Python 3.3, Python 3.4
Added file: http://bugs.python.org/file29162/tracer.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17277>
_______________________________________


More information about the New-bugs-announce mailing list