0

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)
4

1 回答 1

1

不要混淆 printf() 的输出宽度和精度参数。以下将做你的意思:

printf ("%33.10M", $pointer)

在 33 个字符宽的输出字段中打印 10 个字节(20 个十六进制字符)。一个或两个数字可以用 * 代替,以便在 $pointer 之前将各自的宽度作为参数传递。上游手册页已使用示例进行了更新。

于 2014-01-09T15:06:20.577 回答