`
netcome
  • 浏览: 475711 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

How to debug application crash/hang in production environment?

阅读更多

A common tough scenario is the application crash/hang in production environment. Production environment is different from development environment that it normally does not have any powerful tools to obtain information regarding application failure. In this blog entry, I will talk about 2 wonderful tools to help collect information in production environment: Windbg and Process Explorer.

 

Application Crash:

Crash is the most common scenario of application failure. It is actually caused by an unhanded exception generated in the application. There are 2 types of information that are common critical to resolve application crash:

1.       Unhandled exception type (it is called exception code in unmanaged world) and error message

2.       The full stack trace for the unhandled exception

 

These 2 types of information are trivial to obtain in development environment, because the application runs under the VS debugger, the debugger will tell us this information while unhandled exception is caught.

 

In production environment, it may not be practical to install Visual Studio IDE for debugging, because: 1. Visual Studio is not free. 2. VS has a large memory footprint. 3. The problem can even disappear after installing the Visual Studio.

 

Windbg and Process Explorer are 2 free download tools with much less impact on end user.

 

Using Windbg to obtain Application Crash information:

Windbg is included in the Microsoft “Debugging tools for Windows”. You may download the “Debugging tools for Windows” from the link below:

http://www.microsoft.com/whdc/devtools/debugging/default.mspx

 

After installing windbg, the first thing is setting up the symbol path for it. The symbol path is critical during debugging, because windbg will retrieve the Windows system dlls internal symbols from the symbol path to display the meaningful name for functions/variables. Without the correct symbol loaded, the debugger can only display the numeric memory address for the functions/variables. For example, in a windbg without symbol path, if we use “k” command to obtain the current call stack, we will see following output(note the red numeric):

 

0:000> k

*** ERROR: Module load completed but symbols could not be loaded for notepad.exe

ChildEBP RetAddr 

WARNING: Stack unwind information not available. Following frames may be wrong.

0007f6ec 01001fe4 USER32!MessageBoxW

0007f70c 010027e7 notepad+0x1fe4

0007f944 010035b9 notepad+0x27e7

0007f960 7739c3b7 notepad+0x35b9

0007f98c 7739c484 USER32!EnableMenuItem+0x4cd4

0007fa04 7739ca68 USER32!EnableMenuItem+0x4da1

0007fa60 7739ce7a USER32!TranslateMessageEx+0xd5

0007fa88 7c82ec9e USER32!MsgWaitForMultipleObjectsEx+0x126

0007fb08 773966f0 ntdll!KiUserCallbackDispatcher+0x2e

0007fb24 7739668a USER32!DefWindowProcW+0xc7

0007fb6c 010038e2 USER32!DefWindowProcW+0x61

0007fb94 7739c3b7 notepad+0x38e2

0007fbc0 7739c484 USER32!EnableMenuItem+0x4cd4

0007fc38 7739ca68 USER32!EnableMenuItem+0x4da1

0007fc94 7739ce7a USER32!TranslateMessageEx+0xd5

0007fcbc 7c82ec9e USER32!MsgWaitForMultipleObjectsEx+0x126

0007fd3c 773966f0 ntdll!KiUserCallbackDispatcher+0x2e

0007fd58 7739668a USER32!DefWindowProcW+0xc7

0007fda0 010037fc USER32!DefWindowProcW+0x61

0007fdc8 7739c3b7 notepad+0x37fc

 

Yes, the windbg can only recognize the export function names of the dll. Since we do not have the symbol for notepad.exe, the windbg will only display a *magic* number for the function memory address which is not meaningful to us.

 

To set the symbol path, you may set the following path in the windbg menu item File->”Symbol File Path…”:

“srv*DownstreamStore*http://msdl.microsoft.com/download/symbols”

 

 

Change “DownstreamStore” to any local folder to cache the downloaded symbol files on your machine. For example, I normally use “srv*c:\LocalSymbols* http://msdl.microsoft.com/download/symbols”.

 

Now, you may open the windbg and click File->”Open Executable…” and select your application for launching. Windbg will launch your application and break in the initial loader breakpoint. You can check the red rectangle in the figure to ensure the symbol path is correct:


 

You may press “F5” or input “g” command to tell windbg to ignore the initial loader breakpoint. Now, you may manipulate your application to reproduce the crash. When the application crashes with exception, windbg will automatically break-in your application. Then you may input “k” command to get the full stack trace of this exception/failure.

 

Note: the “k” command may require some time to load the symbols from Microsoft symbol server for the system dlls the first time. So the windbg will report “busy…” for sometime. You may wait to have a coffee for the symbol loading and output.

 

Use Process Explorer to obtain application hangs information:

Process Explorer can be free downloaded in the

http://www.microsoft.com/technet/sysinternals/utilities/ProcessExplorer.mspx

 

Process Explorer is especially suitable for troubleshooting hang problem in application, because it has a very good UI for monitor threads activity.

 

After downloading the Process Explorer, the first thing to do is still setting the symbol server path as we do in windbg:

 

 

Note: in the “Dbghelp.dll path” textbox above, I used to Dbghelp.dll in “Debugging Tools for Windows” package, because this Dbghelp.dll has a higher version than the one in “%windir%/System32/”. If you do not have “Debugging Tools for Windows” installed on end user machine, you can live with using the one in “%windir%/System32/” directory.

 

Let’s demonstrate the Process Explorer usage with a sample. In a .Net Winform application, we write the following code in an existing VC application to simulate the hang in application:

 

Sleep(30000);

 

While the application is hang, we can find the application in the Process Explorer and double click it to launch its property dialog. Then, we should switch to the “Threads” tabpage to examine the thread status. This is what I got in the sample:

 

 

As you can see there is only one thread in the test application. Then, we can select the thread and click “Stack” button in the dialog, we got:

 

 

Aha, by examining this stack trace, we can see that “VMQueryHelper” function calls Sleep() function, which causes the hang.

 

Use Windbg to obtain application hangs information:

Windbg can also be used to troubleshoot the application hang. I assume you have downloaded the windbg and set up the symbol path the same way as said in first section.

 

Now, another .Net application is hanging in customer’s machine. We can use windbg to attach the hang application with the menu item below:

 

 

In the dialog, we can choose the hang application and click Ok button:

 

 

In the windbg, the first thing we should do is checking how many threads are there in the hang application with “~*” command, please see the figure below.

 

As you can see in the figure, thread #0 is executing _CorExeMain method, which is .Net Winform application main GUI thread. The thread #5 has a “.” in the front which means the current examine thread. Because the application hang occurs in the main GUI thread, we should switch the current thread to the #0 thread by inputting “~0s”, see figure.

 

Now, the context is switched to the main GUI hang thread. We can input the “K” command to get the full stack trace of the hang thread to see what it is waiting for.

 

All these 3 commands and output are listed in the figure below.

 

 

As you can see it is the Button.Click() method in .Net Winform calls the System.Threading.Thread.Sleep(30000) that caused the hang.

http://blogs.msdn.com/b/msdnts/archive/2006/11/24/how-to-debug-application-crash-hang-in-production-environment.aspx

分享到:
评论

相关推荐

    基于Java语言的蓝牙遥控器设计源码,支持键盘、鼠标、影音遥控器

    该项目为基于Java语言的蓝牙遥控器设计源码,包含539个文件,涵盖307个Java源文件、120个XML配置文件、34个PNG图片文件、16个Gradle构建文件、12个Git忽略文件、9个文本文件、6个JAR包文件、5个JSON配置文件、5个JPG图片文件。该遥控器支持键盘、鼠标和影音控制功能,适用于多种场合。

    数据手册-74HC573-datasheet.zip

    数据手册-74HC573-datasheet.zip

    苏州科技大学在辽宁2020-2024各专业最低录取分数及位次表.pdf

    那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据

    c++的概要介绍与分析

    关于C++的资源描述和项目源码,以下是一些关键信息: 资源描述 C++是一种广泛应用于开发高性能应用程序的编程语言,既有高级语言的特性,也有低级语言的效率。以下是C++学习资源的简要描述: 在线课程:如优达学城提供的C++中级课程,以及北京大学提供的C++程序设计和C++程序设计进阶课程,这些课程适合从零开始系统学习C++,涵盖从基础到高级的编程内容。 书籍:如《C++ Primer》、《Effective C++》和《C++标准库》等,这些书籍详细介绍了C++语言的基本概念和编程技术,适合作为自学或课堂教学的参考资料。 在线社区:如CSDN博客和Stack Overflow等,这些社区提供了丰富的C++编程教程、示例代码和问题解决方案,是学习和交流C++编程技术的重要平台。 开发工具:如Visual C++(VC)等集成开发环境(IDE),提供了编译器、调试器和其他工具,方便开发者进行Windows平台上的C++应用程序开发。 项目源码 由于项目源码通常包含大量的代码文件和资源文件,且涉及版权和知识产权问题,因此无法在此直接提供完整的项目源码。不过,以下是一些获取C++项目源码的

    锻压成型机_三维3D设计图纸.zip

    锻压成型机_三维3D设计图纸.zip

    mmexport1728042361260.mp4

    mmexport1728042361260.mp4

    谷歌浏览器Linux版本google-chrome-stable-current-amd64.deb

    谷歌浏览器Linux版本google-chrome-stable-current-amd64.deb

    天津职业技术师范大学在辽宁2020-2024各专业最低录取分数及位次表.pdf

    那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据

    牡丹江师范学院在辽宁2020-2024各专业最低录取分数及位次表.pdf

    那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据

    基于GPS定位数据的运输车辆风险预估算法设计源码

    该项目是一款基于Python编写的运输车辆风险预估算法设计源码,包含20个文件,其中9个为Python源代码文件,5个为XML配置文件,2个为Git忽略文件,2个为Excel工作簿文件,以及其余文件类型各1个。该系统旨在通过GPS定位数据对运输车辆的风险进行有效预估,为运输安全管理提供技术支持。

    基于HTML/CSS/JavaScript的瑞吉外卖点餐系统设计源码

    本项目是一款瑞吉外卖点餐系统,采用HTML/CSS/JavaScript进行开发,并集成了Java后端支持。整个项目源码共包含196个文件,其中Java文件73个,PNG图片文件43个,JavaScript文件22个,HTML文件21个,CSS文件18个,字体文件6个,图标文件2个,JSON文件2个以及其他格式文件。该系统旨在提供流畅的点餐体验,满足用户在线点餐需求。

    北华大学在辽宁2020-2024各专业最低录取分数及位次表.pdf

    那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据

    基于Java语言的BasketBallDemo约战篮球设计源码

    该项目为基于Java语言的BasketBallDemo约战篮球设计源码,包含488个文件,其中包含433个PNG图片文件、23个XML配置文件、13个Java源文件、9个JPG图片文件、5个aar库文件、1个Markdown文档、1个Git忽略文件、1个Gradle构建文件、1个批处理文件和1个属性文件。该系统专注于篮球爱好者的约战管理功能。

    东北大学在辽宁2020-2024各专业最低录取分数及位次表.pdf

    那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据

    buck双闭环控制仿真降压电路PI调节器设计降压斩波电路建模和数学模型建模 建模方法有状态空间平均法,开关元件平均模型法,开关网

    buck双闭环控制仿真降压电路PI调节器设计降压斩波电路建模和数学模型建模 建模方法有状态空间平均法,开关元件平均模型法,开关网络平均模型法提供双闭环调节器设计方案 从滤波器设计到pi调节器设计再到仿真。 从滤波器设计到建模,得到被控对象的传递函数,再根据传递函数设计pi调节器,最后把计算出来的pi参数带入仿真验证。

    基于Java语言模仿掌上英雄联盟能力分析效果的PolygonsView设计源码

    该项目是一款基于Java语言开发的掌上英雄联盟能力分析效果模拟应用,源码包含44个文件,涵盖9个XML配置文件、8个Java源文件、6个JSON配置文件、4个Gradle构建文件、3个Git忽略文件、3个属性文件以及其他相关文件,旨在重现英雄联盟能力分析的用户界面和交互体验。

    山西师范大学在辽宁2020-2024各专业最低录取分数及位次表.pdf

    那些年,与你同分同位次的同学都去了哪里?全国各大学在辽宁2020-2024年各专业最低录取分数及录取位次数据,高考志愿必备参考数据

    基于Java语言的Android智能家居系统设计源码

    该项目是一款基于Java语言的Android智能家居系统设计源码,共计75个文件,其中包含24个XML配置文件、17个Java源文件、11个PNG图片文件、10个JPG图片文件、3个Git忽略文件、3个Gradle构建文件、2个属性文件以及1个LICENSE文件。该系统设计简单实用,适用于智能家居场景。

    系统级电路 10 100Mbps 10BASE-T ETHERENT-PHY以太网 cadence官方教程和文件,足够专业 有电

    系统级电路 10 100Mbps 10BASE-T ETHERENT-PHY以太网 cadence官方教程和文件,足够专业 有电路,有工艺库,有版图 有两个版本,一份是工艺是Gpdk90nm(主要),一份是Gpdk180nm,都是有版图(TOP,cell都有),Cadence自己家的电路 如图,保姆级操作教程,从导入库启动cadence开始的那种 内容: 有两个锁相环,模拟均衡器eq pi相位差值 flash ADC,带triming bg LDO,比较器 电平移位,译码电路 数字电路,偏置电流源 运放,trans DAC,滤波器 有很多仿真tb,非常的详细 两个子模块PLL仿真,ADC仿真,bg ldo 模块仿真,TOP整体ams仿真,有版图,没流片,不是反向电路。 有几份RAK讲解文件,有讲top的,然后有几份pdf是讲里面的子模块的。

    棉花自动灌装缝纫机_三维3D设计图纸.zip

    棉花自动灌装缝纫机_三维3D设计图纸.zip

Global site tag (gtag.js) - Google Analytics