jj1997jj
jj1997jj

Reputation: 85

How to use -V option in perf probe?

I'm trying to print a value of variable in specific function using perf. So I tried perf probe with -V option, but I got error message like this.

# perf probe -V tcp_sendmsg
Failed to find the path for the kernel: Invalid ELF file
  Error: Failed to show vars.

So I downloaded kernel symbol&source package and I checked that the value CONFIG_DEBUG_INFO in /boot/config-5.3.0-46-generic'set to 1. But still the same error occurs.

How should I fix this problem?

Ubuntu 18.04 LTS release: 5.3.0-46-generic version: 38~18.04.01

Upvotes: 2

Views: 1839

Answers (1)

Arnabjyoti Kalita
Arnabjyoti Kalita

Reputation: 2431

To make perf probe -V work, you will have to pass a vmlinux file that has debuginfo, which you seem to have done as per your comment -

sudo perf probe --vmlinux /usr/lib/debug/boot/vmlinux-4.15.0-1077-azure 
-V tcp_sendmsg
Available variables at tcp_sendmsg
        @<tcp_sendmsg+0>
                size_t  size
                struct msghdr*  msg
                struct sock*    sk

Now as per the man-page, perf probe -L means

-L, --line=
    Show source code lines which can be probed. 
    This needs an argument which specifies a range of the source code. 
    (see LINE SYNTAX for detail) 

which means you need to specify the location of the kernel source code, when you run perf probe -L, otherwise the elfutils tool, that analyzes the vmlinux file with debuginfo would not be able to determine the right path for the kernel sources.

You can download the kernel sources as mentioned here

And then run perf probe where you specify the --source switch,

sudo perf probe --source /usr/src/linux-source-4.4.0 --vmlinux /usr/lib/debug/boot/vmlinux-4.15.0-1077-azure -L tcp_sendmsg
<tcp_sendmsg@/usr/src/linux-source-4.4.0//net/ipv4/tcp.c:0>
      0         /* Clear memory counter. */
      1         tp->ucopy.memory = 0;
         }

      4  static struct sk_buff *tcp_recv_skb(struct sock *sk, u32 seq, u32 *off)
      5  {
      6         struct sk_buff *skb;
                u32 offset;

      9         while ((skb = skb_peek(&sk->sk_receive_queue)) != NULL) {
                        offset = seq - TCP_SKB_CB(skb)->seq;
                        if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_SYN)
                                offset--;

Upvotes: 3

Related Questions