bcc: Fix array type handling due to llvm changes
authorHengqi Chen <chenhengqi@outlook.com>
Mon, 3 Jan 2022 13:36:48 +0000 (21:36 +0800)
committeryonghong-song <ys114321@gmail.com>
Wed, 5 Jan 2022 02:36:06 +0000 (18:36 -0800)
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 <chenhengqi@outlook.com>
src/cc/frontends/clang/b_frontend_action.cc
src/python/bcc/table.py [changed mode: 0755->0644]

index 27b193609023f34b6b9389c7fd16eb02e56d0d9a..9a6e510ed88513cd9773b4b9509d3f8c64e65325 100644 (file)
@@ -946,6 +946,9 @@ bool BTypeVisitor::VisitCallExpr(CallExpr *Call) {
             std::vector<std::string> 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;
old mode 100755 (executable)
new mode 100644 (file)
index 91e0ab1..1ff2411
@@ -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)