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
21eb3db3
Commit
21eb3db3
authored
Jul 02, 2017
by
Alastair Robertson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add names to most LLVM Allocas and Calls to make debugging easier
parent
a48fce1c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
24 deletions
+24
-24
src/codegen_llvm.cpp
src/codegen_llvm.cpp
+10
-10
src/irbuilderbpf.cpp
src/irbuilderbpf.cpp
+13
-13
src/irbuilderbpf.h
src/irbuilderbpf.h
+1
-1
No files found.
src/codegen_llvm.cpp
View file @
21eb3db3
...
...
@@ -56,7 +56,7 @@ void CodegenLLVM::visit(Builtin &builtin)
{
int
arg_num
=
atoi
(
builtin
.
ident
.
substr
(
3
).
c_str
());
AllocaInst
*
dst
=
b_
.
CreateAllocaBPF
();
AllocaInst
*
dst
=
b_
.
CreateAllocaBPF
(
builtin
.
ident
);
int
offset
=
arch
::
arg_offset
(
arg_num
)
*
sizeof
(
uintptr_t
);
Value
*
src
=
b_
.
CreateGEP
(
ctx_
,
b_
.
getInt64
(
offset
));
b_
.
CreateProbeRead
(
dst
,
b_
.
getInt64
(
8
),
src
);
...
...
@@ -64,7 +64,7 @@ void CodegenLLVM::visit(Builtin &builtin)
}
else
if
(
builtin
.
ident
==
"retval"
)
{
AllocaInst
*
dst
=
b_
.
CreateAllocaBPF
();
AllocaInst
*
dst
=
b_
.
CreateAllocaBPF
(
builtin
.
ident
);
int
offset
=
arch
::
ret_offset
()
*
sizeof
(
uintptr_t
);
Value
*
src
=
b_
.
CreateGEP
(
ctx_
,
b_
.
getInt64
(
offset
));
b_
.
CreateProbeRead
(
dst
,
b_
.
getInt64
(
8
),
src
);
...
...
@@ -126,7 +126,7 @@ void CodegenLLVM::visit(Unop &unop)
case
bpftrace
:
:
Parser
::
token
::
BNOT
:
expr_
=
b_
.
CreateNeg
(
expr_
);
break
;
case
bpftrace
:
:
Parser
::
token
::
MUL
:
{
AllocaInst
*
dst
=
b_
.
CreateAllocaBPF
();
AllocaInst
*
dst
=
b_
.
CreateAllocaBPF
(
"deref"
);
b_
.
CreateProbeRead
(
dst
,
b_
.
getInt64
(
8
),
expr_
);
expr_
=
b_
.
CreateLoad
(
dst
);
break
;
...
...
@@ -144,7 +144,7 @@ void CodegenLLVM::visit(AssignMapStatement &assignment)
{
Map
&
map
=
*
assignment
.
map
;
AllocaInst
*
val
=
b_
.
CreateAllocaBPF
();
AllocaInst
*
val
=
b_
.
CreateAllocaBPF
(
map
.
ident
+
"_val"
);
assignment
.
expr
->
accept
(
*
this
);
b_
.
CreateStore
(
expr_
,
val
);
...
...
@@ -162,7 +162,7 @@ void CodegenLLVM::visit(AssignMapCallStatement &assignment)
{
AllocaInst
*
key
=
getMapKey
(
map
);
Value
*
oldval
=
b_
.
CreateMapLookupElem
(
map
,
key
);
AllocaInst
*
newval
=
b_
.
CreateAllocaBPF
();
AllocaInst
*
newval
=
b_
.
CreateAllocaBPF
(
map
.
ident
+
"_val"
);
b_
.
CreateStore
(
b_
.
CreateAdd
(
oldval
,
b_
.
getInt64
(
1
)),
newval
);
b_
.
CreateMapUpdateElem
(
map
,
key
,
newval
);
}
...
...
@@ -174,7 +174,7 @@ void CodegenLLVM::visit(AssignMapCallStatement &assignment)
AllocaInst
*
key
=
getQuantizeMapKey
(
map
,
log2
);
Value
*
oldval
=
b_
.
CreateMapLookupElem
(
map
,
key
);
AllocaInst
*
newval
=
b_
.
CreateAllocaBPF
();
AllocaInst
*
newval
=
b_
.
CreateAllocaBPF
(
map
.
ident
+
"_val"
);
b_
.
CreateStore
(
b_
.
CreateAdd
(
oldval
,
b_
.
getInt64
(
1
)),
newval
);
b_
.
CreateMapUpdateElem
(
map
,
key
,
newval
);
}
...
...
@@ -246,7 +246,7 @@ AllocaInst *CodegenLLVM::getMapKey(Map &map)
{
AllocaInst
*
key
;
if
(
map
.
vargs
)
{
key
=
b_
.
CreateAllocaBPF
(
map
.
vargs
->
size
());
key
=
b_
.
CreateAllocaBPF
(
map
.
ident
+
"_key"
,
map
.
vargs
->
size
());
int
i
=
0
;
for
(
Expression
*
expr
:
*
map
.
vargs
)
{
expr
->
accept
(
*
this
);
...
...
@@ -256,7 +256,7 @@ AllocaInst *CodegenLLVM::getMapKey(Map &map)
}
else
{
key
=
b_
.
CreateAllocaBPF
();
key
=
b_
.
CreateAllocaBPF
(
map
.
ident
+
"_key"
);
b_
.
CreateStore
(
b_
.
getInt64
(
0
),
key
);
}
return
key
;
...
...
@@ -266,7 +266,7 @@ AllocaInst *CodegenLLVM::getQuantizeMapKey(Map &map, Value *log2)
{
AllocaInst
*
key
;
if
(
map
.
vargs
)
{
key
=
b_
.
CreateAllocaBPF
(
map
.
vargs
->
size
()
+
1
);
key
=
b_
.
CreateAllocaBPF
(
map
.
ident
+
"_key"
,
map
.
vargs
->
size
()
+
1
);
int
i
=
0
;
for
(
Expression
*
expr
:
*
map
.
vargs
)
{
expr
->
accept
(
*
this
);
...
...
@@ -278,7 +278,7 @@ AllocaInst *CodegenLLVM::getQuantizeMapKey(Map &map, Value *log2)
}
else
{
key
=
b_
.
CreateAllocaBPF
();
key
=
b_
.
CreateAllocaBPF
(
map
.
ident
+
"_key"
);
b_
.
CreateStore
(
log2
,
key
);
}
return
key
;
...
...
src/irbuilderbpf.cpp
View file @
21eb3db3
...
...
@@ -25,22 +25,22 @@ IRBuilderBPF::IRBuilderBPF(LLVMContext &context,
&
module_
);
}
AllocaInst
*
IRBuilderBPF
::
CreateAllocaBPF
(
int
num_items
,
const
std
::
string
&
name
)
AllocaInst
*
IRBuilderBPF
::
CreateAllocaBPF
(
const
std
::
string
&
name
,
int
num_items
)
{
llvm
::
Type
*
ty
=
getInt64Ty
();
Value
*
array_size
=
getInt64
(
num_items
);
Function
*
parent
=
GetInsertBlock
()
->
getParent
();
BasicBlock
&
entry_block
=
parent
->
getEntryBlock
();
if
(
entry_block
.
empty
())
return
new
AllocaInst
(
ty
,
array_size
,
""
,
&
entry_block
);
return
new
AllocaInst
(
ty
,
array_size
,
name
,
&
entry_block
);
else
return
new
AllocaInst
(
ty
,
array_size
,
""
,
&
entry_block
.
front
());
return
new
AllocaInst
(
ty
,
array_size
,
name
,
&
entry_block
.
front
());
}
CallInst
*
IRBuilderBPF
::
CreateBpfPseudoCall
(
int
mapfd
)
{
Function
*
pseudo_func
=
module_
.
getFunction
(
"llvm.bpf.pseudo"
);
return
CreateCall
(
pseudo_func
,
{
getInt64
(
BPF_PSEUDO_MAP_FD
),
getInt64
(
mapfd
)});
return
CreateCall
(
pseudo_func
,
{
getInt64
(
BPF_PSEUDO_MAP_FD
),
getInt64
(
mapfd
)}
,
"pseudo"
);
}
CallInst
*
IRBuilderBPF
::
CreateBpfPseudoCall
(
Map
&
map
)
...
...
@@ -64,7 +64,7 @@ LoadInst *IRBuilderBPF::CreateMapLookupElem(Map &map, AllocaInst *key)
Instruction
::
IntToPtr
,
getInt64
(
BPF_FUNC_map_lookup_elem
),
lookup_func_ptr_type
);
CallInst
*
call
=
CreateCall
(
lookup_func
,
{
map_ptr
,
key
});
CallInst
*
call
=
CreateCall
(
lookup_func
,
{
map_ptr
,
key
}
,
"lookup_elem"
);
// Check if result == 0
Function
*
parent
=
GetInsertBlock
()
->
getParent
();
...
...
@@ -72,7 +72,7 @@ LoadInst *IRBuilderBPF::CreateMapLookupElem(Map &map, AllocaInst *key)
BasicBlock
*
lookup_failure_block
=
BasicBlock
::
Create
(
module_
.
getContext
(),
"lookup_failure"
,
parent
);
BasicBlock
*
lookup_merge_block
=
BasicBlock
::
Create
(
module_
.
getContext
(),
"lookup_merge"
,
parent
);
Value
*
value
=
CreateAllocaBPF
();
Value
*
value
=
CreateAllocaBPF
(
"lookup_elem_val"
);
Value
*
condition
=
CreateICmpNE
(
CreateIntCast
(
call
,
getInt8PtrTy
(),
true
),
ConstantExpr
::
getCast
(
Instruction
::
IntToPtr
,
getInt64
(
0
),
getInt8PtrTy
()),
...
...
@@ -105,7 +105,7 @@ void IRBuilderBPF::CreateMapUpdateElem(Map &map, AllocaInst *key, Value *val)
Instruction
::
IntToPtr
,
getInt64
(
BPF_FUNC_map_update_elem
),
update_func_ptr_type
);
CallInst
*
call
=
CreateCall
(
update_func
,
{
map_ptr
,
key
,
val
,
flags
});
CallInst
*
call
=
CreateCall
(
update_func
,
{
map_ptr
,
key
,
val
,
flags
}
,
"update_elem"
);
}
void
IRBuilderBPF
::
CreateMapDeleteElem
(
Map
&
map
,
AllocaInst
*
key
)
...
...
@@ -124,7 +124,7 @@ void IRBuilderBPF::CreateMapDeleteElem(Map &map, AllocaInst *key)
Instruction
::
IntToPtr
,
getInt64
(
BPF_FUNC_map_delete_elem
),
delete_func_ptr_type
);
CallInst
*
call
=
CreateCall
(
delete_func
,
{
map_ptr
,
key
});
CallInst
*
call
=
CreateCall
(
delete_func
,
{
map_ptr
,
key
}
,
"delete_elem"
);
}
void
IRBuilderBPF
::
CreateProbeRead
(
AllocaInst
*
dst
,
Value
*
size
,
Value
*
src
)
...
...
@@ -140,7 +140,7 @@ void IRBuilderBPF::CreateProbeRead(AllocaInst *dst, Value *size, Value *src)
Instruction
::
IntToPtr
,
getInt64
(
BPF_FUNC_probe_read
),
proberead_func_ptr_type
);
CallInst
*
call
=
CreateCall
(
proberead_func
,
{
dst
,
size
,
src
});
CallInst
*
call
=
CreateCall
(
proberead_func
,
{
dst
,
size
,
src
}
,
"probe_read"
);
}
CallInst
*
IRBuilderBPF
::
CreateGetNs
()
...
...
@@ -153,7 +153,7 @@ CallInst *IRBuilderBPF::CreateGetNs()
Instruction
::
IntToPtr
,
getInt64
(
BPF_FUNC_ktime_get_ns
),
gettime_func_ptr_type
);
return
CreateCall
(
gettime_func
);
return
CreateCall
(
gettime_func
,
{},
"get_ns"
);
}
CallInst
*
IRBuilderBPF
::
CreateGetPidTgid
()
...
...
@@ -166,7 +166,7 @@ CallInst *IRBuilderBPF::CreateGetPidTgid()
Instruction
::
IntToPtr
,
getInt64
(
BPF_FUNC_get_current_pid_tgid
),
getpidtgid_func_ptr_type
);
return
CreateCall
(
getpidtgid_func
);
return
CreateCall
(
getpidtgid_func
,
{},
"get_pid_tgid"
);
}
CallInst
*
IRBuilderBPF
::
CreateGetUidGid
()
...
...
@@ -179,7 +179,7 @@ CallInst *IRBuilderBPF::CreateGetUidGid()
Instruction
::
IntToPtr
,
getInt64
(
BPF_FUNC_get_current_uid_gid
),
getuidgid_func_ptr_type
);
return
CreateCall
(
getuidgid_func
);
return
CreateCall
(
getuidgid_func
,
{},
"get_uid_gid"
);
}
CallInst
*
IRBuilderBPF
::
CreateGetStackId
(
Value
*
ctx
,
bool
ustack
)
...
...
@@ -202,7 +202,7 @@ CallInst *IRBuilderBPF::CreateGetStackId(Value *ctx, bool ustack)
Instruction
::
IntToPtr
,
getInt64
(
BPF_FUNC_get_stackid
),
getstackid_func_ptr_type
);
return
CreateCall
(
getstackid_func
,
{
ctx
,
map_ptr
,
flags_val
});
return
CreateCall
(
getstackid_func
,
{
ctx
,
map_ptr
,
flags_val
}
,
"get_stackid"
);
}
}
// namespace ast
...
...
src/irbuilderbpf.h
View file @
21eb3db3
...
...
@@ -17,7 +17,7 @@ public:
Module
&
module
,
BPFtrace
&
bpftrace
);
AllocaInst
*
CreateAllocaBPF
(
int
array_size
=
1
,
const
std
::
string
&
name
=
""
);
AllocaInst
*
CreateAllocaBPF
(
const
std
::
string
&
name
=
""
,
int
num_items
=
1
);
CallInst
*
CreateBpfPseudoCall
(
int
mapfd
);
CallInst
*
CreateBpfPseudoCall
(
Map
&
map
);
LoadInst
*
CreateMapLookupElem
(
Map
&
map
,
AllocaInst
*
key
);
...
...
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