0

I am trying to instrument a user-space program using systemtap, Linux 4.2.0-42-generic #49~14.04.1-Ubuntu SMP; stap --version says: "Systemtap translator/driver (version 2.3/0.158, Debian version 2.3-1ubuntu1.4 (trusty))"

So I first tried getting a list of all callable functions, with:

stap -L 'process("/home/username/pathone/subpathtwo/subpaththree/subpathfour/subpathFive/subpathsix/subpathSeven/subpatheight/myprogramab").function("*").call' 2>&1 | tee /tmp/stap

This worked - however, note that the absolute path to my program is massive. So from the /tmp/stap file, I read some probes of interest, however, they are even longer, such as:

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

... and as this is very difficult to read/unreadable for me, I wanted to do something to split this line into more readable pieces. The first thing I thought of was using variables, so I tried this test.stp script:

#!/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)
}

This works, I can run sudo stap /path/to/test.stp, and I get the two strings printed.

However, when I try to use these strings in probes, they fail:

  • Writing a probe like this:

probe process(exepath).function("DoSomething@".srcpath."/BasicTestCodeFileInterface.cpp:201").call { ...

... fails with: parse error: expected literal string or number; saw: identifier 'exepath' ....

  • Trying to put the "process" part in a variable:

global tproc = process("/home/username/pathone/subpathtwo/subpaththree/subpathfour/subpathFive/subpathsix/subpathSeven/subpatheight/myprogramab")

... fails with parse error: expected literal string or number; saw: identifier 'process' ....

So, what options do I have, to somehow shorten the probe lines in a script?

sdaau
  • 36,975
  • 46
  • 198
  • 278

1 Answers1

0

Your best bet is probably to use macros:

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

Note no explicit concatenation operator between the (macros that expand to) string literals. The parser will auto-concatenate them, just as in C.

fche
  • 2,641
  • 20
  • 28