Bug 20394 - inconsistency in exe/library paths searching between @cast() and process.library.function probes
Summary: inconsistency in exe/library paths searching between @cast() and process.libr...
Status: RESOLVED FIXED
Alias: None
Product: systemtap
Classification: Unclassified
Component: translator (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-21 14:55 UTC by David Smith
Modified: 2020-04-24 20:26 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Smith 2016-07-21 14:55:03 UTC
When writing probes, you can do the following:

====
probe
  process("python").library("libpython2.7.so*").function("PyEval_EvalFrameEx")
{
  # ... probe contents here ...
}
====

Notice that I'm just probing "python" as the "process" argument, a non-absolute path. The translator will look up "python" in my PATH and find it. Notice I'm using a wildcarded and non-absolute path for the "library" argument.

The above works fine and is very user friendly.

So, when using @cast(), I'd like to specify the symbol search path the same way:

====
# cat pytest1.stp
function foo:long(object:long)
{
  printf("%d\n",
	 @cast(object, "PyFrameObject", "python:libpython2.7.so*")->f_lineno)
}

probe 
  process("python").library("libpython2.7.so*").function("PyEval_EvalFrameEx")
{
  foo($f)
  exit()
}
# stap -v ./pytest1.stp -c "python -c 'import sys; sys.exit(0)'"
Pass 1: parsed user script and 117 library scripts using 242808virt/39472res/7568shr/32212data kb, in 190usr/30sys/234real ms.
semantic error: while processing function foo

semantic error: type definition 'PyFrameObject' not found in 'python:libpython2.7.so*': operator '@cast' at ./pytest1.stp:4:3
        source: 	 @cast(object, "PyFrameObject", "python:libpython2.7.so*")->f_lineno)
                	 ^

Pass 2: analyzed script: 1 probe, 1 function, 0 embeds, 0 globals using 250612virt/48776res/8880shr/40016data kb, in 120usr/380sys/498real ms.
Pass 2: analysis failed.  [man error::pass2]
====

So, that didn't work. Let's try without the wildcard:

====
# cat pytest2.stp
function foo:long(object:long)
{
  printf("%d\n",
	 @cast(object, "PyFrameObject", "python:libpython2.7.so")->f_lineno)
}

probe 
  process("python").library("libpython2.7.so*").function("PyEval_EvalFrameEx")
{
  foo($f)
  exit()
}
# stap -v ./pytest2.stp -c "python -c 'import sys; sys.exit(0)'"
Pass 1: parsed user script and 117 library scripts using 242808virt/39644res/7740shr/32212data kb, in 200usr/40sys/240real ms.
semantic error: while processing function foo

semantic error: type definition 'PyFrameObject' not found in 'python:libpython2.7.so': operator '@cast' at ./pytest2.stp:4:3
        source: 	 @cast(object, "PyFrameObject", "python:libpython2.7.so")->f_lineno)
                	 ^

Pass 2: analyzed script: 1 probe, 3 functions, 0 embeds, 0 globals using 250608virt/48792res/8892shr/40012data kb, in 100usr/400sys/511real ms.
Pass 2: analysis failed.  [man error::pass2]
====

OK, on this system /usr/lib64/libpython2.7.so is a symbolic link to /usr/lib64/libpython2.7.so.1.0. Let's give that a shot:

====
# cat pytest3.stp
function foo:long(object:long)
{
  printf("%d\n",
	 @cast(object, "PyFrameObject", "python:libpython2.7.so.1.0")->f_lineno)
}

probe 
  process("python").library("libpython2.7.so*").function("PyEval_EvalFrameEx")
{
  foo($f)
  exit()
}
# stap -v ./pytest3.stp -c "python -c 'import sys; sys.exit(0)'"
Pass 1: parsed user script and 117 library scripts using 242804virt/39504res/7604shr/32208data kb, in 210usr/30sys/242real ms.
semantic error: while processing function foo

semantic error: type definition 'PyFrameObject' not found in 'python:libpython2.7.so.1.0': operator '@cast' at ./pytest3.stp:4:3
        source: 	 @cast(object, "PyFrameObject", "python:libpython2.7.so.1.0")->f_lineno)
                	 ^

Pass 2: analyzed script: 1 probe, 1 function, 0 embeds, 0 globals using 250608virt/48804res/8912shr/40012data kb, in 100usr/370sys/492real ms.
Pass 2: analysis failed.  [man error::pass2]
====

Nope.

The only thing I can seem to get to work for @cast() is a full absolute path to the library. One reason why this is annoying is that to handle both 32-bit distros and 64-bit distros, I'll have to specify the library in both /usr/lib/ and /usr/lib64:

====
# cat pytest4.stp
function foo:long(object:long)
{
  printf("%d\n",
	 @cast(object, "PyFrameObject", "python:/usr/lib64/libpython2.7.so:/usr/lib/libpython2.7.so")->f_lineno)
}

probe 
  process("python").library("libpython2.7.so*").function("PyEval_EvalFrameEx")
{
  foo($f)
  exit()
}
# stap -v ./pytest4.stp -c "python -c 'import sys; sys.exit(0)'"
Pass 1: parsed user script and 117 library scripts using 242808virt/39712res/7812shr/32212data kb, in 210usr/30sys/238real ms.
Pass 2: analyzed script: 1 probe, 4 functions, 0 embeds, 0 globals using 251388virt/49532res/8828shr/40792data kb, in 120usr/190sys/317real ms.
Pass 3: translated to C into "/tmp/stapYGfpK4/stap_d4c98f72a2d5b7cef816271d6bd3e397_3084_src.c" using 251388virt/49724res/9020shr/40792data kb, in 20usr/190sys/206real ms.
Pass 4: compiled C into "stap_d4c98f72a2d5b7cef816271d6bd3e397_3084.ko" in 4730usr/1000sys/5459real ms.
Pass 5: starting run.
59
Pass 5: run completed in 30usr/70sys/392real ms.
====
Comment 1 Frank Ch. Eigler 2016-07-21 15:06:03 UTC
Having a search path in @cast in a function() makes it possible that a mismatch will exist between the probe (whose $context variable is being passed) and the @cast (who interprets that pointer).  What you seem to really want is to make @cast() in a function refer to - match - the context of the probe that invoked it.  This is kind of what we do already for @cast()s in probe handler bodies.

It's as though we want to specialize the functions invoked from a probe handler by the probe handler, almost as if they were inlined.  Then syntactic elements inside the functions (even $vars) could conceivably be resolved in the context of each probe where those functions are actually called from.

What do you think?
Comment 2 David Smith 2016-07-21 15:50:24 UTC
(In reply to Frank Ch. Eigler from comment #1)
> Having a search path in @cast in a function() makes it possible that a
> mismatch will exist between the probe (whose $context variable is being
> passed) and the @cast (who interprets that pointer).  What you seem to
> really want is to make @cast() in a function refer to - match - the context
> of the probe that invoked it.  This is kind of what we do already for
> @cast()s in probe handler bodies.
> 
> It's as though we want to specialize the functions invoked from a probe
> handler by the probe handler, almost as if they were inlined.  Then
> syntactic elements inside the functions (even $vars) could conceivably be
> resolved in the context of each probe where those functions are actually
> called from.
> 
> What do you think?

That's an interesting idea. If it is doable, I'd say it would be quite handy.
Comment 3 Frank Ch. Eigler 2020-04-24 20:26:01 UTC
more general solution