简体   繁体   English

调试从Eclipse中的python脚本运行的C ++代码

[英]Debug C++ code running from python script in Eclipse

I have a C++ project and a python script that calls .exe file. 我有一个C ++项目和一个调用.exe文件的python脚本。 I set breakpoints in one of cpp files, but they are not hit. 我在一个cpp文件中设置了断点,但是没有命中。 I can't even go into this C++ project. 我什至不能进入这个C ++项目。 I found similar question here, but for Visual Studio: Debug C++ code in visual studio from python code running in eclipse 我在这里找到了类似的问题,但对于Visual Studio: 从eclipse中运行的python代码在 Visual Studio中调试C ++代码

Is there a similar way to do this trick in Eclipse? 在Eclipse中,有没有类似的方法可以做到这一点? Or is there some other approriate way to debug C++ code, which is called from another process? 还是还有其他一些合适的方法来调试C ++代码(从另一个进程调用)? I tried to attach to the process, but the problem is that, after script makes call, child process finishes very fast and I can't catch its pid. 我尝试附加到该进程,但是问题是,在脚本进行调用之后,子进程非常快速地完成,并且我无法捕获其pid。

To debug the executable, use the DebugBreak function in place of a breakpoint in your program. 若要调试可执行文件,请使用DebugBreak函数代替程序中的断点。 So in your C++ code, call DebugBreak somewhere in your program, preferably near the beginning -- this will serve as the breakpoint. 因此,在您的C ++代码中,最好在程序的某个位置(最好在开头附近)调用DebugBreak -这将作为断点。

What will happen is that when your C++ executable runs from Python, your C++ executable will "crash" (not really crash, but it will seem like it did). 将会发生的是,当您的C ++可执行文件从Python运行时,您的C ++可执行文件将“崩溃”(不是真正崩溃,但看起来确实如此)。 What really is happening is that the DebugBreak function was called. 真正发生的是调用了DebugBreak函数。

After the Windows OS goes through its set of message boxes saying "your application has something wrong with it" (note that there really is nothing wrong with the program), you are then given the option to debug it. Windows操作系统浏览完一组消息框,说“您的应用程序有问题”(请注意,程序确实没有问题)后,您可以选择调试它。 Choose the "debug" option, the debugger you want to use (which will be Visual Studio), and you should be able from that point on to single step through your C++ code. 选择“调试”选项,选择要使用的调试器(将是Visual Studio),从那时起,您应该可以单步执行C ++代码。

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

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