Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bpftrace
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
bpftrace
Commits
895ea46f
Commit
895ea46f
authored
Aug 29, 2018
by
Brendan Gregg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add curtask builtin
parent
8f2c6691
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
59 additions
and
1 deletion
+59
-1
README.md
README.md
+1
-0
src/ast/codegen_llvm.cpp
src/ast/codegen_llvm.cpp
+4
-0
src/ast/irbuilderbpf.cpp
src/ast/irbuilderbpf.cpp
+13
-0
src/ast/irbuilderbpf.h
src/ast/irbuilderbpf.h
+1
-0
src/ast/semantic_analyser.cpp
src/ast/semantic_analyser.cpp
+1
-0
src/lexer.l
src/lexer.l
+1
-1
tests/codegen.cpp
tests/codegen.cpp
+36
-0
tests/parser.cpp
tests/parser.cpp
+1
-0
tests/semantic_analyser.cpp
tests/semantic_analyser.cpp
+1
-0
No files found.
README.md
View file @
895ea46f
...
@@ -218,6 +218,7 @@ Variables:
...
@@ -218,6 +218,7 @@ Variables:
-
`arg0`
,
`arg1`
, ... etc. - Arguments to the function being traced
-
`arg0`
,
`arg1`
, ... etc. - Arguments to the function being traced
-
`retval`
- Return value from function being traced
-
`retval`
- Return value from function being traced
-
`func`
- Name of the function currently being traced
-
`func`
- Name of the function currently being traced
-
`curtask`
- Current task_struct as a u64.
Functions:
Functions:
-
`hist(int n)`
- Produce a log2 histogram of values of
`n`
-
`hist(int n)`
- Produce a log2 histogram of values of
`n`
...
...
src/ast/codegen_llvm.cpp
View file @
895ea46f
...
@@ -70,6 +70,10 @@ void CodegenLLVM::visit(Builtin &builtin)
...
@@ -70,6 +70,10 @@ void CodegenLLVM::visit(Builtin &builtin)
{
{
expr_
=
b_
.
CreateGetCpuId
();
expr_
=
b_
.
CreateGetCpuId
();
}
}
else
if
(
builtin
.
ident
==
"curtask"
)
{
expr_
=
b_
.
CreateGetCurrentTask
();
}
else
if
(
builtin
.
ident
==
"comm"
)
else
if
(
builtin
.
ident
==
"comm"
)
{
{
AllocaInst
*
buf
=
b_
.
CreateAllocaBPF
(
builtin
.
type
,
"comm"
);
AllocaInst
*
buf
=
b_
.
CreateAllocaBPF
(
builtin
.
type
,
"comm"
);
...
...
src/ast/irbuilderbpf.cpp
View file @
895ea46f
...
@@ -307,6 +307,19 @@ CallInst *IRBuilderBPF::CreateGetCpuId()
...
@@ -307,6 +307,19 @@ CallInst *IRBuilderBPF::CreateGetCpuId()
return
CreateCall
(
getcpuid_func
,
{},
"get_cpu_id"
);
return
CreateCall
(
getcpuid_func
,
{},
"get_cpu_id"
);
}
}
CallInst
*
IRBuilderBPF
::
CreateGetCurrentTask
()
{
// u64 bpf_get_current_task(void)
// Return: current task_struct
FunctionType
*
getcurtask_func_type
=
FunctionType
::
get
(
getInt64Ty
(),
false
);
PointerType
*
getcurtask_func_ptr_type
=
PointerType
::
get
(
getcurtask_func_type
,
0
);
Constant
*
getcurtask_func
=
ConstantExpr
::
getCast
(
Instruction
::
IntToPtr
,
getInt64
(
BPF_FUNC_get_current_task
),
getcurtask_func_ptr_type
);
return
CreateCall
(
getcurtask_func
,
{},
"get_cur_task"
);
}
CallInst
*
IRBuilderBPF
::
CreateGetStackId
(
Value
*
ctx
,
bool
ustack
)
CallInst
*
IRBuilderBPF
::
CreateGetStackId
(
Value
*
ctx
,
bool
ustack
)
{
{
Value
*
map_ptr
=
CreateBpfPseudoCall
(
bpftrace_
.
stackid_map_
->
mapfd_
);
Value
*
map_ptr
=
CreateBpfPseudoCall
(
bpftrace_
.
stackid_map_
->
mapfd_
);
...
...
src/ast/irbuilderbpf.h
View file @
895ea46f
...
@@ -36,6 +36,7 @@ public:
...
@@ -36,6 +36,7 @@ public:
CallInst
*
CreateGetPidTgid
();
CallInst
*
CreateGetPidTgid
();
CallInst
*
CreateGetUidGid
();
CallInst
*
CreateGetUidGid
();
CallInst
*
CreateGetCpuId
();
CallInst
*
CreateGetCpuId
();
CallInst
*
CreateGetCurrentTask
();
CallInst
*
CreateGetStackId
(
Value
*
ctx
,
bool
ustack
);
CallInst
*
CreateGetStackId
(
Value
*
ctx
,
bool
ustack
);
CallInst
*
CreateGetJoinMap
(
Value
*
ctx
);
CallInst
*
CreateGetJoinMap
(
Value
*
ctx
);
void
CreateGetCurrentComm
(
AllocaInst
*
buf
,
size_t
size
);
void
CreateGetCurrentComm
(
AllocaInst
*
buf
,
size_t
size
);
...
...
src/ast/semantic_analyser.cpp
View file @
895ea46f
...
@@ -32,6 +32,7 @@ void SemanticAnalyser::visit(Builtin &builtin)
...
@@ -32,6 +32,7 @@ void SemanticAnalyser::visit(Builtin &builtin)
builtin
.
ident
==
"uid"
||
builtin
.
ident
==
"uid"
||
builtin
.
ident
==
"gid"
||
builtin
.
ident
==
"gid"
||
builtin
.
ident
==
"cpu"
||
builtin
.
ident
==
"cpu"
||
builtin
.
ident
==
"curtask"
||
builtin
.
ident
==
"retval"
)
{
builtin
.
ident
==
"retval"
)
{
builtin
.
type
=
SizedType
(
Type
::
integer
,
8
);
builtin
.
type
=
SizedType
(
Type
::
integer
,
8
);
}
}
...
...
src/lexer.l
View file @
895ea46f
...
@@ -45,7 +45,7 @@ header <(\\.|[_\-\./a-zA-Z0-9])*>
...
@@ -45,7 +45,7 @@ header <(\\.|[_\-\./a-zA-Z0-9])*>
<COMMENT>"EOF" driver.error(loc, std::string("end of file during comment"));
<COMMENT>"EOF" driver.error(loc, std::string("end of file during comment"));
<COMMENT>.|"\n" ;
<COMMENT>.|"\n" ;
pid|tid|uid|gid|nsecs|cpu|comm|stack|ustack|arg[0-9]|retval|func|name {
pid|tid|uid|gid|nsecs|cpu|comm|stack|ustack|arg[0-9]|retval|func|name
|curtask
{
return Parser::make_BUILTIN(yytext, loc); }
return Parser::make_BUILTIN(yytext, loc); }
{ident} { return Parser::make_IDENT(yytext, loc); }
{ident} { return Parser::make_IDENT(yytext, loc); }
{path} { return Parser::make_PATH(yytext, loc); }
{path} { return Parser::make_PATH(yytext, loc); }
...
...
tests/codegen.cpp
View file @
895ea46f
...
@@ -489,6 +489,42 @@ attributes #1 = { argmemonly nounwind }
...
@@ -489,6 +489,42 @@ attributes #1 = { argmemonly nounwind }
)EXPECTED"
);
)EXPECTED"
);
}
}
TEST
(
codegen
,
builtin_curtask
)
{
test
(
"kprobe:f { @x = curtask }"
,
R"EXPECTED(; Function Attrs: nounwind
declare i64 @llvm.bpf.pseudo(i64, i64) #0
; Function Attrs: argmemonly nounwind
declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #1
define i64 @"kprobe:f"(i8* nocapture readnone) local_unnamed_addr section "s_kprobe:f" {
entry:
%"@x_val" = alloca i64, align 8
%"@x_key" = alloca i64, align 8
%get_cur_task = tail call i64 inttoptr (i64 35 to i64 ()*)()
%1 = bitcast i64* %"@x_key" to i8*
call void @llvm.lifetime.start.p0i8(i64 -1, i8* nonnull %1)
store i64 0, i64* %"@x_key", align 8
%2 = bitcast i64* %"@x_val" to i8*
call void @llvm.lifetime.start.p0i8(i64 -1, i8* nonnull %2)
store i64 %get_cur_task, i64* %"@x_val", align 8
%pseudo = tail call i64 @llvm.bpf.pseudo(i64 1, i64 1)
%update_elem = call i64 inttoptr (i64 2 to i64 (i8*, i8*, i8*, i64)*)(i64 %pseudo, i64* nonnull %"@x_key", i64* nonnull %"@x_val", i64 0)
call void @llvm.lifetime.end.p0i8(i64 -1, i8* nonnull %1)
call void @llvm.lifetime.end.p0i8(i64 -1, i8* nonnull %2)
ret i64 0
}
; Function Attrs: argmemonly nounwind
declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #1
attributes #0 = { nounwind }
attributes #1 = { argmemonly nounwind }
)EXPECTED"
);
}
TEST
(
codegen
,
builtin_comm
)
TEST
(
codegen
,
builtin_comm
)
{
{
test
(
"kprobe:f { @x = comm }"
,
test
(
"kprobe:f { @x = comm }"
,
...
...
tests/parser.cpp
View file @
895ea46f
...
@@ -29,6 +29,7 @@ TEST(Parser, builtin_variables)
...
@@ -29,6 +29,7 @@ TEST(Parser, builtin_variables)
test
(
"kprobe:f { gid }"
,
"Program
\n
kprobe:f
\n
builtin: gid
\n
"
);
test
(
"kprobe:f { gid }"
,
"Program
\n
kprobe:f
\n
builtin: gid
\n
"
);
test
(
"kprobe:f { nsecs }"
,
"Program
\n
kprobe:f
\n
builtin: nsecs
\n
"
);
test
(
"kprobe:f { nsecs }"
,
"Program
\n
kprobe:f
\n
builtin: nsecs
\n
"
);
test
(
"kprobe:f { cpu }"
,
"Program
\n
kprobe:f
\n
builtin: cpu
\n
"
);
test
(
"kprobe:f { cpu }"
,
"Program
\n
kprobe:f
\n
builtin: cpu
\n
"
);
test
(
"kprobe:f { curtask }"
,
"Program
\n
kprobe:f
\n
builtin: curtask
\n
"
);
test
(
"kprobe:f { comm }"
,
"Program
\n
kprobe:f
\n
builtin: comm
\n
"
);
test
(
"kprobe:f { comm }"
,
"Program
\n
kprobe:f
\n
builtin: comm
\n
"
);
test
(
"kprobe:f { stack }"
,
"Program
\n
kprobe:f
\n
builtin: stack
\n
"
);
test
(
"kprobe:f { stack }"
,
"Program
\n
kprobe:f
\n
builtin: stack
\n
"
);
test
(
"kprobe:f { ustack }"
,
"Program
\n
kprobe:f
\n
builtin: ustack
\n
"
);
test
(
"kprobe:f { ustack }"
,
"Program
\n
kprobe:f
\n
builtin: ustack
\n
"
);
...
...
tests/semantic_analyser.cpp
View file @
895ea46f
...
@@ -67,6 +67,7 @@ TEST(semantic_analyser, builtin_variables)
...
@@ -67,6 +67,7 @@ TEST(semantic_analyser, builtin_variables)
test
(
"kprobe:f { gid }"
,
0
);
test
(
"kprobe:f { gid }"
,
0
);
test
(
"kprobe:f { nsecs }"
,
0
);
test
(
"kprobe:f { nsecs }"
,
0
);
test
(
"kprobe:f { cpu }"
,
0
);
test
(
"kprobe:f { cpu }"
,
0
);
test
(
"kprobe:f { curtask }"
,
0
);
test
(
"kprobe:f { comm }"
,
0
);
test
(
"kprobe:f { comm }"
,
0
);
test
(
"kprobe:f { stack }"
,
0
);
test
(
"kprobe:f { stack }"
,
0
);
test
(
"kprobe:f { ustack }"
,
0
);
test
(
"kprobe:f { ustack }"
,
0
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment