Debugging python extensions

Answered

I am developing a cpython extension implemented in C++ and wrapped with Pybind11. Then the compiled package is imported and used from a python interpreter. The tests/bug reproductions are in python as part of the project. Is there a way to debug the C++ when the extension is called from python script? 

2
8 comments
Avatar
Permanently deleted user

You can do this as long as the shared library is compiled in debug mode `-O0` (optimization zero).

 

The open a python repl, load your python file. Before executing the function you want to hook into open CLion, attach to the python repl process and set a breakpoint in your C Code. Go back to the repl, fire off the function and the debugger should hook in.

2
Avatar
Permanently deleted user

Thanks Joseph! This worked very well

0

Attaching Python process from Clion has been tricky and I have not been able to make it work. Is there a video demonstration?

0

Another link:

https://youtrack.jetbrains.com/issue/CPP-1313

Can .so files with O0 build be debugged now by Clion? I don't know how to set up a debug config for .so files.

0

>Attaching Python process from Clion has been tricky

You just need to choose Run | Attach to Process from the main menu and select the desired process (the python repl process launched in advance)More info: https://www.jetbrains.com/help/clion/attaching-to-local-process.html.

What difficulties have you faced?

-1

I have the .so compiled (cppimport, pybind11) and Pycharm debugging the code stopped at the line where I call the c++ function. Clion configured to attach to the python debug process but nothing happens. 

0

@Augusto Ballardini, sorry for the delay in response.

Clion configured to attach to the python debug process but nothing happens. 

Could you please elaborate on that? Is the debugger attached successfully in CLion?

The related web help article - https://www.jetbrains.com/help/clion/debugging-python-extensions.html#attach-py

0

Please sign in to leave a comment.