SOS.dll (SOS Debugging Extension)

时间:2021-05-31 09:00:47

SOS.dll (SOS Debugging Extension)

  • lays threads associated with a live thread.

  • The -special option displays all special threads created by the CLR. Special threads include garbage collection threads (in concurrent and server garbage collection), debugger helper threads, finalizer threads, AppDomainunload threads, and thread pool timer threads.

ThreadState <State value field>

Displays the state of the thread. 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>

Writes heap information to the specified file in a format understood by the CLR profiler. The -xml option causes the TraverseHeap command to format the file as XML.

You can download the CLR Profiler from the Microsoft Download Center.

U [-gcinfo] [-ehinfo] [-n] <MethodDesc address> | <Code address>

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. The U command displays the entire method from start to finish, with annotations that convert metadata tokens to names.

  • The -gcinfo option causes the U command to display the GCInfo structure for the method.

  • The -ehinfo option displays exception information for the method. You can also obtain this information with the EHInfo command.

  • The -n option disables the display of source file names and line numbers. 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. You can specify the -n option to disable this behavior.

VerifyHeap

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>

Checks the object that is passed as an argument for signs of corruption.

VMMap

Traverses the virtual address space and displays the type of protection applied to each region.

VMStat

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). The TOTAL column displays the result of the AVERAGE column multiplied by the BLK COUNT column.

Remarks

 

The SOS Debugging Extension lets you view information about code that is running inside the common language runtime. 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.

To use the SOS Debugging Extension in Visual Studio, install the Windows Driver Kit (WDK). For information about the integrated debugging environment in Visual Studio, see Debugging Environments in the Windows Dev Center.

You can also use the SOS Debugging Extension by loading it into the WinDbg.exe debugger, which is available from the WDK and Developer Tools Web site, and executing commands within 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 and Visual Studio use a version of SOS.dll that corresponds to the version of Mscorwks.dll currently in use. In versions 1.1 and 2.0 of the .NET Framework, SOS.dll is installed in the same directory as Mscorwks.dll. By default, you should use the version of SOS.dll that matches the current version of Mscorwks.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.

To load a specific version of SOS.dll, type the following command into the Windows Debugger:

 
 
.load <full path to sos.dll>

Examples

 

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

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

The following command writes the contents of the in-memory stress log to a (default) file called StressLog.txt in the current directory.

 
 
!DumpLog

The following command displays the MethodDesc structure at the address 902f40.

 
 
!dumpmd 902f40

The following command displays information about a module at the address 1caa50.

 
 
!dumpmodule 1caa50

The following command displays information about an object at the address a79d40.

 
 
!DumpObj a79d40

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

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

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

The following command displays information about the metadata token at the address 02000003 in the module unittest.exe.

 
 
!token2ee unittest.exe 02000003
 
https://developer.microsoft.com/zh-cn/windows/hardware/windows-driver-kit
http://sharptoolbox.com/tools/dottrace
http://sharptoolbox.com/tools/net-memory-profiler