Bug 206531

Summary: libtraceevent: fail to parse event format file containing '{' and '}' characters in print fmt string
Product: Tools Reporter: Tzvetomir Stoyanov (tstoyanov)
Component: Trace-cmd/KernelsharkAssignee: Default virtual assignee for Trace-cmd and kernelshark (tools_tracecmd_kernelshark)
Status: RESOLVED IMPLEMENTED    
Severity: normal CC: rostedt
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 5.4.14-200.fc31.x86_64 Subsystem:
Regression: No Bisected commit-id:

Description Tzvetomir Stoyanov 2020-02-14 09:31:38 UTC
tep_parse_event() API from traceevent library fails with
   bad op token {
error when parsing print fmt string containing '{' character in unexpected places. There are such format strings in xhci_urb_dequeue, xhci_urb_enqueue, xhci_urb_giveback events from xhci-hcd system:

  cat events/xhci-hcd/xhci_urb_dequeue/format
   [...]
 print fmt: "ep%d%s-%s: urb %p pipe %u slot %d length %d/%d sgs %d/%d stream %d flags %08x", REC->epnum, REC->dir_in ? "in" : "out", ({ char *s; switch (REC->type) { case 3: s = "intr"; break; case 0: s = "control"; break; case 2: s = "bulk"; break; case 1: s = "isoc"; break; default: s = "UNKNOWN"; } s; }), REC->urb, REC->pipe, REC->slot_id, REC->actual, REC->length, REC->num_mapped_sgs, REC->num_sgs, REC->stream, REC->flags

  trace-cmd check-events
  [...]
 [xhci-hcd:xhci_urb_enqueue] bad op token {
 [xhci-hcd:xhci_urb_giveback] bad op token {
 [xhci-hcd:xhci_urb_dequeue] bad op token {


trace-cmd version 2.9.dev (e8fb01140eb2800f9ef419a0f8e5bfeb51292c55+)
Comment 1 Steven Rostedt 2021-03-10 22:12:31 UTC
This is a kernel fix, and it looks like they did so. The parser is not suppose to be able to parse switch statements. That's what __process_symbols() helper was made for.

print fmt: "ep%d%s-%s: urb %p pipe %u slot %d length %d/%d sgs %d/%d stream %d flags %08x", REC->epnum, REC->dir_in ? "in" : "out", __print_symbolic(REC->type, { 3, "intr" }, { 0, "control" }, { 2, "bulk" }, { 1, "isoc" }), REC->urb, REC->pipe, REC->slot_id, REC->actual, REC->length, REC->num_mapped_sgs, REC->num_sgs, REC->stream, REC->flags