SOS.dll(SOS 调试扩展)SOS.dll (SOS debugging extension)

SOS 调试扩展 (SOS.dll) 通过提供有关内部公共语言运行时 (CLR) 环境的信息,帮助你在 Visual Studio 和 Windows 调试器 (WinDbg.exe) 中调试托管程序。The SOS Debugging Extension (SOS.dll) helps you debug managed programs in Visual Studio and in the Windows debugger (WinDbg.exe) by providing information about the internal Common Language Runtime (CLR) environment. 此工具需要你启用项目的非托管调试。This tool requires your project to have unmanaged debugging enabled. SOS.dll 自动随 .NET Framework 一起安装。SOS.dll is automatically installed with the .NET Framework. 若要在 Visual Studio 中使用 SOS.dll,请安装 Windows 驱动程序工具包 (WDK)To use SOS.dll in Visual Studio, install the Windows Driver Kit (WDK).

语法Syntax

![command] [options]

命令Commands

命令Command 描述Description
AnalyzeOOM (ao)AnalyzeOOM (ao) 显示对垃圾回收堆进行分配请求时发生的最后一次内存不足 (OOM) 的信息。Displays the information for the last out of memory (OOM) that occurred on an allocation request to the garbage collection heap. (在服务器垃圾回收中,它将在每个垃圾回收堆上显示 OOM(如果有))。(In server garbage collection, it displays OOM, if any, on each garbage collection heap.)
BPMD [-nofuturemodule] [<module name> <method name>] [-md <MethodDesc>] -list -clear <pending breakpoint number> -clearallBPMD [-nofuturemodule] [<module name> <method name>] [-md <MethodDesc>] -list -clear <pending breakpoint number> -clearall 在指定模块中的指定方法处创建断点。Creates a breakpoint at the specified method in the specified module.

如果尚未加载指定的模块和方法,则此命令将在创建断点之前等待已加载并进行实时 (JIT) 编译的模块的通知。If the specified module and method have not been loaded, this command waits for a notification that the module was loaded and just-in-time (JIT) compiled before creating a breakpoint.

可以通过使用 -list-clear-clearall 选项来管理挂起断点的列表:You can manage the list of pending breakpoints by using the -list, -clear, and -clearall options:

-list 选项生成所有挂起断点的列表。The -list option generates a list of all the pending breakpoints. 如果挂起断点有一个非零模块 ID,则该断点特定于该特定已加载模块中的函数。If a pending breakpoint has a non-zero module ID, that breakpoint is specific to a function in that particular loaded module. 如果挂起断点有一个零模块 ID,则该断点适用于尚未加载的模块。If the pending breakpoint has a zero module ID, that breakpoint applies to modules that have not yet been loaded.

使用 -clear-clearall 选项可从该列表中移除挂起断点。Use the -clear or -clearall option to remove pending breakpoints from the list.
CLRStack [-a] [-l] [-p] [-n]CLRStack [-a] [-l] [-p] [-n] 仅提供托管代码的堆栈跟踪。Provides a stack trace of managed code only.

-p 选项显示托管函数的自变量。The -p option shows arguments to the managed function.

-l 选项显示有关帧中的局部变量的信息。The -l option shows information on local variables in a frame. SOS 调试扩展无法检索本地名称,因此本地名称的输出采用的格式为 <local address> = <value>。The SOS Debugging Extension cannot retrieve local names, so the output for local names is in the format <local address> = <value>.

-a(全部)选项是 -l 和 -p 组合的快捷方式。The -a(all) option is a shortcut for -l and -p combined.

-n 选项禁止显示源文件名和行号。The -n option disables the display of source file names and line numbers. 如果调试器已指定选项 SYMOPT_LOAD_LINES,则 SOS 将查找每个托管帧的符号,如果成功,则将显示对应的源文件名和行号。If the debugger has the option SYMOPT_LOAD_LINES specified, SOS will look up the symbols for every managed frame and if successful will display the corresponding source file name and line number. 可以指定 -n(无行号)参数来禁用此行为。The -n (No line numbers) parameter can be specified to disable this behavior.

在基于 x64 和 IA-64 的平台上,SOS 调试扩展不显示过渡帧。The SOS Debugging Extension does not display transition frames on x64 and IA-64-based platforms.
COMStateCOMState 列出每个线程的 COM 单元模型和 Context 指针(如果可用)。Lists the COM apartment model for each thread and a Context pointer, if available.
DumpArray [-start <startIndex>] [-length <length>] [-details] [-nofields] <array object address>DumpArray [-start <startIndex>] [-length <length>] [-details] [-nofields] <array object address>

-or-

DA [-start <startIndex>] [-length <length>] [-detail] [-nofields] array object address>DA [-start <startIndex>] [-length <length>] [-detail] [-nofields] array object address>
检查数组对象的元素。Examines elements of an array object.

-start 选项指定开始显示元素的起始索引。The -start option specifies the starting index at which to display elements.

-length 选项指定要显示的元素数量。The -length option specifies how many elements to show.

-details 选项使用 DumpObjDumpVC 格式显示元素的详细信息。The -details option displays details of the element using the DumpObj and DumpVC formats.

-nofields 选项可阻止显示数组。The -nofields option prevents arrays from displaying. 此选项仅在指定 -detail 选项后可用。This option is available only when the -detail option is specified.
DumpAssembly <assembly address>DumpAssembly <assembly address> 显示有关程序集的信息。Displays information about an assembly.

DumpAssembly 命令将列出多个模块(如果存在)。The DumpAssembly command lists multiple modules, if they exist.

可以通过使用 DumpDomain 命令获取程序集地址。You can get an assembly address by using the DumpDomain command.
DumpClass <EEClass address>DumpClass <EEClass address> 显示有关与类型关联的 EEClass 结构的信息。Displays information about the EEClass structure associated with a type.

DumpClass 命令显示静态字段值,但不显示非静态字段值。The DumpClass command displays static field values but does not display nonstatic field values.

使用 DumpMTDumpObjName2EEToken2EE 命令获取 EEClass 结构地址。Use the DumpMT, DumpObj, Name2EE, or Token2EE command to get an EEClass structure address.
DumpDomain [<domain address>]DumpDomain [<domain address>] 枚举在指定的 Assembly 对象地址内加载的每个 AppDomain 对象。Enumerates each Assembly object that is loaded within the specified AppDomain object address. 若在调用 DumpDomain 命令时不提供任何参数,则将列出过程中的所有 AppDomain 对象。When called with no parameters, the DumpDomain command lists all AppDomain objects in a process.
DumpHeap [-stat] [-strings] [-short] [-min <size>] [-max <size>] [-thinlock] [-startAtLowerBound] [-mt <MethodTable address>] [-type <partial type name>][start [end]]DumpHeap [-stat] [-strings] [-short] [-min <size>] [-max <size>] [-thinlock] [-startAtLowerBound] [-mt <MethodTable address>] [-type <partial type name>][start [end]] 显示有关垃圾回收堆的信息和有关对象的收集统计信息。Displays information about the garbage-collected heap and collection statistics about objects.

如果 DumpHeap 命令在垃圾回收器堆中检测到过多碎片,将会显示警告。The DumpHeap command displays a warning if it detects excessive fragmentation in the garbage collector heap.

-stat 选项将输出限制为统计类型摘要。The -stat option restricts the output to the statistical type summary.

-strings 选项将输出限制为统计字符串值摘要。The -strings option restricts the output to a statistical string value summary.

-short 选项将输出限制为只是每个对象的地址。The -short option limits output to just the address of each object. 这使你能够轻松地以管道方式将输出从该命令转移到另一个调试器命令以实现自动化。This lets you easily pipe output from the command to another debugger command for automation.

-min 选项忽略小于 size 参数指定的大小(以字节为单位)的对象。The -min option ignores objects that are less than the size parameter, specified in bytes.

-max 选项忽略大于 size 参数指定的大小(以字节为单位)的对象。The -max option ignores objects that are larger than the size parameter, specified in bytes.

-thinlock 选项报告 ThinLocks。The -thinlock option reports ThinLocks. 有关详细信息,请参阅 SyncBlk 命令。For more information, see the SyncBlk command.

-startAtLowerBound 选项将强制在提供的地址范围的下限开始堆审核。The -startAtLowerBound option forces the heap walk to begin at the lower bound of a supplied address range. 在计划阶段,堆通常不可移动,因为对象正在移动。During the planning phase, the heap is often not walkable because objects are being moved. 此选项将强制 DumpHeap 在指定的下限开始其审核。This option forces DumpHeap to begin its walk at the specified lower bound. 你必须提供有效的对象的地址作为使此选项工作的下限。You must supply the address of a valid object as the lower bound for this option to work. 你可以显示错误对象的地址的内存来手动寻找下一个方法表。You can display memory at the address of a bad object to manually find the next method table. 如果垃圾回收当前处于对 memcopy 的调用中,则你还可以通过将大小添加到作为参数提供的起始地址中来查找下一个对象的地址。If the garbage collection is currently in a call to memcopy, you may also be able to find the address of the next object by adding the size to the start address, which is supplied as a parameter.

-mt 选项仅列出与指定的 MethodTable 结构对应的那些对象。The -mt option lists only those objects that correspond to the specified MethodTable structure.

-type 选项仅列出其类型名称为指定字符串的子字符串匹配项的那些对象。The -type option lists only those objects whose type name is a substring match of the specified string.

start 参数从指定的地址处开始列出。The start parameter begins listing from the specified address.

end 参数在指定的地址处停止列出。The end parameter stops listing at the specified address.
DumpIL <Managed DynamicMethod object> | <DynamicMethodDesc pointer> | <MethodDesc pointer>DumpIL <Managed DynamicMethod object> | <DynamicMethodDesc pointer> | <MethodDesc pointer> 显示与托管方法关联的 Microsoft 中间语言 (MSIL)。Displays the Microsoft intermediate language (MSIL) that is associated with a managed method.

请注意,发出的动态 MSIL 与从程序集加载的 MSIL 不同。Note that dynamic MSIL is emitted differently than MSIL that is loaded from an assembly. 动态 MSIL 引用托管对象数组中的对象而不是引用元数据标记。Dynamic MSIL refers to objects in a managed object array rather than to metadata tokens.
DumpLog [-addr <addressOfStressLog>] [<Filename>]DumpLog [-addr <addressOfStressLog>] [<Filename>] 将内存中压力日志的内容写入到指定文件。Writes the contents of an in-memory stress log to the specified file. 如果你不指定名称,则此命令将在当前目录中创建一个名为 StressLog.txt 的文件。If you do not specify a name, this command creates a file called StressLog.txt in the current directory.

内存中压力日志可帮助你在不使用锁或 I/O 的情况下诊断压力故障。The in-memory stress log helps you diagnose stress failures without using locks or I/O. 若要启用压力日志,请在 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework 下设置以下注册表项:To enable the stress log, set the following registry keys under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework:

(DWORD) StressLog = 1(DWORD) StressLog = 1

(DWORD) LogFacility = 0xffffffff(DWORD) LogFacility = 0xffffffff

(DWORD) StressLogSize = 65536(DWORD) StressLogSize = 65536

利用可选的 -addr 选项,你可以指定压力日志而非默认日志。The optional -addr option lets you specify a stress log other than the default log.
DumpMD <MethodDesc address>DumpMD <MethodDesc address> 显示有关指定地址处的 MethodDesc 结构的信息。Displays information about a MethodDesc structure at the specified address.

可以使用 IP2MD 命令从托管函数中获取 MethodDesc 结构地址。You can use the IP2MD command to get the MethodDesc structure address from a managed function.
DumpMT [-MD] <MethodTable address>DumpMT [-MD] <MethodTable address> 显示有关指定地址处的方法表的信息。Displays information about a method table at the specified address. 指定 -MD 选项将显示与对象一起定义的所有方法的列表。Specifying the -MD option displays a list of all methods defined with the object.

每个托管对象均包含一个方法表指针。Each managed object contains a method table pointer.
DumpMethodSig <sigaddr> <moduleaddr>DumpMethodSig <sigaddr> <moduleaddr> 显示有关指定地址处的 MethodSig 结构的信息。Displays information about a MethodSig structure at the specified address.
DumpModule [-mt] <Module address>DumpModule [-mt] <Module address> 显示有关指定地址处的模块的信息。Displays information about a module at the specified address. -mt 选项显示模块中定义的类型和模块所引用的类型The -mt option displays the types defined in a module and the types referenced by the module

可以使用 DumpDomainDumpAssembly 命令检索模块的地址。You can use the DumpDomain or DumpAssembly command to retrieve a module's address.
DumpObj [-nofields] <object address>DumpObj [-nofields] <object address>

-or-

DO <object address>DO <object address>
显示有关指定地址处的对象的信息。Displays information about an object at the specified address. DumpObj 命令显示对象的字段、EEClass 结构信息、方法表和大小。The DumpObj command displays the fields, the EEClass structure information, the method table, and the size of the object.

可以使用 DumpStackObjects 命令检索对象的地址。You can use the DumpStackObjects command to retrieve an object's address.

请注意,可以对 CLASS 类型的字段运行 DumpObj 命令,因为这些字段也是对象。Note that you can run the DumpObj command on fields of type CLASS because they are also objects.

-nofields 选项可阻止显示对象的字段,它对 String 这样的对象很有用。The -nofields option prevents fields of the object being displayed, it is useful for objects like String.
DumpRuntimeTypesDumpRuntimeTypes 显示垃圾回收器堆中的运行时类型对象并列出其关联的类型名称和方法表。Displays the runtime type objects in the garbage collector heap and lists their associated type names and method tables.
DumpStack [-EE] [-n] [top stack [bottom stack]]DumpStack [-EE] [-n] [top stack [bottom stack]] 显示堆栈跟踪。Displays a stack trace.

-EE 选项使 DumpStack 命令仅显示托管函数。The -EE option causes the DumpStack command to display only managed functions. 使用 topbottom 参数可限制 x86 平台上显示的堆栈帧。Use the top and bottom parameters to limit the stack frames displayed on x86 platforms.

-n 选项禁止显示源文件名和行号。The -n option disables the display of source file names and line numbers. 如果调试器已指定选项 SYMOPT_LOAD_LINES,则 SOS 将查找每个托管帧的符号,如果成功,则将显示对应的源文件名和行号。If the debugger has the option SYMOPT_LOAD_LINES specified, SOS will look up the symbols for every managed frame and if successful will display the corresponding source file name and line number. 可以指定 -n(无行号)参数来禁用此行为。The -n (No line numbers) parameter can be specified to disable this behavior.

在 x86 和 x64 平台上,DumpStack 命令将创建详细的堆栈跟踪。On x86 and x64 platforms, the DumpStack command creates a verbose stack trace.

在基于 IA-64 的平台上,DumpStack 命令模拟调试器的 K 命令。On IA-64-based platforms, the DumpStack command mimics the debugger's K command. 在基于 IA-64 的平台上,将忽略 topbottom 参数。The top and bottom parameters are ignored on IA-64-based platforms.
DumpSig <sigaddr> <moduleaddr>DumpSig <sigaddr> <moduleaddr> 显示有关指定地址处的 Sig 结构的信息。Displays information about a Sig structure at the specified address.
DumpSigElem <sigaddr> <moduleaddr>DumpSigElem <sigaddr> <moduleaddr> 显示签名对象的单个元素。Displays a single element of a signature object. 大多数情况下,应使用 DumpSig 查看单个签名对象。In most cases, you should use DumpSig to look at individual signature objects. 但是,如果签名已在某种程度上被损坏,则可使用 DumpSigElem 读取它的有效部分。However, if a signature has been corrupted in some way, you can use DumpSigElem to read the valid portions of it.
DumpStackObjects [-verify] [top stack [bottom stack]]DumpStackObjects [-verify] [top stack [bottom stack]]

-or-

DumpStackObjects [-verify] [top stack [bottom stack]]DSO [-verify] [top stack [bottom stack]]
显示在当前堆栈的边界内找到的所有托管对象。Displays all managed objects found within the bounds of the current stack.

-verify 选项验证对象字段的每个非静态 CLASS 字段。The -verify option validates each non-static CLASS field of an object field.

DumpStackObject 命令与堆栈跟踪命令(如 K 命令和 CLRStack 命令)一起使用以确定局部变量和参数的值。Use the DumpStackObject command with stack tracing commands such as the K command and the CLRStack command to determine the values of local variables and parameters.
DumpVC <MethodTable address> <Address>DumpVC <MethodTable address> <Address> 显示有关指定地址处的值类字段的信息。Displays information about the fields of a value class at the specified address.

MethodTable 参数使 DumpVC 命令可以正确解释字段。The MethodTable parameter allows the DumpVC command to correctly interpret fields. 值类不将方法表作为其第一个字段。Value classes do not have a method table as their first field.
EEHeap [-gc] [-loader]EEHeap [-gc] [-loader] 显示有关内部 CLR 数据结构所使用的进程内存的信息。Displays information about process memory consumed by internal CLR data structures.

-gc-loader 选项将此命令的输出限制为垃圾回收器或加载程序数据结构。The -gc and -loader options limit the output of this command to garbage collector or loader data structures.

有关垃圾回收器的信息列出了托管堆中每个段的范围。The information for the garbage collector lists the ranges of each segment in the managed heap. 如果指针落在由 -gc 给定的段范围内,则该指针是一个对象指针。If the pointer falls within a segment range given by -gc, the pointer is an object pointer.
EEStack [-short] [-EE]EEStack [-short] [-EE] 对一个进程中的所有线程运行 DumpStack 命令。Runs the DumpStack command on all threads in the process.

-EE 选项直接传递给 DumpStack 命令。The -EE option is passed directly to the DumpStack command. -short 参数将输出限制为以下类型的线程:The -short parameter limits the output to the following kinds of threads:

已获取锁的线程。Threads that have taken a lock.

己停止运行以允许垃圾回收的线程。Threads that have been stalled in order to allow a garbage collection.

当前在托管代码中的线程。Threads that are currently in managed code.
EEVersionEEVersion 显示 CLR 版本。Displays the CLR version.
EHInfo [<MethodDesc address>] [<Code address>]EHInfo [<MethodDesc address>] [<Code address>] 显示指定方法中的异常处理块。Displays the exception handling blocks in a specified method. 此命令显示子句块(try 块)和处理程序块(catch 块)的代码地址和偏移量。This command displays the code addresses and offsets for the clause block (the try block) and the handler block (the catch block).
常见问题解答FAQ 显示常见问题。Displays frequently asked questions.
FinalizeQueue [-detail] | [-allReady] [-short]FinalizeQueue [-detail] | [-allReady] [-short] 显示所有已进行终结注册的对象。Displays all objects registered for finalization.

-detail 选项显示有关需要清理的任何 SyncBlocks 的额外信息,以及有关等待清理的任何 RuntimeCallableWrappers (RCW) 的额外信息。The -detail option displays extra information about any SyncBlocks that need to be cleaned up, and any RuntimeCallableWrappers (RCWs) that await cleanup. 这两种数据结构都由终结器线程在运行时进行缓存和清理。Both of these data structures are cached and cleaned up by the finalizer thread when it runs.

-allReady 选项显示所有准备终止的对象,无论它们已被垃圾回收标记成这样,还是将被下一个垃圾回收标记。The -allReady option displays all objects that are ready for finalization, regardless of whether they are already marked by the garbage collection as such, or will be marked by the next garbage collection. “准备终止”列表中的对象为不再为根的可终止对象。The objects that are in the "ready for finalization" list are finalizable objects that are no longer rooted. 此选项可能耗费大量资源,因为它验证可终止队列中的所有对象是否仍然为根对象。This option can be very expensive, because it verifies whether all the objects in the finalizable queues are still rooted.

-short 选项将输出限制为每个对象的地址。The -short option limits the output to the address of each object. 如果将此选项与 -allReady 一起使用,则将枚举具有不再为根的终结器的所有对象。If it is used in conjunction with -allReady, it enumerates all objects that have a finalizer that are no longer rooted. 如果单独使用此选项,则将列出终结和“准备终结”队列中的所有对象。If it is used independently, it lists all objects in the finalizable and "ready for finalization" queues.
FindAppDomain <Object address>FindAppDomain <Object address> 确定指定地址处的对象的应用程序域。Determines the application domain of an object at the specified address.
FindRoots -gen <N> | -gen any |<object address>FindRoots -gen <N> | -gen any |<object address> 导致调试器在指定生成的下次回收时在调试对象中中断。Causes the debugger to break in the debuggee on the next collection of the specified generation. 在中断发生时立即重置该效果。The effect is reset as soon as the break occurs. 若要在下一个集合中断,你必须重新发出该命令。To break on the next collection, you have to reissue the command. 此命令的 <object address> 形式在 -gen-gen any 引起的中断发生后使用。The <object address> form of this command is used after the break caused by the -gen or -gen any has occurred. 此时,调试对象处于正确的状态,以便 FindRoots 从当前已报废的生成中识别出对象的根。At that time, the debuggee is in the right state for FindRoots to identify roots for objects from the current condemned generations.
GCHandles [-perdomain]GCHandles [-perdomain] 显示有关进程中的垃圾回收器句柄的统计信息。Displays statistics about garbage collector handles in the process.

-perdomain 选项将按应用程序域排列统计信息。The -perdomain option arranges the statistics by application domain.

使用 GCHandles 命令可查找由垃圾回收器句柄泄漏导致的内存泄漏。Use the GCHandles command to find memory leaks caused by garbage collector handle leaks. 例如,当代码由于强垃圾回收器句柄仍指向一个大型数组而保留该数组时,若不释放句柄就将其放弃,则会发生内存泄漏。For example, a memory leak occurs when code retains a large array because a strong garbage collector handle still points to it, and the handle is discarded without freeing it.
GCHandleLeaksGCHandleLeaks 在内存中搜索进程中的对强垃圾回收器句柄和固定垃圾回收器句柄的任何引用并显示结果。Searches memory for any references to strong and pinned garbage collector handles in the process and displays the results. 如果找到某个句柄,GCHandleLeaks 命令将显示相应的引用地址。If a handle is found, the GCHandleLeaks command displays the address of the reference. 如果在内存中找不到句柄,此命令将显示一个通知。If a handle is not found in memory, this command displays a notification.
GCInfo <MethodDesc address><Code address>GCInfo <MethodDesc address><Code address> 显示指示寄存器或堆栈位置何时包含托管对象的数据。Displays data that indicates when registers or stack locations contain managed objects. 如果发生垃圾回收,回收器必须知道对象引用的位置,以便可以使用新的对象指针值更新相应的对象引用。If a garbage collection occurs, the collector must know the locations of references to objects so it can update them with new object pointer values.
GCRoot [-nostacks] <Object address>GCRoot [-nostacks] <Object address> 显示有关对指定地址处的对象的引用(或根)的信息。Displays information about references (or roots) to an object at the specified address.

GCRoot 命令将检查整个托管堆和句柄表以查找其他对象内的句柄和堆栈上的句柄。The GCRoot command examines the entire managed heap and the handle table for handles within other objects and handles on the stack. 然后,在每个堆栈中搜索对象的指针,同时还搜索终结器队列。Each stack is then searched for pointers to objects, and the finalizer queue is also searched.

此命令无法确定堆栈根是有效的还是已丢弃。This command does not determine whether a stack root is valid or is discarded. 使用 CLRStackU 命令可对本地或自变量值所属的帧进行反汇编,以便确定堆栈根是否仍在使用中。Use the CLRStack and U commands to disassemble the frame that the local or argument value belongs to in order to determine if the stack root is still in use.

-nostacks 选项将搜索限制为垃圾回收器句柄和 Freachable 对象。The -nostacks option restricts the search to garbage collector handles and freachable objects.
GCWhere <object address>GCWhere <object address> 显示垃圾回收堆中自变量传入的位置和大小。Displays the location and size in the garbage collection heap of the argument passed in. 如果自变量位于托管堆中,但不是有效的对象地址,则大小显示为 0(零)。When the argument lies in the managed heap but is not a valid object address, the size is displayed as 0 (zero).
help [<command>] [faq]help [<command>] [faq] 在未指定参数时显示所有可用命令,或者显示有关指定命令的详细帮助信息。Displays all available commands when no parameter is specified, or displays detailed help information about the specified command.

faq 参数显示常见问题的答案。The faq parameter displays answers to frequently asked questions.
HeapStat [-inclUnrooted | -iu]HeapStat [-inclUnrooted | -iu] 显示每个堆的生成大小及每个堆上各生成的可用空间总量。Displays the generation sizes for each heap and the total free space in each generation on each heap. 如果指定 -inclUnrooted 选项,则报告将包括有关不再为根的垃圾回收堆中的托管对象的信息。If the -inclUnrooted option is specified, the report includes information about the managed objects from the garbage collection heap that is no longer rooted.
HistClearHistClear 释放由 Hist 命令系列使用的任何资源。Releases any resources used by the family of Hist commands.

通常,你不必显式调用 HistClear,因为每个 HistInit 都会清理以前的资源。Generally, you do not have to explicitly call HistClear, because each HistInit cleans up the previous resources.
HistInitHistInit 从保存在调试对象中的压力日志初始化 SOS 结构。Initializes the SOS structures from the stress log saved in the debuggee.
HistObj <obj_address>HistObj <obj_address> 检查所有压力日志的重定位记录,并显示可能已将地址作为自变量传入的垃圾回收重定位链。Examines all stress log relocation records and displays the chain of garbage collection relocations that may have led to the address passed in as an argument.
HistObjFind <obj_address>HistObjFind <obj_address> 显示在指定地址处引用对象的所有日志项。Displays all the log entries that reference an object at the specified address.
HistRoot <root>HistRoot <root> 显示与指定根的提升和重定位相关的信息。Displays information related to both promotions and relocations of the specified root.

根值可用于通过垃圾回收来跟踪对象的移动。The root value can be used to track the movement of an object through the garbage collections.
IP2MD <Code address>IP2MD <Code address> 显示已 JIT 编译的代码中指定地址处的 MethodDesc 结构。Displays the MethodDesc structure at the specified address in code that has been JIT-compiled.
ListNearObj (lno) <obj_address>ListNearObj (lno) <obj_address> 显示指定地址之前和之后的对象。Displays the objects preceding and following the specified address. 该命令在垃圾回收堆和自变量地址之后的对象中寻找地址,而该垃圾回收堆看上去像托管对象(基于有效的方法表)的有效开头。The command looks for the address in the garbage collection heap that looks like a valid beginning of a managed object (based on a valid method table) and the object following the argument address.
MinidumpMode [0] [1]MinidumpMode [0] [1] 防止在使用小型转储时运行不安全的命令。Prevents running unsafe commands when using a minidump.

传递 0 禁用此功能,或传递 1 启用此功能。Pass 0 to disable this feature or 1 to enable this feature. 默认情况下,MinidumpMode 值设置为 0By default, the MinidumpMode value is set to 0.

使用 .dump /m 命令或 .dump 命令创建的小型转储具有有限的 CLR 特定数据,允许只正确地运行一小部分 SOS 命令。Minidumps created with the .dump /m command or .dump command have limited CLR-specific data and allow you to run only a subset of SOS commands correctly. 有些命令可能会因错误而失败,因为所需的内存区域未被映射或仅被部分映射。Some commands may fail with unexpected errors because required areas of memory are not mapped or are only partially mapped. 此选项可防止你对小型转储运行不安全的命令。This option protects you from running unsafe commands against minidumps.
Name2EE <module name> <type or method name>Name2EE <module name> <type or method name>

-or-

Name2EE <module name>!<type or method name>Name2EE <module name>!<type or method name>
显示指定模块中的指定类型或方法的 MethodTable 结构和 EEClass 结构。Displays the MethodTable structure and EEClass structure for the specified type or method in the specified module.

在进程中必须加载指定的模块。The specified module must be loaded in the process.

若要获取正确的类型名称,请通过使用 Ildasm.exe(IL 反汇编程序)浏览模块。To get the proper type name, browse the module by using the Ildasm.exe (IL Disassembler). 也可以将 * 作为模块名参数传递以搜索所有已加载的托管模块。You can also pass * as the module name parameter to search all loaded managed modules. module name 参数也可以是模块的调试器名称,如 mscorlibimage00400000The module name parameter can also be the debugger's name for a module, such as mscorlib or image00400000.

此命令支持 <module>!<type> 的 Windows 调试器语法。This command supports the Windows debugger syntax of <module>!<type>. 类型必须是完全限定的。The type must be fully qualified.
ObjSize [<Object address>] | [-aggregate] [-stat]ObjSize [<Object address>] | [-aggregate] [-stat] 显示指定对象的大小。Displays the size of the specified object. 如果未指定任何参数,则 ObjSize 命令将显示在托管线程上找到的所有对象的大小,显示进程中的所有垃圾回收器句柄,并对这些句柄指向的任何对象的大小进行合计。If you do not specify any parameters, the ObjSize command displays the size of all objects found on managed threads, displays all garbage collector handles in the process, and totals the size of any objects pointed to by those handles. 除父对象之外,ObjSize 命令还包括所有子对象的大小。The ObjSize command includes the size of all child objects in addition to the parent.

-aggregate 选项能够与 -stat 参数一起使用,以获得仍为根类型的类型的详细视图。The -aggregate option can be used in conjunction with the -stat argument to get a detailed view of the types that are still rooted. 通过使用 !dumpheap -stat!objsize -aggregate -stat,可以确定不再为根的对象并诊断各种内存问题。By using !dumpheap -stat and !objsize -aggregate -stat, you can determine which objects are no longer rooted and diagnose various memory issues.
PrintException [-nested] [-lines] [<Exception object address>]PrintException [-nested] [-lines] [<Exception object address>]

-or-

PE [-nested] [<Exception object address>]PE [-nested] [<Exception object address>]
显示从指定地址处的 Exception 类派生的任何对象的字段并设置这些字段的格式。Displays and formats fields of any object derived from the Exception class at the specified address. 如果不指定地址,PrintException 命令将显示在当前线程上引发的最后一个异常。If you do not specify an address, the PrintException command displays the last exception thrown on the current thread.

-nested 选项显示有关嵌套异常对象的详细信息。The -nested option displays details about nested exception objects.

-lines 选项显示源信息(如果可用)。The -lines option displays source information, if available.

可以使用此命令设置 _stackTrace 字段的格式并查看该字段(它是一个二进制数组)。You can use this command to format and view the _stackTrace field, which is a binary array.
ProcInfo [-env] [-time] [-mem]ProcInfo [-env] [-time] [-mem] 显示进程的环境变量、内核 CPU 时间和内存使用统计信息。Displays environment variables for the process, kernel CPU time, and memory usage statistics.
RCWCleanupList <RCWCleanupList address>RCWCleanupList <RCWCleanupList address> 显示在指定地址处等待清理的运行时可调用包装器的列表。Displays the list of runtime callable wrappers at the specified address that are awaiting cleanup.
SaveModule <Base address> <Filename>SaveModule <Base address> <Filename> 将加载到内存中指定地址的图像写入指定文件。Writes an image, which is loaded in memory at the specified address, to the specified file.
SOSFlushSOSFlush 刷新内部 SOS 缓存。Flushes an internal SOS cache.
StopOnException [-derived] [-create | -create2] <Exception> <Pseudo-register number>StopOnException [-derived] [-create | -create2] <Exception> <Pseudo-register number> 使调试器在引发指定异常时停止,但在引发其他异常时继续运行。Causes the debugger to stop when the specified exception is thrown, but to continue running when other exceptions are thrown.

-derived 选项用于捕获指定异常以及从指定异常派生的每个异常。The -derived option catches the specified exception and every exception that derives from the specified exception.
SyncBlk [-all | <syncblk number>]SyncBlk [-all | <syncblk number>] 显示指定的 SyncBlock 结构或所有 SyncBlock 结构。Displays the specified SyncBlock structure or all SyncBlock structures. 如果不传递任何自变量,SyncBlk 命令将显示与一个线程拥有的对象对应的 SyncBlock 结构。If you do not pass any arguments, the SyncBlk command displays the SyncBlock structure corresponding to objects that are owned by a thread.

SyncBlock 结构是一个容器,用于存放无需为每个对象创建的额外信息。A SyncBlock structure is a container for extra information that does not need to be created for every object. 它可以存放 COM 互操作数据、哈希代码和用于线程安全操作的锁定信息。It can hold COM interop data, hash codes, and locking information for thread-safe operations.
ThreadPoolThreadPool 显示有关托管线程池的信息,包括队列中工作请求的数目、完成端口线程的数目和计时器的数目。Displays information about the managed thread pool, including the number of work requests in the queue, the number of completion port threads, and the number of timers.
Token2EE <module name> <token>Token2EE <module name> <token> 将指定模块中的指定元数据标记转换成 MethodTable 结构或 MethodDesc 结构。Turns the specified metadata token in the specified module into a MethodTable structure or MethodDesc structure.

可以传递 * 作为模块名参数,以便在每个已加载的托管模块中查找该标记映射到的内容。You can pass * for the module name parameter to find what that token maps to in every loaded managed module. 也可以传递某个模块的调试器名称,如 mscorlibimage00400000You can also pass the debugger's name for a module, such as mscorlib or image00400000.
Threads [-live] [-special]Threads [-live] [-special] 显示进程中的所有托管线程。Displays all managed threads in the process.

Threads 命令显示调试程序速记 ID、CLR 线程 ID 以及操作系统线程 ID。The Threads command displays the debugger shorthand ID, the CLR thread ID, and the operating system thread ID. 此外,Threads 命令还会显示“Domain”列、“APT”列和“Exception”列,这三列分别用于指示正在执行某线程的应用程序域、显示 COM 单元模式以及显示该线程中引发的上一个异常。Additionally, the Threads command displays a Domain column that indicates the application domain in which a thread is executing, an APT column that displays the COM apartment mode, and an Exception column that displays the last exception thrown in the thread.

-live 选项显示与活动线程关联的线程。The -live option displays threads associated with a live thread.

选项显示由 CLR 创建的所有特殊线程。The -special option displays all special threads created by the CLR. 特殊线程包括垃圾回收线程(在并发垃圾回收和服务器垃圾回收中)、调试器帮助程序线程、终结器线程、AppDomain 卸载线程和线程池计时器线程。Special threads include garbage collection threads (in concurrent and server garbage collection), debugger helper threads, finalizer threads, AppDomain unload threads, and thread pool timer threads.
ThreadState < State value field >ThreadState < State value field > 显示线程的状态。Displays the state of the thread. value 参数为 Threads 报告输出中的 State 字段的值。The value parameter is the value of the State field in the Threads report output.

示例:Example:

0:003> !Threads ThreadCount: 2 UnstartedThread: 0 BackgroundThread: 1 PendingThread: 0 DeadThread: 0 Hosted Runtime: no PreEmptive GC Alloc Lock ID OSID ThreadOBJ State GC Context Domain Count APT Exception 0 1 250 0019b068 a020 Disabled 02349668:02349fe8 0015def0 0 MTA 2 2 944 001a6020 b220 Enabled 00000000:00000000 0015def0 0 MTA (Finalizer) 0:003> !ThreadState b220 Legal to Join Background CLR Owns CoInitialized In Multi Threaded Apartment
TraverseHeap [-xml] <filename>TraverseHeap [-xml] <filename> 以 CLR 探查器能够识别的格式将堆信息写入指定文件。Writes heap information to the specified file in a format understood by the CLR profiler. -xml 选项使 TraverseHeap 命令将文件格式化为 XML。The -xml option causes the TraverseHeap command to format the file as XML.

可以从 Microsoft 下载中心下载 CLR 探查器。You can download the CLR Profiler from the Microsoft Download Center.
U [-gcinfo] [-ehinfo] [-n] <MethodDesc address> | <Code address>U [-gcinfo] [-ehinfo] [-n] <MethodDesc address> | <Code address> 显示由方法的 MethodDesc 结构指针或方法体内的代码地址指定的托管方法的反汇编(带有批注)。Displays an annotated disassembly of a managed method specified either by a MethodDesc structure pointer for the method or by a code address within the method body. U 命令将从开始到结束显示整个方法,并带有将元数据标记转换为名称的批注。The U command displays the entire method from start to finish, with annotations that convert metadata tokens to names.

-gcinfo 选项使 U 命令显示方法的 GCInfo 结构。The -gcinfo option causes the U command to display the GCInfo structure for the method.

-ehinfo 选项显示方法的异常信息。The -ehinfo option displays exception information for the method. 也可以使用 EHInfo 命令获取此信息。You can also obtain this information with the EHInfo command.

-n 选项禁止显示源文件名和行号。The -n option disables the display of source file names and line numbers. 如果调试器已指定选项 SYMOPT_LOAD_LINES,则 SOS 将查找每个托管帧的符号,如果成功,则将显示对应的源文件名和行号。If the debugger has the option SYMOPT_LOAD_LINES specified, SOS looks up the symbols for every managed frame and, if successful, displays the corresponding source file name and line number. 可以指定 -n 选项来禁用此行为。You can specify the -n option to disable this behavior.
VerifyHeapVerifyHeap 检查垃圾回收器堆中是否有损坏迹象,并显示找到的任何错误。Checks the garbage collector heap for signs of corruption and displays any errors found.

错误构造的平台调用可能导致堆损坏。Heap corruptions can be caused by platform invoke calls that are constructed incorrectly.
VerifyObj <object address>VerifyObj <object address> 检查作为自变量传递的对象是否有损坏迹象。Checks the object that is passed as an argument for signs of corruption.
VMMapVMMap 遍历虚拟地址空间并显示应用于每个区域的保护类型。Traverses the virtual address space and displays the type of protection applied to each region.
VMStatVMStat 提供虚拟地址空间的摘要视图,并按应用于该内存的每种保护类型(可用、已保留、已提交、私有、已映射和映像)排序。Provides a summary view of the virtual address space, ordered by each type of protection applied to that memory (free, reserved, committed, private, mapped, image). “TOTAL”列显示“AVERAGE”列乘以“BLK COUNT”列的结果。The TOTAL column displays the result of the AVERAGE column multiplied by the BLK COUNT column.

备注Remarks

SOS 调试扩展允许你查看有关在 CLR 内运行的代码的信息。The SOS Debugging Extension lets you view information about code that is running inside the CLR. 例如,可以使用 SOS 调试扩展显示有关托管堆的信息、查找堆损坏情况、显示运行时所使用的内部数据类型以及查看有关在运行时内运行的所有托管代码的信息。For example, you can use the SOS Debugging Extension to display information about the managed heap, look for heap corruptions, display internal data types used by the runtime, and view information about all managed code running inside the runtime.

若要在 Visual Studio 中使用 SOS 调试扩展,请安装 Windows 驱动程序工具包 (WDK)To use the SOS Debugging Extension in Visual Studio, install the Windows Driver Kit (WDK). 有关 Visual Studio 中的集成调试环境的信息,请参阅调试环境For information about the integrated debugging environment in Visual Studio, see Debugging Environments.

还可以通过将 SOS 调试扩展加载到 WinDbg.exe 调试器中并在 WinDbg.exe 中执行命令来使用此扩展。You can also use the SOS Debugging Extension by loading it into the WinDbg.exe debugger and executing commands within WinDbg.exe.

若要将 SOS 调试扩展加载到 WinDbg.exe 调试器中,请在工具中运行以下命令:To load the SOS Debugging Extension into the WinDbg.exe debugger, run the following command in the tool:

.loadby sos clr

WinDbg.exe 和 Visual Studio 使用与当前使用的 Mscorwks.dll 版本对应的 SOS.dll 版本。WinDbg.exe and Visual Studio use a version of SOS.dll that corresponds to the version of Mscorwks.dll currently in use. 默认情况下,应使用与当前版本的 Mscorwks.dll 匹配的 SOS.dll 版本。By default, you should use the version of SOS.dll that matches the current version of Mscorwks.dll.

若要使用在其他计算机上创建的转储文件,请确保该安装所附带的 Mscorwks.dll 文件存在于符号路径中,并加载相应的 SOS.dll 版本。To use a dump file created on another computer, make sure that the Mscorwks.dll file that came with that installation is in your symbol path, and load the corresponding version of SOS.dll.

若要加载特定版本的 SOS.dll,请在 Windows 调试器中键入以下命令:To load a specific version of SOS.dll, type the following command into the Windows Debugger:

.load <full path to sos.dll>

示例Examples

下面的命令显示在地址 00ad28d0 处的数组内容。The following command displays the contents of an array at the address 00ad28d0. 显示从第二个元素开始,连续显示五个元素。The display starts from the second element and continues for five elements.

!dumparray -start 2 -length 5 -detail 00ad28d0

下面的命令显示在地址 1ca248 处的程序集的内容。The following command displays the contents of an assembly at the address 1ca248.

!dumpassembly 1ca248

下面的命令显示有关垃圾回收器堆的信息。The following command displays information about the garbage collector heap.

!dumpheap

下面的命令将内存中压力日志的内容写入到当前目录中名为 StressLog.txt 的(默认)文件中。The following command writes the contents of the in-memory stress log to a (default) file called StressLog.txt in the current directory.

!DumpLog

下面的命令显示在地址 MethodDesc 处的 902f40 结构。The following command displays the MethodDesc structure at the address 902f40.

!dumpmd 902f40

下面的命令显示有关地址 1caa50 处的模块的信息。The following command displays information about a module at the address 1caa50.

!dumpmodule 1caa50

下面的命令显示有关地址 a79d40 处的对象的信息。The following command displays information about an object at the address a79d40.

!DumpObj a79d40

下面的命令使用地址 00a79d9c 处的方法表显示地址 0090320c 处的值类的字段。The following command displays the fields of a value class at the address 00a79d9c using the method table at the address 0090320c.

!DumpVC 0090320c 00a79d9c

下面的命令显示垃圾回收器所使用的进程内存。The following command displays the process memory used by the garbage collector.

!eeheap -gc

下面的命令显示所有已做好终结计划的对象。The following command displays all objects scheduled for finalization.

!finalizequeue

下面的命令确定地址 00a79d98 处的对象的应用程序域。The following command determines the application domain of an object at the address 00a79d98.

!findappdomain 00a79d98

下面的命令显示当前进程中的所有垃圾回收器句柄。The following command displays all garbage collector handles in the current process.

!gcinfo 5b68dbb8

下面的命令显示模块 MethodTable 的类 EEClass 中的 Main 方法的 MainClassunittest.exe 结构。The following command displays the MethodTable and EEClass structures for the Main method in the class MainClass in the module unittest.exe.

!name2ee unittest.exe MainClass.Main

下面的命令显示有关模块 02000003 中的地址 unittest.exe 处的元数据标记的信息。The following command displays information about the metadata token at the address 02000003 in the module unittest.exe.

!token2ee unittest.exe 02000003

请参阅See also