Debug C-library from Python (ctypes)

前端 未结 2 942
生来不讨喜
生来不讨喜 2021-02-19 21:00

I have a Python-program that uses ctypes and a C-shared library (dll-file). As an IDE, I am using Eclipse, where both projects will be developed (the C-shared library and the py

2条回答
  •  伪装坚强ぢ
    2021-02-19 21:27

    Actually, it is a fairly simple thing to do using the CDT and PyDev environments in Eclipse.

    I assume here that you have already configured the projects correctly, so you can build and debug each one seperately.

    Basically, you simply need to start the Python project in Debug mode and then to attach the CDT debugger to the running python process. To make it easier I'll try to describe it step by step:

    1. Run your Python project in debug mode. Put a breakpoint somewhere after the loading of the dll using ctypes. Make note of the pid of the python process created (you should see a first line in the console view stating the pid. something like: pydev debugger: starting (pid: 1234))

    2. Create a Debug configuration for your CDT project, choosing the type "C/C++ Attach to Application". You can use the default configuration.

    3. Debug your project using the configuration you've created. A window should appear, asking you which process you want to attach to. Choose the python process having the right pid.

    4. You can now add breakpoints to you C code.

    You'll have two debuggers in the debug perspective, as if they were two different processes. You should always make sure the C/C++ debugging session is running when you work with the python debugger - as long as the C/C++ debugging session is suspended, the python debugger will be unresponsive.

提交回复
热议问题