简体   繁体   English

在Eclipse中调试混合的Python / C ++代码

[英]Debugging mixed Python/C++ code in Eclipse

I have a C++ project with a SWIG-generated Python front-end, which I build using CMake. 我有一个使用SWIG生成的Python前端的C ++项目,该项目是使用CMake构建的。 I am now trying to find a convenient way to debug my mixed Python/C++ code. 我现在试图找到一种方便的方法来调试混合的Python / C ++代码。 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. 我可以使用gdb来获取错误的堆栈跟踪记录,但是我想拥有一些更高级的功能,例如单步执行代码并设置断点的功能,例如使用Eclipse。

Using the Eclipse generator for CMake I am able to generate a project that I am able to import into Eclipse. 使用用于CMake的Eclipse生成器,我可以生成一个项目,可以将其导入到Eclipse中。 This works fine and I am also able to step through the pure C++ executables. 这可以正常工作,我也可以逐步完成纯C ++可执行文件。 But then the problem starts. 但是问题开始了。

First of all, I am not able to build the Python front-end from inside Eclipse. 首先,我无法从Eclipse内部构建Python前端。 From command line I just do "make python", but there is no target "python" in the Eclipse project. 在命令行中,我只是执行“ make python”,但是在Eclipse项目中没有目标“ python”。

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. 其次,一旦编译了Python前端,我就不知道如何逐步处理包含对包装的C ++类的调用的Python脚本。 Eclipse has debugging both for Python and for C++, but can they be combined? Eclipse已针对Python和C ++进行了调试,但是可以将它们组合在一起吗?

some more fancy features such as the ability to step through the code and set breakpoints, for example using Eclipse 一些更新颖的功能,例如单步执行代码和设置断点的能力,例如使用Eclipse

how are those features "fancy"? 这些功能如何“花哨”? You can already do those in pdb for Python, or gdb for C++. 您已经可以在Python的pdb或C ++的gdb中完成这些操作。

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. 我建议使用pdb运行python代码(或使用pdb.set_trace()在一个有趣的点中断执行),然后在单独的终端中将gdb附加到进程。 Use pdb to set breakpoints in, and step through, your Python code. 使用pdb在Python代码中设置断点并逐步执行。 Use gdb to set breakpoints in, and step through, your C++ code. 使用gdb在C ++代码中设置断点并逐步执行。 When pdb steps over a native call, gdb will take over. 当pdb结束本机调用时,gdb将接管。 When gdb continue allows Python execution to resume, pdb will take over. 当gdbcontinue允许continue执行Python时,pdb将接管。

This should let you jump between C++ and Python breakpoints without needing to trace through the interpreter. 这应该使您可以在C ++和Python断点之间跳转,而无需通过解释器进行跟踪。


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. 免责声明:我在很大程度上认为IDE是垃圾软件,因此,如果Eclipse 确实有很好的集成方式,那么我将一无所知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM