如何调试 0xc0000417 退出代码的原因 [英] How can I debug the cause of a 0xc0000417 exit code

查看:117
本文介绍了如何调试 0xc0000417 退出代码的原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的可执行文件(混合 Fortran/C)中收到一个退出错误代码 0xc0000417(转换为 STATUS_INVALID_CRUNTIME_PARAMETER)并尝试找出导致它的原因.尝试写入我推断的文件时似乎会发生这种情况,因为该文件已创建但其中没有任何内容.然而我怀疑这不是/real/的原因.当我禁用从 C 代码完成的该文件的写入时,它会在写入不同的文件时崩溃,这次是从 Fortran 代码.

I get an exit error code 0xc0000417 (which translates to STATUS_INVALID_CRUNTIME_PARAMETER) in my executable (mixed Fortran/C) and try to find out what's causing it. It seems to occur when trying to write to a file which I infer because the file is created but there's nothing in it. Yet I have the suspicion that's not the /real/ cause. When I disable writing of that file, which is done from C code, it crashes when writing a different file, this time from Fortran code.

不幸的是:这只会在程序(CPU 繁重的计算)运行约 2-3 天后完成后发生.当我尝试通过各种方式缩短计算时间以方便调试时,问题没有再出现.似乎长时间的运行时间对于触发问题至关重要.

The unfortunate thing is: this only happens after the program (a CPU heavy calculation) has finished after having run for ~2-3 days. When I tried to shorten the calculation time by various means to facilitate debugging, the problem did not occur anymore. It almost seemed like the long runtime was crucial for triggering the problem.

我尝试在 Visual Studio 2015 中运行它,但 VS 不会中断/停止(就像发生了段错误时那样),尽管在所有 C++ 异常中都打开了中断,就像在其他一些线程和所有常见问题中建议的那样语言运行时异常.

I tried running it in Visual Studio 2015 but VS does not break/stop (like it would if e.g. a segfault had happened) despite having turned on breaking at all the C++ Exceptions, like was suggested in some other thread and all Common Language Runtime Exceptions.

我希望 VS 做的是在产生"错误代码时中断并检查变量的值或至少获得堆栈跟踪.

What I would like VS to do is to either break whenever that error code is 'produced' and examine the values of variables or at least get a stack trace.

我进行了大量搜索,但找不到满意的解决方案.本质上,我的问题类似于如何调试"传递给 C 运行时函数的参数无效"? 但我的程序的 linux 版本不会出现此问题,所以我正在寻找有关如何在 Windows 上调试它的说明,无论是使用 Visual Studio 还是其他一些工具.

I searched intensively but I could not find a satisfactory solution to my problem. In essence, my question is similar to how to debug "Invalid parameter passed to C runtime function"? but the problem does not occur with the linux version of my program, so I'm looking for directions on how to debug it on Windows, either with Visual Studio or some other tool.

遗憾的是, 找不到任何方便的方法在错误发生时自动中断.因此,我采用手动方式在假定的崩溃附近设置断点(在 VS 中)并逐步执行代码.原来我从 fopen 得到了一个 NULL 指针:

Sadly, I was not able to find any convenient means of breaking automatically when the error occurs. So I went with the manual way of setting a breakpoint (in VS) near the supposed crash and step through the code. It turned out that I got a NULL pointer from fopen:

myfile = fopen("somedir\\somefile.xml");

尽管正在创建文件.但是当尝试写入该文件时(通过 NULL 句柄!),发生了段错误.奇怪的是,当进程有很长的生命周期时,我似乎只从 fopen 得到一个 NULL 指针.但这对这个问题来说是题外话.

despite the file being created. But when trying to write to that file (via the NULL handle!), a segfault occurred. Strangely, it seems I only get a NULL pointer from fopen when the process has a long lifetime. But that's offtopic for that question.

编辑 2:检查全局 errno 变量给出了错误代码 22,它再次转换为无效参数.但是,fopen 的参数不是无效,因为我已使用调试器进行了验证,并且文件实际上已正确创建(长度为 0 字节).现在我认为 那个错误代码 22 只是误导 因为当我检查(通过 VS 中的手表)$err, hr 我得到:

Edit 2: Checking the global errno variable gave error code 22 which again translates to an invalid argument. However, the argument to fopen is not invalid as I verified with the debugger and the fact that the file is actually created correctly (with 0 bytes length). Now I think that that that error code 22 is simply misleading because when I check (via a watch in VS) $err, hr I get:

0x000005aa ERROR_NO_SYSTEM_RESOURCES : Insufficient system resources exist to complete the requested service.

就像提到的这里,我有很多高清空间(1.4 GB),充足的可用内存(3.2 GB),我担心这不是由我的程序直接引起的,而是由于 Windows 文件处理设计的损坏(在 Linux 下不会发生).

Just like mentioned here, I have plenty of HD space (1.4 GB), plenty of free RAM (3.2 GB), and I fear it is something not directly caused by my program but something due to broken Windows design of file handling (it does not happen under Linux).

编辑 3: 好吧,看来罪魁祸首不是 Windows 本身,而是我使用的 Intel Fortran 编译器.每次我在我的程序中执行格式化的写语句时,都会泄露一个 Mutant(Windows 代表互斥锁)句柄.使用 WinDbg 和 !htrace -enable,然后进一步运行,中断并发出 !htrace -diff 提供这些回溯的负载:

Edit 3: OK, it seems it is not Windows itself that's the culprit but rather the Intel Fortran compiler I'm using. Every time I'm doing formatted write statements in my program, a Mutant (Windows speak for mutex) handle is leaked. Using WinDbg and !htrace -enable, then running a bit further, break and issue !htrace -diff gives loads of these backtraces:

0x00000000777ca25a: ntdll!NtCreateMutant+0x000000000000000a
0x000007fefd54a1b7: KERNELBASE!CreateMutexExW+0x0000000000000057
0x000007fefd551d60: KERNELBASE!CreateMutexExA+0x0000000000000050
0x000007fedfab24db: libifcoremd!for_lge_ssll+0x0000000000001dcb
0x000007fedfb03ed6: libifcoremd!for_write_int_fmt+0x0000000000000056
0x000000014085aa21: myprog!MY_ROUTINE+0x0000000000000121

在程序运行期间,这些变异句柄似乎会不断累积,直到耗尽所有句柄资源(16711680 个句柄),因此文件句柄没有任何剩余.

During the program runtime these mutant handles seem to accumulate until they exhaust all handle resources (16711680 handles) so that there's nothing left for file handles.

编辑 4:这是英特尔 fortran 运行时库中的一个错误,已在更高版本中修复(请参阅 此处).使用补丁版本的 libifcoremd.dll 修复了该问题,即在格式化写入期间句柄计数不再增加.

Edit 4: It's a bug in the intel fortran runtime libraries that has been fixed with a later version (see here). Using the patched version of libifcoremd.dll fixes the problem, i.e. the handle count does not increase anymore during formatted writes.

推荐答案

可能是打开的文件太多或泄漏(未关闭)句柄.您可以使用例如检查Process Explorer(我想你可以用它看到进程中的句柄数量).

It could be too many open files or leaked (not closed) handles. You can check that with e.g. Process Explorer (I think you could see the number of handles in the process with it).

这篇关于如何调试 0xc0000417 退出代码的原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆