Hello, I am Patrick Nelson, a developer on the Visual Studio Debugger Team.
Authoring apps that are using more than one language is not uncommon these days. For example, some developers prefer one language for the UI layer but use another language (or reuse components in another language) for their business logic. When debugging such apps, most of the time you are either debugging one language or the other (and you select which debugger type you want to use through the project properties), but sometimes you need to have the debugger attached to both. In other words, you want to be using both debugger engines at the same time. It is for this reason that in VS2012 Update 1 we enabled and blogged about interop debugging between Managed and Native code in the same app.
- This feature is only present in Visual Studio 2013 it was removed in Visual Studio 2015
- The feature only works when debugging on Windows 8.1, it does NOT work on Windows 10
Visual Studio 2012 workaround
Before delving into the VS2013 experience, it is worth pointing out that even with Visual Studio 2012, it is possible to debug both code types of the same app simultaneously by starting debugging in one instance of Visual Studio, and then opening another instance of Visual Studio to attach to the same process but with a different debug engine selected (in the project properties)
There are some disadvantages to using this workaround including:
- You need to have two instances of Visual Studio running
- Breakpoints have to be set in the correct instance of Visual Studio
Visual Studio 2013 experience
To select this new debugger type, go to project properties –> debugging and for “Debugger Type” select “Native with Script”
Now when you start debugging, you’ll notice the active script documents load in the solution view as they do when Script debugging:
A Concrete Example
Say we are debugging an app that crashes on startup. If we debug it with Script Only, all we see is an unhandled exception in WWAHost and the Visual Studio Just-In-Time debugger:
If we debug with Native only, we get a bit more information. We see a divide by zero first chance exception in FolderInfo.h by looking at the Output window. To see why we are getting the divide by zero error, we can temporarily enable break on divide by zero exception via Debug -> Exceptions:
Running it again with break on first chance exceptions thrown, we see the divide by zero error is being caused because m_ImageList->Size is zero. Unfortunately, the deep call stack provides no clue as to how we got here except that we came from jscript9.dll:
Here we see that the folder we are looking at is “Pictures” and there are no images in that folder. This is the cause of the divide be zero error. If we add a picture to the pictures folder the divide by zero exception goes away. We found and verified a possible fix.
By the way, now is a good time to turn off break on divide by zero exceptions so we don’t get extra noise during future debugging sessions.
If you want to try this yourself, you can download the sample program I used to create this post.
We are actively looking for feedback on both this and other diagnostics features so please stop by our MSDN support forum and let us know what you think.