Sakuragaoka
Sakuragaoka

Reputation: 177

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, i.e. 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, i.e. 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!

Upvotes: 3

Views: 3748

Answers (1)

Zooba
Zooba

Reputation: 11438

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).

Screen shot of the Select Code Type dialog from Microsoft's documentation

Upvotes: 2

Related Questions