简体   繁体   中英

How to debug a DLL in Visual Studio that I call from Python using ctypes?

I am coding a C++ DLL in Visual Studio that I call from Python using ctypes. Calling the functions and returning the results works just fine. However, I haven't figured out how to debug the C++ code while it's being called from Python. I did the obvious thing, ie started debugging the Python code (currently using PyScripter but that's not set in stone), and then attached the VS debugger to the Python process. I also checked the process ID in TaskManager to make sure I attach to the correct process. This seems to work, ie VS doesn't complain, the break points in the C++ code remain full red dots (meaning the breakpoints can be hit), and the "Detach..." command in the Debug menu is active. However, when the Python eventually calls one of the C++ functions, the break point is not hit. The function returns the correct result, but execution does not halt at the break point. Has anybody got experience in this and could help me? Thanks!

The documentation page for mixed-mode debugging spells it out in detail, but the short version is:

When you have a Project

Open Project Properties, switch to the Debug tab, and select Enable native code debugging . Now when you press F5 you will be in a mode that lets you debug both Python and C/C++ code naturally.

When you attach to a running process

Before attaching, click the Select button to select debugging engines. You will want to select both Native and Python together (by default, it will select only Python if it detects Python in the process).

Microsoft文档中“选择代码类型”对话框的屏幕截图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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