windbg for CLR
Posted ahuoheng
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了windbg for CLR相关的知识,希望对你有一定的参考价值。
0:003> .load C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\sos.dll
0:003> !help
-------------------------------------------------------------------------------
SOS is a debugger extension DLL designed to aid in the debugging of managed
programs. Functions are listed by category, then roughly in order of
importance. Shortcut names for popular functions are listed in parenthesis.
Type "!help <functionname>" for detailed info on that function.
Object Inspection Examining code and stacks
----------------------------- -----------------------------
DumpObj (do) Threads
DumpArray (da) CLRStack
DumpStackObjects (dso) IP2MD
DumpHeap U
DumpVC DumpStack
GCRoot EEStack
ObjSize GCInfo
FinalizeQueue EHInfo
PrintException (pe) COMState
TraverseHeap BPMD
Examining CLR data structures Diagnostic Utilities
----------------------------- -----------------------------
DumpDomain VerifyHeap
EEHeap DumpLog
Name2EE FindAppDomain
SyncBlk SaveModule
DumpMT GCHandles
DumpClass GCHandleLeaks
DumpMD VMMap
Token2EE VMStat
EEVersion ProcInfo
DumpModule StopOnException (soe)
ThreadPool MinidumpMode
DumpAssembly
DumpMethodSig Other
DumpRuntimeTypes -----------------------------
DumpSig FAQ
RCWCleanupList
DumpIL
0:003> !dumpdomain
--------------------------------------
System Domain: 7a38bb38
LowFrequencyHeap: 7a38bb5c
HighFrequencyHeap: 7a38bbb8
StubHeap: 7a38bc14
Stage: OPEN
Name: None
--------------------------------------
Shared Domain: 7a38c110
LowFrequencyHeap: 7a38c134
HighFrequencyHeap: 7a38c190
StubHeap: 7a38c1ec
Stage: OPEN
Name: None
Assembly: 00161548
--------------------------------------
Domain 1: 00154808
LowFrequencyHeap: 0015482c
HighFrequencyHeap: 00154888
StubHeap: 001548e4
Stage: OPEN
SecurityDescriptor: 0014a5a8
Name: dotnetForWindbg.exe
Assembly: 00161548 [C:\\WINDOWS\\assembly\\GAC_32\\mscorlib\\2.0.0.0__b77a5c561934e089\\mscorlib.dll]
ClassLoader: 0014ea40
SecurityDescriptor: 0014d2e0
Module Name
790c2000 C:\\WINDOWS\\assembly\\GAC_32\\mscorlib\\2.0.0.0__b77a5c561934e089\\mscorlib.dll
Assembly: 001695e0 [D:\\debug\\dotnetForWindbg.exe]
ClassLoader: 00169668
SecurityDescriptor: 00168ef0
Module Name
00a52c14 D:\\debug\\dotnetForWindbg.exe
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 990 0014a600 200a020 Enabled 013a39a8:013a3fe8 00154808 0 MTA
2 2 e18 0015d740 b220 Enabled 00000000:00000000 00154808 0 MTA (Finalizer)
0:003> ~*e!clrstack
OS Thread Id: 0x990 (0)
ESP EIP
0012f424 7c82ed54 [HelperMethodFrame: 0012f424] System.Threading.Thread.SleepInternal(Int32)
0012f478 793d80f5 System.Threading.Thread.Sleep(Int32)
0012f47c 00d700ba dotnetForWindbg.Program.Main(System.String[])
0012f69c 79e88f63 [GCFrame: 0012f69c]
OS Thread Id: 0xe38 (1)
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
OS Thread Id: 0xe18 (2)
Failed to start stack walk: 80004005
OS Thread Id: 0x5e8 (3)
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
0:000> !threadpool
CPU utilization 0%
Worker Thread: Total: 0 Running: 0 Idle: 0 MaxLimit: 0 MinLimit: 0
Work Request in Queue: 0
--------------------------------------
Number of Timers: 0
--------------------------------------
Completion Port Thread:Total: 0 Free: 0 MaxFree: 0 CurrentLimit: 0 MaxLimit: 1000 MinLimit: 0
0:000> !GCHandles
GC Handle Statistics:
Strong Handles: 14
Pinned Handles: 4
Async Pinned Handles: 0
Ref Count Handles: 0
Weak Long Handles: 0
Weak Short Handles: 1
Other Handles: 0
Statistics:
MT Count TotalSize Class Name
790f9c18 1 12 System.Object
790fc79c 1 24 System.Reflection.Assembly
790fb668 1 28 System.SharedStatics
790fac70 1 72 System.ExecutionEngineException
790fabcc 1 72 System.StackOverflowException
790fab28 1 72 System.OutOfMemoryException
790fb8c8 1 100 System.AppDomain
790fb238 2 104 System.Threading.Thread
790fd824 4 144 System.Security.PermissionSet
790fad14 2 144 System.Threading.ThreadAbortException
79124228 4 8736 System.Object[]
Total 19 objects
0:000> !EEHeap
Loader Heap:
--------------------------------------
System Domain: 7a38bb38
LowFrequencyHeap: Size: 0x0(0)bytes.
HighFrequencyHeap: 00a42000(8000:1000) Size: 0x1000(4096)bytes.
StubHeap: 00a4a000(2000:1000) Size: 0x1000(4096)bytes.
Virtual Call Stub Heap:
IndcellHeap: Size: 0x0(0)bytes.
LookupHeap: Size: 0x0(0)bytes.
ResolveHeap: Size: 0x0(0)bytes.
DispatchHeap: Size: 0x0(0)bytes.
CacheEntryHeap: Size: 0x0(0)bytes.
Total size: 0x2000(8192)bytes
--------------------------------------
Shared Domain: 7a38c110
LowFrequencyHeap: 00a70000(2000:1000) Size: 0x1000(4096)bytes.
HighFrequencyHeap: Size: 0x0(0)bytes.
StubHeap: 00a7a000(2000:1000) Size: 0x1000(4096)bytes.
Virtual Call Stub Heap:
IndcellHeap: Size: 0x0(0)bytes.
LookupHeap: Size: 0x0(0)bytes.
ResolveHeap: 00a8b000(5000:1000) Size: 0x1000(4096)bytes.
DispatchHeap: 00a87000(4000:1000) Size: 0x1000(4096)bytes.
CacheEntryHeap: Size: 0x0(0)bytes.
Total size: 0x4000(16384)bytes
--------------------------------------
Domain 1: 154808
LowFrequencyHeap: 00a50000(2000:2000) Size: 0x2000(8192)bytes.
HighFrequencyHeap: 00a52000(8000:2000) Size: 0x2000(8192)bytes.
StubHeap: Size: 0x0(0)bytes.
Virtual Call Stub Heap:
IndcellHeap: Size: 0x0(0)bytes.
LookupHeap: Size: 0x0(0)bytes.
ResolveHeap: Size: 0x0(0)bytes.
DispatchHeap: Size: 0x0(0)bytes.
CacheEntryHeap: Size: 0x0(0)bytes.
Total size: 0x4000(16384)bytes
--------------------------------------
Jit code heap:
LoaderCodeHeap: 00d70000(10000:1000) Size: 0x1000(4096)bytes.
Total size: 0x1000(4096)bytes
--------------------------------------
Module Thunk heaps:
Module 790c2000: Size: 0x0(0)bytes.
Module 00a52c14: Size: 0x0(0)bytes.
Total size: 0x0(0)bytes
--------------------------------------
Module Lookup Table heaps:
Module 790c2000: Size: 0x0(0)bytes.
Module 00a52c14: Size: 0x0(0)bytes.
Total size: 0x0(0)bytes
--------------------------------------
Total LoaderHeap size: 0xb000(45056)bytes
=======================================
Number of GC Heaps: 1
generation 0 starts at 0x013a1018
generation 1 starts at 0x013a100c
generation 2 starts at 0x013a1000
ephemeral segment allocation context: none
segment begin allocated size
0015f300 790d6358 790f5800 0x0001f4a8(128168)
013a0000 013a1000 013a3ff4 0x00002ff4(12276)
Large object heap starts at 0x023a1000
segment begin allocated size
023a0000 023a1000 023a3250 0x00002250(8784)
Total Size 0x246ec(149228)
------------------------------
GC Heap Size 0x246ec(149228)
SOSEX - Copyright 2007-2011 by Steve Johnson - http://www.stevestechspot.com/
To report bugs or offer feedback about SOSEX, please email sjjohnson@pobox.com
Quick Ref:
--------------------------------------------------
bpsc (Deprecated. Use !mbp instead)
dlk (no parameters) Displays deadlocks between SyncBlocks and/or ReaderWriterLocks
dumpgen <GenNum> [-free] [-stat] [-type <TYPE_NAME>] Dumps the contents of the specified generation
[-nostrings]
finq [GenNum] [-stat] Displays objects in the finalization queue
frq [-stat] Displays objects in the Freachable queue
gcgen <ObjectAddr> Displays the GC generation of the specified object
gch [HandleType]... Lists all GCHandles, optionally filtered by specified handle types
help [CommandName] Display this screen or details about the specified command
mbc <SOSEX breakpoint ID | *> Clears the specified or all managed breakpoints
mbd <SOSEX breakpoint ID | *> Disables the specified or all managed breakpoints
mbe <SOSEX breakpoint ID | *> Enables the specified or all managed breakpoints
mbl [SOSEX breakpoint ID] Prints the specified or all managed breakpoints
mbm <Type/MethodFilter> [ILOffset] [Options] Sets a managed breakpoint on methods matching the specified filter
mbp <SourceFile> <nLineNum> [ColNum] [Options] Sets a managed breakpoint at the specified source code location
mdso [Options] Dumps object references on the stack and in CPU registers in the current context
mdt [TypeName | VarName | MT] [ADDR] [Options] Displays the fields of an object or type, optionally recursively
mdv [nFrameNum] Displays arguments and locals for a managed frame
mfrag [-stat] Reports free blocks in Gen2, the type of object following the free block, and fragmentation statistics
mframe [nFrameNum] Displays or sets the current managed frame for the !mdt and !mdv commands
mgu // TODO: Document
mk [FrameCount] [-l] [-p] [-a] Prints a stack trace of managed and unmanaged frames
mln [expression] Displays the type of managed data located at the specified address or the current instruction pointer
mlocks (no parameters) Lists all managed lock objects and CriticalSections and their owning threads
mt (no parameters) Steps into the managed method at the current position
mu [address] [-s] [-il] [-n] Displays a disassembly around the current instruction with interleaved source, IL and asm code
muf [MD Address | Code Address] [-s] [-il] [-n] Displays a disassembly with interleaved source, IL and asm code
mwaits (no parameters) Lists all waiting threads and, if known, the locks they are waiting on
mx <Filter String> Displays managed type/field/method names matching the specified filter string
refs <ObjectAddr> Displays all references from and to the specified object
rwlock [ObjectAddr] Displays all RWLocks or, if provided a RWLock address, details of the specified lock
sosexhelp [CommandName] Display this screen or details about the specified command
strings [Options] Lists all strings on managed heaps that match the specified criteria
ListGcHandles - See gch
X64
X86
以上是关于windbg for CLR的主要内容,如果未能解决你的问题,请参考以下文章