Question

I'm trying to print the data received on a socket - the contents of ubuf on the return of sys_recv. I cant get the %M format specifier to work properly. Can someone please explain how to use it properly. Thanks

stap -L 'kernel.function("sys_recv@net/socket.c")'
kernel.function("sys_recv@net/socket.c:1800") $fd:int $ubuf:void* $size:size_t $flags:unsigned int

using this probe: [laris@kakitis stap]$ cat socket-recv.stp

#! /usr/bin/env stap
probe kernel.function("sys_recv@net/socket.c").return {
        if (pid() == target())
                printf ("%s  fd %d size %d  ubuf %p %10M \n ", ppfunc(),$fd,$size,$ubuf,$ubuf)
}

From my reading of the man page the format %10M should return 10 bytes from the location pointed to by $ubuf:void but I only get 1. Adjusting the parameter 10 shifts the one character output rather than showing more or less memory

[root@kakitis stap]# stap -x 16796 socket-recv.stp 
sys_recv  fd 13 size 64071  ubuf 0x86ceca0         70 
 sys_recv  fd 13 size 62679  ubuf 0x86cf210         50 

Changing 10 to 2 gives this

[root@kakitis stap]# stap -x 16796 socket-recv.stp 
sys_recv  fd 13 size 64071  ubuf 0x86ceca0 70 
 sys_recv  fd 13 size 62679  ubuf 0x86cf210 50

System particulars are:

[laris@kakitis stap]$ stap --version
Systemtap translator/driver (version 2.1/0.154, rpm 2.1-2.fc17)
Copyright (C) 2005-2013 Red Hat, Inc. and others
This is free software; see the source for copying conditions.
enabled features: AVAHI LIBRPM LIBSQLITE3 NSS TR1_UNORDERED_MAP NLS
[laris@kakitis stap]$ uname -a
Linux kakitis 3.4.33 #1 SMP Tue Jan 7 14:15:58 EST 2014 i686 i686 i386 GNU/Linux
[laris@kakitis stap]$ cat /etc/redhat-release 
Fedora release 17 (Beefy Miracle)
Was it helpful?

Solution

Don't confuse the output-width and precision parameters for printf(). The following will do what you meant:

printf ("%33.10M", $pointer)

to print 10 bytes (20 hex characters) in a 33-character-wide output field. One or both numbers can be replaced by *, so that the respective widths are passed as parameters before the $pointer. The upstream man page has been updated with an example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top