iovisor / bcc

BCC - Tools for BPF-based Linux IO analysis, networking, monitoring, and more
Apache License 2.0
20.58k stars 3.88k forks source link

TRACEPOINT_PROBE failed with event xhci-hcd:xhci_urb_enqueue #2788

Open netedwardwu opened 4 years ago

netedwardwu commented 4 years ago

Source code

#! /usr/bin/python2
# @lint-avoid-python-3-compatibility-imports
#

from __future__ import print_function
from bcc import BPF
from time import sleep, strftime
import argparse
import signal

# define BPF program
bpf_text = """
#include <uapi/linux/ptrace.h>

TRACEPOINT_PROBE(xhci-hcd, xhci_urb_enqueue)
{
    return 0;
}
"""

# load BPF program
b = BPF(text=bpf_text)

Result

/virtual/main.c:4:22: error: expected ';' after top level declarator
TRACEPOINT_PROBE(xhci-hcd, xhci_urb_enqueue)
                     ^
1 error generated.
Traceback (most recent call last):
  File "/usr/sbin/test-bpfcc", line 22, in <module>
    b = BPF(text=bpf_text)
  File "/usr/lib/python2.7/dist-packages/bcc/__init__.py", line 301, in __init__
    raise Exception("Failed to compile BPF module %s" % src_file)
Exception: Failed to compile BPF module

Ubuntu 18.04

edward@edward-VirtualBox:/usr/sbin$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.3 LTS
Release:        18.04
Codename:       bionic

Kernel version

Linux edward-VirtualBox 4.18.0-15-generic

This issue happens when the name of the event has "-" symbol. attach_tracepoint() is workable on this case.

Thank you

yonghong-song commented 4 years ago

Yes, the reason is due to the following definition:

#define TRACEPOINT_PROBE(category, event) \
int tracepoint__##category##__##event(struct tracepoint__##category##__##event *args)

The workaround is to define the function prototype explicitly like

struct tracepoit__xhci_urb_enqueue { ...}
int tracepoint__xhci_urb_enqueue(struct tracepoit__xhci_urb_enqueue *args) { ...}

The function name and struct name can be different from the above.

The name has - is quite rare, it would be good to get it fixed. But probably not urgent.