Debugging cythonized using visual studio 2022

I have the line:
j = 99

and the below variable exists in the locals window but I cannot find the value 99 anywhere in this object; where would I need to look for that?

Ronny

Document

Oh, for that you need to understand how to inspect PyObject values. This is fairly deep and complicated stuff, so generally it’s easiest to focus on the control flow when debugging C code (e.g. watch where it branches to figure out what may be going wrong).

For some (mostly older) versions of Python, Visual Studio supports mixed-mode debugging, which knows how to do this for you and can show you the actual value. It’s very neat how it works, but unfortunately they think that many VS users don’t care about it and so it hasn’t been updated for a while. I think Python 3.9 is the last version that works properly.

The problem is I need to inspect the values of complex objects, and analyzing the control flow isn’t going to help me here. Rolling back to python 3.9 is also not possible due to 3rd party packages requiring newer versions of python.

Any suggestions?

Only to modify the code to either print the values that you need, or to inspect the memory manually.

I suspect you won’t, but just for completeness, you could also get the code for Visual Studio’s Python support from GitHub - microsoft/PTVS: Python Tools for Visual Studio and contribute the updates needed for mixed-mode debugging to work with newer versions.

Print statements are likely the way for you to go.

What will the PTV package provide? Will it allow me to inspect variables?

If you’re getting Python syntax highlighting and regular debugging in Visual Studio, it’s because you’ve installed PTVS. Years ago it wasn’t included in VS, but these days it is. It’s still open source though, so you can contribute if you like.

Ok, thanks.