[ASP.NET Debugging BuggyBits读书笔记] 预备知识 Part 1

原帖来自:

http://blogs.msdn.com/b/johan/archive/2007/11/13/getting-started-with-windbg-part-i.aspx

 

1. !help 可以查看SOS提供的各种命令

 

2. .time 不是一个sos命令,可以用于计算CPU的平均使用率:

0:000> .time 
Debug session time: Tue Oct 23 08:38:35.000 2007 (GMT+1) 
System Uptime: 4 days 17:48:01.906 
Process Uptime: 0 days 0:24:37.000 
  Kernel time: 0 days 0:04:23.000 
  User time: 0 days 0:03:28.000

可见系统启动时间为4天17小时48分1秒906毫秒。(Kernel time+User time)/Process Uptime得到CPU平均使用率。

 

3. !threadpool 可以查看当前CPU的使用率

0:000> !threadpool 
CPU utilization 100% 
Worker Thread: Total: 5 Running: 4 Idle: 1 MaxLimit: 200 MinLimit: 2 
Work Request in Queue: 16 
Unknown Function: 6a2d945d  Context: 023ede30 
Unknown Function: 6a2d945d  Context: 023ee1e8 
AsyncTimerCallbackCompletion TimerInfo@11b53760 
Unknown Function: 6a2d945d  Context: 023ee3a8 
Unknown Function: 6a2d945d  Context: 023e3040 
Unknown Function: 6a2d945d  Context: 023ee178 
Unknown Function: 6a2d945d  Context: 023edfb0 
AsyncTimerCallbackCompletion TimerInfo@11b36428 
AsyncTimerCallbackCompletion TimerInfo@11b53868 
Unknown Function: 6a2d945d  Context: 023ee060 
Unknown Function: 6a2d945d  Context: 023ee290 
Unknown Function: 6a2d945d  Context: 023eded0 
Unknown Function: 6a2d945d  Context: 023edd88 
Unknown Function: 6a2d945d  Context: 023ede98 
Unknown Function: 6a2d945d  Context: 023ee258 
Unknown Function: 6a2d945d  Context: 023edfe8 
-------------------------------------- 
Number of Timers: 9 
-------------------------------------- 
Completion Port Thread:Total: 3 Free: 3 MaxFree: 4 CurrentLimit: 2 MaxLimit: 200 MinLimit: 2

可见当前CPU使用率为100%

 

4.  !runaway 可以用于查看各个运行态的线程的CPU使用率。

0:000> !runaway 
User Mode Time 
  Thread       Time 
  25:1a94      0 days 0:00:39.937 
  16:1bc0      0 days 0:00:38.390 
  50:1e8c      0 days 0:00:08.859 
  52:1e40      0 days 0:00:08.687 
  20:1c2c      0 days 0:00:08.234 
  51:1340      0 days 0:00:08.171 
  21:1bcc      0 days 0:00:06.953 
  26:13ec      0 days 0:00:06.671 
  44:131c      0 days 0:00:03.906 
  22:d8c       0 days 0:00:03.375 
  33:78c       0 days 0:00:02.656 
  34:1a8c      0 days 0:00:00.906 
  29:1f5c      0 days 0:00:00.828 
   6:e28       0 days 0:00:00.625 
   5:1c78      0 days 0:00:00.546 
  23:14a4      0 days 0:00:00.484 
   4:5ac       0 days 0:00:00.437 
  45:5dc       0 days 0:00:00.421 
   3:13b4      0 days 0:00:00.421 
  47:19c8      0 days 0:00:00.375 
  28:1b6c      0 days 0:00:00.250 
  46:1dac      0 days 0:00:00.156 
   7:1dd8      0 days 0:00:00.109 
  48:cdc       0 days 0:00:00.093 
  49:1eac      0 days 0:00:00.062 
  15:1a64      0 days 0:00:00.062 
   0:1804      0 days 0:00:00.046 
  36:4a4       0 days 0:00:00.031 
  11:1eb4      0 days 0:00:00.031 
   1:10b4      0 days 0:00:00.031 
  31:16ac      0 days 0:00:00.015 
  14:4ac       0 days 0:00:00.015 
   2:186c      0 days 0:00:00.015 
  59:590       0 days 0:00:00.000 
  58:294       0 days 0:00:00.000 
  57:16d0      0 days 0:00:00.000 
  56:1578      0 days 0:00:00.000 
  55:1428      0 days 0:00:00.000 
  54:16d8      0 days 0:00:00.000 
  53:fd8       0 days 0:00:00.000 
  43:1b8c      0 days 0:00:00.000 
  42:1c24      0 days 0:00:00.000 
  41:1e2c      0 days 0:00:00.000 
  40:11b0      0 days 0:00:00.000 
  39:edc       0 days 0:00:00.000 
  38:1a08      0 days 0:00:00.000 
  37:171c      0 days 0:00:00.000 
  35:1254      0 days 0:00:00.000 
  32:1f9c      0 days 0:00:00.000 
  30:1ae8      0 days 0:00:00.000 
  27:190c      0 days 0:00:00.000 
  24:1d2c      0 days 0:00:00.000 
  19:1e38      0 days 0:00:00.000 
  18:ee4       0 days 0:00:00.000 
  17:fb8       0 days 0:00:00.000 
  13:1b54      0 days 0:00:00.000 
  12:1a48      0 days 0:00:00.000 
  10:f64       0 days 0:00:00.000 
   9:1024      0 days 0:00:00.000 
   8:1b78      0 days 0:00:00.000

 

5. !threads 可以用于查看个线程的类型以及所用的app domain:

0:000> !threads 
ThreadCount: 48 
UnstartedThread: 0 
BackgroundThread: 29 
PendingThread: 0 
DeadThread: 19 
Hosted Runtime: no 
                                      PreEmptive   GC Alloc           Lock 
       ID OSID ThreadOBJ    State     GC       Context       Domain   Count APT Exception 
  16    1 1bc0 001fccd0   1808220 Enabled  00000000:00000000 0019daf0     0 Ukn (Threadpool Worker) 
  22    2  d8c 002016f0      b220 Enabled  00000000:00000000 0019daf0     0 MTA (Finalizer) 
  14    4  4ac 00242e58   880a220 Enabled  00000000:00000000 0019daf0     0 MTA (Threadpool Completion Port) 
  23    5 14a4 11b39f18    80a220 Enabled  00000000:00000000 0019daf0     0 MTA (Threadpool Completion Port) 
  24    6 1d2c 11b41ad8      1220 Enabled  00000000:00000000 0019daf0     0 Ukn 
  25    7 1a94 11b46c70   180b220 Enabled  27240c98:27241fd8 11b42540     1 MTA (Threadpool Worker) 
  26    9 13ec 12ce2888   200b220 Enabled  2a9f1434:2a9f33c0 11b42540     0 MTA 
  27    a 190c 12d85eb8   200b220 Enabled  00000000:00000000 11b42540     0 MTA 
  29    b 1f5c 13df6a50   200b220 Enabled  2ab1da6c:2ab1f1c0 11b42540     0 MTA 
  30    c 1ae8 12d44a58      b220 Enabled  00000000:00000000 11b42540     0 MTA 
  31    d 16ac 12e2e008   200b220 Enabled  2a81348c:2a8153c0 11b42540     1 MTA 
   5    e 1c78 12da2160       220 Enabled  00000000:00000000 0019daf0     0 Ukn 
  33    8  78c 11b674c8   200b220 Enabled  2707b818:2707c1d8 11b42540     0 MTA
  34   12 1a8c 13f163c8       220 Enabled  00000000:00000000 0019daf0     0 Ukn 
  36   13  4a4 13eef718   200b220 Enabled  2a7db4a4:2a7dd3c0 11b42540     0 MTA
   4   14  5ac 13ef2008       220 Enabled  00000000:00000000 0019daf0     0 Ukn 
  42   10 1c24 13f0e950   880b220 Enabled  00000000:00000000 0019daf0     0 MTA (Threadpool Completion Port) 
   6   11  e28 13f16008       220 Enabled  00000000:00000000 0019daf0     0 Ukn 
   3    f 13b4 13eba008       220 Enabled  00000000:00000000 0019daf0     0 Ukn 
  43   15 1b8c 140db008   880b220 Enabled  00000000:00000000 0019daf0     0 MTA (Threadpool Completion Port) 
  44   17 131c 140ceb28   200b220 Enabled  272288c8:27229fd8 11b42540     0 MTA 
  45   1d  5dc 140cd0a0       220 Enabled  00000000:00000000 0019daf0     0 Ukn 
  47   20 19c8 1651a008       220 Enabled  00000000:00000000 0019daf0     0 Ukn 
XXXX   24    0 16468880   1801820 Enabled  00000000:00000000 0019daf0     0 Ukn (Threadpool Worker) 
  46   1f 1dac 1650ab48       220 Enabled  00000000:00000000 0019daf0     0 Ukn 
XXXX   1a    0 140d5008   1801820 Enabled  00000000:00000000 0019daf0     0 Ukn (Threadpool Worker) 
XXXX   16    0 140c5008   1801820 Enabled  00000000:00000000 0019daf0     0 Ukn (Threadpool Worker) 
  50    3 1e8c 14064420   180b220 Enabled  27246f54:27247fd8 11b42540     1 MTA (Threadpool Worker) 
XXXX   35    0 1406e800   1801820 Enabled  00000000:00000000 0019daf0     0 Ukn (Threadpool Worker) 
  51   36 1340 140df008   180b220 Enabled  2adec9cc:2aded1c0 11b42540     1 MTA (Threadpool Worker) 
XXXX   37    0 16566868   1801820 Enabled  00000000:00000000 0019daf0     0 Ukn (Threadpool Worker) 
  48   38  cdc 16578840       220 Enabled  00000000:00000000 0019daf0     0 Ukn 
XXXX   39    0 16566c28   1801820 Enabled  00000000:00000000 0019daf0     0 Ukn (Threadpool Worker) 
XXXX   3b    0 1646b8b0   1801820 Enabled  00000000:00000000 0019daf0     0 Ukn (Threadpool Worker) 
XXXX   3c    0 16674008   1801820 Enabled  00000000:00000000 0019daf0     0 Ukn (Threadpool Worker) 
XXXX   3d    0 16676418   1801820 Enabled  00000000:00000000 0019daf0     0 Ukn (Threadpool Worker) 
XXXX   3e    0 16676fb8   1801820 Enabled  00000000:00000000 0019daf0     0 Ukn (Threadpool Worker) 
XXXX   3f    0 16674d48   1801820 Enabled  00000000:00000000 0019daf0     0 Ukn (Threadpool Worker) 
XXXX   40    0 1667de10   1801820 Enabled  00000000:00000000 0019daf0     0 Ukn (Threadpool Worker) 
XXXX   41    0 16680050   1801820 Enabled  00000000:00000000 0019daf0     0 Ukn (Threadpool Worker) 
XXXX   42    0 166812e8   1801820 Enabled  00000000:00000000 0019daf0     0 Ukn (Threadpool Worker) 
XXXX   43    0 16683e60   1801820 Enabled  00000000:00000000 0019daf0     0 Ukn (Threadpool Worker) 
  52   44 1e40 165259e8   180b220 Enabled  2adf126c:2adf31c0 11b42540     1 MTA (Threadpool Worker) 
XXXX   45    0 165b7c08   1801820 Enabled  00000000:00000000 0019daf0     0 Ukn (Threadpool Worker) 
XXXX   46    0 165aa3d8   1801820 Enabled  00000000:00000000 0019daf0     0 Ukn (Threadpool Worker) 
XXXX   47    0 165242c8   1801820 Enabled  00000000:00000000 0019daf0     0 Ukn (Threadpool Worker) 
XXXX   48    0 165e9500   1801820 Enabled  00000000:00000000 0019daf0     0 Ukn (Threadpool Worker) 
  49   3a 1eac 165676f0       220 Enabled  00000000:00000000 0019daf0     0 Ukn

比如从上面的结果我们可以发现PID22是一个Finalizer,结果!runaway判定其CPU使用率,可以判定这是否是一个Finalizer的问题。

 

6. ~50s 可以把当前线程切换到50线程。以此类推

 

7. !clrstack  列举当前call stack内的状况

0:050> !clrstack 
OS Thread Id: 0x1e8c (50) 
ESP       EIP     
17a9e750 7d61c828 [NDirectMethodFrameSlim: 17a9e750] System.DirectoryServices.Protocols.Wldap32.ldap_bind_s(IntPtr, System.String, System.DirectoryServices.Protocols.SEC_WINNT_AUTH_IDENTITY_EX, System.DirectoryServices.Protocols.BindMethod) 
17a9e768 14df70f9 System.DirectoryServices.Protocols.LdapConnection.BindHelper(System.Net.NetworkCredential, Boolean) 
17a9e794 14df6de0 System.DirectoryServices.Protocols.LdapConnection.Bind() 
17a9e79c 14df59e9 System.DirectoryServices.Protocols.LdapConnection.SendRequestHelper(System.DirectoryServices.Protocols.DirectoryRequest, Int32 ByRef) 
17a9e8b8 14df56e8 System.DirectoryServices.Protocols.LdapConnection.SendRequest(System.DirectoryServices.Protocols.DirectoryRequest, System.TimeSpan) 
17a9e8bc 14df5657 [InlinedCallFrame: 17a9e8bc]

可见这个thread首先是调用了SendRequest方法,SendRequest调用了SendRequesthelper方法,而SendRequestHelper方法调用了Bind方法…

执行 !clrstack –p 可以查看传递到每个函数的参数

0:050> !clrstack -p 
OS Thread Id: 0x1e8c (50) 
ESP       EIP     
17a9e750 7d61c828 [NDirectMethodFrameSlim: 17a9e750] System.DirectoryServices.Protocols.Wldap32.ldap_bind_s(IntPtr, System.String, System.DirectoryServices.Protocols.SEC_WINNT_AUTH_IDENTITY_EX, System.DirectoryServices.Protocols.BindMethod) 
17a9e768 14df70f9 System.DirectoryServices.Protocols.LdapConnection.BindHelper(System.Net.NetworkCredential, Boolean) 
    PARAMETERS: 
        this = 0x271fdfe0 
        newCredential = 
        needSetCredential = 
17a9e794 14df6de0 System.DirectoryServices.Protocols.LdapConnection.Bind() 
    PARAMETERS: 
        this = 
17a9e79c 14df59e9 System.DirectoryServices.Protocols.LdapConnection.SendRequestHelper(System.DirectoryServices.Protocols.DirectoryRequest, Int32 ByRef) 
    PARAMETERS: 
        this = 0x271fdfe0 
        request = 0x27246e38 
        messageID = 0x17a9e8ec 
17a9e8b8 14df56e8 System.DirectoryServices.Protocols.LdapConnection.SendRequest(System.DirectoryServices.Protocols.DirectoryRequest, System.TimeSpan) 
    PARAMETERS: 
        this = 0x271fdfe0 
        request = 0x27246e38 
        requestTimeout = 
17a9e8bc 14df5657 [InlinedCallFrame: 17a9e8bc]

 

8. !do 可以查看每个对象的具体内容。比如想查看传递给SendRequest方法的request这个参数的内容,可以执行 !do 0x27246e38:

0:050> !do 0x27246e38 
Name: System.DirectoryServices.Protocols.SearchRequest 
MethodTable: 14b394c4 
EEClass: 14d97ce0 
Size: 52(0x34) bytes 
GC Generation: 0 
(C:\WINDOWS\assembly\GAC_MSIL\System.DirectoryServices.Protocols\2.0.0.0__b03f5f7f11d50a3a\System.DirectoryServices.Protocols.dll)
Fields: 
      MT    Field   Offset                 Type VT     Attr    Value                           Name 
02c39310  4000102        4        System.String  0 instance 00000000      directoryRequestID 
14b398bc  4000103        8 ...ControlCollection  0 instance 27246e90  directoryControlCollection 
02c39310  4000111        c        System.String  0 instance 27246d00      dn 
12579f5c  4000112       10 ....StringCollection  0 instance 27246eb4    directoryAttributes 
02c36ca0  4000113       14        System.Object  0 instance 27246ddc    directoryFilter 
14b39344  4000114       18         System.Int32  1 instance        1              directoryScope 
14b393fc  4000115       1c         System.Int32  1 instance        0                directoryRefAlias 
0fd3da00  4000116       20         System.Int32  1 instance        0                directorySizeLimit 
1202af88  4000117       28      System.TimeSpan  1 instance 27246e60  directoryTimeLimit 
120261c8  4000118       24       System.Boolean  1 instance        0

可见这个对象是 System.DirectoryServices.Protocols.SearchRequest 的一个实例。假设我们认为这个类的每个对象都有一个distinguished name,而名字为DN的对象正好是我们要找的,则我们可以执行 !do 0x27246300:

0:050> !do 27246d00 
Name: System.String 
MethodTable: 02c39310 
EEClass: 0fb610ac 
Size: 112(0x70) bytes 
GC Generation: 0 
(C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll) 
String: CN=Dummy,CN=Accounts,CN=useradm,DC=dummy,DC=net 
Fields: 
      MT    Field   Offset                 Type VT     Attr    Value Name 
0fd3da00  4000096        4         System.Int32  1 instance       48 m_arrayLength 
0fd3da00  4000097        8         System.Int32  1 instance       47 m_stringLength 
0fb80010  4000098        c          System.Char  1 instance       43 m_firstChar 
02c39310  4000099       10        System.String  0   shared   static Empty 
    >> Domain:Value  0019daf0:03380310 11b42540:03380310 << 
0fb86d44  400009a       14        System.Char[]  0   shared   static WhitespaceChars
    >> Domain:Value  0019daf0:03380324 11b42540:033855bc <<

这样我们就找到了这个distinguished name。

转载于:https://my.oschina.net/u/587236/blog/119543

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值