gpt4 book ai didi

c# - 无法使用 ProcDump 捕获 OutOfMemory 异常的转储

转载 作者:行者123 更新时间:2023-11-30 15:19:47 26 4
gpt4 key购买 nike

我有一个抛出 OutOfMemoryException 的 .NET 程序。异常已处理,因为 Main 函数具有以下结构:

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

现在我想在抛出这个异常时创建一个内存转储。为此,我使用以下命令:

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: E06D7363.PAVException@@
[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>

注意最后一条消息 - “未达到转储计数”。但是程序确实以 OutOfMemoryException 终止(在 Main 函数末尾的 catch 语句中处理):

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 -f C0020001 -g -ma -w Log4Net2DB.exe

没用。

请注意,运行 procdump.exe -e 1 -g -ma -w Log4Net2DB.exe 确实会为第一个异常生成转储,该异常由运行时在内部引发和处理当 GC 被触发时,更多细节在这里 - RedirectedThreadFrame in Callstack , 所以我知道 procdump 能够为我的程序生成转储。

但我无法让它为 OOM 生成转储。我做错了什么?

附言

我的机器是 64 位的,但由于某些特殊原因,程序以 32 位运行,即使它没有引用任何互操作 DLL。因此,当它消耗大约 3.7GB 的 RAM 时,会引发 OOM。

最佳答案

你需要离开 -g 标志。您想要捕获托管异常,并且 -g 将 procdump 附加为 native 调试器。

考虑 this LinqPad query which generates an OutOfMemoryException :

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

使用 -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: E06D7363.PAVException@@
[00:52:33] Exception: E0434352.CLR
[00:52:34] The process has exited.
[00:52:34] Dump count not reached.

没有-g:

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 位问题 - .Net 4.5+ 二进制文件有一个新标志,它指定“首选 32 位”,即使它设置为 AnyCPU 并在 64 位操作系统上运行。 You can control this in the project properties .

关于c# - 无法使用 ProcDump 捕获 OutOfMemory 异常的转储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41603139/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com