Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging a Python Extension in Eclipse

I have a Python extension that I have successfully built and used on Windows, OSX, and linux. I now need to be able to debug this Python extension. I am averse to the use of gdb at the command line, so I would really like to get this to work in Eclipse.

To begin with, I did my best to follow the instructions in http://www.heikkitoivonen.net/blog/2008/07/21/debugging-python-extension-written-in-c-with-eclipse/, and I added the folder for the Python source as well as the folder for the python extension code as source folders to the empty project. Since it is relatively easy to get debug builds of everything required on linux, I started out with the debug development in Ubuntu.

Once I got a debug build of python (lets call it python_d), I ran the setup.py for my extension with

python_d setup.py build 

which should also yield a debug build of the extension module. I have verified that symbols are being exported by opening the extension as an application in Eclipse and I can see the source code linked with the Python shared object.

Now if I create another project in Eclipse with the folder of my code, and add a breakpoint in the source that is used to create the extension, it doesn't stop at the breakpoint. It is entirely possible that I am missing something rather critical here, but for the life of me I can't get it to work. The crux of the problem is:

How can you get Eclipse to stop at a breakpoint in a Python extension module?

like image 698
Ian Bell Avatar asked May 31 '11 05:05

Ian Bell


People also ask

How do I debug a Python extension?

In order to debug the C/C++ code of an extension, you need to use the native debugger, GDB or LLDB, and debug the interpreter process that loads your script and runs the application. For that, you can either attach to a running Python process or debug a properly configured Custom Build Application.

How do I debug a Python program in Eclipse?

To open the debugger, you need to open the “Debug” perspective. You can do this by selecting “Window → Open Perspective → Other…” from the main menu. In the popup window that appears, select “Debug” and click on the “OK” button. Now, the Eclipse environment changes a little and looks like the one shown in Figure 4.

How do I open a .PY file in Eclipse?

Running Python from within Eclipse Make sure your file ends in . py, and Eclipse will recognize it as Python code. Type in some Python code (for instance: print 2+2 ), then right-click on the Python file you've created and select Run As >> Python run .

How do I open PyDev in Eclipse?

Go to Window → Open Perspective → Other and choose PyDev, then click OK. If you look at the upper right corner you will see that the perspective has changed from "Java" to "PyDev".


1 Answers

Which compiler are you using, MSVC or GCC? For MSVC, you can start python first, and attach the python_d.exe (windbg or visual studio), then you can load your module, setup the breakpoint, you can verify whether your module's symbol got loaded in the debug->module windows (MSVC).

like image 95
kxn Avatar answered Sep 22 '22 22:09

kxn