Capture First Chance Exception Dumps in Azure Web Sites using ADplus
There would be lot of scenarios where you would want to capture dumps for a specific exception in your Azure Web Sites Environment. The below steps illustrates the way to capture dumps for specific first chance exception using ADplus.
Before proceeding further, please note that all first chance exceptions necessarily do not cause any harm if they are properly handled in the application code. But if first chance exceptions are not handled properly, it can crash the application and in those scenarios, the dumps can be captured following the below steps for further investigation.
Download Windows SDK at https://msdn.microsoft.com/en-US/windows/desktop/bg162891
Note: Download only Debugging Tools for Windows, install the Windows SDK, and, during the installation, select the Debugging Tools for Windows box and clear all the other boxes
By default, the files will be put under C:\Program Files (x86)\Windows Kits\8.1\Debuggers\x86
Upload following binaries to "/site/diagnostics" folder of the site using FTP client like FileZilla or other tools
- Adplus.exe
- Adplusext.dll
- Cdb.exe
- Dbgeng.dll
- Dbghelp.dll
Copy the below contents to the file "specific-managed-exceptions.adplus.config" under "/site/diagnostics" folder of the site using FTP client like FileZilla or other tools. The below sample is for System.OutOfMemoryException. Do change this value to the specific exception for which you would like to capture the dump.
<adplus version="2">
<keywords>
<keyword name="LoadSOS">.loadby sos clr</keyword>
<keyword name="FullDumpOnSystemOutOfMemoryException">!soe System.OutOfMemoryException 1;.if(@$t1==1) {.dump /ma /u ${AdpDumpDir}\FULLDUMP_SystemArgumentException_${AdpProcName}_.dmp}</keyword>
</keywords>
<settings>
<runmode>crash</runmode>
<Option> NoDumpOnFirst </Option>
</settings>
<PreCommands>
<debugactions>LoadSOS</debugactions>
</PreCommands>
<exceptions>
<exception code="clr">
<actions1>FullDumpOnSystemOutOfMemoryException</actions1>
<returnaction1>GN</returnaction1>
</exception>
</exceptions>
</adplus>
Create "dumps" folder in "/site/diagnostics" folder of the site using FTP client like FileZilla or other tools
Set WEBSITE_DISABLE_SCM_SEPARATION to "true" as shown below in the 'APP SETTINGS' section under 'CONFIGURE' option in the Azure Web Site
The process ID <PID> for the w3wp process for which the dump has to be captured can be checked at https://<your-site>.scm.azurewebsites.net/ProcessExplorer/
Note: Replace <your-site> with your Azure Web Site name
Run below command in the 'CMD' option under https://<your-site>.scm.azurewebsites.net/DebugConsole/
after going to the "D:\home\site\diagnostics>" folder to set automated dumps for specific exceptionsadplus -c specific-managed-exceptions.adplus.config -o ".\dumps" -p <PID>
-c indicates the configuration file to load for the adplus process
-o indicates the output directory where the dumps should be written
-p indicates the process ID picked in step 7 for the specific process to be monitored for the exception
NOTE: If new deployment of websites is done or website is restarted for some reason, then <PID> would change and step 8 should be repeated.
- When the exception happens for the process, FULL memory dumps of the process will be captured at the time of the issue in the output folder specified which can be downloaded and analyzed as any other dumps