f_locals is NULL inside a method

P

Paul Drummond

Hi all,

I am developing a new python debugger which is coming on quite nicely
except that f_locals always becomes NULL when entering new functions.
Can anyone help with this? Someone else has posted earlier with a
similar problem but there are no replies. I can't understand why
f_locals would be NULL - it works fine at the module level but as soon
as I "step into" a function, the contents of frame->f_locals when
converted to a string is null. The conversion is as follows:

int tracer(PyObject*, PyFrameObject* frame, int what, PyObject* arg)
{
PyObject* locals = PyObject_Str(frame->f_locals);
std::cout << "LOCALS: " << PyString_AsString(locals) << std::endl;
Py_DECREF(locals);
}

Is there anything wrong with this or can I assume f_locals is actually
NULL?

Note: I have ran the same test module in PDB and it's f_locals is fine!
 
H

Howard

Paul Drummond said:
Hi all,

I am developing a new python debugger which is coming on quite nicely
except that f_locals always becomes NULL when entering new functions.

You don't provide any declaration for the class which contains this f_locals
variable, or a declaration for what that variable is. Perhaps you're just
encountering some problems with copy constructors?
Can anyone help with this? Someone else has posted earlier with a
similar problem but there are no replies. I can't understand why
f_locals would be NULL - it works fine at the module level but as soon
as I "step into" a function, the contents of frame->f_locals when
converted to a string is null. The conversion is as follows:

int tracer(PyObject*, PyFrameObject* frame, int what, PyObject* arg)
{
PyObject* locals = PyObject_Str(frame->f_locals);
std::cout << "LOCALS: " << PyString_AsString(locals) << std::endl;
Py_DECREF(locals);
}

Is frame->f_locals NULL immediately upon entering this function, or after
executing PyObject_Str (whatever that is)? Or does it just APPEAR to be
NULL when output via that PyString_AsString function?

We have no was of knowing what any of that code is doing, or how the data
was created or passed to this function, so it would be pretty hard to guess.
Note: I have ran the same test module in PDB and it's f_locals is fine!

I take it that's some kind of debugger? When you see the problem you're
describing above, how exactly are you determining that frame->f_locals is
NULL? Are you using another debugger? Perhaps it's a problem with that
debugger? No way for us to know, unfortunately.

-Howard
 
P

Paul Drummond

Hi Howard,

The tracer function is a callback provided by the python interpreter by
PyEval_SetTrace() and all parameters are provided by Python, hence the
problem - python is providing frame->f_locals as a null when it should
be a dictionary to all the current locals.

I have solved the problem anyway for anyone who is interested, a call
PyFrame_FastToLocals(frame) will update f_locals to be correct. As far
as I can tell you also need to call PyFrame_LocalsToFast(frame, 0) when
you are finished with f_locals.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top