如何识别STATUS_INVALID_CRUNTIME_PARAMETER异常 [英] How do identify STATUS_INVALID_CRUNTIME_PARAMETER exception

查看:277
本文介绍了如何识别STATUS_INVALID_CRUNTIME_PARAMETER异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

平台是Windows 7 SP1.

Platform is Windows 7 SP1.

我最近花了一些时间调试由于代码将无效参数传递给安全" CRT函数之一而导致的问题.结果,我的应用程序立即中止,没有任何警告或任何警告-甚至没有崩溃对话框.

I recently spent some time debugging an issue that was caused because a code was passing an invalid parameter to one of the "safe" CRT functions. As a result my application was aborted right away with no warning or anything -- not even a crash dialog.

起初,我试图通过将Windbg附加到我的应用程序来解决这个问题.但是,当崩溃发生时,代码被破解为Windbg时,几乎每个线程都被杀死,除了Windbg必须攻入的一个线程.到底有什么问题没有任何线索.因此,我将Visual Studio附加为调试器,并且当我的应用程序终止时,我看到每个线程都退出,错误代码为 0xc0000417 . 是给我线索的是某个地方存在无效的参数问题.

At first, I tried to figure this out by attaching Windbg to my application. However when the crash happened, by the time the code broke into Windbg pretty much every thread had been killed save for ONE thread on which Windbg had to break into. There was no clue as to what was wrong. So, I attached Visual Studio as a debugger instead and when my application terminated, I saw every thread exiting with error code 0xc0000417. That is what gave me the clue that there is an invalid parameter issue somewhere.

接下来,我要尝试调试的方法是再次将Windbg附加到我的应用程序,但是这次是随机(通过试验和错误)将断点放置在各个位置,例如kernel32!TerminateThreadkernel32!UnhandledExceptionFilter.

Next, the way I went about trying to debug this is to once again attach Windbg to my application but this time randomly (by trial & error) place breakpoints in various places like kernel32!TerminateThread, kernel32!UnhandledExceptionFilter and kernel32!SetUnhandledExceptionFilter.

在很多地方,在SetUnhandledExceptionFilter处放置一个断点会立即显示崩溃发生时有问题的线程的调用堆栈以及我们未正确调用的CRT函数.

Of the lot, placing a break point at SetUnhandledExceptionFilter immediately showed the callstack of the offending thread when the crash occurred and the CRT function that we were calling incorrectly.

问题:是否有什么直觉可以告诉我立即在 SUEF 上放置bp?我想更好地理解这一点,而不是通过反复试验来做到这一点.第二个问题是我通过Visual Studio确定的错误代码.在不求助于VS的情况下,如何确定Windbg上的线程退出代码?

Question: Is there anything intuitive that should have told me to place bp on SUEF right away? I would like to understand this a bit better and not do this by trial and error. Second question is w.r.t to the error code I determined via Visual Studio. Without resorting to VS, how do I determine thread exit codes on Windbg?

推荐答案

我只想发表评论,但这变得更大了,所以一个答案

i was going to just comment but this became bigger so an answer

使用Windbg -I将windbg设置为事后调试器,还将所有未处理的异常路由到windbg

setting windbg as postmortem debugger using Windbg -I will also route all the unhandled exception to windbg

Windbg-我应该将windbg注册为事后调试器
默认情况下,AeDebug注册表项中的自动"设置为1
如果您不想调试每个程序,则可以将其编辑为0
在wer对话框中为您提供其他的DoYouWanttoDebug选项

Windbg -I should Register windbg as postmortem debugger
by default Auto is set to 1 in AeDebug Registry Key
if you don't want to debug every program you can edit this to 0
to provide you an additional DoYouWanttoDebug option in the wer Dialog

reg query "hklm\software\microsoft\windows nt\currentversion\aedebug"

HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\aedebug
    Debugger    REG_SZ    "xxxxxxxxxx\windbg.exe" -p %ld -e %ld -g
    Auto    REG_SZ    0

假设您注册了事后调试器,然后运行此代码

assuming you registered a postmortem debugger and you run this code

#include <stdio.h>
#include <stdlib.h>
int main (void) 
{
    unsigned long input[] = {1,45,0xf001,0xffffffff};
    int i = 0;
    char buf[5] = {0};
    for(i=0;i<_countof(input);i++)
    {
        _ultoa_s(input[i],buf,sizeof(buf),16);
        printf("%s\n",buf);
    }
    return 1;   
}

在例外情况下,您会看到这样的错误对话框

on the exception you will see a wer dialog like this

您现在可以选择调试该程序

you can now choose to debug this program

Windows还将未处理的异常的退出代码写入事件日志

windows also writes the exit code on unhandled exception to event log

您可以使用powershell检索这样的一个事件

you can use powershell to retrieve one event like this

PS C:\> Get-EventLog -LogName Application -Source "Application Error" -newest 1| format-list


Index              : 577102
EntryType          : Error
InstanceId         : 1000
Message            : Faulting application name: 
ultos.exe, version: 0.0.0.0, time stamp: 0x577680f1
                     Faulting module name: ultos.exe, version: 
0.0.0.0, time stamp: 0x577680f1
                     Exception code: 0xc0000417
                     Fault offset: 0x000211c2
                     Faulting process id: 0x4a8
                     Faulting application start time: 0x01d1d3aaf61c8aaa
                     Faulting application path: E:\test\ulto\ultos.exe
                     Faulting module path: E:\test\ulto\ultos.exe
                     Report Id: 348d86fc-3f9e-11e6-ade2-005056c00008
Category           : Application Crashing Events
CategoryNumber     : 100
ReplacementStrings : {ultos.exe, 0.0.0.0, 577680f1, ultos.exe...}
Source             : Application Error
TimeGenerated      : 7/1/2016 8:42:21 PM
TimeWritten        : 7/1/2016 8:42:21 PM
UserName           :

,如果您选择调试

您可以查看CallStack

you can view the CallStack

0:000> kPL
 # ChildEBP RetAddr  
00 001ffdc8 77cf68d4 ntdll!KiFastSystemCallRet
01 001ffdcc 75e91fdb ntdll!NtTerminateProcess+0xc
02 001ffddc 012911d3 KERNELBASE!TerminateProcess+0x2c
03 001ffdec 01291174 ultos!_invoke_watson(
            wchar_t * expression = 0x00000000 "", 
            wchar_t * function_name = 0x00000000 "", 
            wchar_t * file_name = 0x00000000 "", 
            unsigned int line_number = 0, 
            unsigned int reserved = 0)+0x31
04 001ffe10 01291181 ultos!_invalid_parameter(
            wchar_t * expression = <Value unavailable error>, 
            wchar_t * function_name = <Value unavailable error>, 
            wchar_t * file_name = <Value unavailable error>, 
            unsigned int line_number = <Value unavailable error>, 
            unsigned int reserved = <Value unavailable error>)+0x7a
05 001ffe28 0128ad96 ultos!_invalid_parameter_noinfo(void)+0xc
06 001ffe3c 0128affa ultos!common_xtox<unsigned long,char>(
            unsigned long original_value = 0xffffffff, 
            char * buffer = 0x001ffea4 "", 
            unsigned int buffer_count = 5, 
            unsigned int radix = 0x10, 
            bool is_negative = false)+0x58
07 001ffe5c 0128b496 ultos!common_xtox_s<unsigned long,char>(
            unsigned long value = 0xffffffff, 
            char * buffer = 0x001ffea4 "", 
            unsigned int buffer_count = 5, 
            unsigned int radix = 0x10, 
            bool is_negative = false)+0x59
08 001ffe78 012712b2 ultos!_ultoa_s(
            unsigned long value = 0xffffffff, 
            char * buffer = 0x001ffea4 "", 
            unsigned int buffer_count = 5, 
            int radix = 0n16)+0x18
09 001ffeac 0127151b ultos!main(void)+0x52
0a (Inline) -------- ultos!invoke_main+0x1d
0b 001ffef8 76403c45 ultos!__scrt_common_main_seh(void)+0xff
0c 001fff04 77d137f5 kernel32!BaseThreadInitThunk+0xe
0d 001fff44 77d137c8 ntdll!__RtlUserThreadStart+0x70
0e 001fff5c 00000000 ntdll!_RtlUserThreadStart+0x1b

这篇关于如何识别STATUS_INVALID_CRUNTIME_PARAMETER异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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