Commit 17117141 authored by Alastair Robertson's avatar Alastair Robertson

Add retval builtin

parent fb4c1733
......@@ -61,6 +61,7 @@ Variables:
- `nsecs` - Nanosecond timestamp
- `stack` - Kernel stack trace
- `arg0`, `arg1`, ... etc. - Arguments to the function being traced
- `retval` - Return value from function being traced
Functions:
- `quantize(int n)` - produce a log2 histogram of values of `n`
......
......@@ -62,6 +62,14 @@ void CodegenLLVM::visit(Builtin &builtin)
b_.CreateProbeRead(dst, b_.getInt64(8), src);
expr_ = b_.CreateLoad(dst);
}
else if (builtin.ident == "retval")
{
AllocaInst *dst = b_.CreateAllocaBPF();
int offset = arch::ret_offset() * sizeof(uintptr_t);
Value *src = b_.CreateGEP(ctx_, b_.getInt64(offset));
b_.CreateProbeRead(dst, b_.getInt64(8), src);
expr_ = b_.CreateLoad(dst);
}
else
{
abort();
......
......@@ -19,7 +19,8 @@ void SemanticAnalyser::visit(Builtin &builtin)
builtin.ident == "pid" ||
builtin.ident == "tid" ||
builtin.ident == "uid" ||
builtin.ident == "gid") {
builtin.ident == "gid" ||
builtin.ident == "retval") {
type_ = Type::integer;
}
else if (builtin.ident == "stack")
......
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