【发布时间】:2017-10-19 07:36:11
【问题描述】:
我正在尝试使用systemtap,Linux 4.2.0-42-generic #49~14.04.1-Ubuntu SMP 来检测用户空间程序; stap --version 说:“Systemtap 转换器/驱动程序(版本 2.3/0.158,Debian 版本 2.3-1ubuntu1.4(信任))”
所以我首先尝试获取所有可调用函数的列表,其中:
stap -L 'process("/home/username/pathone/subpathtwo/subpaththree/subpathfour/subpathFive/subpathsix/subpathSeven/subpatheight/myprogramab").function("*").call' 2>&1 | tee /tmp/stap
这行得通 - 但是,请注意,我的程序的绝对路径是巨大的。所以从/tmp/stap 文件中,我读到了一些感兴趣的探针,然而,它们甚至更长,例如:
process("/home/username/pathone/subpathtwo/subpaththree/subpathfour/subpathFive/subpathsix/subpathSeven/subpatheight/myprogramab").function("DoSomething@/home/username/pathone/subpathtwo/subpaththree/subpathfour/subpathFive/src/BasicTestCodeFileInterface.cpp:201").call
...由于这对我来说很难阅读/不可读,我想做一些事情来将这一行分成更易读的部分。我首先想到的是使用变量,所以我尝试了这个test.stp 脚本:
#!/usr/bin/env stap
global exepath = "/home/username/pathone/subpathtwo/subpaththree/subpathfour/subpathFive/subpathsix/subpathSeven/subpatheight/myprogramab"
global srcpath = "/home/username/pathone/subpathtwo/subpaththree/subpathfour/subpathFive/src"
probe begin {
printf("%s\n", exepath)
exit() # must have; else probe end runs only upon Ctrl-C
}
probe end {
newstr = "DoSomething@" . srcpath # concatenate strings
printf("%s\n", newstr)
}
这行得通,我可以运行sudo stap /path/to/test.stp,然后打印出两个字符串。
但是,当我尝试在探针中使用这些字符串时,它们会失败:
- 像这样编写探针:
probe process(exepath).function("DoSomething@".srcpath."/BasicTestCodeFileInterface.cpp:201").call { ...
...失败:parse error: expected literal string or number; saw: identifier 'exepath' ...。
- 尝试将“进程”部分放入变量中:
global tproc = process("/home/username/pathone/subpathtwo/subpaththree/subpathfour/subpathFive/subpathsix/subpathSeven/subpatheight/myprogramab")
... 以parse error: expected literal string or number; saw: identifier 'process' ... 失败。
那么,我有什么选择,以某种方式缩短脚本中的探测行?
【问题讨论】: