Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging mixed Python/C++ code in Eclipse

I have a C++ project with a SWIG-generated Python front-end, which I build using CMake. I am now trying to find a convenient way to debug my mixed Python/C++ code. I am able to get a stack-trace of errors using gdb, but I would like to have some more fancy features such as the ability to step through the code and set breakpoints, for example using Eclipse.

Using the Eclipse generator for CMake I am able to generate a project that I am able to import into Eclipse. This works fine and I am also able to step through the pure C++ executables. But then the problem starts.

First of all, I am not able to build the Python front-end from inside Eclipse. From command line I just do "make python", but there is no target "python" in the Eclipse project.

Secondly, once I've compiled the Python front-end, I have no clue how to step through a Python script that contains calls to my wrapped C++ classes. Eclipse has debugging both for Python and for C++, but can they be combined?

like image 294
Joel Avatar asked Nov 01 '12 13:11

Joel


People also ask

How do I debug Python code 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.


1 Answers

some more fancy features such as the ability to step through the code and set breakpoints, for example using Eclipse

how are those features "fancy"? You can already do those in pdb for Python, or gdb for C++.

I'd suggest running the python code with pdb (or using pdb.set_trace() to interrupt execution at an interesting point), and attach gdb to the process in a separate terminal. Use pdb to set breakpoints in, and step through, your Python code. Use gdb to set breakpoints in, and step through, your C++ code. When pdb steps over a native call, gdb will take over. When gdb continue allows Python execution to resume, pdb will take over.

This should let you jump between C++ and Python breakpoints without needing to trace through the interpreter.


Disclaimer: I largely think IDEs are rubbish bloatware, so if Eclipse does have a good way to integrate this, I wouldn't know about it anyway.

like image 151
Useless Avatar answered Oct 03 '22 21:10

Useless