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

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