Introduction to asp.net win dbg debugging

3,245 views
3,161 views

Published on

Published in: Education
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,245
On SlideShare
0
From Embeds
0
Number of Embeds
77
Actions
Shares
0
Downloads
118
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Introduction to asp.net win dbg debugging

  1. 1. AHMET MİTHAT BOSTANCI<br />MICROSOFT, GTSC<br />IIS/Web Development Support<br />Ahmet.bostanci@microsoft.com<br />Introduction To Debugging ASP.NET applications withWinDBG and Dump Analysis<br />
  2. 2. SCOPE<br />This is NOT a full dump analysis workshop.<br />The goal is to introduce the dump analysis as one of the ASP.NET 2.0 web application debugging technics and introduce the tools that help to achieve this task.<br />
  3. 3. AGENDA<br />ASP.NET Debugging Technics<br />What is WinDBG<br />When are WinDBG and dump analysis useful?<br />What are dump files?<br />How to collect dump?<br />Basic commands<br />Toolbox & References<br />
  4. 4. ASP.NET Debugging<br />Old School Debugging<br />Using Response.Write<br />Mostly not useful in production<br />Not useful in hang scenario<br />Usful in development<br />Useful in production if there is a repro<br />Looks easy but not useful<br />Debugging in VS.NET<br />Good for debugging in development<br />Useful in production with remote debugging / attaching to w3wp.exe<br />Not useful in most production env. issues.<br />Debugging with WinDBG<br />Live debugging / attaching to w3wp.exe<br />Offline debugging: Collecting dumps of w3wp.exe and analysing in WinDBG<br />
  5. 5. What is WinDBG<br />A GUI Debugger with commands.<br /><ul><li>Part of Debugging Tools For Windows</li></ul>User mode and kernel mode debugging.<br />Its commands are mainly useful in unmanaged debugging.<br />Extensions are sets of commands to ease debugging.<br />SOS and PSSCOR2 extensions for .NET debugging.<br />
  6. 6. Debugging with WinDBG<br />Offline debugging<br />Collecting dump files with specific tools for different scenarios<br />Analysing in WinDBG.<br />Live debugging<br />Attaching a process<br />Using breakpoints, catching exceptions, dumping the process out to a file, etc... when necessary.<br />
  7. 7. Debugging Scenarios<br />Slow performance<br /><ul><li>Web site is responsive but slow.</li></ul>Hang<br />Web site is unresponsive.<br />Crash<br />Exceptions<br />
  8. 8. Exceptions and ASP.NET<br />Exceptions are important objects in debugging.<br />FirstChance exceptions<br />Too many exceptions may cause high CPU.<br />Second Chance<br />Exceptions which are not handled<br />Causes crash.<br />First chance exceptions may cause w3wp.exe crashes, if it is thrown in a background thread, such as finalizer threads.<br />
  9. 9. When do we need WinDBG?<br />Hang / Performance Problems – Manuel<br />Web site is running slow / performance issues.<br />Web site is leaking memory - ends with performance problems, hang or crash.<br />Web site is running with high memory but not not leaking.<br />Web site is running with 100% CPU.<br />Web site is running with high CPU or CPU usage spikes.<br />Web site is completely hung - Does not response any (dynamic) requests.<br />
  10. 10. When do we need WinDBG?<br />Crash<br />Web site or a specific page / method is throwing exceptions but not crashing the w3wp.exe process, first chance exceptions.<br />Web site is crashing - w3wp.exe is crashing. Second chance exceptions.<br />
  11. 11. When do we NOT need WinDBG?<br />When there is an easier way for debugging, such as a specific page / method is not functioning as expected<br />In this case, debugging in VS.NET with a repro code might be easier.<br />«Page cannot be displayed» type issues.<br />In this case, troubleshooting IIS or network side is the correct approach.<br />
  12. 12. Dump<br />A dump is a snapshot of a process (user mode) or a snapshot of all of the memory in kernel mode.<br />Usermode dump: Process specific, such as w3wp.exe<br />Kernel mode dump: Snapshot of the kernel memory<br />Complete memory dump: Snapshot of the whole memory including kernel and user mode.<br />
  13. 13. Types of Dump<br />Minidump<br />Contains only selected parts of the memory used by the process.<br />Fulldump<br />Containsthe full copy of the process memory. Size of the fulldump is somewhat equal to the virtual memory used by the process.<br />This is the dump type we are interested in most of the times.<br />
  14. 14. What a dump contains<br />All the things in the memory of the process.<br />Information about the objects in heaps, threads, information about the callstack, stack memory, etc...<br />Limited information about the dead objects which are not garbage collected yet.<br />
  15. 15. What a dump does NOT contain<br />Other processes' information.<br />What was the CPU or memory usage in time. It is only a snapshot.<br />Also: Minidump is the smallest in size and does not contain some useful information such as stack objects, local variables, etc...<br />
  16. 16. Tools for collecting dumps<br />ADPlus<br />Part of Debugging Tools For Windows<br />Command line<br />adplus -hang -pn w3wp.exe<br />adplus -crash –iis<br />Debug Diagnostic Tool<br />GUI based<br />Easy to configure and use<br />ProcDump<br />Command line<br />Specific for high CPU usage but can be used for collecting manuel dumps as well<br />procdump.exe -c 80 -s 30 -n 5 -ma NNNN >procdump.log<br />Task manager<br />Can be used to collect manuel dump<br />Right click and create userdump<br />Only on Win 7 and Win 2008<br />
  17. 17. 32bit vs 64bit<br />If the process is 32bit then the dump should be taken by the32bit version of the related tools. The dump should be opened with the WinDBG’s 32bit version.<br />Same rule applies to 64bit process.<br />
  18. 18. Which dump in which scenario?<br />Web site is crashing / throwing exceptions<br />Crash rule with Debug Diagnostic Tool, ADPlus<br />Web site is slow, hanging, using high memory<br />Manuel dump(s) with Debug Diagnostic Tool,ADPlus.<br />Web site is using high CPU or CPU is spiking<br />Manuel dump(s) with Debug Diagnostic Tool, ADPlus.<br />ProcDump for CPU spikes<br />Web site is leaking memory<br />Manuel hang dumps.<br />Memory leak rule created in Debug Diagnostic Tool.<br />Full IIS dumps<br />Manuel dump<br />Collects dumps for all of w3wp.exe, all of dllhost.exe and inetinfo.exe process.<br />
  19. 19. How many dump files should I collect?<br />Dump is a snapshot of the memory and does not contain the process history.<br />Most of the crash scenarios<br />One crash dump is enough to start debugging and find the reason of the crash.<br />Performance, hang<br />Consecutive dump files of the same process.<br />For example taking three dumps of w3wp.exe, each are taken one minute apart.<br />
  20. 20. Symbol Files<br />Footprint information of functions in EXE or DLL files<br />Necessary to see useful information in dumps, such as callstacks or variables.<br />
  21. 21. Private vs Public symbols<br />Private symbols contain local variables, structure type information, functions, source line no., etc...<br />Public symbols are the stripped version of the private symbols.<br />
  22. 22. Symbols and WinDBG<br />Symbol server<br />http://msdl.microsoft.com/download/symbols<br />Setting symbol server in WinDBG<br />srv*c:symbolspublic*http://msdl.microsoft.com/download/symbols<br />Symbols are downloaded to the local folder when needed.<br />
  23. 23. Commands in WinDBG<br />WinDBG commands<br />Mostly used in unmanaged debugging.<br />Extensions<br />DLL files<br />Command sets for specific debugging requirements<br />
  24. 24. Extensions<br />Copied to the WinDBG installation directory<br />.NET related extensions<br />SOS<br />Comes with .NET framework<br />PSSCOR2<br />Superset of SOS<br />.NET 2.0 specific extension<br />http://www.microsoft.com/downloads/details.aspx?FamilyID=5c068e9f-ebfe-48a5-8b2f-0ad6ab454ad4&displayLang=en<br />Extract and copy to the WinDBG installation folder.<br />Load from WinDBG:<br />.load psscor2<br />
  25. 25. WinDBG and ASP.NET 2.0 dump analysis<br />Open dump file<br />Check and set symbol server<br />Load the PSSCOR2 extenstion<br />.load psscor2<br />
  26. 26. Some WinDBG commands<br />Vertarget<br />Shows information about the system on which you are debugging<br />Lm<br />Displays loaded module information<br />~<br />Lists all OS threads<br />~Ns<br />Switch to thread #N<br />K<br />Shows unmanaged call stack of the thread switched.<br />.hh<br />Opens help file<br />.reload /f<br />Forces to reload the symbols.<br />!runaway<br />Shows the thread’s CPU time<br />
  27. 27. Some PSSCOR2 commands<br />!DumpAllExceptions (!dae)<br />Shows managed exceptions thrown.<br />!DumpDataTables<br />Shows data tables objects in memory. Useful when debugging memory issues.<br />!DumpColumnNames (!dcn)<br />Prints out the column names for a data table given.<br />!ASPXPages<br />Shows ASPX pages running on all threads.<br />!threadpool<br />Shows ASP.NET thread pool information including the requests in the queue and the current CPU usage of OS.<br />!FindDebugTrue<br />Shows the web applications running in debug mode.<br />!FindDebugModules<br />Shows the modules built in debug mode.<br />!SaveAllModules (!sam)<br />Saves the all modules in the process. Useful when using the reflector to get the code from dump file.<br />!eeversion<br />Prints the .NET framework version. Useful when checking the fixes or service packs installed.<br />!help<br />!help <command><br />
  28. 28. Toolbox<br />Debugging Tools For Windows (WinDBG and ADPlus)<br />http://www.microsoft.com/whdc/DevTools/Debugging/default.mspx<br />Debug Diagnostic Tool v1.1<br />http://www.microsoft.com/downloads/details.aspx?FamilyID=28BD5941-C458-46F1-B24D-F60151D875A3&displaylang=en<br />ProcDump<br />http://technet.microsoft.com/en-us/sysinternals/dd996900.aspx<br />PSSCOR2<br />http://www.microsoft.com/downloads/details.aspx?familyid=5C068E9F-EBFE-48A5-8B2F-0AD6AB454AD4&displaylang=en<br />
  29. 29. Refernces<br />http://blogs.msdn.com/tess/ (İngilizce)<br />http://blogs.msdn.com/amb/<br />http://blogs.msdn.com/farukceliktr/<br />http://blogs.msdn.com/cenkiscan/<br />http://www.codeproject.com/KB/debug/windbg_part1.aspx<br />http://www.cengizhan.com/<br />
  30. 30. Q & A<br />?<br />

×