Commit e5f2c42a authored by Alastair Robertson's avatar Alastair Robertson

Parser: Accept uprobe style probes

parent 41096840
......@@ -112,12 +112,13 @@ public:
class Probe : public Node {
public:
Probe(std::string &type, std::string &attach_point, StatementList *stmts)
: type(type), attach_point(attach_point), name(type+":"+attach_point), pred(nullptr), stmts(stmts) { }
Probe(std::string &type, std::string &attach_point, Predicate *pred, StatementList *stmts)
Probe(const std::string &type, const std::string &attach_point, Predicate *pred, StatementList *stmts)
: type(type), attach_point(attach_point), name(type+":"+attach_point), pred(pred), stmts(stmts) { }
Probe(const std::string &type, const std::string &path, const std::string &attach_point, Predicate *pred, StatementList *stmts)
: type(type), path(path), attach_point(attach_point), name(type+":"+path+":"+attach_point), pred(pred), stmts(stmts) { }
std::string type;
std::string path;
std::string attach_point;
std::string name;
Predicate *pred;
......
......@@ -22,6 +22,7 @@ int [0-9]+|0[xX][0-9a-fA-F]+
hspace [ \t]
vspace [\n\r]
space {hspace}|{vspace}
path :(\\.|[_\-\./a-zA-Z0-9])*:
%%
......@@ -34,6 +35,7 @@ space {hspace}|{vspace}
"//".*$ // Comments
{ident} { return Parser::make_IDENT(yytext, loc); }
{path} { return Parser::make_PATH(yytext, loc); }
{map} { return Parser::make_MAP(yytext, loc); }
{int} { return Parser::make_INT(strtoul(yytext, NULL, 0), loc); }
":" { return Parser::make_COLON(loc); }
......
......@@ -68,12 +68,14 @@ void yyerror(bpftrace::Driver &driver, const char *s);
;
%token <std::string> IDENT "identifier"
%token <std::string> PATH "path"
%token <std::string> MAP "map"
%token <int> INT "integer"
%type <ast::ProbeList *> probes
%type <ast::StatementList *> block stmts
%type <ast::Probe *> probe
%type <ast::Predicate *> pred
%type <ast::Statement *> stmt
%type <ast::Expression *> expr
%type <ast::Call *> call
......@@ -105,10 +107,13 @@ probes : probes probe { $$ = $1; $1->push_back($2); }
| probe { $$ = new ast::ProbeList; $$->push_back($1); }
;
probe : IDENT ":" IDENT block { $$ = new ast::Probe($1, $3, $4); }
| IDENT ":" IDENT DIV expr ENDPRED block { $$ = new ast::Probe($1, $3, new ast::Predicate($5), $7); }
probe : IDENT ":" IDENT pred block { $$ = new ast::Probe($1, $3, $4, $5); }
| IDENT PATH IDENT pred block { $$ = new ast::Probe($1, $2.substr(1, $2.size()-2), $3, $4, $5); }
;
pred : DIV expr ENDPRED { $$ = new ast::Predicate($2); }
| { $$ = nullptr; }
block : "{" stmts "}" { $$ = $2; }
| "{" stmts ";" "}" { $$ = $2; }
......
......@@ -105,7 +105,7 @@ void Printer::visit(Predicate &pred)
void Printer::visit(Probe &probe)
{
std::string indent(depth_, ' ');
out_ << indent << probe.type << ":" << probe.attach_point << std::endl;
out_ << indent << probe.name << std::endl;
++depth_;
if (probe.pred) {
......
......@@ -168,4 +168,12 @@ TEST(Parser, multiple_probes)
" int: 2\n");
}
TEST(Parser, uprobe)
{
test("uprobe:/my/program:func { 1; }",
"Program\n"
" uprobe:/my/program:func\n"
" int: 1\n");
}
} // 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