how to debug "Invalid parameter passed to C runtime function"?
Since the log is printed to the debug console then it should be reported by OutputDebugStringA
function. You can place a breakpoint on the function to see who results in that log. To place a breakpoint on a function you can Ctrl+B
in Visual Studio and enter function name:
But this might not work, or you may have too many other messages logged using OutputDebugStringA
. Usually Invalid parameter passed to C runtime function
is reported by _invalid_parameter, so, you may as well try to place a breakpoint on _invalid_parameter
function. This might not work as well because it could be reported from some other system dll that your process links to: ntdll.dll
, KernelBase.dll
etc. To place a breakpoint on a function exported by a 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
All of these are different functions and you can see their addresses:
In my case only when I set a breakpoint on ntdll.dll!__invalid_parameter
I was able to see backtrace and the log message was caused by GetAdaptersAddresses
winapi. The reason breakpoint on OutputDebugStringA
wasn't helpful was because the log was printed through DbgPrint
api. Placing breakpoint on DbgPrint
works in this case.
In Visual Studio 2017 at least, you can hit CTRL+B and add a function breakpoint on _invalid_parameter
. This will stop your program at the point where the message would have been logged, which will let you find the offending function in the call stack. It will work even if someone else's code undoes your call to _CrtSetReportMode()
.
Things I learned from this question (and that might help people searching for this question) :
- Turns out that this error could be traced back to a line of code saying
throw 1;
This means It can just be some bad code, it does not even need to be a C function, and nothing needs to be wrong with your parameters. Searching your code and libraries' source for "throw" - Turns out that getting timeouts on gdb are not an indicator of anything. Keep trying things and retrying and maybe at one time you might get a stack trace.