From ca1d3fd07a8483270041ef2899ed72fa28473811 Mon Sep 17 00:00:00 2001 From: Hengqi Chen Date: Mon, 3 Jan 2022 21:36:48 +0800 Subject: [PATCH] bcc: Fix array type handling due to llvm changes The llvm commit aee49255074f ([0]) changes array type from `int [4]` to `int[4]` (with space removed), which breaks the assumption in BCC. This commit fixes this issue and adds a comment to the related code. While at it, also remove execution permission of file `table.py`. [0]: https://github.com/llvm/llvm-project/commit/aee49255074fd4ef38d97e6e70cbfbf2f9fd0fa7 Signed-off-by: Hengqi Chen --- src/cc/frontends/clang/b_frontend_action.cc | 3 +++ src/python/bcc/table.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) mode change 100755 => 100644 src/python/bcc/table.py diff --git a/src/cc/frontends/clang/b_frontend_action.cc b/src/cc/frontends/clang/b_frontend_action.cc index 27b19360..9a6e510e 100644 --- a/src/cc/frontends/clang/b_frontend_action.cc +++ b/src/cc/frontends/clang/b_frontend_action.cc @@ -946,6 +946,9 @@ bool BTypeVisitor::VisitCallExpr(CallExpr *Call) { std::vector perf_event; for (auto it = r->field_begin(); it != r->field_end(); ++it) { + // After LLVM commit aee49255074f + // (https://github.com/llvm/llvm-project/commit/aee49255074fd4ef38d97e6e70cbfbf2f9fd0fa7) + // array type change from `comm#char [16]` to `comm#char[16]` perf_event.push_back(it->getNameAsString() + "#" + it->getType().getAsString()); //"pid#u32" } fe_.perf_events_[name] = perf_event; diff --git a/src/python/bcc/table.py b/src/python/bcc/table.py old mode 100755 new mode 100644 index 91e0ab16..1ff24114 --- a/src/python/bcc/table.py +++ b/src/python/bcc/table.py @@ -227,8 +227,8 @@ def _get_event_class(event_map): 'unsigned __int128' : (ct.c_ulonglong * 2), 'void *' : ct.c_void_p } - # handle array types e.g. "int [16] foo" - array_type = re.compile(r"(.+) \[([0-9]+)\]$") + # handle array types e.g. "int [16]" or "char[16]" + array_type = re.compile(r"([^ ]+) ?\[([0-9]+)\]$") fields = [] num_fields = lib.bpf_perf_event_fields(event_map.bpf.module, event_map._name) -- 2.34.1