How to debug "Invalid parameter passed to C runtime function"?

Background

I have terabytes of raw data files with a relatively small subset of tagged data. I wrote C ++ code (calling some ancient MSVC ++ 2003 code, which I greatly modified to compile on the latest compilers) to combine annotated data slices.

Most of this tagged data is concentrated in one file, but this file appears to be where my program crashes.

Problem

I get

Invalid parameter passed to C runtime function. Invalid parameter passed to C runtime function. terminate called after throwing an instance of 'int' 

In my Qt output window, and the windows tell me the same thing in a popup window, but at the moment it is too late to get any useful information from the executable / debugger, it seems (although I don’t have a debugger with Qt at all).

What i tried

I searched all the information and found a lot of people with this error message, but it is so common that none of their problems can be the same as mine, and there is such a long list of various C runtime functions that sift them all slowly and don't seem to help.

My question

"Find a man a mistake, and you will help him for one day. Teach a man to debug, and you will help him all his life. Send a path to stackoverflow and you will help many men and get a lot of points."

Is there a general method to find the C runtime function, and what was the argument? Did I miss some fancy debugger features? Is there anything else you could recommend or information that I could provide?

I hope to get an answer to this question to help everyone with this problem, and not just me, but I will be glad if they help me too.

Specifically for my problem:

My stack trace looks like this:

0 ntdll! DbgBreakPoint 0x7727000d
1 ntdll! DbgUiRemoteBreakin 0x772ff156
2 ?? 0x6f06eaa1
3 KERNEL32! BaseThreadInitThunk 0x7501338a
4 ntdll! RtlInitializeExceptionChain 0x77299902
5 ntdll! RtlInitializeExceptionChain 0x772998d5
6 ??

and gdb cannot get a better trace (it seems that I'm trying to do with it, I get a timeout error).

After trying a couple more functions to be sure that everything gave a timeout, to try to "backtrace" again give me the result. I guess I just never put this much time in gdb after he once attacked me.

However, I could find something with this new information. Think that my problem is closed, but my general point is still true. I believe: now I have found a function with a problem (I think), but not why this is a problem, and that this is an invalid parameter. Even better, I traced it to a line that says "throw 1". So now I assume that windows / Qt translates this to an "invalid parameter". But this is not true.

It may just be the wrong code, it doesn't even need to be a C function, and nothing should be wrong with your parameters.

...

# 17 0x00c17d72 in libstdC ++ - 6! .Cxa_throw () from C: \ Qt \ 5.5 \ mingw492_32 \ bin \ libstdC ++ - 6.dll Information about the character table is not available. ...

+11
source share
5 answers

Personally on a Linux terminal, I use gcc for compilation and gdb for debugging. To compile a program with debugging options using gcc, you just need to add -g to the other flags. Example: gcc file.c -o file -std=c99 -g . Then you can enter gdb file and enter the interactive debugger. Among other useful things, you can run the program, call functions, and insert breakpoints. For full and well-explained usage, go to this site - http://www.tutorialspoint.com/gnu_debugger/index.htm

+3
source

At least in Visual Studio 2017, you can press CTRL + B and add _invalid_parameter break the function into _invalid_parameter . This will stop your program in the place where the message would be logged, which will allow you to find the violating function in the call stack. This will work even if someone else code cancels your call to _CrtSetReportMode() .

+3
source

Things I learned from this question (and this can help people who are looking for this question):

  • It turns out that this error can be traced to a line of code that says: quit 1;
    This means that it may just be the wrong code, it doesn’t even need to be a C function, and nothing should be wrong with your parameters. Search your code and library source for "throw"
  • It turns out that gdb latency is not an indicator of anything. Keep trying and try again, and maybe someday you can get a stack trace.
+2
source

I encountered the same error message "Invalid parameter ..." while debugging a Windows driver. The technique on this page, even if for Windows, and not for addressing on this issue, may be useful to those who are looking for this particular error message. IOW HTH ..

http://dennisyurichev.blogspot.com/2013/05/warning-invalid-parameter-passed-to-c.html

So, you should narrow down the specifics of your environment where the debugging line is displayed, possibly using the function of the "auxiliary" debugging function. Once you know, set a breakpoint there, and then look at the call stack. IMHO, this is a very smart solution for something that can be hard to find.

0
source

Since the log is displayed on the debug console, it must be reported by the OutputDebugStringA function. You can set a breakpoint on a function to see who leads to this log. To set a breakpoint on a function, you can Ctrl+B in Visual Studio and enter the name of the function:

enter image description here

But this may not work, or you may record too many other messages using OutputDebugStringA . Normally an Invalid parameter passed to C runtime function , an _invalid_parameter is reported, so you can also try setting a _invalid_parameter breakpoint in the _invalid_parameter function. This may not work so well, because from some other system dll it may be reported that your process is referencing: ntdll.dll , KernelBase.dll , etc. To install KernelBase.dll breakpoint on the function exported by the dll, you need to use: <dll>!<exportname> :

 _invalid_parameter ntdll.dll!__invalid_parameter KernelBase.dll!__invalid_parameter msvcrt.dll!__invalid_parameter ucrtbase.dll!__invalid_parameter 

These are all different functions, and you can see their addresses:

enter image description here

In my case, only when I set a breakpoint on ntdll.dll!__invalid_parameter I able to see the reverse trace, and the log message was called winapi GetAdaptersAddresses . The breakpoint at OutputDebugStringA turned out to be useless because the log was printed through the DbgPrint API. Placing a breakpoint on DbgPrint works in this case.

0
source

All Articles