This project has moved and is read-only. For the latest updates, please go here.


Stepping into ctypes call does not end up in C++


I'm using Python Tools for Visual Studio Express 2013. I can't do the c++ debugging of an extension. I've already enabled native code debugging. My doubt is how to link the 2 projects (c++ and python)? The c++ library is loaded in this way in python (3.4 - 64bit):
cpplib = ctypes.cdll.LoadLibrary(CPPLIB_PATH)
During the debugging I arrive to this point in the python execution:
def update(self, dtrain):
        """ update """
        assert isinstance(dmatr, DMatrix)
        cpplib.Update( self.handle, dtrain.handle )
then I see that Visual Studio opens
 def __getattr__(self, name):
        if name.startswith('__') and name.endswith('__'):
            raise AttributeError(name)
        func = self.__getitem__(name)
        setattr(self, name, func)
        return func
and finally it opens the disassemby instead of a proper c++ debug environment... :-(

Screenshot of call stack:

file attachments

Closed Apr 11, 2015 at 8:28 PM by pminaev


giuliohome wrote Aug 11, 2014 at 10:41 AM

You can find also other comments in my question on SO

pminaev wrote Aug 11, 2014 at 4:46 PM

In SO comments, you mentioned that you have a C++ breakpoint on the other side. Does it show up as bound (i.e. solid red) in VS before stepping in?

Also, you mentioned that trying to step through that thunk landed you somewhere inside clr.dll machinery, and that one of the functions is IJWNOADThunk::FindThunkTarget. Is the DLL that you're trying to call compiled with Managed C++, or with C++/CLI?

giuliohome wrote Aug 11, 2014 at 5:46 PM

The C++ dll is compiled with VS Express 2013.
BP is not solid if debugger support type is auto,
but if I change it to managed it becomes solid...
I assume I have cli/c++ but I'm not sure and
if you can point me to a brief example of code
that is called by python ctypes and it is debugged by PTVS,
I would appreciate and double check everything :)

pminaev wrote Aug 13, 2014 at 12:40 AM

This does seem to indicate that it is managed.

Note that if you're attaching to your process using automatic code type detection, it will default to "Python" only, so you won't be debugging C++ at all. To enable mixed-mode, you must manually check "Python" and the other code types that you want to debug - but, at the very minimum, you always need "Native" to be checked. So in your case, if the DLL is compiled as native, then you need to select Python+Native. If it's compiled as managed, then you need to select Python+Native+Managed.

giuliohome wrote Aug 13, 2014 at 2:01 AM

Find attached the debugger types available on Visual Studio Express 2013:

only native
only managed
only gpu

I think I've tried more or less all of them many times...
Sorry, I can't see the possibility to select Python+Native+Managed.
Please help, thanks

giuliohome wrote Aug 13, 2014 at 2:06 AM


pminaev wrote Oct 1, 2014 at 4:15 AM

This will only work when attaching to a process via Debug -> Attach (you can select whatever debug engines you want there). When launching a process, you are limited to the debug engines that this particular project system (in your case, C++) saw fit to list.

giuliohome wrote Oct 1, 2014 at 5:18 AM

I remember that in facy I could step into c++ when attaching to the process.
But this is something that would work even without pytools, wouldn't it?
Furthermore it appears that python3 code is not in the call stack so actually I could not step from python to c++ ...

giuliohome wrote Oct 1, 2014 at 5:22 AM

I meant "in fact" (sorry for the typo) I could break into c++ (but not passing from python 3 64bit code to c++ code)

pminaev wrote Apr 10, 2015 at 9:07 PM

When you were attaching, did you select the code types manually (Python+Native+Managed)?

giuliohome wrote Apr 11, 2015 at 4:57 PM

Oh ... the issue is a bit old, however this is what I did:


but I can't see the python source in the stack

giuliohome wrote Apr 11, 2015 at 5:12 PM

Oh... Yes, I could do that now!!!

Thank you :-)


pminaev wrote Apr 11, 2015 at 8:27 PM

Awesome! :)