出口类变量
与位于系统调用或用户函数出口位置点的探针点相关联的子句可访问系统调用或用户函数的返回值。
只有一个出口类变量由 Vue 语言定义。 这是从函数或系统调用返回的值,可使用特殊的内置变量名称 __rv 对其进行访问。
系统调用探针管理器支持位于出口位置点的调查。 例如,read 系统调用返回读取的实际字节数或错误返回码 -1。 该返回值可在 @@syscall:*:read:exit 探针点进行访问,该探针点标识 read 系统调用的所有出口点。
与入口类变量类似,仅当与 Vue 子句关联的探针规范标识唯一探针点时,在该子句中使用出口类变量才合法。 因此,不能在具有探针规范中指定的多个探针点的 Vue 子句中使用 __rv 。 而且,必须在 Vue 脚本中显式提供正被探测的函数的 C 式声明,特别是返回值的数据类型。 事实上,指定函数声明却不提供其返回类型是错误的。
可在子句的谓词部分使用出口类变量。
以下脚本是非法脚本,将导致 ProbeVue 编译器失败并产生语法错误,因为未指定 read 函数的返回类型:
/* Bad example. */
int read(int fd, char *buf, unsigned long size);
@@syscall:*:read:exit
when (__rv > 0)
{
/* Entered on read success: return value = # of bytes read */
printf("Number of bytes read = %d\n", __rv);
}
以下修改后的脚本有效:
/* Good example. */
int read(int fd, char *buf, unsigned long size);
@@syscall:*:read:exit
when (__rv > 0)
{
/* Entered on read success: return value = # of bytes read */
printf("Number of bytes read = %d\n", __rv);
}