Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bcc
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
bcc
Commits
d45a6ee8
Commit
d45a6ee8
authored
Oct 01, 2015
by
4ast
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #259 from iovisor/bblanco_dev
Don't treat fundamentally typed args as needing probe_read
parents
19a48d57
c48ab4b0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
5 deletions
+24
-5
src/cc/frontends/clang/b_frontend_action.cc
src/cc/frontends/clang/b_frontend_action.cc
+11
-5
tests/cc/test_clang.py
tests/cc/test_clang.py
+13
-0
No files found.
src/cc/frontends/clang/b_frontend_action.cc
View file @
d45a6ee8
...
...
@@ -97,11 +97,15 @@ bool BMapDeclVisitor::VisitBuiltinType(const BuiltinType *T) {
class
ProbeChecker
:
public
RecursiveASTVisitor
<
ProbeChecker
>
{
public:
explicit
ProbeChecker
(
Expr
*
arg
,
const
set
<
Decl
*>
&
ptregs
)
:
needs_probe_
(
false
),
ptregs_
(
ptregs
)
{
if
(
arg
)
:
needs_probe_
(
false
),
is_transitive_
(
false
),
ptregs_
(
ptregs
)
{
if
(
arg
)
{
TraverseStmt
(
arg
);
if
(
arg
->
getType
()
->
isPointerType
())
is_transitive_
=
needs_probe_
;
}
}
bool
VisitCallExpr
(
CallExpr
*
E
)
{
needs_probe_
=
false
;
return
false
;
}
bool
VisitDeclRefExpr
(
DeclRefExpr
*
E
)
{
...
...
@@ -110,8 +114,10 @@ class ProbeChecker : public RecursiveASTVisitor<ProbeChecker> {
return
true
;
}
bool
needs_probe
()
const
{
return
needs_probe_
;
}
bool
is_transitive
()
const
{
return
is_transitive_
;
}
private:
bool
needs_probe_
;
bool
is_transitive_
;
const
set
<
Decl
*>
&
ptregs_
;
};
...
...
@@ -131,7 +137,7 @@ ProbeVisitor::ProbeVisitor(Rewriter &rewriter) : rewriter_(rewriter) {}
bool
ProbeVisitor
::
VisitVarDecl
(
VarDecl
*
Decl
)
{
if
(
Expr
*
E
=
Decl
->
getInit
())
{
if
(
ProbeChecker
(
E
,
ptregs_
).
needs_prob
e
())
if
(
ProbeChecker
(
E
,
ptregs_
).
is_transitiv
e
())
set_ptreg
(
Decl
);
}
return
true
;
...
...
@@ -157,7 +163,7 @@ bool ProbeVisitor::VisitBinaryOperator(BinaryOperator *E) {
if
(
!
E
->
isAssignmentOp
())
return
true
;
// copy probe attribute from RHS to LHS if present
if
(
ProbeChecker
(
E
->
getRHS
(),
ptregs_
).
needs_prob
e
())
{
if
(
ProbeChecker
(
E
->
getRHS
(),
ptregs_
).
is_transitiv
e
())
{
ProbeSetter
setter
(
&
ptregs_
);
setter
.
TraverseStmt
(
E
->
getLHS
());
}
...
...
@@ -570,7 +576,7 @@ bool ProbeConsumer::HandleTopLevelDecl(DeclGroupRef Group) {
if
(
FunctionDecl
*
F
=
dyn_cast
<
FunctionDecl
>
(
D
))
{
if
(
F
->
isExternallyVisible
()
&&
F
->
hasBody
())
{
for
(
auto
arg
:
F
->
parameters
())
{
if
(
arg
!=
F
->
getParamDecl
(
0
))
if
(
arg
!=
F
->
getParamDecl
(
0
)
&&
!
arg
->
getType
()
->
isFundamentalType
()
)
visitor_
.
set_ptreg
(
arg
);
}
visitor_
.
TraverseDecl
(
D
);
...
...
tests/cc/test_clang.py
View file @
d45a6ee8
...
...
@@ -235,6 +235,19 @@ int kprobe__finish_task_switch(struct pt_regs *ctx, struct task_struct *prev) {
}
"""
)
def
test_probe_simple_assign
(
self
):
b
=
BPF
(
text
=
"""
#include <uapi/linux/ptrace.h>
#include <linux/gfp.h>
struct leaf { size_t size; };
BPF_HASH(simple_map, u32, struct leaf);
int kprobe____kmalloc(struct pt_regs *ctx, size_t size) {
u32 pid = bpf_get_current_pid_tgid();
struct leaf* leaf = simple_map.lookup(&pid);
if (leaf)
leaf->size += size;
return 0;
}"""
,
debug
=
4
)
if
__name__
==
"__main__"
:
main
()
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