Itamar Katz
Itamar Katz

Reputation: 9655

Eclipse: debug shared library loaded from python

In Linux, I am trying to debug the C++ code of a shared library which is loaded from Python code. The loading is done using the ctypes package. In Eclipse, I set breakpoints both in the Python and in the C++ code, however Eclipse just skips the breakpoints in the C++ code (breakpoints in the Python code work OK).

I have tried using attach to application in Eclipse (under Debug Configurations) and choosing the Python process, but it didn't change anything. In the attach to application dialog box I choose the shared library as the Project, and I choose /usr/bin/python2.6 as the C/C++ application. Is that the correct way?

I've tried it both before running the python code, and after a breakpoint in the Python code was caught, just before the line calling a function of the shared library.

EDIT

Meanwhile I am using a workaround of calling the python code and debugging using a gdb command-line session by attaching to the python process. But I would like to hear a solution to doing this from within Eclipse.

Upvotes: 3

Views: 3644

Answers (1)

kenny-liu
kenny-liu

Reputation: 309

I have been able to debug the c++ shared library loaded by the python in Eclipse successfully.

The prerequisites: Two eclipse projects in an eclipse workspace: one is the C++ project, from which the c++ shared library is generated, the other is the python project (PyDev), which loads the generated c++ shared library.

The steps are:

  1. create a "Python Run" debug configuration named PythonDebug with the corresponding python environment and parameters
  2. create a "C/C++ Attach to Application" debug configuration named CppDebug. The project field is the C++ project, leave the C/C++ Application field empty
  3. set a breakpoint in python code where after the c++ shared library has already been loaded
  4. start the debug session PythonDebug, the program will be breaked at the created breakpoint at step 3
  5. start the debug session CppDebug, a menu will be popped up, select python process with correct pid (there will be 3 pids, the correct one can be found in PythonDebug session)
  6. set a breakpoint in c++ source code where you want the program to break
  7. continue the PythonDebug session
  8. continue the CppDebug session
  9. the program will break at the c++ breakpoint

I tested the above procedure with Eclipse Mars version.

Hopefully it helps.

Upvotes: 2

Related Questions