This project has moved. For the latest updates, please go here.

Debugging python scripts which are called from C++ VS project

Apr 15, 2015 at 4:03 PM

I am currently working on a VS C++ project. On occasion we call external Python scripts to perform some routines for us. Currently we do not have a way to use the debugger on our Python code, i.e. we cannot make the transition from debugging in C++ to debugging in Python as well.

Having looked at the capabilities of the PTVS mixed-mode debugging, I was wondering if this might be possible. The PTVS documentation explains how to set up everything to debug C++ code which is called from Python where the Python code is part of a VS project. Our case is different as we call Python (which is not part of a VS project) from C++.

Does anyone know if mixed-mode debugging is possible for our case? And if yes, what are the steps to make it work?

Many thanks for your help and best regards,

Apr 15, 2015 at 4:39 PM
It is possible - it doesn't really matter which code calls which to get to the state where you have both on the stack, the debugger can handle it.

The only tricky part there is starting debugging. When you have a Python project as your entry point, you can just set the "Enable native debugging" option in project settings. C++ projects, on the other hand, don't know anything about Python, and so for them the equivalent setting only covers .NET. However, you can always select an arbitrary assortment of debug engines when attaching to a process using Debug -> Attach. So if you start your C++ project without debugging, and then do Debug -> Attach and manually select both Native and Python in Code Types, everything should work.