Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 562
Itamar Katz Avatar asked Apr 08 '26 09:04

Itamar Katz


1 Answers

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.

like image 167
kenny-liu Avatar answered Apr 10 '26 22:04

kenny-liu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!