C++ Production Debugging

4,679 views
4,510 views

Published on

Tips and techniques for production debugging of C++ applications, including capturing and analyzing crash and hang dumps.

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

  • Be the first to like this

No Downloads
Views
Total views
4,679
On SlideShare
0
From Embeds
0
Number of Embeds
2,907
Actions
Shares
0
Downloads
37
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

C++ Production Debugging

  1. 1. Noam ShefferSenior Architect and Bugs Hunterhttp://blogs.microsoft.co.il/blogs/noams@NoamSheffer
  2. 2. The First Computer Bug
  3. 3.  When ever we have a live system that we :  Have a limited access to the system  Don’t want or can’t install Visual Studio on it  Can’t Stop the service and attach a debugger to it  Log files are inefficient or non exists (90% of the cases)  Still Need to “Fix” the problem
  4. 4.  A dump file is a snapshot of a running process  Kernel dumps are snapshots of the entire system, but we will not discuss them here Dump files are useful for post-mortem diagnostics and for production debugging A dump can contain lots of information, A full process dump takes at least as much as the process’ virtual size. It’s possible to take a smaller dump, e.g. only thread stacks and loaded modules
  5. 5.  Dump files are a static snapshot You can’t debug a dump, just analyze it Sometimes a repro is required (or more than one repro) Sometimes several dumps must be compared
  6. 6.  On Vista and higher: Task Manager, right-click and choose “Create Dump File”
  7. 7.  Before Vista, use ntsd.exe  ntsd -pn app.exe -c ".dump /ma /u C:app.dmp; qd"
  8. 8.  Use ADPlus from Debugging Tools for Windows  Can do crash / hang dumps  Example command lines: adplus -crash -o C:dumps -sc C:myappmyapp.exe adplus -hang -o C:dumps -p 1234 Can be configured further:  Dump on a specific exception  Perform additional debugger actions  …see documentation (Debugging Tools for Windows)
  9. 9.  Sysinternals utility for creating crash / hang dumps Can use process reflection (Windows 7) to minimize process suspension time Examples: Procdump -h app.exe hang.dmp Procdump -e app.exe crash.dmp Procdump -c 90 app.exe excessive_cpu.dmp
  10. 10.  Visual Studio can open dump files  But it’s not the perfect analysis tool Visual Studio 2008 can handle native dumps very well  Can’t handle managed dumps AT ALL Visual Studio 2010 can handle both native and managed dumps  For managed dumps, CLR 4.0 is required
  11. 11.  WinDbg is usually much better at dump analysis  Not that good for managed source code reading, but everything else is much easier   Try !analyze -v for native dumps  Try opening a kernel (system) dump
  12. 12. Links  http://blogs.microsoft.co.il/blogs/noams  http://blogs.microsoft.co.il/blogs/sasha (all your base are belong to us)  http://blogs.msdn.com/b/ntdebugging/ (ntdebugging)  http://blogs.technet.com/markrussinovich/ (Mark’s blog)

×