WinDbg コマンドメモ
WinDbgはカーネルデバッグができるので欠かせないのだが、なにぶん情報が少ない。特にヘルプがwebベースになっていないのでなかなか大変。とりあえず、使った分だけメモしておくけど、構文とかはヘルプファイルを見てくださいな。
#08/05/10追記
MSDNにありました(Debugging Tools for Windows Introduction)。コマンドリファレンスはDebugger Commandsを参照。
- x (Examine Symbols)
- シンボルの名前とアドレスを確認できる。ワイルドカードが利用できるので
>x *!*
とするとすべてのシンボルを表示することができる。
- lm (List Loaded Modules)
- ロードされているモジュールを列挙する。
>lm l
とするとシンボルの読み込み状態が確認できる。>lm { k|u }
とすると、カーネルもしくはユーザモードのモジュールに限定して表示できる。
- dt (Display Type)
- 指定した構造体の定義、もしくは構造体変数の内容を表示する。
>dt type [-r [n] ]
とするとtype構造体のメンバ変数の型、名前、オフセットなどを表示する。-r を指定するとメンバの型についても再帰的に表示する。n で再帰の深さを指定する。>dt type [-r [n] ] [address]
とするとaddressをtypeと解釈して表示する。
- .reload (Reload Module)
- シンボルを再読み込みする。-f を渡すとすべてのシンボルを読みにいく。
- !thread
- ETHREAD構造体変数のサマリを表示する。
kd> !thread THREAD 81d27da8 Cid 02b8.02bc Teb: 7ffdd000 Win32Thread: e169fd28 RUNNING on processor 0 IRP List: 81f8ec18: (0006,0094) Flags: 00000800 Mdl: 00000000 Impersonation token: e15dad48 (Level Impersonation) DeviceMap e1a48428 Owning Process 81df6a20 Image: winlogon.exe Wait Start TickCount 3341119 Ticks: 0 Context Switch Count 3315 LargeStack UserTime 00:00:01.796 KernelTime 00:00:06.015 Start Address 0x0103d353 Stack Init f8610000 Current f860fc98 Base f8610000 Limit f860d000 Call 0 Priority 15 BasePriority 15 PriorityDecrement 0 DecrementCount 0 ChildEBP RetAddr Args to Child // 以下スタックトレース
表示内容の補足を少し。
- THREAD
- ETHREAD構造体変数のアドレス
- Cid
- PIDとスレッドID(16進数)
- Teb
- KTHREAD構造の中にあるTEB構造体のアドレス
- Win32Thread
- KTHREAD構造の中にあるメンバWin32Threadの値だが、詳細不明*1
- Owning Process
- このスレッドを所有するプロセスのEPROCESS構造体アドレス
- Image
- プロセスの名前
- !process
- EPROCESS構造体変数のサマリを表示する。!process pid でPIDの情報、!process 0 0 でプロセスの一覧を表示する。
kd> !process PROCESS 81df6a20 SessionId: 0 Cid: 02b8 Peb: 7ffde000 ParentCid: 0260 DirBase: 090f9000 ObjectTable: e167a328 HandleCount: 442. Image: winlogon.exe VadRoot 81d28c48 Vads 198 Clone 0 Private 1291. Modified 2683. Locked 0. DeviceMap e10020e0 Token e1738488 ElapsedTime 23:08:55.590 UserTime 00:00:02.031 KernelTime 00:00:07.234 QuotaPoolUsage[PagedPool] 103300 QuotaPoolUsage[NonPagedPool] 42432 Working Set Sizes (now,min,max) (512, 50, 345) (2048KB, 200KB, 1380KB) PeakWorkingSetSize 3079 VirtualSize 94 Mb PeakVirtualSize 104 Mb PageFaultCount 9450 MemoryPriority BACKGROUND BasePriority 13 CommitCharge 1975 THREAD 81d27da8 Cid 02b8.02bc Teb: 7ffdd000 Win32Thread: e169fd28 RUNNING on processor 0 THREAD 81eb6600 Cid 02b8.02c4 Teb: 7ffdc000 Win32Thread: 00000000 WAIT: (DelayExecution) UserMode Alertable 81eb66f0 NotificationTimer // 以下所有スレッドに関する情報が続く
- !dskheap
- デスクトップヒープの内容を表示する。らしい。なぜかうまくいかない。
kd> !dskheap Error Reading rpdeskList from WINDOWSTATION @ 81ec8a40 Failed counting Desktops for Winsta @81ec8a40 EnumDsktps failed on Winsta: 81ec8a40FillWinstaArray failedkd
kd> !pcr KPCR for Processor 0 at ffdff000: Major 1 Minor 1 NtTib.ExceptionList: 80557cb0 NtTib.StackBase: 805584f0 NtTib.StackLimit: 80555700 NtTib.SubSystemTib: 00000000 NtTib.Version: 00000000 NtTib.UserPointer: 00000000 NtTib.SelfTib: 00000000 SelfPcr: ffdff000 Prcb: ffdff120 Irql: 00000000 IRR: 00000000 IDR: ffffffff InterruptMode: 00000000 IDT: 8003f400 GDT: 8003f000 TSS: 80042000 CurrentThread: 80562ca0 NextThread: 00000000 IdleThread: 80562ca0 DpcQueue: 0x80563300 0x804e3fd0 [Normal] nt!KiTimerExpiration
アドレス 0xffdff000 にあることがわかる。型を表示させてみる。
kd> dt _kpcr nt!_KPCR +0x000 NtTib : _NT_TIB +0x01c SelfPcr : Ptr32 _KPCR +0x020 Prcb : Ptr32 _KPRCB +0x024 Irql : UChar +0x028 IRR : Uint4B +0x02c IrrActive : Uint4B +0x030 IDR : Uint4B +0x034 KdVersionBlock : Ptr32 Void +0x038 IDT : Ptr32 _KIDTENTRY +0x03c GDT : Ptr32 _KGDTENTRY +0x040 TSS : Ptr32 _KTSS +0x044 MajorVersion : Uint2B +0x046 MinorVersion : Uint2B +0x048 SetMember : Uint4B +0x04c StallScaleFactor : Uint4B +0x050 DebugActive : UChar +0x051 Number : UChar +0x052 Spare0 : UChar +0x053 SecondLevelCacheAssociativity : UChar +0x054 VdmAlert : Uint4B +0x058 KernelReserved : [14] Uint4B +0x090 SecondLevelCacheSize : Uint4B +0x094 HalReserved : [16] Uint4B +0x0d4 InterruptMode : Uint4B +0x0d8 Spare1 : UChar +0x0dc KernelReserved2 : [17] Uint4B +0x120 PrcbData : _KPRCB
内容も表示させてみる。GDTとかIDTとか、つい弄ってみたくなるような情報を持っている。
kd> dt _kpcr 0xffdff000 nt!_KPCR +0x000 NtTib : _NT_TIB +0x01c SelfPcr : 0xffdff000 _KPCR +0x020 Prcb : 0xffdff120 _KPRCB +0x024 Irql : 0 '' +0x028 IRR : 0 +0x02c IrrActive : 0 +0x030 IDR : 0xffffffff +0x034 KdVersionBlock : 0x805542b8 +0x038 IDT : 0x8003f400 _KIDTENTRY +0x03c GDT : 0x8003f000 _KGDTENTRY +0x040 TSS : 0x80042000 _KTSS +0x044 MajorVersion : 1 +0x046 MinorVersion : 1 +0x048 SetMember : 1 +0x04c StallScaleFactor : 0xaf2 +0x050 DebugActive : 0 '' +0x051 Number : 0 '' +0x052 Spare0 : 0 '' +0x053 SecondLevelCacheAssociativity : 0x8 '' +0x054 VdmAlert : 0 +0x058 KernelReserved : [14] 0 +0x090 SecondLevelCacheSize : 0x80000 +0x094 HalReserved : [16] 0 +0x0d4 InterruptMode : 0 +0x0d8 Spare1 : 0 '' +0x0dc KernelReserved2 : [17] 0 +0x120 PrcbData : _KPRCB
*1:W32THREAD構造体へのアドレスなのかとも考えたが、殆どのメンバが0のため確証がもててない。