【翻译 windbg - 6】NET 调试示例实验 1:挂起

来源:互联网 发布:淘宝助理登陆失败 编辑:程序博客网 时间:2024/05/10 22:13

 

 

<!-- /* Font Definitions */ @font-face{font-family:宋体;panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-alt:SimSun;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;}@font-face{font-family:"Cambria Math";panose-1:2 4 5 3 5 4 6 3 2 4;mso-font-charset:0;mso-generic-font-family:roman;mso-font-pitch:variable;mso-font-signature:-1610611985 1107304683 0 0 159 0;}@font-face{font-family:Calibri;panose-1:2 15 5 2 2 2 4 3 2 4;mso-font-charset:0;mso-generic-font-family:swiss;mso-font-pitch:variable;mso-font-signature:-1610611985 1073750139 0 0 159 0;}@font-face{font-family:华文仿宋;panose-1:2 1 6 0 4 1 1 1 1 1;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:647 135200768 16 0 262303 0;}@font-face{font-family:仿宋_GB2312;mso-font-alt:"Arial Unicode MS";mso-font-charset:134;mso-generic-font-family:modern;mso-font-pitch:fixed;mso-font-signature:1 135135232 16 0 262144 0;}@font-face{font-family:"/@宋体";panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;}@font-face{font-family:"/@华文仿宋";panose-1:2 1 6 0 4 1 1 1 1 1;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:647 135200768 16 0 262303 0;}@font-face{font-family:"/@仿宋_GB2312";mso-font-charset:134;mso-generic-font-family:modern;mso-font-pitch:fixed;mso-font-signature:1 135135232 16 0 262144 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-unhide:no;mso-style-qformat:yes;mso-style-parent:"";mso-margin-top-alt:auto;margin-right:0cm;mso-margin-bottom-alt:auto;margin-left:0cm;text-align:justify;text-justify:inter-ideograph;mso-pagination:none;font-size:10.5pt;mso-bidi-font-size:12.0pt;font-family:"Times New Roman","serif";mso-fareast-font-family:宋体;mso-font-kerning:1.0pt;}p.MsoHeader, li.MsoHeader, div.MsoHeader{mso-style-unhide:no;mso-style-link:"页眉 Char";mso-margin-top-alt:auto;margin-right:0cm;mso-margin-bottom-alt:auto;margin-left:0cm;text-align:center;mso-pagination:none;tab-stops:center 207.65pt right 415.3pt;layout-grid-mode:char;border:none;mso-border-bottom-alt:solid windowtext .75pt;padding:0cm;mso-padding-alt:0cm 0cm 1.0pt 0cm;font-size:9.0pt;font-family:"Times New Roman","serif";mso-fareast-font-family:宋体;mso-font-kerning:1.0pt;}p.MsoFooter, li.MsoFooter, div.MsoFooter{mso-style-unhide:no;mso-style-link:"页脚 Char";mso-margin-top-alt:auto;margin-right:0cm;mso-margin-bottom-alt:auto;margin-left:0cm;mso-pagination:none;tab-stops:center 207.65pt right 415.3pt;layout-grid-mode:char;font-size:9.0pt;font-family:"Times New Roman","serif";mso-fareast-font-family:宋体;mso-font-kerning:1.0pt;}a:link, span.MsoHyperlink{mso-style-unhide:no;color:blue;text-decoration:underline;text-underline:single;}a:visited, span.MsoHyperlinkFollowed{mso-style-noshow:yes;mso-style-priority:99;color:purple;mso-themecolor:followedhyperlink;text-decoration:underline;text-underline:single;}span.Char{mso-style-name:"页眉 Char";mso-style-unhide:no;mso-style-locked:yes;mso-style-link:页眉;mso-ansi-font-size:9.0pt;mso-bidi-font-size:9.0pt;mso-font-kerning:1.0pt;}span.Char0{mso-style-name:"页脚 Char";mso-style-unhide:no;mso-style-locked:yes;mso-style-link:页脚;mso-ansi-font-size:9.0pt;mso-bidi-font-size:9.0pt;mso-font-kerning:1.0pt;}.MsoChpDefault{mso-style-type:export-only;mso-default-props:yes;font-size:10.0pt;mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt;mso-ascii-font-family:"Times New Roman";mso-fareast-font-family:宋体;mso-hansi-font-family:"Times New Roman";mso-font-kerning:0pt;} /* Page Definitions */ @page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}@page Section1{size:595.3pt 841.9pt;margin:72.0pt 90.0pt 72.0pt 90.0pt;mso-header-margin:42.55pt;mso-footer-margin:49.6pt;mso-paper-source:0;layout-grid:15.6pt;}div.Section1{page:Section1;} /* List Definitions */ @list l0{mso-list-id:19279271;mso-list-type:hybrid;mso-list-template-ids:740694748 -1948457286 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}@list l0:level1{mso-level-text:%1、;mso-level-tab-stop:none;mso-level-number-position:left;margin-left:18.0pt;text-indent:-18.0pt;}@list l1{mso-list-id:20782973;mso-list-type:hybrid;mso-list-template-ids:-1211467244 -487314002 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}@list l1:level1{mso-level-text:%1、;mso-level-tab-stop:none;mso-level-number-position:left;margin-left:18.0pt;text-indent:-18.0pt;}@list l2{mso-list-id:226843431;mso-list-type:hybrid;mso-list-template-ids:16440274 -1356712622 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}@list l2:level1{mso-level-text:%1、;mso-level-tab-stop:none;mso-level-number-position:left;margin-left:18.0pt;text-indent:-18.0pt;}@list l3{mso-list-id:471949270;mso-list-type:hybrid;mso-list-template-ids:1670299938 182721054 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}@list l3:level1{mso-level-text:%1、;mso-level-tab-stop:none;mso-level-number-position:left;margin-left:18.0pt;text-indent:-18.0pt;}@list l4{mso-list-id:533545918;mso-list-type:hybrid;mso-list-template-ids:-2139948442 1611324982 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}@list l4:level1{mso-level-text:%1、;mso-level-tab-stop:none;mso-level-number-position:left;text-indent:-18.0pt;}-->

NET 调试示例实验 1:挂起

原文

http://blogs.msdn.com/tess/archive/2008/02/04/net-debugging-demos-lab-1-hang.aspx

作者

tess

翻译

AloneSword

译文

http://blog.csdn.net/alonesword/

NET 调试实验室 1 :挂起

这是关于NET 调试实验的10个当中一个。实验中将使用BuggyBits作为站点名称,而且实验名称建议采用 Buggy

安装信息可以在此处获取。

可以预测:这些动手实验室当中会有很多问题,虽然我会尽量回答在评论中提到的问题,但是不能保证是所有的内容。如果您能回答评论中的问题,请不要吝啬您的答案。提问题前,请确保已执行过安装指南中所有步骤。

注意: 实验室中提问(Q:)仅仅是一个问题解决的目标。我会实验复习课程中,编辑评论中关于此问题的答案(每个实验大概会有一周左右的思考时间,这期间是没有答案的)。

自由的评论实验的格式好坏,以便我能在下次实验内容中知道什么做的好,什么不应该继续。

将来无约定,这儿就是实验 1

现象重复

1、  浏览页面: http://localhost/BuggyBits/FeaturedProducts.aspx
这个页面大概需要5秒左右时间才能显示,可在页面底端的看到页面开始时间和执行时间。

2、  同时打开5个浏览器窗口,浏览上述网页
注意尽量做到同时打开这些网页(否则可能是没有执行reg文件)

Q:  什么是执行时间?

Q:  什么是 w3wp.exe CPU使用率?高低标准?

Q:  系统挂起的潜在原因?

获取内存转储:

1、  开启命令行窗口并定位到调试目录中,键入如下命令(不要按回车键):
adplus -hang -pn w3wp.exe -quiet

2、  利用上述的同时打开5个窗口 tinyget 进行压力测试站点,以便重复问题
tinyget -srv:localhost -uri:/BuggyBits/FeaturedProducts.aspx -threads:30 -loop:50

3、  执行第2步中的方法时,在命令窗口中按下回车键,以获得内存快照信息。

Q:当使用 adplus hang 模式时,如何触动内存快照?

Q:获取内存快照时,需要怎样的权限呢?

Q:转储文件存储的位置?提示:查看windbg帮助中关于adplus/hang 模式的内容

windbg.exe 中打开转储文件

1、  打开windbg,选择文件->打开,打开转储的 *.dmp 文件;

2、  设置符号文件路径(查看 安装指南和信息获取更多的内容)

3、  加载 sos (查看 安装指南和信息获取更多的内容)

检查堆栈信息:

1、  检查本地的堆栈信息:
~* kb 2000

2、  检查 dotnet 堆栈信息:
~* e!clrstack

QDo you see any patterns orrecognize any of the callstacks that suggests a thread is waiting for asynchronization mechanism?

跟踪诊断挂起现象:

1、  检查等待锁的线程ID
!syncblk

0:000> !syncblk

Index SyncBlock MonitorHeld Recursion Owning Thread Info  SyncBlock Owner

   26 0018e4b4           19         1 001edef0   d3c  15   0160f440 System.Object

-----------------------------

Q:那个线程拥有锁?

Q:有多少线程正等待锁?(提示:MonitorHeld = 1 代表拥有者,2为等待者)

2、  挑选任何一个等待者(提示:等待线程用 AwareLock::Enter 标示),查看当前正在执行的任务;

~5s         (切换到线程 5,用真实的线程ID替换5即可)
kb 2000  
(检查本地堆栈信息)
!clrstack  
(查看dotnet 堆栈信息)

0:000> ~19s

eax=77e56bf0 ebx=00000000 ecx=7c99c0d8 edx=7c939b3f esi=00153080 edi=00153124

eip=7c92eb94 esp=0468fe1c ebp=0468ff80 iopl=0         nv up ei pl zr na pe nc

cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000246

ntdll!KiFastSystemCallRet:

7c92eb94 c3              ret

0:019> kb 2000

ChildEBP RetAddr  Args to Child             

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

0468ff80 77e56c22 0468ffa8 77e56a3b 00153080 ntdll!KiFastSystemCallRet

0468ff88 77e56a3b 00153080 0021fac8 0121fac8 rpcrt4!I_RpcBCacheFree+0x5ea

0468ffa8 77e56c0a 0015c008 0468ffec 7c80b50b rpcrt4!I_RpcBCacheFree+0x403

0468ffb4 7c80b50b 001e5598 0021fac8 0121fac8 rpcrt4!I_RpcBCacheFree+0x5d2

0468ffec 00000000 77e56bf0 001e5598 00000000 kernel32!GetModuleFileNameA+0x1b4

0:019> !clrstack

OS Thread Id: 0xf08 (19)

Unable to walk the managed stack. The current thread is likely not a

managed thread. You can run !threads to get a list of managed threads in

the process

Q:如何知道那个 dotnet 方法在等待锁?

3、  检查拥有者线程执行的内容:

 

~5s         (切换到线程 5,用真实的线程ID替换5即可)
kb 2000  
(检查本地堆栈信息)
!clrstack  
(查看dotnet 堆栈信息)

Q:为什么会阻塞?

4、  检查dotnet代码中的对应的方法,以验证我们的猜想。

提示:

但愿如下文章对诊断挂起问题有作用:

Thingsto ignore when debugging an ASP.NET Hang - Update for .NET 2.0

A Hang Scenario,Locks and Critical Sections

.NETHang Debugging Walkthrough

Automated.NET Hang Analysis

 

调试愉快!

/Tess