2017-01-12 68 views
2

私はOutOfMemoryExceptionを投げる.NETプログラムを持っています。ProcDumpを使用してOutOfMemory例外のダンプをキャプチャできません

public static int Main(string[] args) 
{ 
    try 
    { 
     ... 
    } 
    catch (Exception exc) 
    { 
     Console.Error.WriteLine(exc); 
     return 1; 
    } 
} 

今、私はこの例外がスローされた瞬間を作成するメモリダンプを希望:Main関数は次のような構造を有しているため、例外が、処理されます。そのために私は次のコマンドを使用します。

procdump.exe -e 1 -f OutOfMemoryException -g -ma -w Log4Net2DB.exe 

をしかし、それは動作しません:

PS D:\tmp> procdump.exe -e 1 -f OutOfMemoryException -g -ma -w Log4Net2DB.exe 

ProcDump v7.0 - Writes process dump files 
Copyright (C) 2009-2014 Mark Russinovich 
Sysinternals - www.sysinternals.com 
With contributions from Andrew Richards 

Waiting for process named Log4Net2DB.exe... 

Process:    Log4Net2DB.exe (47712) 
CPU threshold:   n/a 
Performance counter: n/a 
Commit threshold:  n/a 
Threshold seconds:  10 
Hung window check:  Disabled 
Log debug strings:  Disabled 
Exception monitor:  First Chance+Unhandled 
Exception filter:  *OutOfMemoryException* 
Terminate monitor:  Disabled 
Cloning type:   Disabled 
Concurrent limit:  n/a 
Avoid outage:   n/a 
Number of dumps:  1 
Dump folder:   D:\tmp\ 
Dump filename/mask: PROCESSNAME_YYMMDD_HHMMSS 


Press Ctrl-C to end monitoring without terminating the process. 

[18:09:30] Exception: E0434F4E.CON 
[18:09:41] Exception: E0434F4E.CON 
[18:09:41] Exception: E0434F4E.CON 
[18:09:48] Exception: E0434F4E.CON 
[18:10:27] Exception: E0434F4E.CON 
[18:10:36] Exception: E0434F4E.CON 
[18:10:43] Exception: E0434F4E.CON 
[18:10:45] Exception: E0434F4E.CON 
[18:10:46] Exception: E0434F4E.CON 
[18:10:51] Exception: E0434F4E.CON 
[18:10:55] Exception: E0434F4E.CON 
[18:10:59] Exception: E0434F4E.CON 
[18:11:10] Exception: E0434F4E.CON 
[18:11:28] Exception: E0434F4E.CON 
[18:11:38] Exception: E0434F4E.CON 
[18:11:55] Exception: E0434F4E.CON 
[18:13:58] Exception: E0434F4E.CON 
[18:15:33] Exception: [email protected]@ 
[18:15:33] Exception: E0434352.CLR 
[18:15:33] Exception: E0434352.CLR 
[18:15:33] Exception: E0434352.CLR 
[18:15:33] Exception: E0434352.CLR 
[18:15:33] Exception: E0434352.CLR 
[18:15:33] Exception: E0434352.CLR 
[18:15:33] Exception: E0434352.CLR 
[18:15:33] Exception: E0434352.CLR 
[18:15:33] Exception: E0434352.CLR 
[18:15:33] Exception: E0434352.CLR 
[18:15:33] Exception: E0434352.CLR 
[18:15:33] Exception: C0020001 
[18:15:35] The process has exited. 
[18:15:35] Dump count not reached. 

PS D:\tmp> 

お知らせの最後のメッセージ - 「に達していないカウントダンプ」。しかし、プログラムが(Main関数の最後にcatch声明で取り扱わ)OutOfMemoryExceptionで終了しない:

procdump.exe -e 1 -f C0020001 -g -ma -w Log4Net2DB.exe 

:レコードの

PS D:\tmp> logs2db.ps1 -- -dir D:\tmp\us850 -r -db us850 
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown. 
    at System.Security.Cryptography.SHA1Managed..ctor() 
    at Log4Net2DB.Program.ComputeHash(ILogEntry logEntry, BinaryWriter bw) in C:\Log4Net2DB\Log4Net2DB\Program.cs:line 246 
    at Log4Net2DB.Program.<>c__DisplayClass10_0.<GetBatchSource>b__2(ILogEntry entry) in C:\Log4Net2DB\Log4Net2DB\Program.cs:line 232 
    at System.Reactive.Linq.ObservableImpl.Select`2._.OnNext(TSource value) 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Reactive.PlatformServices.DefaultExceptionServices.Rethrow(Exception exception) 
    at System.Reactive.ExceptionHelpers.ThrowIfNotNull(Exception exception) 
    at System.Reactive.Subjects.AsyncSubject`1.GetResult() 
    at Log4Net2DB.Program.Main(String[] args) in C:\Log4Net2DB\Log4Net2DB\Program.cs:line 200 
PS D:\tmp> 

、私はまた、このようなprocdumpを実行しようとしました無駄に。

注意、procdump.exe -e 1 -g -ma -w Log4Net2DB.exeを実行すると上昇し、GCがトリガされ、実行時によって内部的に処理された非常に最初の例外のためのダンプを生成しないことを、より多くの詳細はこちらです - RedirectedThreadFrame in Callstackので、私はprocdumpをすることができます知っています私のプログラムのためのダンプを作り出す。

しかし、OOMのダンプを生成することはできません。私は間違って何をしていますか?

P.S.

私のマシンは64ビットですが、いくつかの特殊な理由から、プログラムは32ビットとして実行されますが、インターロックDLLを参照しません。したがって、約3.7GBのRAMを消費するとOOMが発生します。

答えて

2

-gフラグをオフにする必要があります。管理対象の例外をキャッチしたい場合、-gは、ネイティブのデバッガとしてprocdumpを接続します。

this LinqPad query which generates an OutOfMemoryExceptionを考えてみましょう:

void Main() 
{ 
    var list = new List<Int32>(); 
    for (int i = 0; i < Int32.MaxValue; i++) 
    { 
     list.Add(i); 
    } 
} 

-gで実行:

-gなし
> procdump -ma -e 1 -f OutOfMemoryException -g -w "LINQPad.UserQuery" 

...

Press Ctrl-C to end monitoring without terminating the process. 

[00:52:33] Exception: [email protected]@ 
[00:52:33] Exception: E0434352.CLR 
[00:52:34] The process has exited. 
[00:52:34] Dump count not reached. 

procdump -ma -e 1 -f OutOfMemoryException -w "LINQPad.UserQuery" 

...

CLR Version: v4.0.30319 

[00:53:01] Exception: E0434F4D.System.OutOfMemoryException 
[00:53:01] Dump 1 initiated: LINQPad.UserQuery.exe_170720_005301.dmp 
[00:53:02] Dump 1 writing: Estimated dump file size is 496 MB. 
[00:53:02] Dump 1 complete: 497 MB written in 0.5 seconds 
[00:53:02] Dump count reached. 

また、32ビットの問題に対処するために - ネット4.5+バイナリは、それがAnyCPUに設定されている場合でも、「32ビットを優先」を指定する新しいフラグを持っています64ビットOSで動作します。 You can control this in the project properties

関連する問題