【问题标题】:Handling long probe paths in systemtap userspace scripts (variables)?处理 systemtap 用户空间脚本(变量)中的长探测路径?
【发布时间】: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' ... 失败。

那么,我有什么选择,以某种方式缩短脚本中的探测行?

【问题讨论】:

    标签: linux systemtap


    【解决方案1】:

    你最好的选择可能是使用

    @define part1 %(  "/path/part/1" %)
    @define part2 %(  "/part/2" %)
    probe process(@part1 @part2).function("...") { }
    

    注意(扩展为的宏)字符串文字之间没有显式的连接运算符。解析器将自动连接它们,就像在 C 中一样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-01
      • 1970-01-01
      • 2010-10-25
      • 1970-01-01
      • 2017-02-01
      • 2011-10-10
      • 2017-12-14
      • 1970-01-01
      相关资源
      最近更新 更多