
Enabling and Disabling MDAs
You can enable and disable MDAs by using a registry key, an environment variable, and application configuration settings. You must enable either the registry key or the environment variable to use the application configuration settings.
In Visual Studio 2005 and later versions, when the hosting process is enabled, you cannot disable MDAs that are in the default set or enable MDAs that are not in the default set. The hosting process is enabled by default, so it must be explicitly disabled.
To disable the hosting process in Visual Studio, do the following:
In Solution Explorer, select a project.
On the Project menu, click Properties.
The Project Designer window appears.
Click the Debug tab.
In the Enable Debuggers section, clear the Enable the Visual Studio hosting process check box.
However, disabling the hosting process can affect performance. You can avoid the need to disable MDAs by preventing Visual Studio from displaying the MDA dialog box whenever an MDA notification is received. To do that, click Exceptions on the Debug menu, expand the Managed Debugging Assistants list, and then select or clear the Thrown check box for the individual MDA.
Enabling and Disabling by Using a Registry Key
You can enable MDAs by adding the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\MDA subkey in the Windows registry. Copy the following example into a text file named "MDAEnable.reg":
|
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework]
"MDA"="1"
|
From a command prompt, execute the MDAEnable.reg file to enable MDAs on that computer. To disable MDAs, copy the following example into a text file named "MDADisable.reg":
|
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework]
"MDA"="0"
|
Then, run the MDADisable.reg file from a command prompt.
By default, some MDAs are enabled when running the application attached to a debugger, even without adding the registry key. Examples of such assistants are pInvokeStackImbalance MDA and invalidApartmentStateChange MDA. You can disable these assistants by running the MDADisable.reg file as described above.
Enabling and Disabling by Using an Environment Variable
MDA activation can also controlled by the environment variable COMPLUS_MDA. The environment variable overrides the registry key. The string is a case-insensitive, semicolon delimited list of MDA names or other special control strings. Starting under a managed or unmanaged debugger enables a set of MDAs by default. This is done by implicitly prepending the semicolon delimited list of MDAs enabled by default under debuggers to the value of the environment variable or registry key. The special control strings are the following:
0 - Deactivates all MDAs.
1 - Reads MDA settings from ApplicationName.mda.config.
managedDebugger - Explicitly activates all MDAs that are implicitly activated when a managed executable is started under a debugger.
unmanagedDebugger - Explicitly activates all MDAs that are implicitly activated when an unmanaged executable is started under a debugger.
If there are conflicting settings, the most recent settings override previous settings:
COMPLUS_MDA=0 disables all MDAs including those implicitly enabled under a debugger.
COMPLUS_MDA=gcUnmanagedToManaged enables gcUnmanagedToManaged in addition to any implicitly enabled under a debugger.
COMPLUS_MDA =0;gcUnmanagedToManaged enables gcUnmanagedToManaged but disables those MDAs that would otherwise be implicitly enabled under a debugger.
Enabling and Disabling by Using Application-Specific Configuration Settings
You can enable, disable, and configure some assistants individually in the MDA configuration file for the application. To enable the use of an application configuration file for configuring MDAs, either the MDA registry key or the COMPLUS_MDA environment variable must be set. The application configuration file is typically located in the same directory as the application's executable file (.exe). The file name takes the form ApplicationName.mda.config; for example, notepad.exe.mda.config. Assistants enabled in the application configuration file may have attributes or elements specifically designed to control that assistant's behavior. The following example shows how to enable and configure the marshaling MDA.
|
<mdaConfig>
<assistants>
<marshaling>
<methodFilter>
<match name="*"/>
</methodFilter>
<fieldFilter>
<match name="*"/>
</fieldFilter>
</marshaling>
</assistants>
</mdaConfig>
|
These settings enable and configure the Marshaling MDA, which emits information describing the managed type that is being marshaled to an unmanaged type for each managed-to-unmanaged transition in the application. The Marshaling MDA has further flexibility to filter the name of the method and structure fields supplied in the <methodFilter> and <fieldFilter> child elements, respectively.
For more information on the settings specific to each individual MDA, see the documentation for that MDA.
MDA Output
MDA output is similar to the following example, which shows the output from the pInvokeStackImbalance MDA.
A call to PInvoke function 'MDATest!MDATest.Program::StdCall' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.