Cython debugging, put a break point

后端 未结 1 1116
小蘑菇
小蘑菇 2021-02-05 16:37

I am trying to use cython debugger to put in a break point:

Here is my code:

cython_file.pyx

cimport cython

def big_sum():
             


        
相关标签:
1条回答
  • 2021-02-05 16:55

    I believe you are setting the breakpoint correctly. The cython_file.so shared library created by cython isn't loaded by the interpreter until the module is imported. So the pending gdb breakpoint is fine as gdb will set this breakpoint when cython_file.so is dynamically loaded.

    UPDATE 1: I did modify the setup.py slightly from what was posted. I based my setup.py on these cython debugging instructions... the main difference being the use of cythonize:

    setup.py

    from distutils.core import setup
    from distutils.extension import Extension
    from Cython.Build import cythonize
    
    setup(
        extensions = [Extension('cython_file', ["cython_file.pyx"])],
        ext_modules=cythonize(Extension("cython_file", ["cython_file.pyx"]),
                              gdb_debug=True)
    )
    

    UPDATE 3: For reference, here are the commands I used to get setup. They differ slightly from those posted in the question as I didn't add the --pyrex-gdb option when running setup.py:

    $ ls
    cython_file.pyx  python_file.py  setup.py
    $ cython --gdb cython_file.pyx 
    $ python setup.py build_ext --inplace
    

    UPDATE 2: Here is my sample cygdb session using your files, first I let python_file.py run to completion and then I set the breakpoint and re-ran:

    drew@ubuntu:~/stackoverflow/21033553-cython$ cygdb .
    
    GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
    Copyright (C) 2012 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "x86_64-linux-gnu".
    For bug reporting instructions, please see:
    <http://bugs.launchpad.net/gdb-linaro/>.
    Install pygments for colorized source code.
    Python was not compiled with debug symbols (or it was stripped). 
    Some functionality may not work (properly).
    (gdb) cy run python_file.py
    499500
    
    (gdb) cy break cython_file.big_sum
    Breakpoint 1 at 0x7ffff5db0270: file cython_file.c, line 435.
    No frame is currently selected.
    (gdb) cy run python_file.py
    3    def big_sum():
    (gdb) cy break :10
    Breakpoint 2 at 0x7ffff5db02a6: file cython_file.c, line 468.
    (gdb) cy cont
    11        for i in range(1000):
    (gdb) cy list
         6        for i in range(10000):
         7            a[i] = i
         8        # <==================== I want to put a break here
         9        cdef int my_sum
        10        my_sum = 0
    >   11        for i in range(1000):
        12            my_sum += a[i]
        13        return my_sum
        14    
    
    0 讨论(0)
提交回复
热议问题