SilverIce
SilverIce

Reputation: 75

How to access return value from user-space probing with systemtap

I want to access data that return from "open" function of glibc such as filename or file descriptor

I try

probe process("/lib*/libc.so.*").function("open") { 
   fd = $fd
   filename = user_string($filename)
   printf("%d %d %s %s\n",pid(),ppid(),filename,fd)
}

but it error

semantic error: unresolved target-symbol expression: identifier '$fd' at malloc.stp:3:10 source: fd = $fd ^

Pass 2: analysis failed. [man error::pass2]

Upvotes: 2

Views: 1464

Answers (1)

fche
fche

Reputation: 2790

The open system call does not take an fd argument, so a .function probe naturally won't find it. If you'd like to see the file descriptor returned from open, then probe the .function("...").return point, and $return.

probe process("/lib*/libc.so.6").function("open").return {
    fd=$return
    path=user_string(@entry(@choose_defined($file,$filename)))
    printf("open %s -> %d\n", path, fd)
}

(Added the @choose_defined() here because some versions of glibc have renamed this parameter.)

Upvotes: 6

Related Questions