Debugging mixed python/FORTRAN code on windows gives exception

Aug 7, 2013 at 2:37 PM
I'm having problems debugging mixed python/intel fortran code.

Python 2.7.3

Start debugging of python application results in Unhandled exception:

Unhandled exception at 0x1E017915 (python27.dll) in python.exe: 0xC0000005: Access violation reading location 0x1013364C.

Stack Trace:
[Native to Python Transition]   
msvcr90.dll!<Unknown function> Unknown
[Python to Native Transition]   
[Native to Python Transition]   
msvcr90.dll!<Unknown function>  Unknown
[Python to Native Transition]   
[Native to Python Transition]   
msvcr90.dll!<Unknown function>  Unknown
msvcr90.dll!<Unknown function>  Unknown
msvcr90.dll!<Unknown function>  Unknown
[Python to Native Transition]   
[Native to Python Transition]   
python.exe!pre_cpp_init() Line 330  C
msvcr90.dll!<Unknown function>  Unknown
python.exe!__tmainCRTStartup() Line 586 C
kernel32.dll!<Unknown function> Unknown
ntdll.dll!<Unknown function>    Unknown
ntdll.dll!<Unknown function>    Unknown

Any tips on how to find out what goes wrong?

When I try to debug python test which calls native DLL (fortran) it does not step into native code at all.
Aug 7, 2013 at 2:44 PM
... it happens in any new python applications after "Enable native code debugging" is checked".
Coordinator
Aug 7, 2013 at 4:44 PM
This is not something that we've run into before, and so I will need more information to debug this. Can you do this on a minimal repro (which I assume is an empty .py file?), capture a crash dump of the debugged process (when VS breaks on exception, do Debug -> Save Dump As), and upload it here?

I also wonder if it still crashes if you attach to the running process (Debug -> Attach to Process, and select both Python and Native in "Attach To" box) instead of launching it.
Coordinator
Aug 7, 2013 at 5:11 PM
i can get us an intel fortran vs plug-in if need be. lmk.
Coordinator
Aug 7, 2013 at 5:16 PM

He says it repros on any Python project, not just his. Judging by the callstack, it didn’t even get to executing any Python code yet, much less calling out to FORTRAN – it’s actually doing CRT initialization at this point…

Aug 7, 2013 at 7:13 PM
The problem (exception) is gone after upgrade to 2.7.5.
Coordinator
Aug 7, 2013 at 8:06 PM
Thank you for reporting this - I was able to reproduce the issue on 2.7.3. It looks like we're running into an issue (?) with the native debugger where it can't read some data inside the Python process when trying to parse frames. I doubt that we can fix this at this point, but we can certainly add a version check.
Coordinator
Aug 7, 2013 at 8:10 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Aug 7, 2013 at 8:12 PM
By the way, I would love to hear more about your experience with FORTRAN debugging. While we haven't anticipated that use case and haven't tested it, due to the way debugger it designed, I would expect it to work, sans C++-specific features (i.e. [C++ view] and [Python view] nodes). Does stepping from Python to FORTRAN and back work well for you?
Aug 7, 2013 at 9:18 PM
After some experiments with chdir in my code (changed the current directory to the location of dll before LoadLibrary call) it seems that debugging into fortran code works as well, thank for the tips!

Unfortunately, native debugging does not work during tests debugging. Does it skip python project option "Enable native code debugging"?

... a dream: make tests/refactor python code work using ReSharper :)
Coordinator
Aug 7, 2013 at 9:51 PM
It's great to hear that debugging is working for you!

Yes, this checkbox is pretty much ignored by "Debug Tests", so you always get the regular Python debugger. VS extensibility story for unit tests is rather convoluted at the moment, and when we implemented them we didn't think this could be made to work. After some investigation now, it looks like this is doable at least on VS 2013+ - so go ahead and open a feature request in the tracker, and we'll see where it fits in our schedule.

In the meantime, keep in mind that you can use "Run Tests" in combination with Attach to Process to enable native debugging. Of course, for this, you'd need to pause the test process so that you can attach to it - e.g. by placing input() in your setUp method.
Aug 7, 2013 at 10:32 PM
input in setUp and attach should work for a time being, thanks.