Oct-13-2021, 01:55 PM
I've been trying to track down an issue with some Python code compiled from C (using swig). I've spent days trying to debug this in the python debugger and gdb, and I have hit a wall
Any sort of hint as to what else to look at would be greatly appreciated.
The following information was retrieved by executing gdb using python3-dbg (python version 3.8).
Python crashes with this error:
Fatal Python error: deallocating None
Python runtime state: initialized
The offending line of python code on the call stack is:
The first call to none_dealloc in the stack trace is here:
#26 0x000000000046ef6e in none_dealloc (ignore=<optimized out>) at ../Objects/object.c:1585
#27 0x00000000004706da in _Py_Dealloc (op=<optimized out>) at ../Objects/object.c:2215
#28 0x00000000004470e8 in _Py_DECREF (op=<optimized out>, lineno=430, filename=0x699244 "../Objects/frameobject.c") at ../Include/object.h:478
#29 frame_dealloc (f=0x25938d0) at ../Objects/frameobject.c:430
#30 0x00000000004706da in _Py_Dealloc (op=op@entry=0x25938d0) at ../Objects/object.c:2215
#31 0x00000000004e02e6 in _Py_DECREF (op=0x25938d0, lineno=4314, filename=0x6e3343 "../Python/ceval.c") at ../Include/object.h:478
#32 _PyEval_EvalCodeWithName (_co=0x7fdc678c0520, globals=<optimized out>, locals=locals@entry=0x0, args=<optimized out>, argcount=2, kwnames=0x0, kwargs=0x7fdc6468cf90, kwcount=<optimized out>, kwstep=1, defs=0x7fdc678bf6f8, defcount=1, kwdefs=0x0, closure=0x0, name=0x7fdc67d0c270, qualname=0x7fdc678c2280) at ../Python/ceval.c:4314
This is confusing to me since since the Python code initiating the dealloc at frameobject.c 430 in Python 3.8 is:
The last thing that I feel like I could try is compiling a flavor of python-dbg without optimization so I can look further into some of the things that gdb says are "optimized out". Is there anything else I can try?

The following information was retrieved by executing gdb using python3-dbg (python version 3.8).
Python crashes with this error:
Fatal Python error: deallocating None
Python runtime state: initialized
The offending line of python code on the call stack is:
value = self.get(name)(The value of name should be a valid string)
The first call to none_dealloc in the stack trace is here:
#26 0x000000000046ef6e in none_dealloc (ignore=<optimized out>) at ../Objects/object.c:1585
#27 0x00000000004706da in _Py_Dealloc (op=<optimized out>) at ../Objects/object.c:2215
#28 0x00000000004470e8 in _Py_DECREF (op=<optimized out>, lineno=430, filename=0x699244 "../Objects/frameobject.c") at ../Include/object.h:478
#29 frame_dealloc (f=0x25938d0) at ../Objects/frameobject.c:430
#30 0x00000000004706da in _Py_Dealloc (op=op@entry=0x25938d0) at ../Objects/object.c:2215
#31 0x00000000004e02e6 in _Py_DECREF (op=0x25938d0, lineno=4314, filename=0x6e3343 "../Python/ceval.c") at ../Include/object.h:478
#32 _PyEval_EvalCodeWithName (_co=0x7fdc678c0520, globals=<optimized out>, locals=locals@entry=0x0, args=<optimized out>, argcount=2, kwnames=0x0, kwargs=0x7fdc6468cf90, kwcount=<optimized out>, kwstep=1, defs=0x7fdc678bf6f8, defcount=1, kwdefs=0x0, closure=0x0, name=0x7fdc67d0c270, qualname=0x7fdc678c2280) at ../Python/ceval.c:4314
This is confusing to me since since the Python code initiating the dealloc at frameobject.c 430 in Python 3.8 is:
/* Kill all local variables */ valuestack = f->f_valuestack; for (p = f->f_localsplus; p < valuestack; p++) Py_CLEAR(*p);The definition of Py_CLEAR checks for NULL before trying to deallocate the pointer. NULL is the same as "None", right? When I look at the value of op or _py_tmp in the call stack, it reads as "optimized out".
#define Py_CLEAR(op) \ do { \ PyObject *_py_tmp = _PyObject_CAST(op); \ if (_py_tmp != NULL) { \ (op) = NULL; \ Py_DECREF(_py_tmp); \ } \ } while (0)I get the feeling though that something in my code is corrupting a pointer within Python scope. This error is pretty repeatable - it usually happens while processing the same set of data.
The last thing that I feel like I could try is compiling a flavor of python-dbg without optimization so I can look further into some of the things that gdb says are "optimized out". Is there anything else I can try?