Commit 613f19a2 authored by Jon Haslam's avatar Jon Haslam Committed by Alastair Robertson

gracefully handle invalid probe names

parent 56fdbc0a
#include <iostream> #include <iostream>
#include <algorithm>
#include "types.h" #include "types.h"
...@@ -53,24 +54,36 @@ std::string typestr(Type t) ...@@ -53,24 +54,36 @@ std::string typestr(Type t)
} }
} }
ProbeType probetype(const std::string &type) ProbeType probetype(const std::string &probeName)
{ {
for (int i = 0; i < sizeof(PROBE_LIST); i++) ProbeType retType = ProbeType::invalid;
{
if (type == PROBE_LIST[i].name || type == PROBE_LIST[i].abbr) auto v = std::find_if(PROBE_LIST.begin(), PROBE_LIST.end(),
return PROBE_LIST[i].type; [&probeName] (const ProbeItem& p) {
} return (p.name == probeName ||
abort(); p.abbr == probeName);
});
if (v != PROBE_LIST.end())
retType = v->type;
return retType;
} }
std::string probetypeName(const std::string &type) std::string probetypeName(const std::string &probeName)
{ {
for (int i = 0; i < sizeof(PROBE_LIST); i++) std::string res = probeName;
{
if (type == PROBE_LIST[i].name || type == PROBE_LIST[i].abbr) auto v = std::find_if(PROBE_LIST.begin(), PROBE_LIST.end(),
return PROBE_LIST[i].name; [&probeName] (const ProbeItem& p) {
} return (p.name == probeName ||
return type; p.abbr == probeName);
});
if (v != PROBE_LIST.end())
res = v->name;
return res;
} }
uint64_t asyncactionint(AsyncAction a) uint64_t asyncactionint(AsyncAction a)
......
...@@ -79,7 +79,7 @@ struct ProbeItem ...@@ -79,7 +79,7 @@ struct ProbeItem
ProbeType type; ProbeType type;
}; };
const ProbeItem PROBE_LIST[] = const std::vector<ProbeItem> PROBE_LIST =
{ {
{ "kprobe", "k", ProbeType::kprobe }, { "kprobe", "k", ProbeType::kprobe },
{ "kretprobe", "kr", ProbeType::kretprobe }, { "kretprobe", "kr", ProbeType::kretprobe },
......
...@@ -417,6 +417,17 @@ TEST(bpftrace, add_probes_hardware) ...@@ -417,6 +417,17 @@ TEST(bpftrace, add_probes_hardware)
check_hardware(bpftrace.get_probes().at(0), "cache-references", 1000000, probe_orig_name); check_hardware(bpftrace.get_probes().at(0), "cache-references", 1000000, probe_orig_name);
} }
TEST(bpftrace, invalid_provider)
{
ast::AttachPoint a("lookatme", "invalid");
ast::AttachPointList attach_points = { &a };
ast::Probe probe(&attach_points, nullptr, nullptr);
StrictMock<MockBPFtrace> bpftrace;
EXPECT_EQ(0, bpftrace.add_probe(probe));
}
std::pair<std::vector<uint8_t>, std::vector<uint8_t>> key_value_pair_int(std::vector<uint64_t> key, int val) std::pair<std::vector<uint8_t>, std::vector<uint8_t>> key_value_pair_int(std::vector<uint64_t> key, int val)
{ {
std::pair<std::vector<uint8_t>, std::vector<uint8_t>> pair; std::pair<std::vector<uint8_t>, std::vector<uint8_t>> pair;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment