Skip to content

bpo-24565: f->f_lineno is now -1 when tracing is not set #12419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed

bpo-24565: f->f_lineno is now -1 when tracing is not set #12419

wants to merge 5 commits into from

Conversation

xdegaye
Copy link
Contributor

@xdegaye xdegaye commented Mar 18, 2019

This is a follow up on PR #6233 that has been closed after becoming from unknown repository.

The Python/ceval.c conflict in PR #6233 has been resolved and master merged into branch [bpo-24565](https://bugs.python.org/issue24565).

https://bugs.python.org/issue24565

xdegaye added 3 commits March 25, 2018 13:38
When tracing is set, f->f_lineno is valid for all the frames of the
stack except upon starting or resuming a frame where it is -1 until
the first call to maybe_call_line_trace().

Fix issues 7238, 16482, 17277 and 17697.
The coverage.py test suite expects f_lineno to be valid on trace call
events.
@blueyed
Copy link
Contributor

blueyed commented May 12, 2019

This has a (trivial?) conflict now due to 09532fe.

/cc @vstinner: maybe you can help get this merged? It fixes issues with wrong stack traces, especially when pdb / settrace is being used, and I've hoped for it to get into 3.7 already - let's not miss it for 3.8 also, please.

@blueyed
Copy link
Contributor

blueyed commented Dec 5, 2019

@xdegaye
Please fix conflicts again (I've done so manually for py38):

diff --cc Python/ceval.c
index 9f46b56fdd,3306fb9728..853b8b9881
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@@ -4467,8 -4596,7 +4597,8 @@@ call_trace_protected(Py_tracefunc func
  {
      PyObject *type, *value, *traceback;
      int err;
 +    frame->f_lineno = PyFrame_GetLineNumber(frame);
-     PyErr_Fetch(&type, &value, &traceback);
+     _PyErr_Fetch(tstate, &type, &value, &traceback);
      err = call_trace(func, obj, tstate, frame, what, arg);
      if (err == 0)
      {
@@@ -4574,7 -4706,10 +4708,11 @@@ PyEval_SetProfile(Py_tracefunc func, Py
  void
  PyEval_SetTrace(Py_tracefunc func, PyObject *arg)
  {
+     if (PySys_Audit("sys.settrace", NULL) < 0) {
+         return;
+     }
+
 +    PyFrameObject *f;
      _PyRuntimeState *runtime = &_PyRuntime;
      PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
      PyObject *temp = tstate->c_traceobj;

@xdegaye xdegaye closed this Dec 10, 2019
@xdegaye xdegaye deleted the bpo-24565 branch December 10, 2019 12:23
@blueyed
Copy link
Contributor

blueyed commented Dec 14, 2019

@xdegaye
Are you giving up? (which I could understand, but would be a pity really)

@blueyed
Copy link
Contributor

blueyed commented Dec 29, 2020

Related: https://www.python.org/dev/peps/pep-0626/
Implemented for Python 3.10 (in 877df85).

@xdegaye xdegaye mannequin mentioned this pull request Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants