Skip to content

Commit

Permalink
Add --disable-feature option
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Olsa <[email protected]>
  • Loading branch information
olsajiri committed Oct 22, 2023
1 parent d1672f6 commit ff9fc4c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/bpffeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,12 @@ bool BPFfeature::has_kprobe_multi()
if (has_kprobe_multi_.has_value())
return *has_kprobe_multi_;

if (disable_feature_.find("kprobe_multi") != std::string::npos)
{
has_kprobe_multi_ = false;
return *has_kprobe_multi_;
}

const char* sym = "ksys_read";
DECLARE_LIBBPF_OPTS(bpf_link_create_opts, link_opts);
int progfd, linkfd = -1;
Expand Down Expand Up @@ -413,6 +419,12 @@ bool BPFfeature::has_uprobe_multi()
if (has_uprobe_multi_.has_value())
return *has_uprobe_multi_;

if (disable_feature_.find("uprobe_multi") != std::string::npos)
{
has_uprobe_multi_ = false;
return *has_uprobe_multi_;
}

LIBBPF_OPTS(bpf_prog_load_opts,
load_opts,
.expected_attach_type = static_cast<enum ::bpf_attach_type>(
Expand Down
3 changes: 3 additions & 0 deletions src/bpffeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public: \
class BPFfeature
{
public:
BPFfeature(std::string disable_feature) : disable_feature_(disable_feature) { }
BPFfeature() = default;
virtual ~BPFfeature() = default;

Expand Down Expand Up @@ -142,6 +143,8 @@ class BPFfeature
int* outfd = nullptr);

BTF btf_ = BTF({ "vmlinux" });

std::string disable_feature_;
};

#undef DEFINE_PROG_TEST
Expand Down
4 changes: 2 additions & 2 deletions src/bpftrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ class WildcardException : public std::exception
class BPFtrace
{
public:
BPFtrace(std::unique_ptr<Output> o = std::make_unique<TextOutput>(std::cout))
BPFtrace(std::unique_ptr<Output> o = std::make_unique<TextOutput>(std::cout), std::string disable_feature = "")
: out_(std::move(o)),
feature_(std::make_unique<BPFfeature>()),
feature_(std::make_unique<BPFfeature>(disable_feature)),
probe_matcher_(std::make_unique<ProbeMatcher>(this)),
ncpus_(get_possible_cpus().size())
{
Expand Down
8 changes: 7 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ enum Options
INCLUDE,
EMIT_ELF,
EMIT_LLVM,
DISABLE_FEATURE,
};
} // namespace

Expand Down Expand Up @@ -499,6 +500,7 @@ struct Args
std::string output_elf;
std::string output_llvm;
std::string aot;
std::string disable_feature;
OutputBufferConfig obc = OutputBufferConfig::UNSET;
BuildMode build_mode = BuildMode::DYNAMIC;
std::vector<std::string> include_dirs;
Expand All @@ -525,6 +527,7 @@ Args parse_args(int argc, char* argv[])
option{ "no-warnings", no_argument, nullptr, Options::NO_WARNING },
option{ "test", required_argument, nullptr, Options::TEST },
option{ "aot", required_argument, nullptr, Options::AOT },
option{ "disable-feature", required_argument, nullptr, Options::DISABLE_FEATURE },
option{ nullptr, 0, nullptr, 0 }, // Must be last
};

Expand Down Expand Up @@ -564,6 +567,9 @@ Args parse_args(int argc, char* argv[])
args.aot = optarg;
args.build_mode = BuildMode::AHEAD_OF_TIME;
break;
case Options::DISABLE_FEATURE: // --disable-feature
args.disable_feature = optarg;
break;
case 'o':
args.output_file = optarg;
break;
Expand Down Expand Up @@ -797,7 +803,7 @@ int main(int argc, char* argv[])

libbpf_set_print(libbpf_print);

BPFtrace bpftrace(std::move(output));
BPFtrace bpftrace(std::move(output), args.disable_feature);
bool verify_llvm_ir = false;

if (!args.cmd_str.empty())
Expand Down

0 comments on commit ff9fc4c

Please sign in to comment.