Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

We can see the sequence and depth of calls. From the sandbox for instance:

./test --trace "APP*" --out trace.log

Will give us this in the trace.log:

  10:24:30.683662 0x1087f75c0 APPfactorial            >APPfactorial Line:10
  10:24:30.684335 0x1087f75c0 APPfactorial            . N = 6
  10:24:30.684372 0x1087f75c0 APPfactorial            . >APPfactorial Line:10
  10:24:30.684423 0x1087f75c0 APPfactorial            . . N = 5
  10:24:30.684458 0x1087f75c0 APPfactorial            . . >APPfactorial Line:10
  10:24:30.684509 0x1087f75c0 APPfactorial            . . . N = 4
  10:24:30.684545 0x1087f75c0 APPfactorial            . . . >APPfactorial Line:10
  10:24:30.684595 0x1087f75c0 APPfactorial            . . . . N = 3
  10:24:30.684631 0x1087f75c0 APPfactorial            . . . . >APPfactorial Line:10
  10:24:30.684682 0x1087f75c0 APPfactorial            . . . . . N = 2
  10:24:30.684718 0x1087f75c0 APPfactorial            . . . . . >APPfactorial Line:10
  10:24:30.684768 0x1087f75c0 APPfactorial            . . . . . . N = 1
  10:24:30.684806 0x1087f75c0 APPfactorial            . . . . . . Ending recursion
  10:24:30.684843 0x1087f75c0 APPfactorial            . . . . . <APPfactorial
  10:24:30.684887 0x1087f75c0 APPfactorial            . . . . . Result = 2
  10:24:30.684923 0x1087f75c0 APPfactorial            . . . . <APPfactorial
  10:24:30.684966 0x1087f75c0 APPfactorial            . . . . Result = 6
  10:24:30.685002 0x1087f75c0 APPfactorial            . . . <APPfactorial
  10:24:30.685045 0x1087f75c0 APPfactorial            . . . Result = 24
  10:24:30.685081 0x1087f75c0 APPfactorial            . . <APPfactorial
  10:24:30.685124 0x1087f75c0 APPfactorial            . . Result = 120
  10:24:30.685173 0x1087f75c0 APPfactorial            . <APPfactorial
  10:24:30.685212 0x1087f75c0 APPfactorial            . Result = 720
  10:24:30.685244 0x1087f75c0 APPfactorial            <APPfactorial

We can see the entry into the APPfactorial which is calling itself recursively. Here’s the code:

int APPfactorial(int N){
   BAS_FUNCTION(APPfactorial);
   BAS_VAR(N);
   if (N == 1){
      BAS_TRC("Ending recursion");
      return 1;   
   }
   int Result = N * APPfactorial(N-1);
   BAS_VAR(Result);
   return Result;
}

The BAS_FUNCTION macro allows us to see when we enter and exit the function. BAS_VAR shows the variable we want to see in Name=Value format in the trace. BAS_TRC is like a print statement in tracing.

  • No labels