Stack trace type

Stack trace type

A variable of type stktrace_t is used to hold the return value from the ProbeVue function get_stktrace, which returns the current stack trace. The stack trace returned is the stack trace of the current thread. This variable can also be stored in an associative array either as a key or as a value. The stktrace_t type is an abstract data type, and this variable cannot be used directly with the standard C uninary or binary operators. Internally, this variable is an array of unsigned longs.

Vue supports the following characteristics and operations for the stack trace type variables:

Declaration of stack trace type variable

A variable can be declared to be of type stack trace by declaring it as follows in the script:
      stktrace_t  st;              // st is a stktrace_t variable.
      st = get_stktrace(5);        //  Get the stack trace up to five levels. 
      a_st[0] = get_stktrace(-1);  // Get the stack trace up to the extent possible and
                                  // store in the associative array a_st as value.
The qualifiers signed, unsigned, register, static, auto, thread, kernel, and const are not supported for the stktrace_t type variables.

Assignment operation

The assignment (=) operator allows a stktrace_t type variable to be assigned to another stktrace_t type variable. The original values in the target stktrace_t variables are destroyed. No type casting is allowed from or to the stktrace_t variable types. In the following example, the content of the stack trace t1 is assigned to t2.
      stktrace_t     t1, t2;          // Declares two stack trace variables.
      t1 = get_stktrace();            // Get the current stack trace in t1.
      t2 = t1 ;                       // Get the content of t1 into t2.

Comparison operation

Only equality (==) and inequality (! =) operators are allowed for the stktrace_t variables. The result of theses operator is either True(1) or False(0) based on the entire entries of the stktrace_t variables. Comparisons of individual entries of stktrace_t variables are not allowed. No other comparison operators (>=, >, < or =<) are allowed for the stktrace_t type variables.
            if( t1 == t2)  // comparing two stktrace_t type variables.
                     printf(“Entries are similar”);
              else
                     printf(“Entries are not similar”);

Printing stack trace type variable

The stktrace_t variable can be printed by using the %t or %T format specifiers in the printf function of Vue. The output is the symbolic stack trace of the thread that is saved in the variable. The symbol with the address (symbol plus address) are printed only when the thread that corresponds to the stktrace_t variable is in the running state and when the %t format specifier is used to print the stack trace; otherwise only the stack trace as the address is printed for the variable.

The stktrace_t type variable stored in associative array either as key or value can be printed with print function of associative array. Addresses with symbol (symbol name + offset) is printed if thread that corresponds to the stktrace_t type stored in the associative array is running; otherwise only addresses is printed. When you set the STKTRC_NO_SYM flag in the set_aso_print_options() function, this variable prints raw addresses of the running thread.
    stktrace_t t1;
    t1 = get_stktrace (5);
    printf (“%t”, t1);       // Displays the stack trace stored in variable t1.         
    printf (“%T”, t1);      // Displays the stack trace stored in variable t1 with raw addresses.
    a[__tid] = t1;         // Store t1 as value in an associative array a.
    print(a) ;            // Print associative array a, whose value 
																			//	type is stktrace_t variable. 
                                                     

Limitations for stack trace type variable

  • The array of the stktrace_t variable cannot be declared.
  • The stktrace_t variables cannot be used as a member of a struct or a union.
  • Access of any individual entry of the stack trace is not allowed.
  • The operations (assignment, comparison, and printing) of the stktrace_t type variables is not supported in the systrace probe.