How to determine where a long function returns

Suppose there is a function with 1000 LongFunction string code, and we used it:

bool bSuccess = LongFunction();
assert(bSuccess);

Here I got a statement when debugging, and I know that something is wrong with LongFunction, so I need to find where the function encounters problems and returns:

  • I could probably debug it step by step, it works, but it takes a lot of time, we do not do it that way.

  • I could search for the “return” keyword (or even a more sophisticated search using RegExp) and set a breakpoint on these returns, it should be faster, but it's still tedious manual work that cannot be automated.

  • #define return TRACE ( LINE ); return

It works, but has the following problems:

  • It will print too much redundant information since return is often used (or we can use some EnvVar to turn it on or off).
  • It does not work for the following case: if (bOK) returns true;

Do you have any other creative ideas on how to identify the problem?

Edit: Here are some details so we can focus on the issue.

  • This is about C ++, not the specfic platform.

  • We don’t want to reorganize the functions (yes, I know, we should), we don’t even want to change any code - at this stage we just want to provide some opportunities for debugging our application Easier. I also believe that this should be a general requirement, have you ever come across this?

  • LongFunction() , bool (HRESULT, ...)

. :
:

  • .
    , , , . , .

  • , LongFunction() , .
    , , , , , , , , ? (, , )

2 :

  • ReturnMarker Crashworks, , , , , debuger

  • CMyBool (x) Binary Sadsido, LongFunction CMyBool, bool, LongFunction , .

+5
9

, , ++ :

class ReturnMarker
{
   public:
   ReturnMarker()  {};
   ~ReturnMarker() 
   {
      dummy += 1; //<-- put your breakpoint here
   }
   static int dummy;
}

int ReturnMarker::dummy = 0;

ReturnMarker . , , .

void LongFunction()
{
    ReturnMarker foo;

    // ...
}
+13

LongFunction()...

1000 - . , , . (-), , .

+8

C ++?

++, , bool (, CMyBool), bool.

LongFunction CMyBool ( LongFuntion, " CMyBool (x)".

ctor CMyBool, CMyBool, return LongFunction.

bool CMyBool , CMyBool.

, LongFunction.

, .

+4

- ( btw), , LongFunction

return(value);

return value;

(, )

, :

#define return(value) { if (!value) TRACE(__LINE__); return(value); }

...

#define return(value) { assert(value); return(value); }

... ,

+4
#define return { TRACE(LINE); return; }

4.

, . (, HRESULT COM-) / - .

1000 . , .

: , ?

#define return TRACE(LINE), return

, .

0

, . LongFunction , gdb:

, "f.cc" :

1: bool LongFunction () {  /* ... */ }
2:
3: void bar ()
4: {
5:   bool bSuccess = LongFunction ();
6:   assert (bSuccess);
7: }

gdb:

  • , assert: break f.cc:6

  • , bSuccess false: condition 1 (bSuccess==0)

  • : break f.cc:4

  • ( ): jump f.cc:4

  • LongFunction, , .

, , LongFunction, , LongFunction .., . , :

3: void bar ()
4: {
5:   bool bSuccess = LongFunction ();
5:   bSuccess = LongFunction ();
6:   assert (bSuccess);
7: }
0

assert, , , .

0

" , , , , , ".

?

:

1) , .

2) .

1000 , "", , .

, . , IDE .

, .

0

1982 -. , Harris FORTRAN ( , FORTRAN IV FORTRAN 77), 1100 , 900 , 10 20 .

, ( ), .

160 - , , - , .

. , 1000- , , , , .

. Microsoft Abysmal++: "return"

"printf (" \n\n --- → > % d\n\n ", __LINE__);"

( ). , ; . , .

, , 1000 . 40 , , , , ( 60 ), . .

, , , , , , , , , .

Finally: think that this is probably not the last time someone should work on this module, and perhaps this is not the last time you should work on it. Such things are usually courageous babies: as soon as you touch them, you never come off from them. It might be worth the time refactoring, at least, and perhaps redesigning / rewriting it from SCRATCH and first principles.

0
source

All Articles