I am new in to C++ programming. _set_invalid_parameter_handler give me function name,file and line when I pass invalid parameter to a C++ system function -for ex.:in _tmain printf line generates error-, but I want to get function name, file and line of my programming, not about system function.
void myInvalidParameterHandler(const wchar_t* expression, const wchar_t* function, const wchar_t* file, unsigned int line, uintptr_t pReserved) { wprintf(L"Invalid parameter detected in function %s." L" File: %s Line: %d\n", function, file, line); wprintf(L"Expression: %s\n", expression); call_stack st; st.stack.back(); cout << st.stack.back().to_string(); cout << st.to_string(); } int _tmain(int argc, _TCHAR* argv[]) { char* formatString; _invalid_parameter_handler oldHandler, newHandler; newHandler = myInvalidParameterHandler; oldHandler = _set_invalid_parameter_handler(newHandler); formatString = NULL; printf(formatString); // I want to get this line return 0; } in this sample myInvalidParameterHandler generates below output: function = printf, file = f:\dd\vctools\crt\crtw32\stdio\printf.c, expression = (format != NULL) , line = 54
But I want to get something like: function = _tmain , file : ...\MySample.cpp , line = (printf line in mysample.cpp) How can I do that ?(like C# stack trace) ?
I also tried stack walker (call_stack), it gives me self line and i could not get my need by this way.
EDIT : Did not answer anyone yet . PLEASE HELP. 2015.02.25 16:42 Turkiye(Athens zone)
call_stackstructure should give you a hint, it's stack that you have to pop until it's empty.