概要
オブジェクト参照時のスタックトレースを保存することができる Object Reference Tracing を紹介します。オブジェクトのリーク時のトラブルシューティング等に使用できます。
概要
Object Reference Tracing の手順を紹介します。
手順1. gflags を起動します。

gflags は、
Windows SDK に含まれています。Windows SDK のインストール時に「Debugging Tools for Windows」にチェックを入れインストールします。

2.「Kernel Flags」タブの「Object Reference Tracing」の「Enable」にチェックを入れ「Pool Tags」に Object Reference Tracing を有効にしたいタグを入力します。ここでは File オブジェクトのトレースを実行するため「File」を入力します。設定後、OS の再起動は必要ありません。

3. 任意のファイルを開き、ファイルオブジェクトにアクセスするようにします。
4. ダンプを作成します。
ここでは
NotMyFault を使いました。

5. ダンプを開きます。
6. ファイルオブジェクトを探すため「!handle」を実行してみます。
出力された ffffb68369721dd0 のオブジェクト例に、Object Reference Tracing を確認します。
0034: Object: ffffb68369721dd0 GrantedAccess: 00100020 (Inherit) Entry: ffffa30443cb50d0 Object: ffffb68369721dd0 Type: (ffffb6834faacaf0) File ObjectHeader: ffffb68369721da0 (new version) HandleCount: 1 PointerCount: 32768 Directory Object: 00000000 Name: \Users\Administrator\Desktop\NotMyFault {HarddiskVolume1}
|

7.「!obtrace <オブジェクト>」を実行します。
オブジェクトにアクセスした際のスタックトレースがわかります。
3: kd> !obtrace ffffb68369721dd0 Object: ffffb68369721dd0 Image: notmyfault64.e Sequence (+/-) Tag Stack -------- ----- ---- --------------------------------------------------- 3b50e1 +1 Dflt nt!IopAllocRealFileObject+1358c5 nt!IopParseDevice+fb0 nt!ObpLookupObjectName+8af nt!ObOpenObjectByNameEx+1dd nt!IopCreateFile+860 nt!NtOpenFile+58 nt!KiSystemServiceCopyEnd+13 3b50ec +1 Dflt nt!ObfReferenceObject+b2fa6 nt!IopParseDevice+1e6e nt!ObpLookupObjectName+8af nt!ObOpenObjectByNameEx+1dd nt!IopCreateFile+860 nt!NtOpenFile+58 nt!KiSystemServiceCopyEnd+13 3b50ee -1 Dflt nt!ObfDereferenceObject+b23e9 nt!IopCreateFile+b5b nt!NtOpenFile+58 nt!KiSystemServiceCopyEnd+13 3b50f0 +1 Dflt nt!ObpReferenceObjectByHandleWithTag+1253b9 nt!ObReferenceObjectByHandle+2e nt!NtQueryVolumeInformationFile+19a nt!KiSystemServiceCopyEnd+13 3b50f2 -1 Dflt nt!ObfDereferenceObject+b23e9 nt!NtQueryVolumeInformationFile+295 nt!KiSystemServiceCopyEnd+13 -------- ----- --------------------------------------------------- References: 3, Dereferences 2 Tag: Dflt References: 3 Dereferences: 2 Over reference by: 1
|

ここの「+1」はオブジェクト参照がインクリメントされた際のコールスタックです。「-1」がオブジェクト参照がデクリメントされた際のコールスタックです。ファイル参照が終わっているはずであるにも関わらず「-1」が表示されない場合は、ドライバーが適切に参照をデクリメントしていないため、ドライバーのバグが疑われます。
注意Microsoft の
ドキュメントにあるように、x64 の Windows では、必ずしも全てのオブジェクトアクセスを記録するとは限りません。(原文:The object reference traces on x64-based target computers might be incomplete because it is not always possible to acquire stack traces at IRQL levels higher than PASSIVE_LEVEL.)
情報元Object Reference Tracing with Tags (英語)
Tracking Down a FILE_OBJECT leak (英語)
- 2019/11/18(月) 09:59:33|
- WinDbg
-
| トラックバック:0
-
| コメント:0