【问题标题】:Debug in release mode在发布模式下调试
【发布时间】:2014-02-18 07:37:59
【问题描述】:

我正在尝试使用 WinDbgSOS 调试 .NET 托管代码应用程序以用于教育目的。

Module Module1

  Sub Main()

    Console.Read()
    throwExceptionMethod()

  End Sub

  Private Sub throwExceptionMethod()

    Dim localString As String = "bad string"
    If localString = "bad string" Then
      Throw New System.NotSupportedException("Can't process the string.")
    End If

  End Sub

End Module

在调试模式下编译时,我可以看到抛出异常的方法和破坏我的应用程序的本地字符串。

!CLRStack 命令的输出:

0:000> !CLRStack
OS Thread Id: 0x1148 (0)
DBGHELP: mscorwks - public symbols
         C:\Program Files\Debugging Tools for Windows (x64)\sym\mscorwks.pdb\EC7B2AF3D7A74E1FB2A04CB8AF5F867A1\mscorwks.pdb
DBGHELP: ntdll - public symbols
         C:\Program Files\Debugging Tools for Windows (x64)\sym\ntdll.pdb\9D04EB0AA387494FBD81ED062072B99C2\ntdll.pdb
DBGHELP: mscoreei - public symbols
         C:\Program Files\Debugging Tools for Windows (x64)\sym\mscoreei.pdb\F2445BD7B5494942A39C87ED630879A92\mscoreei.pdb
DBGHELP: MSCOREE - public symbols
         C:\Program Files\Debugging Tools for Windows (x64)\sym\mscoree.pdb\FB53EF9DD104439E9903F0B34128E0392\mscoree.pdb
DBGHELP: KERNEL32 - public symbols
         C:\Program Files\Debugging Tools for Windows (x64)\sym\kernel32.pdb\C4D1D9065632419699A8B2F25B62381D2\kernel32.pdb
Child-SP         RetAddr          Call Site
000000000020ec70 000007ff0019014a Prototipos.Module1.throwExceptionMethod()
000000000020ecc0 000007fef881d432 Prototipos.Module1.Main()

以及该方法无法处理的本地字符串。

!dso 和 !do 00000000027002c0 的输出:

0:000> !dso
OS Thread Id: 0x1148 (0)
RSP/REG          Object           Name
000000000020ea80 00000000026ff4c8 System.Text.DecoderNLS
000000000020eaa8 0000000002700340 System.NotSupportedException
000000000020eac0 0000000002700340 System.NotSupportedException
000000000020eae0 0000000002700340 System.NotSupportedException
000000000020ebb0 0000000002700340 System.NotSupportedException
000000000020ebc0 00000000027002f0 System.String
000000000020ec60 00000000027002f0 System.String
000000000020ec90 00000000027002c0 System.String
000000000020eca8 0000000002700340 System.NotSupportedException
000000000020ecc0 00000000026ff828 System.IO.TextReader+SyncTextReader

0:000> !do 00000000027002c0
Name: System.String
MethodTable: 000007fef7ab7d90
EEClass: 000007fef76be560
Size: 46(0x2e) bytes
 (C:\Windows\assembly\GAC_64\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll)
String: bad string
Fields:
              MT    Field   Offset                 Type VT     Attr            Value Name
000007fef7abf000  4000096        8         System.Int32  1 instance               11 m_arrayLength
000007fef7abf000  4000097        c         System.Int32  1 instance               10 m_stringLength
000007fef7ab97d8  4000098       10          System.Char  1 instance               62 m_firstChar
000007fef7ab7d90  4000099       20        System.String  0   shared           static Empty
                                 >> Domain:Value  00000000000bac20:00000000026f1308 <<
000007fef7ab9688  400009a       28        System.Char[]  0   shared           static WhitespaceChars
                                 >> Domain:Value  00000000000bac20:00000000026f1ba0 <<

但在发布模式下,即使加载了 pdb,我也无法通过 WinDbg 看到有用的信息。

模块信息的输出。符号已加载:

0:000> !lmi Prototipos.exe
Loaded Module Info: [prototipos.exe]
         Module: Prototipos
   Base Address: 0000000000940000
     Image Name: C:\Users\joseluis.vaquero\Documents\Visual Studio 2008\Projects\Prototipos\Prototipos\bin\Release\Prototipos.exe
   Machine Type: 332 (I386)
     Time Stamp: 52e64b75 Mon Jan 27 13:05:09 2014
           Size: a000
       CheckSum: 0
Characteristics: 102
Debug Data Dirs: Type  Size     VA  Pointer
             CODEVIEW    89,  401c,    1c1c RSDS - GUID: {ABB91DE1-4132-4D69-B9E7-2D48B4C9A548}
               Age: 1, Pdb: C:\Users\joseluis.vaquero\Documents\Visual Studio 2008\Projects\Prototipos\Prototipos\obj\Release\Prototipos.pdb
     Image Type: FILE     - Image read successfully from debugger.
                 C:\Users\joseluis.vaquero\Documents\Visual Studio 2008\Projects\Prototipos\Prototipos\bin\Release\Prototipos.exe
    Symbol Type: PDB      - Symbols loaded successfully from image path.
                 C:\Users\joseluis.vaquero\Documents\Visual Studio 2008\Projects\Prototipos\Prototipos\bin\Release\Prototipos.pdb
    Load Report: private symbols & lines, not source indexed
                 C:\Users\joseluis.vaquero\Documents\Visual Studio 2008\Projects\Prototipos\Prototipos\bin\Release\Prototipos.pdb

我在 Stack 中看不到 ThrowExcetionMethod。

0:000> !CLRStack
OS Thread Id: 0xae4 (0)
Child-SP         RetAddr          Call Site
00000000001fe920 000007fef881d432 Prototipos.Module1.Main()

我看不到本地字符串转储堆栈对象。

0:000> !dso
OS Thread Id: 0xae4 (0)
RSP/REG          Object           Name
00000000001fe758 000000000268a840 System.NotImplementedException
00000000001fe770 000000000268a840 System.NotImplementedException
00000000001fe790 000000000268a840 System.NotImplementedException
00000000001fe860 000000000268a840 System.NotImplementedException
00000000001fe870 000000000268a840 System.NotImplementedException
00000000001fe910 000000000268a840 System.NotImplementedException
00000000001fe920 000000000268a840 System.NotImplementedException
00000000001fe928 000000000268a8c8 System.String

我无法通过此信息发现生产环境中发生的情况。

有没有办法在发布模式下使用 WinDbg 获取更多信息?

【问题讨论】:

  • 您在发布模式下是否停在同一点?目前我假设您将使用sxe clr 停止任何.NET 异常,然后在引发异常时运行命令。这个假设正确吗?
  • 是的。我附加到该进程,在控制台窗口中按 Enter 以传递“console.read”,并且调试在异常时停止,其方式与在调试模式下相同。

标签: .net debugging windbg sos


【解决方案1】:

这是完全正常的,抖动优化器的副作用使您的代码快速。该方法消失了,因为它被内联了,堆栈变量消失了,因为它们存储在 CPU 寄存器中。您会在this answer 中找到抖动执行的优化类型。

如果您更喜欢可诊断性而不是速度,那么从技术上讲,禁用优化器是一种选择。选择 Release build configuration,Project + Properties,Compiled 选项卡,Advanced 按钮,取消选中“Enable optimizations”选项。并不是说我实际上建议您这样做。

【讨论】:

  • 除了可靠的 QA 之外,没有任何一种策略能够始终如一地提供结果。也不是WinDbg。记录日志总是一个好主意。
猜你喜欢
  • 2011-09-02
  • 2010-11-17
  • 2012-06-30
  • 1970-01-01
  • 1970-01-01
  • 2012-06-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多