Suppose there is a function with 1000 code of line named LongFunction, and we used it:
bool bSuccess = LongFunction();
assert(bSuccess);
Here I got an assert when debugging, and I know there is something wrong with LongFunction, so I need to find where the function meet problems and returns:
I could probably debug it step by step, it works but is time-consuming, we don't what to do it this way.
I could search the keyword "return" (or even more refined search use RegExp), and set breakpoint at those returns, it should be faster, but it is still tedious manual work which can't be automated.
#define return TRACE(LINE); return
It works but have following problems:
- It will print too much redundant information as return is frequently used.(Or we could use some EnvVar to switch it on or off)
- Does't work for following case: if(bOK) return true;
Do you have any other creative ideas on how to pinpoint the problem?
Edit: Here are some details to let us focus on the problem.
It is about C++, and not platform specfic.
We don't want to refactoring the functions(Yea, I know we should), we even don't want to change any code - at this point we just want to provide some facility to make our application debugging easier. I also believe this should be a common requirement, don't you ever run into this?
The LongFunction() have multiple exit point, and the return type is not necessay bool(HRESULT, user defined errorcode...)
Edit: A summary of current discussions:
We have some controversies:
You should refactor the function.
Yea, everyone know that we should, but that is not the point.If I had make the call to refactor the function, I won't be here to ask the question.Find where the LongFunction() returns failure doesn't help.
It is always the first thing I do to locate where the error occurs to know what happened, I am curious why this doesn't help, what did you do in this situation? (Assume I am already familiar with how the function works)
And we have 2 reasonable solutions:
ReturnMarker from Crashworks, a stack object in the function will destruct when function returns, set the breakpoint at the destructor will show you where it returns in debuger
CMyBool(x) from Binary & Sadsido, change the return type of LongFunction to CMyBool which can contruct from a bool, return from LongFunction will contruct that object, so just set a breakpoint at the constructor will work.