堆栈跟踪类型

堆栈跟踪类型

类型为 stktrace_t 的变量用于保存 ProbeVue 函数 get_stktrace(可返回当前堆栈跟踪)中的返回值。 返回的堆栈跟踪是当前线程的堆栈跟踪。 此变量还可作为键或值而存储在关联数组中。 stktrace_t 类型是一种抽象数据类型,并且此变量无法直接与标准 C 语言的一元运算符或二目运算符一起使用。 在内部,此变量是无符号长整形的数组。

Vue 支持堆栈跟踪类型变量的下列特征和操作:

堆栈跟踪类型变量的声明

可以将变量声明为堆栈跟踪类型,方法是在脚本中以如下方式来声明变量:
      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.
stktrace_t 类型变量不支持限定词 signed、unsigned、register、static、auto、thread、kernel 和 const。

分配操作

赋值 (=) 运算符允许将 stktrace_t 类型变量赋给其他 stktrace_t 类型变量。 将破坏目标 stktrace_t 变量中的原始值。 不允许对 stktrace_t 变量类型进行任何强制类型转换。 在以下示例中,将堆栈跟踪 t1 的内容分配到了 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.

比较操作

对于 stktrace_t 变量,仅允许等式 (==) 和不等式 (! =) 运算符。 根据 stktrace_t 变量的整个条目,这些运算符的结果为 True(1) 或 False(0)。 不允许比较 stktrace_t 变量的个别条目。 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”);

显示堆栈跟踪类型变量

可以使用 Vue 的 printf 函数中的 %t%T 格式说明符来打印 stktrace_t 变量。 输出是变量中保存的线程的符号堆栈跟踪。 仅当对应于 stktrace_t 变量的线程处于运行状态并且使用 %t 格式说明符来打印堆栈跟踪时,才会打印具有地址 (符号加地址) 的符号; 否则,仅打印作为该变量的地址的堆栈跟踪。

作为键或值而存储在关联数组中的 stktrace_t 类型变量可以通过关联数组的 print 函数来显示。 如果对应于 stktrace_t 类型(存储在关联数组中)的线程正在运行中,那么将显示带有符号的地址(符号名称和偏移);否则,仅显示地址。 set_aso_print_options () 函数中设置 STKTRC_NO_SYM 标志时,此变量将打印正在运行的线程的原始地址。
    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. 
                                                     

堆栈跟踪类型变量的限制

  • 不能声明 stktrace_t 变量的数组。
  • stktrace_t 变量无法用作 struct 或 union 的成员。
  • 不允许访问堆栈跟踪的任何单个条目。
  • 在 systrace 调查中,不支持 stktrace_t 类型变量的运算符(赋值、比较和显示)。