systemtap 用户空间函数跟踪
systemtap userspace function tracing
我有一个简单的c++程序
main.cpp
#include <iostream>
using namespace std;
int addition (int a, int b)
{
int r;
r=a+b;
return r;
}
int main ()
{
int z;
z = addition (5,3);
cout << "The result is " << z;
}
我想为此生成函数跟踪
- 打印函数名称及其输入输出和 return 类型
我的 systemtap 脚本:para-callgraph.stp
#! /usr/bin/env stap
function trace(entry_p, extra) {
%( $# > 1 %? if (tid() in trace) %)
printf("%s%s%s %s\n",
thread_indent (entry_p),
(entry_p>0?"->":"<-"),
probefunc (),
extra)
}
probe .call { trace(1, $$parms) }
probe .return { trace(-1, $$return) }
我的 C++ Exec 被称为:a(编译为 g++ -g main.cpp)
Command I run
stap para-callgraph.stp 'process("a").function("*")' -c "./a > /dev/null"
0 a(15119):->_GLOBAL__I__Z8additionii
27 a(15119): ->__static_initialization_and_destruction_0 __initialize_p=0x0 __priority=0x0
168 a(15119): <-__static_initialization_and_destruction_0
174 a(15119):<-_GLOBAL__I__Z8additionii
0 a(15119):->main
18 a(15119): ->addition a=0x0 b=0x400895
30 a(15119): <-addition return=0x8
106 a(15119):<-main return=0x0
此处 ->addition a=0x0 b=0x400895 :它的地址而不是实际值,即我想要的 5、3。
How to modify my stap script?
这似乎是一个 systemtap 错误。它应该打印 b 的值,而不是它的地址。请将其报告给 systemtap@sourceware.org
邮件列表(包含 compiler/etc。版本和其他信息,如 man error::reporting
中所述。
关于更改脚本,$$parms
部分是将局部变量转换为漂亮的字符串的地方。它可以更改为...
trace(1, $$parms . (@defined($foobar) ? (" foobar=".$foobar$) : ""))
将 foobar=XYZ
附加到跟踪记录,只要参数 foobar
可用。要解决有问题的 systemtap 错误,您可以尝试
trace(1, $$parms . (@defined($b) ? (" *b=".user_int($b)) : ""))
取消引用 b
变量,就好像它是一个 int *
。
我有一个简单的c++程序
main.cpp
#include <iostream>
using namespace std;
int addition (int a, int b)
{
int r;
r=a+b;
return r;
}
int main ()
{
int z;
z = addition (5,3);
cout << "The result is " << z;
}
我想为此生成函数跟踪 - 打印函数名称及其输入输出和 return 类型
我的 systemtap 脚本:para-callgraph.stp
#! /usr/bin/env stap
function trace(entry_p, extra) {
%( $# > 1 %? if (tid() in trace) %)
printf("%s%s%s %s\n",
thread_indent (entry_p),
(entry_p>0?"->":"<-"),
probefunc (),
extra)
}
probe .call { trace(1, $$parms) }
probe .return { trace(-1, $$return) }
我的 C++ Exec 被称为:a(编译为 g++ -g main.cpp)
Command I run
stap para-callgraph.stp 'process("a").function("*")' -c "./a > /dev/null"
0 a(15119):->_GLOBAL__I__Z8additionii
27 a(15119): ->__static_initialization_and_destruction_0 __initialize_p=0x0 __priority=0x0
168 a(15119): <-__static_initialization_and_destruction_0
174 a(15119):<-_GLOBAL__I__Z8additionii
0 a(15119):->main
18 a(15119): ->addition a=0x0 b=0x400895
30 a(15119): <-addition return=0x8
106 a(15119):<-main return=0x0
此处 ->addition a=0x0 b=0x400895 :它的地址而不是实际值,即我想要的 5、3。
How to modify my stap script?
这似乎是一个 systemtap 错误。它应该打印 b 的值,而不是它的地址。请将其报告给 systemtap@sourceware.org
邮件列表(包含 compiler/etc。版本和其他信息,如 man error::reporting
中所述。
关于更改脚本,$$parms
部分是将局部变量转换为漂亮的字符串的地方。它可以更改为...
trace(1, $$parms . (@defined($foobar) ? (" foobar=".$foobar$) : ""))
将 foobar=XYZ
附加到跟踪记录,只要参数 foobar
可用。要解决有问题的 systemtap 错误,您可以尝试
trace(1, $$parms . (@defined($b) ? (" *b=".user_int($b)) : ""))
取消引用 b
变量,就好像它是一个 int *
。