I have the following three files:
$ cat fib.pyx
#cython: language_level=3
def fibonacci(n):
cdef int a, b, i
a, b = 1, 1
for i in range(1, n):
a, b = b, a+b
return b
$ cat t.py
from fib import fibonacci
print(fibonacci(10))
$ cat setup.py
from setuptools import setup
from Cython.Build import cythonize
from setuptools import Extension, setup
extensions = [
Extension(
"fib",
["fib.pyx"],
extra_compile_args=["-g"],
)
]
setup(
name="source",
ext_modules=cythonize(
extensions, gdb_debug=True
),
)
I then run
python setup.py build_ext --inplace -f --debug
cygdb
Then, inside cygdb:
warning: .cygdbinit: No such file or directory
(gdb) cy break fibonacci
Function "__pyx_pw_3fib_1fibonacci" not defined.
Breakpoint 1 (__pyx_pw_3fib_1fibonacci) pending.
(gdb) cy run t.py
Warning: 'set logging on', an alias for the command 'set logging enabled', is deprecated.
Use 'set logging enabled on'.
Breakpoint 1, __pyx_pw_3fib_1fibonacci (__pyx_self=0x0, __pyx_v_n=10) at fib.c:1218
1218 static PyObject *__pyx_pw_3fib_1fibonacci(PyObject *__pyx_self, PyObject *__pyx_v_n) {
2 def fibonacci(n):
(gdb) cy print locals
Python Exception <class 'AttributeError'>: 'PyDictObjectPtr' object has no attribute 'items'
Error occurred in Python: 'PyDictObjectPtr' object has no attribute 'items'
What does this error mean? I was expecting it to print out the value of n. Am I running it correctly? Have I passed the right arguments to cythonize?
I'm running Ubuntu 22.04.1 via WSL2
Python 3.8.14
Cython 0.29.32
gdb 12.0.90
I've also done sudo apt install python3.8-dbg