ASP. NET Debug Series 3: Crash debugging

Source: Internet
Author: User

Author: Tess
Link: http://blogs.msdn.com/tess/archive/2008/02/11/net-debugging-demos-lab-2-crash-review.aspx
Wencui http://www.cnblogs.com/David-Qian

Two days ago, I translated the Hang debugging of the Tess Debug series. Today I will continue to share with you the third article, Crash debugging. Similarly, due to machine differences, your debugging results may be different from Tess, but it doesn't matter, as long as you know the principles. The picture of the article may be unclear. If necessary, you can read it in the original text of Tess.

One of ASP. NET Debug series: Environment matching

Common Windbg, sos, tinyget, and adplus commands

ASP. NET Debug Series II: Hang debugging

 

1. Problem Reproduction

1) Go to the http: // localhost/BuggyBits/Reviews. aspx page.

2) Click Refresh to press the button. The w3wp.exe program crash (aspnet_wp.exe under IIS 5) will be obtained ). Note: If you have Visual Studio installed, the Just-In-Time message will pop up. You can click "no". In this case, real-Time debugging is not required.

2. Check System Logs

Logging (you can enter eventvwr.exe in the command line ). Logs may be different for different versions of the system and IIS. In the system log, we can see this information:

Question 1: What does your log look like?
Result 1: In the Tess machine (Windows 2003,. NET 2.0 SP1), the system log is shown as above. At the same time, there are two pieces of information in the program log:

According to the first information, it is caused by an nullreference exception.

The second information shows that the Finalize method of Review causes nullreference exceptions. However, you may not be able to see the second message, which varies with systems, IIS versions, and. NET versions.

Question 2: What does exit code 0xe0434f4d mean?
Result 2: the code is an equivalent of a. NET exception. Both SQL exception, nullreference exception, and FileNotFoundException are represented by 0xe0434f4d code.

Question 3: Can you tell from these logs what causes the program crash?
Result 3: from the second piece of information in the program log, we can easily see that the program crash is caused by exceptions in the Finalize Review object.

3. Get a dump file

1) Open the http: // localhost/BuggyBits/Reviews. aspx page, but do not click "Refresh.

2) Open the command line window, switch to the directory where debugger tools is located, enter adplus-crash-pn w3wp.exe, and press Enter.

Question 1: a new window will appear on the toolbar. What is this program?
Result 1: The program icon is:

In fact, this is the debugger, which is running cdb, which is the equivalent of windbg In the UI state.

Question 2: What is dubugger waiting?
Result 2: The following table shows the events/exceptions adplus monitored and what adplus will do when one of them occurs.

Some abbreviations: L = write logs in debuglog, T = record time, S = record stack, M = Minimum dump, F = Full dump, E = write logs in eventlog. If you want adplus to capture the events you want, you can customize a cfg file for adplus.

3) Click "Refresh" on the reviews page to reproduce the problem.

Question 1: In the debugger tools directory, what files have been created?
Result 1: On the Tess machine, the following file is created in the crash folder (the name contains crash_mode:

ADPlus_report.txt
<DIR> CDBScripts
PID-4628__W3WP.EXE _ Date_02-11-2008 _ Time_13-14-0808.log
Process_List.txt
PID-4628__W3WP.EXE _ 1st_chance_AccessViolation _ mini_17a4_2008-02-11_13-14-19-358_1214.dmp
PID-4628__W3WP.EXE _ 1st_chance_Process_Shut_Down _ full_17a4_2008-02-11_13-14-31-889_1214.dmp
PID-4628__W3WP.EXE _ 2nd_chance_NET_CLR _ full_17a4_2008-02-11_13-14-20-093_1214.dmp

From the above file, we can see that adplus generates three dump files. The first access violation (NullReferenceException) will generate a minimum dump file. This exception was not handled, causing the second CLR exception. Eventually, it causes the shutdown of the process. In fact, it is easy to know the sequence of the Three dump files from their timestamps.

4. Use windbg for debugging

1) Open the dump file of CLR exception (xx_2nd_chance_NET_CLR_xx ).

Here are some things to explain .. . NET, exception is more common. When an exception is thrown in our program, this is called 1st chance. In this case, we can use the try/catch statement to catch this exception. However, if the exception is not captured in time and cannot be handled by the Global. NET exception, it becomes a 2nd exception. Any 2nd exception will cause the process crash.

2) set the symbols path and load sos. These are basic steps, which have been mentioned earlier.

In crash mode, because dump is generated when an exception occurs, the active thread is the abnormal thread.

Question 1: Which thread is active in your dump?
Result 1: the active thread is #20. If we use it! Threads command to view the thread information, we can find that #20 thread is Finalizer thread.

5. Check callstack and exception

1) Check native and managed callstack.

Question 1: What type of thread is this thread?
Result 1: From the kb 2000 command, we can see that it is a Finalizer thread, but we cannot use it because it is an abnormal thread! Clrstack to view more information about managed callstack.

Question 2: What is this thread doing?
Result 2: Some objects are being recycled. An exception is thrown during the collection process and the 2nd exception is finally thrown.

2) Check exception

! Pe

! Pe /! The PrintException command prints the exception being thrown on the current stack.

Question 1: What type of exception is this?
Result 1: NullReferenceException is returned.

Note: In most cases, it is difficult to obtain the stack trace before 2nd exception occurs. In this case, we need to use other commands to find more information about 1st exception.

3) view more information about 1st exception on the stack

Question 1: What is the 1st exception address?
Result 1: in, we can see that the 2nd exception address is 0x2f0cb3c. Therefore, we can see that the 1st exception address is 0x6f1e5e4.

4) view the 1st exception information and callstack.

Question 1: In which method is exception thrown?
Result 1: In the Finalizer method of Review class.

Question 2: What object is being recycled?
Result 2: The object is a Review object.

Problem 3: Normally, when an exception is thrown, if we do not use a try/catch Block, it will be ASP.. NET global exception to be processed, and an error prompt page is displayed to the user. Why can't this exception be handled and cause the crash of process?
Result 3: ASP. NET's global exception handling is only used to capture the exception when processing requests. In our example, an exception occurs in the Finalizer thread. It does not belong to a specific user and therefore cannot display the error information to a specific user. This leads to the crash of process.

6. Verify our code

1) open Review. cs to view its Finalizer method.

Question 1: Which line of code will throw an exception?
Result 1: In the code, we can easily see that when the string is not empty, it is assigned null, which causes NullReferenceException. If we cannot view the source code, we can go through! Run the u command to view the compiled code generated by JIT. I will not discuss it here for the time being. I will explain it in a later article.

Similarly, this article is very long and has been translated for a long time. I hope it will be helpful to you.

Have a nice day!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.