bpftrace/bpftrace-0.23.5-Remove-cstring_view.patch
Viktor Malik ded68d8989
Rebase bpftrace to 0.23.5
Resolves: RHEL-78918
Resolves: RHEL-81775

This version comes with LLVM 20 support.

Also needs two extra patches:

- GCC in c9s is throwing some errors while compiling
  src/container/cstring_view.h. Since the file is dropped in a later
  version, just apply that patch.
- RHEL 9 kernel doesn't have 736c55a02c47 ("sched/fair: Rename
  cfs_rq.nr_running into nr_queued") so we need to use the older version
  of runqlen.bt.

Signed-off-by: Viktor Malik <vmalik@redhat.com>
2025-06-09 15:01:52 +02:00

208 lines
5.2 KiB
Diff

From 8c587382b686a776178e7fc105f3b5468cab360f Mon Sep 17 00:00:00 2001
From: Thierry Treyer <ttreyer@meta.com>
Date: Fri, 11 Apr 2025 09:04:29 -0700
Subject: [PATCH] Remove 'cstring_view'
The `cstring_view` class was a `std::string_view` with the added
guarantee that it is NULL-terminated. It was only used by BpfMap.
This commit replaces it by a `std::string`
Fixes: #4001
Signed-off-by: Thierry Treyer <ttreyer@meta.com>
---
src/bpfmap.cpp | 2 +-
src/bpfmap.h | 10 +++---
src/container/cstring_view.h | 39 -----------------------
tests/CMakeLists.txt | 1 -
tests/cstring_view.cpp | 60 ------------------------------------
5 files changed, 5 insertions(+), 107 deletions(-)
delete mode 100644 src/container/cstring_view.h
delete mode 100644 tests/cstring_view.cpp
diff --git a/src/bpfmap.cpp b/src/bpfmap.cpp
index 9464e8ed..eb65621e 100644
--- a/src/bpfmap.cpp
+++ b/src/bpfmap.cpp
@@ -12,7 +12,7 @@ libbpf::bpf_map_type BpfMap::type() const
return type_;
}
-cstring_view BpfMap::bpf_name() const
+const std::string &BpfMap::bpf_name() const
{
return name_;
}
diff --git a/src/bpfmap.h b/src/bpfmap.h
index 09153764..d48763ed 100644
--- a/src/bpfmap.h
+++ b/src/bpfmap.h
@@ -11,8 +11,6 @@ namespace libbpf {
#include "libbpf/bpf.h"
} // namespace libbpf
-#include "container/cstring_view.h"
-
namespace bpftrace {
class BpfMap {
@@ -28,12 +26,12 @@ public:
}
BpfMap(libbpf::bpf_map_type type,
- cstring_view name,
+ std::string name,
uint32_t key_size,
uint32_t value_size,
uint32_t max_entries)
: type_(type),
- name_(name),
+ name_(std::move(name)),
key_size_(key_size),
value_size_(value_size),
max_entries_(max_entries)
@@ -42,7 +40,7 @@ public:
int fd() const;
libbpf::bpf_map_type type() const;
- cstring_view bpf_name() const;
+ const std::string &bpf_name() const;
std::string name() const;
uint32_t key_size() const;
uint32_t value_size() const;
@@ -56,7 +54,7 @@ public:
private:
struct bpf_map *bpf_map_;
libbpf::bpf_map_type type_;
- cstring_view name_;
+ std::string name_;
uint32_t key_size_;
uint32_t value_size_;
uint32_t max_entries_;
diff --git a/src/container/cstring_view.h b/src/container/cstring_view.h
deleted file mode 100644
index 2e1c4602..00000000
--- a/src/container/cstring_view.h
+++ /dev/null
@@ -1,39 +0,0 @@
-#pragma once
-
-#include <string>
-#include <string_view>
-
-namespace bpftrace {
-
-// cstring_view
-//
-// A restricted version of std::string_view which guarantees that the underlying
-// string buffer will be null-terminated. This can be useful when interacting
-// with C APIs while avoiding the use of char* and unnecessary copies from using
-// std::string.
-//
-// We only allow constructing cstring_view from types which are guaranteed to
-// store null-terminated strings. All modifiers or operations on cstring_view
-// will also maintain the null-terminated property.
-class cstring_view : public std::string_view {
-public:
- constexpr cstring_view(const char *str) noexcept : std::string_view{ str }
- {
- }
- constexpr cstring_view(const std::string &str) noexcept
- : std::string_view{ str }
- {
- }
- constexpr const char *c_str() const noexcept
- {
- return data();
- }
-
-private:
- // Disallow use of functions which can break the null-termination invariant
- using std::string_view::copy;
- using std::string_view::remove_suffix;
- using std::string_view::substr;
-};
-
-} // namespace bpftrace
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index c5d10f9c..d012cad7 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -33,7 +33,6 @@ add_executable(bpftrace_test
clang_parser.cpp
config.cpp
collect_nodes.cpp
- cstring_view.cpp
field_analyser.cpp
function_registry.cpp
log.cpp
diff --git a/tests/cstring_view.cpp b/tests/cstring_view.cpp
deleted file mode 100644
index 5b82a990..00000000
--- a/tests/cstring_view.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-#include "container/cstring_view.h"
-#include "gtest/gtest.h"
-
-#include <type_traits>
-
-namespace bpftrace::test::cstring_view {
-
-using bpftrace::cstring_view;
-
-TEST(cstring_view, c_string)
-{
- const char *str = "abc";
- cstring_view sv{ str };
-
- EXPECT_EQ("abc", sv);
-
- EXPECT_EQ('a', sv[0]);
- EXPECT_EQ('b', sv[1]);
- EXPECT_EQ('c', sv[2]);
- EXPECT_EQ('\0', sv[3]);
-}
-
-TEST(cstring_view, std_string)
-{
- std::string str = "abc";
- cstring_view sv{ str };
-
- EXPECT_EQ("abc", sv);
-
- EXPECT_EQ('a', sv[0]);
- EXPECT_EQ('b', sv[1]);
- EXPECT_EQ('c', sv[2]);
- EXPECT_EQ('\0', sv[3]);
-}
-
-TEST(cstring_view, std_string_view)
-{
- EXPECT_FALSE((std::is_constructible_v<cstring_view, std::string_view>));
-
- // Sanity checks:
- EXPECT_TRUE((std::is_constructible_v<cstring_view, std::string>));
- EXPECT_TRUE((std::is_constructible_v<cstring_view, const char *>));
-}
-
-TEST(cstring_view, length)
-{
- cstring_view sv{ "abc" };
-
- EXPECT_EQ("abc", sv);
- EXPECT_EQ(3, sv.size());
- EXPECT_EQ(3, sv.length());
-}
-
-TEST(cstring_view, c_str)
-{
- cstring_view sv{ "abc" };
- EXPECT_EQ(0, strcmp(sv.c_str(), "abc"));
-}
-
-} // namespace bpftrace::test::cstring_view
--
2.49.0