Commit 38276a11 authored by williangaspar's avatar williangaspar
parent 51500dfb
......@@ -677,30 +677,33 @@ void SemanticAnalyser::visit(Predicate &pred)
void SemanticAnalyser::visit(AttachPoint &ap)
{
if (ap.provider == "kprobe" || ap.provider == "kretprobe") {
auto type = probetypeName(ap.provider);
type = type == "" ? ap.provider : type;
if (type == "kprobe" || type == "kretprobe") {
if (ap.target != "")
err_ << "kprobes should not have a target" << std::endl;
if (ap.func == "")
err_ << "kprobes should be attached to a function" << std::endl;
}
else if (ap.provider == "uprobe" || ap.provider == "uretprobe") {
else if (type == "uprobe" || type == "uretprobe") {
if (ap.target == "")
err_ << "uprobes should have a target" << std::endl;
if (ap.func == "")
err_ << "uprobes should be attached to a function" << std::endl;
}
else if (ap.provider == "usdt") {
else if (type == "usdt") {
if (ap.target == "" || ap.func == "")
err_ << "usdt probe must have a target" << std::endl;
struct stat s;
if (stat(ap.target.c_str(), &s) != 0)
err_ << "usdt target file " << ap.target << " does not exist" << std::endl;
}
else if (ap.provider == "tracepoint") {
else if (type == "tracepoint") {
if (ap.target == "" || ap.func == "")
err_ << "tracepoint probe must have a target" << std::endl;
}
else if (ap.provider == "profile") {
else if (type == "profile") {
if (ap.target == "")
err_ << "profile probe must have unit of time" << std::endl;
else if (ap.target != "hz" &&
......@@ -713,7 +716,7 @@ void SemanticAnalyser::visit(AttachPoint &ap)
else if (ap.freq <= 0)
err_ << "profile frequency should be a positive integer" << std::endl;
}
else if (ap.provider == "interval") {
else if (type == "interval") {
if (ap.target == "")
err_ << "interval probe must have unit of time" << std::endl;
else if (ap.target != "ms" &&
......@@ -722,7 +725,7 @@ void SemanticAnalyser::visit(AttachPoint &ap)
if (ap.func != "")
err_ << "interval probe must have an integer frequency" << std::endl;
}
else if (ap.provider == "software") {
else if (type == "software") {
if (ap.target == "")
err_ << "software probe must have a software event name" << std::endl;
else if (ap.target != "cpu-clock" && ap.target != "cpu" &&
......@@ -742,7 +745,7 @@ void SemanticAnalyser::visit(AttachPoint &ap)
else if (ap.freq < 0)
err_ << "software count should be a positive integer" << std::endl;
}
else if (ap.provider == "hardware") {
else if (type == "hardware") {
if (ap.target == "")
err_ << "hardware probe must have a hardware event name" << std::endl;
else if (ap.target != "cpu-cycles" && ap.target != "cycles" &&
......@@ -760,16 +763,16 @@ void SemanticAnalyser::visit(AttachPoint &ap)
else if (ap.freq < 0)
err_ << "hardware frequency should be a positive integer" << std::endl;
}
else if (ap.provider == "BEGIN" || ap.provider == "END") {
else if (type == "BEGIN" || type == "END") {
if (ap.target != "" || ap.func != "")
err_ << "BEGIN/END probes should not have a target" << std::endl;
if (is_final_pass()) {
if (ap.provider == "BEGIN") {
if (type == "BEGIN") {
if (has_begin_probe_)
err_ << "More than one BEGIN probe defined" << std::endl;
has_begin_probe_ = true;
}
if (ap.provider == "END") {
if (type == "END") {
if (has_end_probe_)
err_ << "More than one END probe defined" << std::endl;
has_end_probe_ = true;
......
......@@ -55,33 +55,24 @@ std::string typestr(Type t)
ProbeType probetype(const std::string &type)
{
if (type == "kprobe")
return ProbeType::kprobe;
else if (type == "kretprobe")
return ProbeType::kretprobe;
else if (type == "uprobe")
return ProbeType::uprobe;
else if (type == "uretprobe")
return ProbeType::uretprobe;
else if (type == "usdt")
return ProbeType::usdt;
else if (type == "BEGIN")
return ProbeType::uprobe;
else if (type == "END")
return ProbeType::uprobe;
else if (type == "tracepoint")
return ProbeType::tracepoint;
else if (type == "profile")
return ProbeType::profile;
else if (type == "interval")
return ProbeType::interval;
else if (type == "software")
return ProbeType::software;
else if (type == "hardware")
return ProbeType::hardware;
for (int i = 0; i < sizeof(PROBE_LIST); i++)
{
if (type == PROBE_LIST[i].name || type == PROBE_LIST[i].abbr)
return PROBE_LIST[i].type;
}
abort();
}
std::string probetypeName(const std::string &type)
{
for (int i = 0; i < sizeof(PROBE_LIST); i++)
{
if (type == PROBE_LIST[i].name || type == PROBE_LIST[i].abbr)
return PROBE_LIST[i].name;
}
return "";
}
uint64_t asyncactionint(AsyncAction a)
{
return (uint64_t)a;
......
......@@ -72,8 +72,32 @@ enum class ProbeType
hardware,
};
struct ProbeItem
{
std::string name;
std::string abbr;
ProbeType type;
};
const ProbeItem PROBE_LIST[] =
{
{ "kprobe", "k", ProbeType::kprobe },
{ "kretprobe", "kr", ProbeType::kretprobe },
{ "uprobe", "u", ProbeType::uprobe },
{ "uretprobe", "ur", ProbeType::uretprobe },
{ "usdt", "usdt", ProbeType::usdt },
{ "BEGIN", "BEGIN", ProbeType::uprobe },
{ "END", "END", ProbeType::uprobe },
{ "tracepoint", "t", ProbeType::tracepoint },
{ "profile", "p", ProbeType::profile },
{ "interval", "i", ProbeType::interval },
{ "software", "s", ProbeType::software },
{ "hardware", "h", ProbeType::hardware }
};
std::string typestr(Type t);
ProbeType probetype(const std::string &type);
std::string probetypeName(const std::string &type);
class Probe
{
......
......@@ -638,6 +638,19 @@ TEST(semantic_analyser, field_access_is_internal)
EXPECT_EQ(true, var_assignment2->var->type.is_internal);
}
TEST(semantic_analyser, probe_short_name)
{
test("t:a:b { args }", 0);
test("k:f { pid }", 0);
test("kr:f { pid }", 0);
test("u:path:f { 1 }", 0);
test("ur:path:f { 1 }", 0);
test("p:hz:997 { 1 }", 0);
test("h:cache-references:1000000 { 1 }", 0);
test("s:faults:1000 { 1 }", 0);
test("i:s:1 { 1 }", 0);
}
} // namespace semantic_analyser
} // namespace test
} // namespace bpftrace
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