Commit 36d75e06 authored by Alastair Robertson's avatar Alastair Robertson

Add sym and usym builtins

parent 8bae57b9
......@@ -194,8 +194,10 @@ Variables:
- `func` - Name of the function currently being traced
Functions:
- `quantize(int n)` - produce a log2 histogram of values of `n`
- `count()` - count the number of times this function is called
- `delete()` - delete the map element this is assigned to
- `str(char *s)` - returns the string pointed to by `s`
- `printf(char *fmt, ...)` - write to stdout
- `quantize(int n)` - Produce a log2 histogram of values of `n`
- `count()` - Count the number of times this function is called
- `delete()` - Delete the map element this is assigned to
- `str(char *s)` - Returns the string pointed to by `s`
- `printf(char *fmt, ...)` - Write to stdout
- `sym(void *p)` - Resolve kernel address
- `usym(void *p)` - Resolve user space address (incomplete)
......@@ -160,6 +160,10 @@ void CodegenLLVM::visit(Call &call)
b_.CreateProbeReadStr(buf, call.type.size, expr_);
expr_ = buf;
}
else if (call.func == "sym" || call.func == "usym")
{
call.vargs->front()->accept(*this);
}
else if (call.func == "printf")
{
ArrayType *string_type = ArrayType::get(b_.getInt8Ty(), STRING_SIZE);
......
......@@ -119,16 +119,22 @@ void SemanticAnalyser::visit(Call &call)
}
call.type = SizedType(Type::del, 0);
}
else if (call.func == "str") {
else if (call.func == "str" || call.func == "sym" || call.func == "usym") {
if (nargs != 1) {
err_ << "str() should take 1 arguments (";
err_ << call.func << "() should take 1 arguments (";
err_ << nargs << " provided)" << std::endl;
}
if (is_final_pass() && call.vargs->at(0)->type.type != Type::integer) {
err_ << "str() only supports integer arguments";
err_ << call.func << "() only supports integer arguments";
err_ << " (" << call.vargs->at(0)->type.type << " provided)" << std::endl;
}
call.type = SizedType(Type::string, STRING_SIZE);
if (call.func == "str")
call.type = SizedType(Type::string, STRING_SIZE);
else if (call.func == "sym")
call.type = SizedType(Type::sym, 8);
else if (call.func == "usym")
call.type = SizedType(Type::usym, 8);
}
else if (call.func == "printf") {
if (call.map) {
......
......@@ -101,6 +101,23 @@ TEST(semantic_analyser, call_str)
test("kprobe:f { str(arg0); }", 0);
test("kprobe:f { @x = str(arg0); }", 0);
test("kprobe:f { str(); }", 1);
test("kprobe:f { str(\"hello\"); }", 10);
}
TEST(semantic_analyser, call_sym)
{
test("kprobe:f { sym(arg0); }", 0);
test("kprobe:f { @x = sym(arg0); }", 0);
test("kprobe:f { sym(); }", 1);
test("kprobe:f { sym(\"hello\"); }", 10);
}
TEST(semantic_analyser, call_usym)
{
test("kprobe:f { usym(arg0); }", 0);
test("kprobe:f { @x = usym(arg0); }", 0);
test("kprobe:f { usym(); }", 1);
test("kprobe:f { usym(\"hello\"); }", 10);
}
TEST(semantic_analyser, map_reassignment)
......
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