1. Resolve the line. NET applications include the following issues:
- Collapse
- High CPU
- Program exception
- Program Hang Dead
2. Install WinDbg:
Http://msdn.microsoft.com/en-us/windows/hardware/gg463009.aspx
3. Configure WinDbg:
Run the windbg-> menu->file->symbol File path-> Set the _NT_SYMBOL_PATH variable as follows:
In the box that pops up, enter "C:\MyCodesSymbols; Srv*c:\mylocalsymbols*http://msdl.microsoft.com/download/symbols "(Following this setting, WinDbg will first be from the local folder \ c \ Find Symbol in Mycodessymbols, if not found, automatically download symbols from MS's symbol server). Another approach is to http://www.microsoft.com/whdc/devtools/debugging/symbolpkg.mspx from this symbol , Download the complete symbol installation package required by the appropriate operating system and install it,
4. Use ADPlus in WinDbg to get the dump file.
The dump file is a memory image of the process . You can save the execution state of the program through the debugger to the dump file.
You can find Adplus.exe in the WinDbg installation directory, drag him to the command line, and then use the command
ADPLUS.EXE-HANG-PN test.exe-o c:\dumps//Fetch the current dump file
ADPLUS.EXE-CRASH-PN test.exe-o C:\dumps//monitoring application, when crash, get dump file
Command-PN: Application name,-P: Application pid,-odump file Output path
5. Load the debugger with WinDbg load dump file
Run the windbg-> menu->file->open Cresh dump to open the dump file and load the. NET debugger
. Loadby SOS Mscorwks. Net version 3.5 and below
. Loadby SOS CLR. Net 4.0
If the server's. NET version does not match native requires server version of the Mscordacwks.dll file
and set. Sympath = Mscordacwks_x86_x86_2.0.50727.3607.dl
6. Basic commands for WinDbg
Help SOS Instructions
!threads Show All Threads
!dumpheap displaying information about the managed heap
!clrstack Show Call Stack
!dumpobj Display the contents of an object
!dumparray Display Array
!SYNCBLK Display synchronization Blocks
!runaway Show Thread CPU time
!gcroot Tracking Object Memory Reference
!pe Printing Exceptions
7. Use of WinDbg
When I execute this code in a form:
[CSharp]View Plaincopyprint?
- Public Form1 () {
- InitializeComponent ();
- AppDomain.CurrentDomain.UnhandledException + = new Unhandledexceptioneventhandler (currentdomain_ UnhandledException);
- }
- private void Unhandledexceptionproc (object obj) {
- try {
- throw New Exception ("1st chance");
- } catch (Exception) {
- MessageBox.Show ("after 1st");
- }
- int d = 0;
- int n = 1/d;
- }
and active dump file
Enter-PE after opening the dump file with WinDbg: You can see where the problem is.
exceptions are so important that the operating system provides the appropriate debugging capabilities, and you can use the debugger to view exceptions. After an exception occurs, the operating system checks to see if the current user-state program has a debugger loaded before calling the user-state program's exception-handling function. If there is, then the operating system will first send the exception information to the debugger, so that the debugger can observe the exception of the first opportunity, so also known as the chance exception, the debugger after processing, the operating system to let the user state program to process. if the user-state program handles this exception, there is no debugger. Otherwise, before unhandled exception crashes, the operating system gives the debugger the opportunity to see the exception for the second time, so it is also called Second chance exception.
"Windows user-state program efficient Troubleshooting"
Analyze the following code: You can see that dummyobject consumes a lot of memory and even causes memory overflow
[CSharp]View Plaincopyprint?
- Private void Memeryleakproc (object obj)
- {
- While (true) {
- For (int i = 0; i < * 1024x768; i++) {
- Dummyobject o = new Dummyobject ();
- List. ADD (o);
- }
- Thread.Sleep (1000);
- }
- }
windbg command:!dumpheap–stat statistics stack Memory
Common causes of thread hang
-The thread pool or worker thread is concentrated in a time-consuming job, or locked by another thread
Core issue, find the thread that is stuck
!threads
~*e!clrstack
!synblk
[CSharp]View Plaincopyprint?
- Lock (SyncRoot) {
- int TP;
- int io;
- //threadpool.getmaxthreads (out tp, out IO);
- For (int i = 0; i <; i++) {
- Thread hangthread = new Thread (HANGPROC);
- Hangthread.start ();
- }
- MessageBox.Show ("Press to release lock");
- }
[CSharp]View Plaincopyprint?
- private void Hangproc (object obj)
- {
- Lock (syncRoot) {
- n = 0;
- }
- }
High CPU
-If there is no promotion with the business volume, the thread is processed over a long period of time
Core issue, find the thread that consumes the CPU
!runaway
~*e!clrstack
What happens when a thread deadlock occurs:
Two locks A, B,
A thread has got lock A, request lock B,
Another thread has got lock B, request lock A
Core issue: Find Locked threads
!threads
!syncblk
~*e!clrstack
• Two instructions to solve most of the problems!dumpheap–stat ~*e!clrstack http://blog.csdn.net/kntao/article/details/7086616
Debugging. NET applications using WinDbg [go]