Error running cython debugger on Ubuntu

97 views
Skip to first unread message

Mohit Tiwari

unread,
Jul 20, 2022, 4:29:41 PM7/20/22
to cython-users

I’m trying to get cygdb running on Ubuntu 22.04 LTS by following the official docs. I’m getting errors like Cannot find bounds of current function when trying to step through the code.

I set up my environment by:

  1. Downloading the gdb-12.1 source code and running:

    ./configure --with-python=python2
    make
    sudo make install
    
  2. Creating the following files:
    cython_file.pyx:

def big_sum():
cdef int a[10000]

for i in range(10000):
a[i] = i
# <==================== I want to put a break here
cdef int my_sum
my_sum = 0
for i in range(1000):
my_sum += a[i]
return my_sum

if __name__ == "__main__":
print("Calling cython_file as main")
print(big_sum())

python_file.py:

import pyximport
pyximport.install()

from cython_file import big_sum

result = big_sum()
print(result)

setup.py:

from setuptools import Extension, setup
from Cython.Build import cythonize

setup(
    ext_modules = cythonize(
        Extension(
            "cython_file",
            ["cython_file.pyx"]),
            gdb_debug=True,

        ),
    extra_compile_args=["-g"],
)
  1. Running cython --gdb cython_file.pyx (from a Python3 virtual environment, so Python3 version of cython?)

  2. Running python3 setup.py build_ext --inplace

After performing these steps and running cygdb, I get error messages in this paste.

Does anyone know how to fix?


Stefan Behnel

unread,
Jul 21, 2022, 3:32:32 AM7/21/22
to cython...@googlegroups.com
Mohit Tiwari schrieb am 20.07.22 um 21:59:
> I’m trying to get cygdb running on Ubuntu 22.04 LTS by following the
> official docs
> <https://cython.readthedocs.io/en/latest/src/userguide/debugging.html>.

Those seem a bit outdated. Many (most?) Linux distributions, definitely
Ubuntu, come with Python 3 as default these days, and probably also have
gdb built for it. That means that you no longer have to do anything big to
get things working with Python 3, which most people use anyway.

I created a ticket for that:
https://github.com/cython/cython/issues/4911


> 1.
> Running cython --gdb cython_file.pyx (from a Python3 virtual
> environment, so Python3 version of cython?)
> 2.
> Running python3 setup.py build_ext --inplace

This looks like it's all using Python 3 then. That's good.


> After performing these steps and running cygdb, I get error messages in this
> paste <https://pastebin.com/vec5e3FP>.
>
> Does anyone know how to fix?

That looks like it worked. The only thing that's missing is debugging
symbols for your Python installation, so that gdb understands what's going
on inside of Python. Those come with the `python-gdb` package. (Add a 2 or
3 at your convenience.)

Stefan

Stefan Behnel

unread,
Jul 21, 2022, 3:34:55 AM7/21/22
to cython...@googlegroups.com
Stefan Behnel schrieb am 21.07.22 um 09:32:
> The only thing that's missing is debugging
> symbols for your Python installation, so that gdb understands what's going
> on inside of Python. Those come with the `python-gdb` package. (Add a 2 or
> 3 at your convenience.)

… where your most convenient "2 or 3" is probably 3. :)

Stefan

Mo Tiwari

unread,
Jul 22, 2022, 4:44:44 PM7/22/22
to cython-users
Thanks Stefan! I got it working. It seems I was only an inch away in my original approach!
Reply all
Reply to author
Forward
0 new messages