Blame SOURCES/bpftrace-0.11.1-Fix-clear-when-called-on-an-array.patch

544983
From ed9caea4efcffdd9f37c67b272324a87abfd20c8 Mon Sep 17 00:00:00 2001
544983
From: Jerome Marchand <jmarchan@redhat.com>
544983
Date: Thu, 5 Nov 2020 15:17:14 +0100
544983
Subject: [PATCH] Fix clear() when called on an array
544983
544983
Fixes the following error:
544983
Error looking up elem: -1
544983
terminate called after throwing an instance of 'std::runtime_error'
544983
  what():  Could not clear map with ident "@", err=-1
544983
Aborted (core dumped)
544983
---
544983
 src/bpftrace.cpp | 5 +++++
544983
 src/imap.h       | 4 ++++
544983
 2 files changed, 9 insertions(+)
544983
544983
diff --git a/src/bpftrace.cpp b/src/bpftrace.cpp
544983
index 23b65a5..fe2fb66 100644
544983
--- a/src/bpftrace.cpp
544983
+++ b/src/bpftrace.cpp
544983
@@ -1147,6 +1147,11 @@ int BPFtrace::print_maps()
544983
 int BPFtrace::clear_map(IMap &map)
544983
 {
544983
   std::vector<uint8_t> old_key;
544983
+  if (map.is_array_type())
544983
+  {
544983
+    return zero_map(map);
544983
+  }
544983
+
544983
   try
544983
   {
544983
     if (map.type_.IsHistTy() || map.type_.IsLhistTy() ||
544983
diff --git a/src/imap.h b/src/imap.h
544983
index 27d0d74..ca9f424 100644
544983
--- a/src/imap.h
544983
+++ b/src/imap.h
544983
@@ -27,6 +27,10 @@ class IMap
544983
     return map_type_ == BPF_MAP_TYPE_PERCPU_HASH ||
544983
            map_type_ == BPF_MAP_TYPE_PERCPU_ARRAY;
544983
   }
544983
+  bool is_array_type()
544983
+  {
544983
+    return map_type_ == BPF_MAP_TYPE_PERCPU_ARRAY;
544983
+  }
544983
 
544983
   // unique id of this map. Used by (bpf) runtime to reference
544983
   // this map
544983
-- 
544983
2.25.4
544983